blob: bc7e2303cd4fec7a41713c6dc48da77161a74a1b [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. */
84#define GEN8_IRQ_INIT_NDX(type, which) do { \
85 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 Zanonia9d356a2014-04-01 15:37:09 -030094#define GEN5_IRQ_INIT(type) do { \
95 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
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +0100105static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300106ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800107{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200108 assert_spin_locked(&dev_priv->irq_lock);
109
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300110 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300111 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300112 dev_priv->pm.regsave.deimr &= ~mask;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300113 return;
114 }
115
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000116 if ((dev_priv->irq_mask & mask) != 0) {
117 dev_priv->irq_mask &= ~mask;
118 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000119 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800120 }
121}
122
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300123static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300124ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800125{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200126 assert_spin_locked(&dev_priv->irq_lock);
127
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300128 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300129 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300130 dev_priv->pm.regsave.deimr |= mask;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300131 return;
132 }
133
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000134 if ((dev_priv->irq_mask & mask) != mask) {
135 dev_priv->irq_mask |= mask;
136 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000137 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800138 }
139}
140
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300141/**
142 * ilk_update_gt_irq - update GTIMR
143 * @dev_priv: driver private
144 * @interrupt_mask: mask of interrupt bits to update
145 * @enabled_irq_mask: mask of interrupt bits to enable
146 */
147static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
148 uint32_t interrupt_mask,
149 uint32_t enabled_irq_mask)
150{
151 assert_spin_locked(&dev_priv->irq_lock);
152
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300153 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300154 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300155 dev_priv->pm.regsave.gtimr &= ~interrupt_mask;
156 dev_priv->pm.regsave.gtimr |= (~enabled_irq_mask &
Paulo Zanonic67a4702013-08-19 13:18:09 -0300157 interrupt_mask);
158 return;
159 }
160
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300161 dev_priv->gt_irq_mask &= ~interrupt_mask;
162 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
163 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
164 POSTING_READ(GTIMR);
165}
166
167void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
168{
169 ilk_update_gt_irq(dev_priv, mask, mask);
170}
171
172void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
173{
174 ilk_update_gt_irq(dev_priv, mask, 0);
175}
176
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300177/**
178 * snb_update_pm_irq - update GEN6_PMIMR
179 * @dev_priv: driver private
180 * @interrupt_mask: mask of interrupt bits to update
181 * @enabled_irq_mask: mask of interrupt bits to enable
182 */
183static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
184 uint32_t interrupt_mask,
185 uint32_t enabled_irq_mask)
186{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300187 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300188
189 assert_spin_locked(&dev_priv->irq_lock);
190
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300191 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300192 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300193 dev_priv->pm.regsave.gen6_pmimr &= ~interrupt_mask;
194 dev_priv->pm.regsave.gen6_pmimr |= (~enabled_irq_mask &
Paulo Zanonic67a4702013-08-19 13:18:09 -0300195 interrupt_mask);
196 return;
197 }
198
Paulo Zanoni605cd252013-08-06 18:57:15 -0300199 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300200 new_val &= ~interrupt_mask;
201 new_val |= (~enabled_irq_mask & interrupt_mask);
202
Paulo Zanoni605cd252013-08-06 18:57:15 -0300203 if (new_val != dev_priv->pm_irq_mask) {
204 dev_priv->pm_irq_mask = new_val;
205 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300206 POSTING_READ(GEN6_PMIMR);
207 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300208}
209
210void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
211{
212 snb_update_pm_irq(dev_priv, mask, mask);
213}
214
215void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
216{
217 snb_update_pm_irq(dev_priv, mask, 0);
218}
219
Paulo Zanoni86642812013-04-12 17:57:57 -0300220static bool ivb_can_enable_err_int(struct drm_device *dev)
221{
222 struct drm_i915_private *dev_priv = dev->dev_private;
223 struct intel_crtc *crtc;
224 enum pipe pipe;
225
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200226 assert_spin_locked(&dev_priv->irq_lock);
227
Paulo Zanoni86642812013-04-12 17:57:57 -0300228 for_each_pipe(pipe) {
229 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
230
231 if (crtc->cpu_fifo_underrun_disabled)
232 return false;
233 }
234
235 return true;
236}
237
238static bool cpt_can_enable_serr_int(struct drm_device *dev)
239{
240 struct drm_i915_private *dev_priv = dev->dev_private;
241 enum pipe pipe;
242 struct intel_crtc *crtc;
243
Daniel Vetterfee884e2013-07-04 23:35:21 +0200244 assert_spin_locked(&dev_priv->irq_lock);
245
Paulo Zanoni86642812013-04-12 17:57:57 -0300246 for_each_pipe(pipe) {
247 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
248
249 if (crtc->pch_fifo_underrun_disabled)
250 return false;
251 }
252
253 return true;
254}
255
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200256static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
257{
258 struct drm_i915_private *dev_priv = dev->dev_private;
259 u32 reg = PIPESTAT(pipe);
260 u32 pipestat = I915_READ(reg) & 0x7fff0000;
261
262 assert_spin_locked(&dev_priv->irq_lock);
263
264 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
265 POSTING_READ(reg);
266}
267
Paulo Zanoni86642812013-04-12 17:57:57 -0300268static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
269 enum pipe pipe, bool enable)
270{
271 struct drm_i915_private *dev_priv = dev->dev_private;
272 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
273 DE_PIPEB_FIFO_UNDERRUN;
274
275 if (enable)
276 ironlake_enable_display_irq(dev_priv, bit);
277 else
278 ironlake_disable_display_irq(dev_priv, bit);
279}
280
281static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200282 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300283{
284 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300285 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200286 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
287
Paulo Zanoni86642812013-04-12 17:57:57 -0300288 if (!ivb_can_enable_err_int(dev))
289 return;
290
Paulo Zanoni86642812013-04-12 17:57:57 -0300291 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
292 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200293 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
294
295 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300296 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200297
298 if (!was_enabled &&
299 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
300 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
301 pipe_name(pipe));
302 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300303 }
304}
305
Daniel Vetter38d83c962013-11-07 11:05:46 +0100306static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
307 enum pipe pipe, bool enable)
308{
309 struct drm_i915_private *dev_priv = dev->dev_private;
310
311 assert_spin_locked(&dev_priv->irq_lock);
312
313 if (enable)
314 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
315 else
316 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
317 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
318 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
319}
320
Daniel Vetterfee884e2013-07-04 23:35:21 +0200321/**
322 * ibx_display_interrupt_update - update SDEIMR
323 * @dev_priv: driver private
324 * @interrupt_mask: mask of interrupt bits to update
325 * @enabled_irq_mask: mask of interrupt bits to enable
326 */
327static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
328 uint32_t interrupt_mask,
329 uint32_t enabled_irq_mask)
330{
331 uint32_t sdeimr = I915_READ(SDEIMR);
332 sdeimr &= ~interrupt_mask;
333 sdeimr |= (~enabled_irq_mask & interrupt_mask);
334
335 assert_spin_locked(&dev_priv->irq_lock);
336
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300337 if (dev_priv->pm.irqs_disabled &&
Paulo Zanonic67a4702013-08-19 13:18:09 -0300338 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
339 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300340 dev_priv->pm.regsave.sdeimr &= ~interrupt_mask;
341 dev_priv->pm.regsave.sdeimr |= (~enabled_irq_mask &
Paulo Zanonic67a4702013-08-19 13:18:09 -0300342 interrupt_mask);
343 return;
344 }
345
Daniel Vetterfee884e2013-07-04 23:35:21 +0200346 I915_WRITE(SDEIMR, sdeimr);
347 POSTING_READ(SDEIMR);
348}
349#define ibx_enable_display_interrupt(dev_priv, bits) \
350 ibx_display_interrupt_update((dev_priv), (bits), (bits))
351#define ibx_disable_display_interrupt(dev_priv, bits) \
352 ibx_display_interrupt_update((dev_priv), (bits), 0)
353
Daniel Vetterde280752013-07-04 23:35:24 +0200354static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
355 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300356 bool enable)
357{
Paulo Zanoni86642812013-04-12 17:57:57 -0300358 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200359 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
360 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300361
362 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200363 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300364 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200365 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300366}
367
368static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
369 enum transcoder pch_transcoder,
370 bool enable)
371{
372 struct drm_i915_private *dev_priv = dev->dev_private;
373
374 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200375 I915_WRITE(SERR_INT,
376 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
377
Paulo Zanoni86642812013-04-12 17:57:57 -0300378 if (!cpt_can_enable_serr_int(dev))
379 return;
380
Daniel Vetterfee884e2013-07-04 23:35:21 +0200381 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300382 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200383 uint32_t tmp = I915_READ(SERR_INT);
384 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
385
386 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200387 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200388
389 if (!was_enabled &&
390 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
391 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
392 transcoder_name(pch_transcoder));
393 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300394 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300395}
396
397/**
398 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
399 * @dev: drm device
400 * @pipe: pipe
401 * @enable: true if we want to report FIFO underrun errors, false otherwise
402 *
403 * This function makes us disable or enable CPU fifo underruns for a specific
404 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
405 * reporting for one pipe may also disable all the other CPU error interruts for
406 * the other pipes, due to the fact that there's just one interrupt mask/enable
407 * bit for all the pipes.
408 *
409 * Returns the previous state of underrun reporting.
410 */
Imre Deakf88d42f2014-03-04 19:23:09 +0200411bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
412 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300413{
414 struct drm_i915_private *dev_priv = dev->dev_private;
415 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
416 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300417 bool ret;
418
Imre Deak77961eb2014-03-05 16:20:56 +0200419 assert_spin_locked(&dev_priv->irq_lock);
420
Paulo Zanoni86642812013-04-12 17:57:57 -0300421 ret = !intel_crtc->cpu_fifo_underrun_disabled;
422
423 if (enable == ret)
424 goto done;
425
426 intel_crtc->cpu_fifo_underrun_disabled = !enable;
427
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200428 if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
429 i9xx_clear_fifo_underrun(dev, pipe);
430 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300431 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
432 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200433 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100434 else if (IS_GEN8(dev))
435 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300436
437done:
Imre Deakf88d42f2014-03-04 19:23:09 +0200438 return ret;
439}
440
441bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
442 enum pipe pipe, bool enable)
443{
444 struct drm_i915_private *dev_priv = dev->dev_private;
445 unsigned long flags;
446 bool ret;
447
448 spin_lock_irqsave(&dev_priv->irq_lock, flags);
449 ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300450 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Imre Deakf88d42f2014-03-04 19:23:09 +0200451
Paulo Zanoni86642812013-04-12 17:57:57 -0300452 return ret;
453}
454
Imre Deak91d181d2014-02-10 18:42:49 +0200455static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
456 enum pipe pipe)
457{
458 struct drm_i915_private *dev_priv = dev->dev_private;
459 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
460 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
461
462 return !intel_crtc->cpu_fifo_underrun_disabled;
463}
464
Paulo Zanoni86642812013-04-12 17:57:57 -0300465/**
466 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
467 * @dev: drm device
468 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
469 * @enable: true if we want to report FIFO underrun errors, false otherwise
470 *
471 * This function makes us disable or enable PCH fifo underruns for a specific
472 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
473 * underrun reporting for one transcoder may also disable all the other PCH
474 * error interruts for the other transcoders, due to the fact that there's just
475 * one interrupt mask/enable bit for all the transcoders.
476 *
477 * Returns the previous state of underrun reporting.
478 */
479bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
480 enum transcoder pch_transcoder,
481 bool enable)
482{
483 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200484 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
485 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300486 unsigned long flags;
487 bool ret;
488
Daniel Vetterde280752013-07-04 23:35:24 +0200489 /*
490 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
491 * has only one pch transcoder A that all pipes can use. To avoid racy
492 * pch transcoder -> pipe lookups from interrupt code simply store the
493 * underrun statistics in crtc A. Since we never expose this anywhere
494 * nor use it outside of the fifo underrun code here using the "wrong"
495 * crtc on LPT won't cause issues.
496 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300497
498 spin_lock_irqsave(&dev_priv->irq_lock, flags);
499
500 ret = !intel_crtc->pch_fifo_underrun_disabled;
501
502 if (enable == ret)
503 goto done;
504
505 intel_crtc->pch_fifo_underrun_disabled = !enable;
506
507 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200508 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300509 else
510 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
511
512done:
513 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
514 return ret;
515}
516
517
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100518static void
Imre Deak755e9012014-02-10 18:42:47 +0200519__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
520 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800521{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200522 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200523 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800524
Daniel Vetterb79480b2013-06-27 17:52:10 +0200525 assert_spin_locked(&dev_priv->irq_lock);
526
Imre Deak755e9012014-02-10 18:42:47 +0200527 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
528 status_mask & ~PIPESTAT_INT_STATUS_MASK))
529 return;
530
531 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200532 return;
533
Imre Deak91d181d2014-02-10 18:42:49 +0200534 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
535
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200536 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200537 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200538 I915_WRITE(reg, pipestat);
539 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800540}
541
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100542static void
Imre Deak755e9012014-02-10 18:42:47 +0200543__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
544 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800545{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200546 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200547 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800548
Daniel Vetterb79480b2013-06-27 17:52:10 +0200549 assert_spin_locked(&dev_priv->irq_lock);
550
Imre Deak755e9012014-02-10 18:42:47 +0200551 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
552 status_mask & ~PIPESTAT_INT_STATUS_MASK))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200553 return;
554
Imre Deak755e9012014-02-10 18:42:47 +0200555 if ((pipestat & enable_mask) == 0)
556 return;
557
Imre Deak91d181d2014-02-10 18:42:49 +0200558 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
559
Imre Deak755e9012014-02-10 18:42:47 +0200560 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200561 I915_WRITE(reg, pipestat);
562 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800563}
564
Imre Deak10c59c52014-02-10 18:42:48 +0200565static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
566{
567 u32 enable_mask = status_mask << 16;
568
569 /*
570 * On pipe A we don't support the PSR interrupt yet, on pipe B the
571 * same bit MBZ.
572 */
573 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
574 return 0;
575
576 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
577 SPRITE0_FLIP_DONE_INT_EN_VLV |
578 SPRITE1_FLIP_DONE_INT_EN_VLV);
579 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
580 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
581 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
582 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
583
584 return enable_mask;
585}
586
Imre Deak755e9012014-02-10 18:42:47 +0200587void
588i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
589 u32 status_mask)
590{
591 u32 enable_mask;
592
Imre Deak10c59c52014-02-10 18:42:48 +0200593 if (IS_VALLEYVIEW(dev_priv->dev))
594 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
595 status_mask);
596 else
597 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200598 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
599}
600
601void
602i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
603 u32 status_mask)
604{
605 u32 enable_mask;
606
Imre Deak10c59c52014-02-10 18:42:48 +0200607 if (IS_VALLEYVIEW(dev_priv->dev))
608 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
609 status_mask);
610 else
611 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200612 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
613}
614
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000615/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300616 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000617 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300618static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000619{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300620 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000621 unsigned long irqflags;
622
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300623 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
624 return;
625
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000626 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000627
Imre Deak755e9012014-02-10 18:42:47 +0200628 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300629 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200630 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200631 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000632
633 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000634}
635
636/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700637 * i915_pipe_enabled - check if a pipe is enabled
638 * @dev: DRM device
639 * @pipe: pipe to check
640 *
641 * Reading certain registers when the pipe is disabled can hang the chip.
642 * Use this routine to make sure the PLL is running and the pipe is active
643 * before reading such registers if unsure.
644 */
645static int
646i915_pipe_enabled(struct drm_device *dev, int pipe)
647{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300648 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200649
Daniel Vettera01025a2013-05-22 00:50:23 +0200650 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
651 /* Locking is horribly broken here, but whatever. */
652 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
653 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300654
Daniel Vettera01025a2013-05-22 00:50:23 +0200655 return intel_crtc->active;
656 } else {
657 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
658 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700659}
660
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300661static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
662{
663 /* Gen2 doesn't have a hardware frame counter */
664 return 0;
665}
666
Keith Packard42f52ef2008-10-18 19:39:29 -0700667/* Called from drm generic code, passed a 'crtc', which
668 * we use as a pipe index
669 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700670static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700671{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300672 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700673 unsigned long high_frame;
674 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300675 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700676
677 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800678 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800679 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700680 return 0;
681 }
682
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300683 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
684 struct intel_crtc *intel_crtc =
685 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
686 const struct drm_display_mode *mode =
687 &intel_crtc->config.adjusted_mode;
688
689 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
690 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100691 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300692 u32 htotal;
693
694 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
695 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
696
697 vbl_start *= htotal;
698 }
699
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800700 high_frame = PIPEFRAME(pipe);
701 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100702
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700703 /*
704 * High & low register fields aren't synchronized, so make sure
705 * we get a low value that's stable across two reads of the high
706 * register.
707 */
708 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100709 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300710 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100711 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700712 } while (high1 != high2);
713
Chris Wilson5eddb702010-09-11 13:48:45 +0100714 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300715 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100716 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300717
718 /*
719 * The frame counter increments at beginning of active.
720 * Cook up a vblank counter by also checking the pixel
721 * counter against vblank start.
722 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200723 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700724}
725
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700726static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800727{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300728 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800729 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800730
731 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800732 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800733 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800734 return 0;
735 }
736
737 return I915_READ(reg);
738}
739
Mario Kleinerad3543e2013-10-30 05:13:08 +0100740/* raw reads, only for fast reads of display block, no need for forcewake etc. */
741#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100742
Ville Syrjälä095163b2013-10-29 00:04:43 +0200743static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300744{
745 struct drm_i915_private *dev_priv = dev->dev_private;
746 uint32_t status;
Ville Syrjälä24302622014-03-11 12:58:46 +0200747 int reg;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300748
Ville Syrjälä24302622014-03-11 12:58:46 +0200749 if (INTEL_INFO(dev)->gen >= 8) {
750 status = GEN8_PIPE_VBLANK;
751 reg = GEN8_DE_PIPE_ISR(pipe);
752 } else if (INTEL_INFO(dev)->gen >= 7) {
753 status = DE_PIPE_VBLANK_IVB(pipe);
754 reg = DEISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300755 } else {
Ville Syrjälä24302622014-03-11 12:58:46 +0200756 status = DE_PIPE_VBLANK(pipe);
757 reg = DEISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300758 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100759
Ville Syrjälä24302622014-03-11 12:58:46 +0200760 return __raw_i915_read32(dev_priv, reg) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300761}
762
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700763static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200764 unsigned int flags, int *vpos, int *hpos,
765 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100766{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300767 struct drm_i915_private *dev_priv = dev->dev_private;
768 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
769 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
770 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300771 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100772 int vbl_start, vbl_end, htotal, vtotal;
773 bool in_vbl = true;
774 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100775 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100776
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300777 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100778 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800779 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100780 return 0;
781 }
782
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300783 htotal = mode->crtc_htotal;
784 vtotal = mode->crtc_vtotal;
785 vbl_start = mode->crtc_vblank_start;
786 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100787
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200788 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
789 vbl_start = DIV_ROUND_UP(vbl_start, 2);
790 vbl_end /= 2;
791 vtotal /= 2;
792 }
793
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300794 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
795
Mario Kleinerad3543e2013-10-30 05:13:08 +0100796 /*
797 * Lock uncore.lock, as we will do multiple timing critical raw
798 * register reads, potentially with preemption disabled, so the
799 * following code must not block on uncore.lock.
800 */
801 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
802
803 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
804
805 /* Get optional system timestamp before query. */
806 if (stime)
807 *stime = ktime_get();
808
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300809 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100810 /* No obvious pixelcount register. Only query vertical
811 * scanout position from Display scan line register.
812 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300813 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100814 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300815 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100816 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300817
Ville Syrjäläfcb81822014-03-11 12:58:45 +0200818 if (HAS_DDI(dev)) {
819 /*
820 * On HSW HDMI outputs there seems to be a 2 line
821 * difference, whereas eDP has the normal 1 line
822 * difference that earlier platforms have. External
823 * DP is unknown. For now just check for the 2 line
824 * difference case on all output types on HSW+.
825 *
826 * This might misinterpret the scanline counter being
827 * one line too far along on eDP, but that's less
828 * dangerous than the alternative since that would lead
829 * the vblank timestamp code astray when it sees a
830 * scanline count before vblank_start during a vblank
831 * interrupt.
832 */
833 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
834 if ((in_vbl && (position == vbl_start - 2 ||
835 position == vbl_start - 1)) ||
836 (!in_vbl && (position == vbl_end - 2 ||
837 position == vbl_end - 1)))
838 position = (position + 2) % vtotal;
839 } else if (HAS_PCH_SPLIT(dev)) {
Ville Syrjälä095163b2013-10-29 00:04:43 +0200840 /*
841 * The scanline counter increments at the leading edge
842 * of hsync, ie. it completely misses the active portion
843 * of the line. Fix up the counter at both edges of vblank
844 * to get a more accurate picture whether we're in vblank
845 * or not.
846 */
847 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
848 if ((in_vbl && position == vbl_start - 1) ||
849 (!in_vbl && position == vbl_end - 1))
850 position = (position + 1) % vtotal;
851 } else {
852 /*
853 * ISR vblank status bits don't work the way we'd want
854 * them to work on non-PCH platforms (for
855 * ilk_pipe_in_vblank_locked()), and there doesn't
856 * appear any other way to determine if we're currently
857 * in vblank.
858 *
859 * Instead let's assume that we're already in vblank if
860 * we got called from the vblank interrupt and the
861 * scanline counter value indicates that we're on the
862 * line just prior to vblank start. This should result
863 * in the correct answer, unless the vblank interrupt
864 * delivery really got delayed for almost exactly one
865 * full frame/field.
866 */
867 if (flags & DRM_CALLED_FROM_VBLIRQ &&
868 position == vbl_start - 1) {
869 position = (position + 1) % vtotal;
870
871 /* Signal this correction as "applied". */
872 ret |= 0x8;
873 }
874 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100875 } else {
876 /* Have access to pixelcount since start of frame.
877 * We can split this into vertical and horizontal
878 * scanout position.
879 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100880 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100881
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300882 /* convert to pixel counts */
883 vbl_start *= htotal;
884 vbl_end *= htotal;
885 vtotal *= htotal;
886 }
887
Mario Kleinerad3543e2013-10-30 05:13:08 +0100888 /* Get optional system timestamp after query. */
889 if (etime)
890 *etime = ktime_get();
891
892 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
893
894 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
895
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300896 in_vbl = position >= vbl_start && position < vbl_end;
897
898 /*
899 * While in vblank, position will be negative
900 * counting up towards 0 at vbl_end. And outside
901 * vblank, position will be positive counting
902 * up since vbl_end.
903 */
904 if (position >= vbl_start)
905 position -= vbl_end;
906 else
907 position += vtotal - vbl_end;
908
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300909 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300910 *vpos = position;
911 *hpos = 0;
912 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100913 *vpos = position / htotal;
914 *hpos = position - (*vpos * htotal);
915 }
916
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100917 /* In vblank? */
918 if (in_vbl)
919 ret |= DRM_SCANOUTPOS_INVBL;
920
921 return ret;
922}
923
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700924static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100925 int *max_error,
926 struct timeval *vblank_time,
927 unsigned flags)
928{
Chris Wilson4041b852011-01-22 10:07:56 +0000929 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100930
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700931 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000932 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100933 return -EINVAL;
934 }
935
936 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000937 crtc = intel_get_crtc_for_pipe(dev, pipe);
938 if (crtc == NULL) {
939 DRM_ERROR("Invalid crtc %d\n", pipe);
940 return -EINVAL;
941 }
942
943 if (!crtc->enabled) {
944 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
945 return -EBUSY;
946 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100947
948 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000949 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
950 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300951 crtc,
952 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100953}
954
Jani Nikula67c347f2013-09-17 14:26:34 +0300955static bool intel_hpd_irq_event(struct drm_device *dev,
956 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200957{
958 enum drm_connector_status old_status;
959
960 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
961 old_status = connector->status;
962
963 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300964 if (old_status == connector->status)
965 return false;
966
967 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200968 connector->base.id,
969 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300970 drm_get_connector_status_name(old_status),
971 drm_get_connector_status_name(connector->status));
972
973 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200974}
975
Jesse Barnes5ca58282009-03-31 14:11:15 -0700976/*
977 * Handle hotplug events outside the interrupt handler proper.
978 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200979#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
980
Jesse Barnes5ca58282009-03-31 14:11:15 -0700981static void i915_hotplug_work_func(struct work_struct *work)
982{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300983 struct drm_i915_private *dev_priv =
984 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700985 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700986 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200987 struct intel_connector *intel_connector;
988 struct intel_encoder *intel_encoder;
989 struct drm_connector *connector;
990 unsigned long irqflags;
991 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200992 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200993 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700994
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100995 /* HPD irq before everything is fully set up. */
996 if (!dev_priv->enable_hotplug_processing)
997 return;
998
Keith Packarda65e34c2011-07-25 10:04:56 -0700999 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -08001000 DRM_DEBUG_KMS("running encoder hotplug functions\n");
1001
Egbert Eichcd569ae2013-04-16 13:36:57 +02001002 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +02001003
1004 hpd_event_bits = dev_priv->hpd_event_bits;
1005 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +02001006 list_for_each_entry(connector, &mode_config->connector_list, head) {
1007 intel_connector = to_intel_connector(connector);
1008 intel_encoder = intel_connector->encoder;
1009 if (intel_encoder->hpd_pin > HPD_NONE &&
1010 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
1011 connector->polled == DRM_CONNECTOR_POLL_HPD) {
1012 DRM_INFO("HPD interrupt storm detected on connector %s: "
1013 "switching from hotplug detection to polling\n",
1014 drm_get_connector_name(connector));
1015 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1016 connector->polled = DRM_CONNECTOR_POLL_CONNECT
1017 | DRM_CONNECTOR_POLL_DISCONNECT;
1018 hpd_disabled = true;
1019 }
Egbert Eich142e2392013-04-11 15:57:57 +02001020 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1021 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
1022 drm_get_connector_name(connector), intel_encoder->hpd_pin);
1023 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001024 }
1025 /* if there were no outputs to poll, poll was disabled,
1026 * therefore make sure it's enabled when disabling HPD on
1027 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001028 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +02001029 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02001030 mod_timer(&dev_priv->hotplug_reenable_timer,
1031 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
1032 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001033
1034 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1035
Egbert Eich321a1b32013-04-11 16:00:26 +02001036 list_for_each_entry(connector, &mode_config->connector_list, head) {
1037 intel_connector = to_intel_connector(connector);
1038 intel_encoder = intel_connector->encoder;
1039 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1040 if (intel_encoder->hot_plug)
1041 intel_encoder->hot_plug(intel_encoder);
1042 if (intel_hpd_irq_event(dev, connector))
1043 changed = true;
1044 }
1045 }
Keith Packard40ee3382011-07-28 15:31:19 -07001046 mutex_unlock(&mode_config->mutex);
1047
Egbert Eich321a1b32013-04-11 16:00:26 +02001048 if (changed)
1049 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001050}
1051
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02001052static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
1053{
1054 del_timer_sync(&dev_priv->hotplug_reenable_timer);
1055}
1056
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001057static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001058{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001059 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001060 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001061 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001062
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001063 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001064
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001065 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1066
Daniel Vetter20e4d402012-08-08 23:35:39 +02001067 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001068
Jesse Barnes7648fa92010-05-20 14:28:11 -07001069 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001070 busy_up = I915_READ(RCPREVBSYTUPAVG);
1071 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001072 max_avg = I915_READ(RCBMAXAVG);
1073 min_avg = I915_READ(RCBMINAVG);
1074
1075 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001076 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001077 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1078 new_delay = dev_priv->ips.cur_delay - 1;
1079 if (new_delay < dev_priv->ips.max_delay)
1080 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001081 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001082 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1083 new_delay = dev_priv->ips.cur_delay + 1;
1084 if (new_delay > dev_priv->ips.min_delay)
1085 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001086 }
1087
Jesse Barnes7648fa92010-05-20 14:28:11 -07001088 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001089 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001090
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001091 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001092
Jesse Barnesf97108d2010-01-29 11:27:07 -08001093 return;
1094}
1095
Chris Wilson549f7362010-10-19 11:19:32 +01001096static void notify_ring(struct drm_device *dev,
1097 struct intel_ring_buffer *ring)
1098{
Chris Wilson475553d2011-01-20 09:52:56 +00001099 if (ring->obj == NULL)
1100 return;
1101
Chris Wilson814e9b52013-09-23 17:33:19 -03001102 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001103
Chris Wilson549f7362010-10-19 11:19:32 +01001104 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001105 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001106}
1107
Ben Widawsky4912d042011-04-25 11:25:20 -07001108static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001109{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001110 struct drm_i915_private *dev_priv =
1111 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001112 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001113 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001114
Daniel Vetter59cdb632013-07-04 23:35:28 +02001115 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001116 pm_iir = dev_priv->rps.pm_iir;
1117 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -07001118 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Deepak Sa6706b42014-03-15 20:23:22 +05301119 snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001120 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001121
Paulo Zanoni60611c12013-08-15 11:50:01 -03001122 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301123 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001124
Deepak Sa6706b42014-03-15 20:23:22 +05301125 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001126 return;
1127
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001128 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001129
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001130 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001131 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001132 if (adj > 0)
1133 adj *= 2;
1134 else
1135 adj = 1;
Ben Widawskyb39fb292014-03-19 18:31:11 -07001136 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001137
1138 /*
1139 * For better performance, jump directly
1140 * to RPe if we're below it.
1141 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001142 if (new_delay < dev_priv->rps.efficient_freq)
1143 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001144 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001145 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1146 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001147 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001148 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001149 adj = 0;
1150 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1151 if (adj < 0)
1152 adj *= 2;
1153 else
1154 adj = -1;
Ben Widawskyb39fb292014-03-19 18:31:11 -07001155 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001156 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001157 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001158 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001159
Ben Widawsky79249632012-09-07 19:43:42 -07001160 /* sysfs frequency interfaces may have snuck in while servicing the
1161 * interrupt
1162 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001163 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001164 dev_priv->rps.min_freq_softlimit,
1165 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301166
Ben Widawskyb39fb292014-03-19 18:31:11 -07001167 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001168
1169 if (IS_VALLEYVIEW(dev_priv->dev))
1170 valleyview_set_rps(dev_priv->dev, new_delay);
1171 else
1172 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001173
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001174 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001175}
1176
Ben Widawskye3689192012-05-25 16:56:22 -07001177
1178/**
1179 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1180 * occurred.
1181 * @work: workqueue struct
1182 *
1183 * Doesn't actually do anything except notify userspace. As a consequence of
1184 * this event, userspace should try to remap the bad rows since statistically
1185 * it is likely the same row is more likely to go bad again.
1186 */
1187static void ivybridge_parity_work(struct work_struct *work)
1188{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001189 struct drm_i915_private *dev_priv =
1190 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001191 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001192 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001193 uint32_t misccpctl;
1194 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001195 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001196
1197 /* We must turn off DOP level clock gating to access the L3 registers.
1198 * In order to prevent a get/put style interface, acquire struct mutex
1199 * any time we access those registers.
1200 */
1201 mutex_lock(&dev_priv->dev->struct_mutex);
1202
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001203 /* If we've screwed up tracking, just let the interrupt fire again */
1204 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1205 goto out;
1206
Ben Widawskye3689192012-05-25 16:56:22 -07001207 misccpctl = I915_READ(GEN7_MISCCPCTL);
1208 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1209 POSTING_READ(GEN7_MISCCPCTL);
1210
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001211 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1212 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001213
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001214 slice--;
1215 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1216 break;
1217
1218 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1219
1220 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1221
1222 error_status = I915_READ(reg);
1223 row = GEN7_PARITY_ERROR_ROW(error_status);
1224 bank = GEN7_PARITY_ERROR_BANK(error_status);
1225 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1226
1227 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1228 POSTING_READ(reg);
1229
1230 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1231 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1232 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1233 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1234 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1235 parity_event[5] = NULL;
1236
Dave Airlie5bdebb12013-10-11 14:07:25 +10001237 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001238 KOBJ_CHANGE, parity_event);
1239
1240 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1241 slice, row, bank, subbank);
1242
1243 kfree(parity_event[4]);
1244 kfree(parity_event[3]);
1245 kfree(parity_event[2]);
1246 kfree(parity_event[1]);
1247 }
Ben Widawskye3689192012-05-25 16:56:22 -07001248
1249 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1250
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001251out:
1252 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001253 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001254 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001255 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1256
1257 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001258}
1259
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001260static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001261{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001262 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001263
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001264 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001265 return;
1266
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001267 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001268 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001269 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001270
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001271 iir &= GT_PARITY_ERROR(dev);
1272 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1273 dev_priv->l3_parity.which_slice |= 1 << 1;
1274
1275 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1276 dev_priv->l3_parity.which_slice |= 1 << 0;
1277
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001278 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001279}
1280
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001281static void ilk_gt_irq_handler(struct drm_device *dev,
1282 struct drm_i915_private *dev_priv,
1283 u32 gt_iir)
1284{
1285 if (gt_iir &
1286 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1287 notify_ring(dev, &dev_priv->ring[RCS]);
1288 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1289 notify_ring(dev, &dev_priv->ring[VCS]);
1290}
1291
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001292static void snb_gt_irq_handler(struct drm_device *dev,
1293 struct drm_i915_private *dev_priv,
1294 u32 gt_iir)
1295{
1296
Ben Widawskycc609d52013-05-28 19:22:29 -07001297 if (gt_iir &
1298 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001299 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001300 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001301 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001302 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001303 notify_ring(dev, &dev_priv->ring[BCS]);
1304
Ben Widawskycc609d52013-05-28 19:22:29 -07001305 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1306 GT_BSD_CS_ERROR_INTERRUPT |
1307 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001308 i915_handle_error(dev, false, "GT error interrupt 0x%08x",
1309 gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001310 }
Ben Widawskye3689192012-05-25 16:56:22 -07001311
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001312 if (gt_iir & GT_PARITY_ERROR(dev))
1313 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001314}
1315
Ben Widawskyabd58f02013-11-02 21:07:09 -07001316static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1317 struct drm_i915_private *dev_priv,
1318 u32 master_ctl)
1319{
1320 u32 rcs, bcs, vcs;
1321 uint32_t tmp = 0;
1322 irqreturn_t ret = IRQ_NONE;
1323
1324 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1325 tmp = I915_READ(GEN8_GT_IIR(0));
1326 if (tmp) {
1327 ret = IRQ_HANDLED;
1328 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1329 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1330 if (rcs & GT_RENDER_USER_INTERRUPT)
1331 notify_ring(dev, &dev_priv->ring[RCS]);
1332 if (bcs & GT_RENDER_USER_INTERRUPT)
1333 notify_ring(dev, &dev_priv->ring[BCS]);
1334 I915_WRITE(GEN8_GT_IIR(0), tmp);
1335 } else
1336 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1337 }
1338
1339 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1340 tmp = I915_READ(GEN8_GT_IIR(1));
1341 if (tmp) {
1342 ret = IRQ_HANDLED;
1343 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1344 if (vcs & GT_RENDER_USER_INTERRUPT)
1345 notify_ring(dev, &dev_priv->ring[VCS]);
1346 I915_WRITE(GEN8_GT_IIR(1), tmp);
1347 } else
1348 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1349 }
1350
1351 if (master_ctl & GEN8_GT_VECS_IRQ) {
1352 tmp = I915_READ(GEN8_GT_IIR(3));
1353 if (tmp) {
1354 ret = IRQ_HANDLED;
1355 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1356 if (vcs & GT_RENDER_USER_INTERRUPT)
1357 notify_ring(dev, &dev_priv->ring[VECS]);
1358 I915_WRITE(GEN8_GT_IIR(3), tmp);
1359 } else
1360 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1361 }
1362
1363 return ret;
1364}
1365
Egbert Eichb543fb02013-04-16 13:36:54 +02001366#define HPD_STORM_DETECT_PERIOD 1000
1367#define HPD_STORM_THRESHOLD 5
1368
Daniel Vetter10a504d2013-06-27 17:52:12 +02001369static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001370 u32 hotplug_trigger,
1371 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001372{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001373 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001374 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001375 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001376
Daniel Vetter91d131d2013-06-27 17:52:14 +02001377 if (!hotplug_trigger)
1378 return;
1379
Imre Deakcc9bd492014-01-16 19:56:54 +02001380 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1381 hotplug_trigger);
1382
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001383 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001384 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001385
Chris Wilson34320872014-01-10 18:49:20 +00001386 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001387 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001388 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1389 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001390
Egbert Eichb543fb02013-04-16 13:36:54 +02001391 if (!(hpd[i] & hotplug_trigger) ||
1392 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1393 continue;
1394
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001395 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001396 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1397 dev_priv->hpd_stats[i].hpd_last_jiffies
1398 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1399 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1400 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001401 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001402 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1403 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001404 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001405 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001406 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001407 } else {
1408 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001409 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1410 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001411 }
1412 }
1413
Daniel Vetter10a504d2013-06-27 17:52:12 +02001414 if (storm_detected)
1415 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001416 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001417
Daniel Vetter645416f2013-09-02 16:22:25 +02001418 /*
1419 * Our hotplug handler can grab modeset locks (by calling down into the
1420 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1421 * queue for otherwise the flush_work in the pageflip code will
1422 * deadlock.
1423 */
1424 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001425}
1426
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001427static void gmbus_irq_handler(struct drm_device *dev)
1428{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001429 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001430
Daniel Vetter28c70f12012-12-01 13:53:45 +01001431 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001432}
1433
Daniel Vetterce99c252012-12-01 13:53:47 +01001434static void dp_aux_irq_handler(struct drm_device *dev)
1435{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001436 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001437
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001438 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001439}
1440
Shuang He8bf1e9f2013-10-15 18:55:27 +01001441#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001442static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1443 uint32_t crc0, uint32_t crc1,
1444 uint32_t crc2, uint32_t crc3,
1445 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001446{
1447 struct drm_i915_private *dev_priv = dev->dev_private;
1448 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1449 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001450 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001451
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001452 spin_lock(&pipe_crc->lock);
1453
Damien Lespiau0c912c72013-10-15 18:55:37 +01001454 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001455 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001456 DRM_ERROR("spurious interrupt\n");
1457 return;
1458 }
1459
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001460 head = pipe_crc->head;
1461 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001462
1463 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001464 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001465 DRM_ERROR("CRC buffer overflowing\n");
1466 return;
1467 }
1468
1469 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001470
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001471 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001472 entry->crc[0] = crc0;
1473 entry->crc[1] = crc1;
1474 entry->crc[2] = crc2;
1475 entry->crc[3] = crc3;
1476 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001477
1478 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001479 pipe_crc->head = head;
1480
1481 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001482
1483 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001484}
Daniel Vetter277de952013-10-18 16:37:07 +02001485#else
1486static inline void
1487display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1488 uint32_t crc0, uint32_t crc1,
1489 uint32_t crc2, uint32_t crc3,
1490 uint32_t crc4) {}
1491#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001492
Daniel Vetter277de952013-10-18 16:37:07 +02001493
1494static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001495{
1496 struct drm_i915_private *dev_priv = dev->dev_private;
1497
Daniel Vetter277de952013-10-18 16:37:07 +02001498 display_pipe_crc_irq_handler(dev, pipe,
1499 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1500 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001501}
1502
Daniel Vetter277de952013-10-18 16:37:07 +02001503static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001504{
1505 struct drm_i915_private *dev_priv = dev->dev_private;
1506
Daniel Vetter277de952013-10-18 16:37:07 +02001507 display_pipe_crc_irq_handler(dev, pipe,
1508 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1509 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1510 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1511 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1512 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001513}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001514
Daniel Vetter277de952013-10-18 16:37:07 +02001515static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001516{
1517 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001518 uint32_t res1, res2;
1519
1520 if (INTEL_INFO(dev)->gen >= 3)
1521 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1522 else
1523 res1 = 0;
1524
1525 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1526 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1527 else
1528 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001529
Daniel Vetter277de952013-10-18 16:37:07 +02001530 display_pipe_crc_irq_handler(dev, pipe,
1531 I915_READ(PIPE_CRC_RES_RED(pipe)),
1532 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1533 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1534 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001535}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001536
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001537/* The RPS events need forcewake, so we add them to a work queue and mask their
1538 * IMR bits until the work is done. Other interrupts can be processed without
1539 * the work queue. */
1540static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001541{
Deepak Sa6706b42014-03-15 20:23:22 +05301542 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001543 spin_lock(&dev_priv->irq_lock);
Deepak Sa6706b42014-03-15 20:23:22 +05301544 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1545 snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001546 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001547
1548 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001549 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001550
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001551 if (HAS_VEBOX(dev_priv->dev)) {
1552 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1553 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001554
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001555 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001556 i915_handle_error(dev_priv->dev, false,
1557 "VEBOX CS error interrupt 0x%08x",
1558 pm_iir);
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001559 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001560 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001561}
1562
Imre Deakc1874ed2014-02-04 21:35:46 +02001563static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1564{
1565 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001566 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001567 int pipe;
1568
Imre Deak58ead0d2014-02-04 21:35:47 +02001569 spin_lock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001570 for_each_pipe(pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001571 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001572 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001573
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001574 /*
1575 * PIPESTAT bits get signalled even when the interrupt is
1576 * disabled with the mask bits, and some of the status bits do
1577 * not generate interrupts at all (like the underrun bit). Hence
1578 * we need to be careful that we only handle what we want to
1579 * handle.
1580 */
1581 mask = 0;
1582 if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
1583 mask |= PIPE_FIFO_UNDERRUN_STATUS;
1584
1585 switch (pipe) {
1586 case PIPE_A:
1587 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1588 break;
1589 case PIPE_B:
1590 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1591 break;
1592 }
1593 if (iir & iir_bit)
1594 mask |= dev_priv->pipestat_irq_mask[pipe];
1595
1596 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001597 continue;
1598
1599 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001600 mask |= PIPESTAT_INT_ENABLE_MASK;
1601 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001602
1603 /*
1604 * Clear the PIPE*STAT regs before the IIR
1605 */
Imre Deak91d181d2014-02-10 18:42:49 +02001606 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1607 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001608 I915_WRITE(reg, pipe_stats[pipe]);
1609 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001610 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001611
1612 for_each_pipe(pipe) {
1613 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1614 drm_handle_vblank(dev, pipe);
1615
Imre Deak579a9b02014-02-04 21:35:48 +02001616 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001617 intel_prepare_page_flip(dev, pipe);
1618 intel_finish_page_flip(dev, pipe);
1619 }
1620
1621 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1622 i9xx_pipe_crc_irq_handler(dev, pipe);
1623
1624 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1625 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1626 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1627 }
1628
1629 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1630 gmbus_irq_handler(dev);
1631}
1632
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001633static void i9xx_hpd_irq_handler(struct drm_device *dev)
1634{
1635 struct drm_i915_private *dev_priv = dev->dev_private;
1636 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1637
1638 if (IS_G4X(dev)) {
1639 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1640
1641 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_g4x);
1642 } else {
1643 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1644
1645 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1646 }
1647
1648 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
1649 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1650 dp_aux_irq_handler(dev);
1651
1652 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1653 /*
1654 * Make sure hotplug status is cleared before we clear IIR, or else we
1655 * may miss hotplug events.
1656 */
1657 POSTING_READ(PORT_HOTPLUG_STAT);
1658}
1659
Daniel Vetterff1f5252012-10-02 15:10:55 +02001660static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001661{
1662 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001663 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001664 u32 iir, gt_iir, pm_iir;
1665 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001666
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001667 while (true) {
1668 iir = I915_READ(VLV_IIR);
1669 gt_iir = I915_READ(GTIIR);
1670 pm_iir = I915_READ(GEN6_PMIIR);
1671
1672 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1673 goto out;
1674
1675 ret = IRQ_HANDLED;
1676
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001677 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001678
Imre Deakc1874ed2014-02-04 21:35:46 +02001679 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001680
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001681 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001682 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1683 i9xx_hpd_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001684
Paulo Zanoni60611c12013-08-15 11:50:01 -03001685 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001686 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001687
1688 I915_WRITE(GTIIR, gt_iir);
1689 I915_WRITE(GEN6_PMIIR, pm_iir);
1690 I915_WRITE(VLV_IIR, iir);
1691 }
1692
1693out:
1694 return ret;
1695}
1696
Adam Jackson23e81d62012-06-06 15:45:44 -04001697static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001698{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001699 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001700 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001701 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001702
Daniel Vetter91d131d2013-06-27 17:52:14 +02001703 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1704
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001705 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1706 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1707 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001708 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001709 port_name(port));
1710 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001711
Daniel Vetterce99c252012-12-01 13:53:47 +01001712 if (pch_iir & SDE_AUX_MASK)
1713 dp_aux_irq_handler(dev);
1714
Jesse Barnes776ad802011-01-04 15:09:39 -08001715 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001716 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001717
1718 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1719 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1720
1721 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1722 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1723
1724 if (pch_iir & SDE_POISON)
1725 DRM_ERROR("PCH poison interrupt\n");
1726
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001727 if (pch_iir & SDE_FDI_MASK)
1728 for_each_pipe(pipe)
1729 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1730 pipe_name(pipe),
1731 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001732
1733 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1734 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1735
1736 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1737 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1738
Jesse Barnes776ad802011-01-04 15:09:39 -08001739 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001740 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1741 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001742 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001743
1744 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1745 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1746 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001747 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001748}
1749
1750static void ivb_err_int_handler(struct drm_device *dev)
1751{
1752 struct drm_i915_private *dev_priv = dev->dev_private;
1753 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001754 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001755
Paulo Zanonide032bf2013-04-12 17:57:58 -03001756 if (err_int & ERR_INT_POISON)
1757 DRM_ERROR("Poison interrupt\n");
1758
Daniel Vetter5a69b892013-10-16 22:55:52 +02001759 for_each_pipe(pipe) {
1760 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1761 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1762 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001763 DRM_ERROR("Pipe %c FIFO underrun\n",
1764 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001765 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001766
Daniel Vetter5a69b892013-10-16 22:55:52 +02001767 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1768 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001769 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001770 else
Daniel Vetter277de952013-10-18 16:37:07 +02001771 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001772 }
1773 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001774
Paulo Zanoni86642812013-04-12 17:57:57 -03001775 I915_WRITE(GEN7_ERR_INT, err_int);
1776}
1777
1778static void cpt_serr_int_handler(struct drm_device *dev)
1779{
1780 struct drm_i915_private *dev_priv = dev->dev_private;
1781 u32 serr_int = I915_READ(SERR_INT);
1782
Paulo Zanonide032bf2013-04-12 17:57:58 -03001783 if (serr_int & SERR_INT_POISON)
1784 DRM_ERROR("PCH poison interrupt\n");
1785
Paulo Zanoni86642812013-04-12 17:57:57 -03001786 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1787 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1788 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001789 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001790
1791 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1792 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1793 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001794 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001795
1796 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1797 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1798 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001799 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001800
1801 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001802}
1803
Adam Jackson23e81d62012-06-06 15:45:44 -04001804static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1805{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001806 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04001807 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001808 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001809
Daniel Vetter91d131d2013-06-27 17:52:14 +02001810 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1811
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001812 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1813 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1814 SDE_AUDIO_POWER_SHIFT_CPT);
1815 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1816 port_name(port));
1817 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001818
1819 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001820 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001821
1822 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001823 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001824
1825 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1826 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1827
1828 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1829 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1830
1831 if (pch_iir & SDE_FDI_MASK_CPT)
1832 for_each_pipe(pipe)
1833 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1834 pipe_name(pipe),
1835 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001836
1837 if (pch_iir & SDE_ERROR_CPT)
1838 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001839}
1840
Paulo Zanonic008bc62013-07-12 16:35:10 -03001841static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1842{
1843 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001844 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001845
1846 if (de_iir & DE_AUX_CHANNEL_A)
1847 dp_aux_irq_handler(dev);
1848
1849 if (de_iir & DE_GSE)
1850 intel_opregion_asle_intr(dev);
1851
Paulo Zanonic008bc62013-07-12 16:35:10 -03001852 if (de_iir & DE_POISON)
1853 DRM_ERROR("Poison interrupt\n");
1854
Daniel Vetter40da17c2013-10-21 18:04:36 +02001855 for_each_pipe(pipe) {
1856 if (de_iir & DE_PIPE_VBLANK(pipe))
1857 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001858
Daniel Vetter40da17c2013-10-21 18:04:36 +02001859 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1860 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001861 DRM_ERROR("Pipe %c FIFO underrun\n",
1862 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001863
Daniel Vetter40da17c2013-10-21 18:04:36 +02001864 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1865 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001866
Daniel Vetter40da17c2013-10-21 18:04:36 +02001867 /* plane/pipes map 1:1 on ilk+ */
1868 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1869 intel_prepare_page_flip(dev, pipe);
1870 intel_finish_page_flip_plane(dev, pipe);
1871 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001872 }
1873
1874 /* check event from PCH */
1875 if (de_iir & DE_PCH_EVENT) {
1876 u32 pch_iir = I915_READ(SDEIIR);
1877
1878 if (HAS_PCH_CPT(dev))
1879 cpt_irq_handler(dev, pch_iir);
1880 else
1881 ibx_irq_handler(dev, pch_iir);
1882
1883 /* should clear PCH hotplug event before clear CPU irq */
1884 I915_WRITE(SDEIIR, pch_iir);
1885 }
1886
1887 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1888 ironlake_rps_change_irq_handler(dev);
1889}
1890
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001891static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1892{
1893 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00001894 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001895
1896 if (de_iir & DE_ERR_INT_IVB)
1897 ivb_err_int_handler(dev);
1898
1899 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1900 dp_aux_irq_handler(dev);
1901
1902 if (de_iir & DE_GSE_IVB)
1903 intel_opregion_asle_intr(dev);
1904
Damien Lespiau07d27e22014-03-03 17:31:46 +00001905 for_each_pipe(pipe) {
1906 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
1907 drm_handle_vblank(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001908
1909 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00001910 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
1911 intel_prepare_page_flip(dev, pipe);
1912 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001913 }
1914 }
1915
1916 /* check event from PCH */
1917 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1918 u32 pch_iir = I915_READ(SDEIIR);
1919
1920 cpt_irq_handler(dev, pch_iir);
1921
1922 /* clear PCH hotplug event before clear CPU irq */
1923 I915_WRITE(SDEIIR, pch_iir);
1924 }
1925}
1926
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001927static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001928{
1929 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001930 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001931 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001932 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001933
Paulo Zanoni86642812013-04-12 17:57:57 -03001934 /* We get interrupts on unclaimed registers, so check for this before we
1935 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001936 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001937
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001938 /* disable master interrupt before clearing iir */
1939 de_ier = I915_READ(DEIER);
1940 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001941 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001942
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001943 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1944 * interrupts will will be stored on its back queue, and then we'll be
1945 * able to process them after we restore SDEIER (as soon as we restore
1946 * it, we'll get an interrupt if SDEIIR still has something to process
1947 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001948 if (!HAS_PCH_NOP(dev)) {
1949 sde_ier = I915_READ(SDEIER);
1950 I915_WRITE(SDEIER, 0);
1951 POSTING_READ(SDEIER);
1952 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001953
Chris Wilson0e434062012-05-09 21:45:44 +01001954 gt_iir = I915_READ(GTIIR);
1955 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001956 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001957 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001958 else
1959 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001960 I915_WRITE(GTIIR, gt_iir);
1961 ret = IRQ_HANDLED;
1962 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001963
1964 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001965 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001966 if (INTEL_INFO(dev)->gen >= 7)
1967 ivb_display_irq_handler(dev, de_iir);
1968 else
1969 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001970 I915_WRITE(DEIIR, de_iir);
1971 ret = IRQ_HANDLED;
1972 }
1973
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001974 if (INTEL_INFO(dev)->gen >= 6) {
1975 u32 pm_iir = I915_READ(GEN6_PMIIR);
1976 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001977 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001978 I915_WRITE(GEN6_PMIIR, pm_iir);
1979 ret = IRQ_HANDLED;
1980 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001981 }
1982
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001983 I915_WRITE(DEIER, de_ier);
1984 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001985 if (!HAS_PCH_NOP(dev)) {
1986 I915_WRITE(SDEIER, sde_ier);
1987 POSTING_READ(SDEIER);
1988 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001989
1990 return ret;
1991}
1992
Ben Widawskyabd58f02013-11-02 21:07:09 -07001993static irqreturn_t gen8_irq_handler(int irq, void *arg)
1994{
1995 struct drm_device *dev = arg;
1996 struct drm_i915_private *dev_priv = dev->dev_private;
1997 u32 master_ctl;
1998 irqreturn_t ret = IRQ_NONE;
1999 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002000 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002001
Ben Widawskyabd58f02013-11-02 21:07:09 -07002002 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2003 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2004 if (!master_ctl)
2005 return IRQ_NONE;
2006
2007 I915_WRITE(GEN8_MASTER_IRQ, 0);
2008 POSTING_READ(GEN8_MASTER_IRQ);
2009
2010 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2011
2012 if (master_ctl & GEN8_DE_MISC_IRQ) {
2013 tmp = I915_READ(GEN8_DE_MISC_IIR);
2014 if (tmp & GEN8_DE_MISC_GSE)
2015 intel_opregion_asle_intr(dev);
2016 else if (tmp)
2017 DRM_ERROR("Unexpected DE Misc interrupt\n");
2018 else
2019 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
2020
2021 if (tmp) {
2022 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2023 ret = IRQ_HANDLED;
2024 }
2025 }
2026
Daniel Vetter6d766f02013-11-07 14:49:55 +01002027 if (master_ctl & GEN8_DE_PORT_IRQ) {
2028 tmp = I915_READ(GEN8_DE_PORT_IIR);
2029 if (tmp & GEN8_AUX_CHANNEL_A)
2030 dp_aux_irq_handler(dev);
2031 else if (tmp)
2032 DRM_ERROR("Unexpected DE Port interrupt\n");
2033 else
2034 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
2035
2036 if (tmp) {
2037 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2038 ret = IRQ_HANDLED;
2039 }
2040 }
2041
Daniel Vetterc42664c2013-11-07 11:05:40 +01002042 for_each_pipe(pipe) {
2043 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002044
Daniel Vetterc42664c2013-11-07 11:05:40 +01002045 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2046 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002047
Daniel Vetterc42664c2013-11-07 11:05:40 +01002048 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2049 if (pipe_iir & GEN8_PIPE_VBLANK)
2050 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002051
Daniel Vetterc42664c2013-11-07 11:05:40 +01002052 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
2053 intel_prepare_page_flip(dev, pipe);
2054 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002055 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002056
Daniel Vetter0fbe7872013-11-07 11:05:44 +01002057 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2058 hsw_pipe_crc_irq_handler(dev, pipe);
2059
Daniel Vetter38d83c962013-11-07 11:05:46 +01002060 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
2061 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2062 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002063 DRM_ERROR("Pipe %c FIFO underrun\n",
2064 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01002065 }
2066
Daniel Vetter30100f22013-11-07 14:49:24 +01002067 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
2068 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2069 pipe_name(pipe),
2070 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2071 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002072
2073 if (pipe_iir) {
2074 ret = IRQ_HANDLED;
2075 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
2076 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002077 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2078 }
2079
Daniel Vetter92d03a82013-11-07 11:05:43 +01002080 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2081 /*
2082 * FIXME(BDW): Assume for now that the new interrupt handling
2083 * scheme also closed the SDE interrupt handling race we've seen
2084 * on older pch-split platforms. But this needs testing.
2085 */
2086 u32 pch_iir = I915_READ(SDEIIR);
2087
2088 cpt_irq_handler(dev, pch_iir);
2089
2090 if (pch_iir) {
2091 I915_WRITE(SDEIIR, pch_iir);
2092 ret = IRQ_HANDLED;
2093 }
2094 }
2095
Ben Widawskyabd58f02013-11-02 21:07:09 -07002096 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2097 POSTING_READ(GEN8_MASTER_IRQ);
2098
2099 return ret;
2100}
2101
Daniel Vetter17e1df02013-09-08 21:57:13 +02002102static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2103 bool reset_completed)
2104{
2105 struct intel_ring_buffer *ring;
2106 int i;
2107
2108 /*
2109 * Notify all waiters for GPU completion events that reset state has
2110 * been changed, and that they need to restart their wait after
2111 * checking for potential errors (and bail out to drop locks if there is
2112 * a gpu reset pending so that i915_error_work_func can acquire them).
2113 */
2114
2115 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2116 for_each_ring(ring, dev_priv, i)
2117 wake_up_all(&ring->irq_queue);
2118
2119 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2120 wake_up_all(&dev_priv->pending_flip_queue);
2121
2122 /*
2123 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2124 * reset state is cleared.
2125 */
2126 if (reset_completed)
2127 wake_up_all(&dev_priv->gpu_error.reset_queue);
2128}
2129
Jesse Barnes8a905232009-07-11 16:48:03 -04002130/**
2131 * i915_error_work_func - do process context error handling work
2132 * @work: work struct
2133 *
2134 * Fire an error uevent so userspace can see that a hang or error
2135 * was detected.
2136 */
2137static void i915_error_work_func(struct work_struct *work)
2138{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002139 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2140 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002141 struct drm_i915_private *dev_priv =
2142 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002143 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002144 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2145 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2146 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002147 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002148
Dave Airlie5bdebb12013-10-11 14:07:25 +10002149 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002150
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002151 /*
2152 * Note that there's only one work item which does gpu resets, so we
2153 * need not worry about concurrent gpu resets potentially incrementing
2154 * error->reset_counter twice. We only need to take care of another
2155 * racing irq/hangcheck declaring the gpu dead for a second time. A
2156 * quick check for that is good enough: schedule_work ensures the
2157 * correct ordering between hang detection and this work item, and since
2158 * the reset in-progress bit is only ever set by code outside of this
2159 * work we don't need to worry about any other races.
2160 */
2161 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002162 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002163 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002164 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002165
Daniel Vetter17e1df02013-09-08 21:57:13 +02002166 /*
2167 * All state reset _must_ be completed before we update the
2168 * reset counter, for otherwise waiters might miss the reset
2169 * pending state and not properly drop locks, resulting in
2170 * deadlocks with the reset work.
2171 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002172 ret = i915_reset(dev);
2173
Daniel Vetter17e1df02013-09-08 21:57:13 +02002174 intel_display_handle_reset(dev);
2175
Daniel Vetterf69061b2012-12-06 09:01:42 +01002176 if (ret == 0) {
2177 /*
2178 * After all the gem state is reset, increment the reset
2179 * counter and wake up everyone waiting for the reset to
2180 * complete.
2181 *
2182 * Since unlock operations are a one-sided barrier only,
2183 * we need to insert a barrier here to order any seqno
2184 * updates before
2185 * the counter increment.
2186 */
2187 smp_mb__before_atomic_inc();
2188 atomic_inc(&dev_priv->gpu_error.reset_counter);
2189
Dave Airlie5bdebb12013-10-11 14:07:25 +10002190 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002191 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002192 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002193 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002194 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002195
Daniel Vetter17e1df02013-09-08 21:57:13 +02002196 /*
2197 * Note: The wake_up also serves as a memory barrier so that
2198 * waiters see the update value of the reset counter atomic_t.
2199 */
2200 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002201 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002202}
2203
Chris Wilson35aed2e2010-05-27 13:18:12 +01002204static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002205{
2206 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002207 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002208 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002209 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002210
Chris Wilson35aed2e2010-05-27 13:18:12 +01002211 if (!eir)
2212 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002213
Joe Perchesa70491c2012-03-18 13:00:11 -07002214 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002215
Ben Widawskybd9854f2012-08-23 15:18:09 -07002216 i915_get_extra_instdone(dev, instdone);
2217
Jesse Barnes8a905232009-07-11 16:48:03 -04002218 if (IS_G4X(dev)) {
2219 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2220 u32 ipeir = I915_READ(IPEIR_I965);
2221
Joe Perchesa70491c2012-03-18 13:00:11 -07002222 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2223 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002224 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2225 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002226 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002227 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002228 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002229 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002230 }
2231 if (eir & GM45_ERROR_PAGE_TABLE) {
2232 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002233 pr_err("page table error\n");
2234 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002235 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002236 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002237 }
2238 }
2239
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002240 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002241 if (eir & I915_ERROR_PAGE_TABLE) {
2242 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002243 pr_err("page table error\n");
2244 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002245 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002246 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002247 }
2248 }
2249
2250 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002251 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002252 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002253 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002254 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002255 /* pipestat has already been acked */
2256 }
2257 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002258 pr_err("instruction error\n");
2259 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002260 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2261 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002262 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002263 u32 ipeir = I915_READ(IPEIR);
2264
Joe Perchesa70491c2012-03-18 13:00:11 -07002265 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2266 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002267 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002268 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002269 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002270 } else {
2271 u32 ipeir = I915_READ(IPEIR_I965);
2272
Joe Perchesa70491c2012-03-18 13:00:11 -07002273 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2274 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002275 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002276 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002277 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002278 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002279 }
2280 }
2281
2282 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002283 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002284 eir = I915_READ(EIR);
2285 if (eir) {
2286 /*
2287 * some errors might have become stuck,
2288 * mask them.
2289 */
2290 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2291 I915_WRITE(EMR, I915_READ(EMR) | eir);
2292 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2293 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002294}
2295
2296/**
2297 * i915_handle_error - handle an error interrupt
2298 * @dev: drm device
2299 *
2300 * Do some basic checking of regsiter state at error interrupt time and
2301 * dump it to the syslog. Also call i915_capture_error_state() to make
2302 * sure we get a record and make it available in debugfs. Fire a uevent
2303 * so userspace knows something bad happened (should trigger collection
2304 * of a ring dump etc.).
2305 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002306void i915_handle_error(struct drm_device *dev, bool wedged,
2307 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002308{
2309 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002310 va_list args;
2311 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002312
Mika Kuoppala58174462014-02-25 17:11:26 +02002313 va_start(args, fmt);
2314 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2315 va_end(args);
2316
2317 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002318 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002319
Ben Gamariba1234d2009-09-14 17:48:47 -04002320 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002321 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2322 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002323
Ben Gamari11ed50e2009-09-14 17:48:45 -04002324 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002325 * Wakeup waiting processes so that the reset work function
2326 * i915_error_work_func doesn't deadlock trying to grab various
2327 * locks. By bumping the reset counter first, the woken
2328 * processes will see a reset in progress and back off,
2329 * releasing their locks and then wait for the reset completion.
2330 * We must do this for _all_ gpu waiters that might hold locks
2331 * that the reset work needs to acquire.
2332 *
2333 * Note: The wake_up serves as the required memory barrier to
2334 * ensure that the waiters see the updated value of the reset
2335 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002336 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002337 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002338 }
2339
Daniel Vetter122f46b2013-09-04 17:36:14 +02002340 /*
2341 * Our reset work can grab modeset locks (since it needs to reset the
2342 * state of outstanding pagelips). Hence it must not be run on our own
2343 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2344 * code will deadlock.
2345 */
2346 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002347}
2348
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002349static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002350{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002351 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002352 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2353 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002354 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002355 struct intel_unpin_work *work;
2356 unsigned long flags;
2357 bool stall_detected;
2358
2359 /* Ignore early vblank irqs */
2360 if (intel_crtc == NULL)
2361 return;
2362
2363 spin_lock_irqsave(&dev->event_lock, flags);
2364 work = intel_crtc->unpin_work;
2365
Chris Wilsone7d841c2012-12-03 11:36:30 +00002366 if (work == NULL ||
2367 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2368 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002369 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2370 spin_unlock_irqrestore(&dev->event_lock, flags);
2371 return;
2372 }
2373
2374 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002375 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002376 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002377 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002378 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002379 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002380 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002381 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002382 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002383 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002384 crtc->x * crtc->fb->bits_per_pixel/8);
2385 }
2386
2387 spin_unlock_irqrestore(&dev->event_lock, flags);
2388
2389 if (stall_detected) {
2390 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2391 intel_prepare_page_flip(dev, intel_crtc->plane);
2392 }
2393}
2394
Keith Packard42f52ef2008-10-18 19:39:29 -07002395/* Called from drm generic code, passed 'crtc' which
2396 * we use as a pipe index
2397 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002398static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002399{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002400 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002401 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002402
Chris Wilson5eddb702010-09-11 13:48:45 +01002403 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002404 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002405
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002406 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002407 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002408 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002409 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002410 else
Keith Packard7c463582008-11-04 02:03:27 -08002411 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002412 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002413
2414 /* maintain vblank delivery even in deep C-states */
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002415 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002416 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002417 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002418
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002419 return 0;
2420}
2421
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002422static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002423{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002424 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002425 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002426 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002427 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002428
2429 if (!i915_pipe_enabled(dev, pipe))
2430 return -EINVAL;
2431
2432 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002433 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002434 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2435
2436 return 0;
2437}
2438
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002439static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2440{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002441 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002442 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002443
2444 if (!i915_pipe_enabled(dev, pipe))
2445 return -EINVAL;
2446
2447 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002448 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002449 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002450 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2451
2452 return 0;
2453}
2454
Ben Widawskyabd58f02013-11-02 21:07:09 -07002455static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2456{
2457 struct drm_i915_private *dev_priv = dev->dev_private;
2458 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002459
2460 if (!i915_pipe_enabled(dev, pipe))
2461 return -EINVAL;
2462
2463 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002464 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2465 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2466 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002467 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2468 return 0;
2469}
2470
Keith Packard42f52ef2008-10-18 19:39:29 -07002471/* Called from drm generic code, passed 'crtc' which
2472 * we use as a pipe index
2473 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002474static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002475{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002476 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002477 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002478
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002479 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002480 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002481 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002482
Jesse Barnesf796cf82011-04-07 13:58:17 -07002483 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002484 PIPE_VBLANK_INTERRUPT_STATUS |
2485 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002486 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2487}
2488
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002489static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002490{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002491 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002492 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002493 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002494 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002495
2496 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002497 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002498 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2499}
2500
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002501static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2502{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002503 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002504 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002505
2506 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002507 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002508 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002509 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2510}
2511
Ben Widawskyabd58f02013-11-02 21:07:09 -07002512static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2513{
2514 struct drm_i915_private *dev_priv = dev->dev_private;
2515 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002516
2517 if (!i915_pipe_enabled(dev, pipe))
2518 return;
2519
2520 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002521 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2522 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2523 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002524 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2525}
2526
Chris Wilson893eead2010-10-27 14:44:35 +01002527static u32
2528ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002529{
Chris Wilson893eead2010-10-27 14:44:35 +01002530 return list_entry(ring->request_list.prev,
2531 struct drm_i915_gem_request, list)->seqno;
2532}
2533
Chris Wilson9107e9d2013-06-10 11:20:20 +01002534static bool
2535ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002536{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002537 return (list_empty(&ring->request_list) ||
2538 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002539}
2540
Daniel Vettera028c4b2014-03-15 00:08:56 +01002541static bool
2542ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2543{
2544 if (INTEL_INFO(dev)->gen >= 8) {
2545 /*
2546 * FIXME: gen8 semaphore support - currently we don't emit
2547 * semaphores on bdw anyway, but this needs to be addressed when
2548 * we merge that code.
2549 */
2550 return false;
2551 } else {
2552 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2553 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2554 MI_SEMAPHORE_REGISTER);
2555 }
2556}
2557
Chris Wilson6274f212013-06-10 11:20:21 +01002558static struct intel_ring_buffer *
Daniel Vetter921d42e2014-03-18 10:26:04 +01002559semaphore_wait_to_signaller_ring(struct intel_ring_buffer *ring, u32 ipehr)
2560{
2561 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2562 struct intel_ring_buffer *signaller;
2563 int i;
2564
2565 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
2566 /*
2567 * FIXME: gen8 semaphore support - currently we don't emit
2568 * semaphores on bdw anyway, but this needs to be addressed when
2569 * we merge that code.
2570 */
2571 return NULL;
2572 } else {
2573 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2574
2575 for_each_ring(signaller, dev_priv, i) {
2576 if(ring == signaller)
2577 continue;
2578
2579 if (sync_bits ==
2580 signaller->semaphore_register[ring->id])
2581 return signaller;
2582 }
2583 }
2584
2585 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x\n",
2586 ring->id, ipehr);
2587
2588 return NULL;
2589}
2590
2591static struct intel_ring_buffer *
Chris Wilson6274f212013-06-10 11:20:21 +01002592semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002593{
2594 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002595 u32 cmd, ipehr, head;
2596 int i;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002597
2598 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002599 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002600 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002601
Daniel Vetter88fe4292014-03-15 00:08:55 +01002602 /*
2603 * HEAD is likely pointing to the dword after the actual command,
2604 * so scan backwards until we find the MBOX. But limit it to just 3
2605 * dwords. Note that we don't care about ACTHD here since that might
2606 * point at at batch, and semaphores are always emitted into the
2607 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002608 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002609 head = I915_READ_HEAD(ring) & HEAD_ADDR;
2610
2611 for (i = 4; i; --i) {
2612 /*
2613 * Be paranoid and presume the hw has gone off into the wild -
2614 * our ring is smaller than what the hardware (and hence
2615 * HEAD_ADDR) allows. Also handles wrap-around.
2616 */
2617 head &= ring->size - 1;
2618
2619 /* This here seems to blow up */
2620 cmd = ioread32(ring->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002621 if (cmd == ipehr)
2622 break;
2623
Daniel Vetter88fe4292014-03-15 00:08:55 +01002624 head -= 4;
2625 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002626
Daniel Vetter88fe4292014-03-15 00:08:55 +01002627 if (!i)
2628 return NULL;
2629
2630 *seqno = ioread32(ring->virtual_start + head + 4) + 1;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002631 return semaphore_wait_to_signaller_ring(ring, ipehr);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002632}
2633
Chris Wilson6274f212013-06-10 11:20:21 +01002634static int semaphore_passed(struct intel_ring_buffer *ring)
2635{
2636 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2637 struct intel_ring_buffer *signaller;
2638 u32 seqno, ctl;
2639
2640 ring->hangcheck.deadlock = true;
2641
2642 signaller = semaphore_waits_for(ring, &seqno);
2643 if (signaller == NULL || signaller->hangcheck.deadlock)
2644 return -1;
2645
2646 /* cursory check for an unkickable deadlock */
2647 ctl = I915_READ_CTL(signaller);
2648 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2649 return -1;
2650
2651 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2652}
2653
2654static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2655{
2656 struct intel_ring_buffer *ring;
2657 int i;
2658
2659 for_each_ring(ring, dev_priv, i)
2660 ring->hangcheck.deadlock = false;
2661}
2662
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002663static enum intel_ring_hangcheck_action
Chris Wilson50877442014-03-21 12:41:53 +00002664ring_stuck(struct intel_ring_buffer *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002665{
2666 struct drm_device *dev = ring->dev;
2667 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002668 u32 tmp;
2669
Chris Wilson6274f212013-06-10 11:20:21 +01002670 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002671 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002672
Chris Wilson9107e9d2013-06-10 11:20:20 +01002673 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002674 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002675
2676 /* Is the chip hanging on a WAIT_FOR_EVENT?
2677 * If so we can simply poke the RB_WAIT bit
2678 * and break the hang. This should work on
2679 * all but the second generation chipsets.
2680 */
2681 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002682 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002683 i915_handle_error(dev, false,
2684 "Kicking stuck wait on %s",
2685 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002686 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002687 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002688 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002689
Chris Wilson6274f212013-06-10 11:20:21 +01002690 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2691 switch (semaphore_passed(ring)) {
2692 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002693 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002694 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002695 i915_handle_error(dev, false,
2696 "Kicking stuck semaphore on %s",
2697 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002698 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002699 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002700 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002701 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002702 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002703 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002704
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002705 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002706}
2707
Ben Gamarif65d9422009-09-14 17:48:44 -04002708/**
2709 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002710 * batchbuffers in a long time. We keep track per ring seqno progress and
2711 * if there are no progress, hangcheck score for that ring is increased.
2712 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2713 * we kick the ring. If we see no progress on three subsequent calls
2714 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002715 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002716static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002717{
2718 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002719 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002720 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002721 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002722 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002723 bool stuck[I915_NUM_RINGS] = { 0 };
2724#define BUSY 1
2725#define KICK 5
2726#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002727
Jani Nikulad330a952014-01-21 11:24:25 +02002728 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002729 return;
2730
Chris Wilsonb4519512012-05-11 14:29:30 +01002731 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002732 u64 acthd;
2733 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002734 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002735
Chris Wilson6274f212013-06-10 11:20:21 +01002736 semaphore_clear_deadlocks(dev_priv);
2737
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002738 seqno = ring->get_seqno(ring, false);
2739 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002740
Chris Wilson9107e9d2013-06-10 11:20:20 +01002741 if (ring->hangcheck.seqno == seqno) {
2742 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002743 ring->hangcheck.action = HANGCHECK_IDLE;
2744
Chris Wilson9107e9d2013-06-10 11:20:20 +01002745 if (waitqueue_active(&ring->irq_queue)) {
2746 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002747 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002748 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2749 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2750 ring->name);
2751 else
2752 DRM_INFO("Fake missed irq on %s\n",
2753 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002754 wake_up_all(&ring->irq_queue);
2755 }
2756 /* Safeguard against driver failure */
2757 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002758 } else
2759 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002760 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002761 /* We always increment the hangcheck score
2762 * if the ring is busy and still processing
2763 * the same request, so that no single request
2764 * can run indefinitely (such as a chain of
2765 * batches). The only time we do not increment
2766 * the hangcheck score on this ring, if this
2767 * ring is in a legitimate wait for another
2768 * ring. In that case the waiting ring is a
2769 * victim and we want to be sure we catch the
2770 * right culprit. Then every time we do kick
2771 * the ring, add a small increment to the
2772 * score so that we can catch a batch that is
2773 * being repeatedly kicked and so responsible
2774 * for stalling the machine.
2775 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002776 ring->hangcheck.action = ring_stuck(ring,
2777 acthd);
2778
2779 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002780 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002781 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002782 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002783 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002784 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002785 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002786 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002787 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002788 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002789 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002790 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002791 stuck[i] = true;
2792 break;
2793 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002794 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002795 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002796 ring->hangcheck.action = HANGCHECK_ACTIVE;
2797
Chris Wilson9107e9d2013-06-10 11:20:20 +01002798 /* Gradually reduce the count so that we catch DoS
2799 * attempts across multiple batches.
2800 */
2801 if (ring->hangcheck.score > 0)
2802 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002803 }
2804
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002805 ring->hangcheck.seqno = seqno;
2806 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002807 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002808 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002809
Mika Kuoppala92cab732013-05-24 17:16:07 +03002810 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002811 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002812 DRM_INFO("%s on %s\n",
2813 stuck[i] ? "stuck" : "no progress",
2814 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002815 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002816 }
2817 }
2818
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002819 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02002820 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04002821
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002822 if (busy_count)
2823 /* Reset timer case chip hangs without another request
2824 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002825 i915_queue_hangcheck(dev);
2826}
2827
2828void i915_queue_hangcheck(struct drm_device *dev)
2829{
2830 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02002831 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002832 return;
2833
2834 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2835 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002836}
2837
Paulo Zanoni91738a92013-06-05 14:21:51 -03002838static void ibx_irq_preinstall(struct drm_device *dev)
2839{
2840 struct drm_i915_private *dev_priv = dev->dev_private;
2841
2842 if (HAS_PCH_NOP(dev))
2843 return;
2844
Paulo Zanoni0bda1cf2014-04-01 15:37:10 -03002845 GEN5_IRQ_INIT(SDE);
Paulo Zanoni91738a92013-06-05 14:21:51 -03002846 /*
2847 * SDEIER is also touched by the interrupt handler to work around missed
2848 * PCH interrupts. Hence we can't update it after the interrupt handler
2849 * is enabled - instead we unconditionally enable all PCH interrupt
2850 * sources here, but then only unmask them as needed with SDEIMR.
2851 */
2852 I915_WRITE(SDEIER, 0xffffffff);
2853 POSTING_READ(SDEIER);
2854}
2855
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002856static void gen5_gt_irq_preinstall(struct drm_device *dev)
2857{
2858 struct drm_i915_private *dev_priv = dev->dev_private;
2859
Paulo Zanonia9d356a2014-04-01 15:37:09 -03002860 GEN5_IRQ_INIT(GT);
2861 if (INTEL_INFO(dev)->gen >= 6)
2862 GEN5_IRQ_INIT(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002863}
2864
Linus Torvalds1da177e2005-04-16 15:20:36 -07002865/* drm_dma.h hooks
2866*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002867static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002868{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002869 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002870
2871 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002872
Paulo Zanonia9d356a2014-04-01 15:37:09 -03002873 GEN5_IRQ_INIT(DE);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002874
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002875 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002876
Paulo Zanoni91738a92013-06-05 14:21:51 -03002877 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002878}
2879
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002880static void valleyview_irq_preinstall(struct drm_device *dev)
2881{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002882 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002883 int pipe;
2884
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002885 /* VLV magic */
2886 I915_WRITE(VLV_IMR, 0);
2887 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2888 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2889 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2890
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002891 /* and GT */
2892 I915_WRITE(GTIIR, I915_READ(GTIIR));
2893 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002894
2895 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002896
2897 I915_WRITE(DPINVGTT, 0xff);
2898
2899 I915_WRITE(PORT_HOTPLUG_EN, 0);
2900 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2901 for_each_pipe(pipe)
2902 I915_WRITE(PIPESTAT(pipe), 0xffff);
2903 I915_WRITE(VLV_IIR, 0xffffffff);
2904 I915_WRITE(VLV_IMR, 0xffffffff);
2905 I915_WRITE(VLV_IER, 0x0);
2906 POSTING_READ(VLV_IER);
2907}
2908
Ben Widawskyabd58f02013-11-02 21:07:09 -07002909static void gen8_irq_preinstall(struct drm_device *dev)
2910{
2911 struct drm_i915_private *dev_priv = dev->dev_private;
2912 int pipe;
2913
Ben Widawskyabd58f02013-11-02 21:07:09 -07002914 I915_WRITE(GEN8_MASTER_IRQ, 0);
2915 POSTING_READ(GEN8_MASTER_IRQ);
2916
Ben Widawskyabd58f02013-11-02 21:07:09 -07002917 GEN8_IRQ_INIT_NDX(GT, 0);
2918 GEN8_IRQ_INIT_NDX(GT, 1);
2919 GEN8_IRQ_INIT_NDX(GT, 2);
2920 GEN8_IRQ_INIT_NDX(GT, 3);
2921
2922 for_each_pipe(pipe) {
2923 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2924 }
2925
Paulo Zanoni5c502442014-04-01 15:37:11 -03002926 GEN5_IRQ_INIT(GEN8_DE_PORT_);
2927 GEN5_IRQ_INIT(GEN8_DE_MISC_);
2928 GEN5_IRQ_INIT(GEN8_PCU_);
Jesse Barnes09f23442014-01-10 13:13:09 -08002929
2930 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002931}
2932
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002933static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002934{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002935 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002936 struct drm_mode_config *mode_config = &dev->mode_config;
2937 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002938 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002939
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002940 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002941 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002942 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002943 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002944 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002945 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002946 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002947 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002948 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002949 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002950 }
2951
Daniel Vetterfee884e2013-07-04 23:35:21 +02002952 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002953
2954 /*
2955 * Enable digital hotplug on the PCH, and configure the DP short pulse
2956 * duration to 2ms (which is the minimum in the Display Port spec)
2957 *
2958 * This register is the same on all known PCH chips.
2959 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002960 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2961 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2962 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2963 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2964 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2965 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2966}
2967
Paulo Zanonid46da432013-02-08 17:35:15 -02002968static void ibx_irq_postinstall(struct drm_device *dev)
2969{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002970 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002971 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002972
Daniel Vetter692a04c2013-05-29 21:43:05 +02002973 if (HAS_PCH_NOP(dev))
2974 return;
2975
Paulo Zanoni86642812013-04-12 17:57:57 -03002976 if (HAS_PCH_IBX(dev)) {
Daniel Vetter5c673b62014-03-07 20:34:46 +01002977 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002978 } else {
Daniel Vetter5c673b62014-03-07 20:34:46 +01002979 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03002980
2981 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2982 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002983
Paulo Zanonid46da432013-02-08 17:35:15 -02002984 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2985 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002986}
2987
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002988static void gen5_gt_irq_postinstall(struct drm_device *dev)
2989{
2990 struct drm_i915_private *dev_priv = dev->dev_private;
2991 u32 pm_irqs, gt_irqs;
2992
2993 pm_irqs = gt_irqs = 0;
2994
2995 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002996 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002997 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002998 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2999 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003000 }
3001
3002 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3003 if (IS_GEN5(dev)) {
3004 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3005 ILK_BSD_USER_INTERRUPT;
3006 } else {
3007 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3008 }
3009
3010 I915_WRITE(GTIIR, I915_READ(GTIIR));
3011 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
3012 I915_WRITE(GTIER, gt_irqs);
3013 POSTING_READ(GTIER);
3014
3015 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303016 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003017
3018 if (HAS_VEBOX(dev))
3019 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3020
Paulo Zanoni605cd252013-08-06 18:57:15 -03003021 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003022 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03003023 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003024 I915_WRITE(GEN6_PMIER, pm_irqs);
3025 POSTING_READ(GEN6_PMIER);
3026 }
3027}
3028
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003029static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003030{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003031 unsigned long irqflags;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003032 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003033 u32 display_mask, extra_mask;
3034
3035 if (INTEL_INFO(dev)->gen >= 7) {
3036 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3037 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3038 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003039 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003040 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003041 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003042
3043 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
3044 } else {
3045 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3046 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003047 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003048 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3049 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003050 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3051 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003052 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003053
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003054 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003055
3056 /* should always can generate irq */
3057 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003058 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003059 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00003060 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003061
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003062 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003063
Paulo Zanonid46da432013-02-08 17:35:15 -02003064 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003065
Jesse Barnesf97108d2010-01-29 11:27:07 -08003066 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003067 /* Enable PCU event interrupts
3068 *
3069 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003070 * setup is guaranteed to run in single-threaded context. But we
3071 * need it to make the assert_spin_locked happy. */
3072 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003073 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003074 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003075 }
3076
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003077 return 0;
3078}
3079
Imre Deakf8b79e52014-03-04 19:23:07 +02003080static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3081{
3082 u32 pipestat_mask;
3083 u32 iir_mask;
3084
3085 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3086 PIPE_FIFO_UNDERRUN_STATUS;
3087
3088 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3089 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3090 POSTING_READ(PIPESTAT(PIPE_A));
3091
3092 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3093 PIPE_CRC_DONE_INTERRUPT_STATUS;
3094
3095 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3096 PIPE_GMBUS_INTERRUPT_STATUS);
3097 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3098
3099 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3100 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3101 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3102 dev_priv->irq_mask &= ~iir_mask;
3103
3104 I915_WRITE(VLV_IIR, iir_mask);
3105 I915_WRITE(VLV_IIR, iir_mask);
3106 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3107 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3108 POSTING_READ(VLV_IER);
3109}
3110
3111static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3112{
3113 u32 pipestat_mask;
3114 u32 iir_mask;
3115
3116 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3117 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003118 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003119
3120 dev_priv->irq_mask |= iir_mask;
3121 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3122 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3123 I915_WRITE(VLV_IIR, iir_mask);
3124 I915_WRITE(VLV_IIR, iir_mask);
3125 POSTING_READ(VLV_IIR);
3126
3127 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3128 PIPE_CRC_DONE_INTERRUPT_STATUS;
3129
3130 i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3131 PIPE_GMBUS_INTERRUPT_STATUS);
3132 i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3133
3134 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3135 PIPE_FIFO_UNDERRUN_STATUS;
3136 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3137 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3138 POSTING_READ(PIPESTAT(PIPE_A));
3139}
3140
3141void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3142{
3143 assert_spin_locked(&dev_priv->irq_lock);
3144
3145 if (dev_priv->display_irqs_enabled)
3146 return;
3147
3148 dev_priv->display_irqs_enabled = true;
3149
3150 if (dev_priv->dev->irq_enabled)
3151 valleyview_display_irqs_install(dev_priv);
3152}
3153
3154void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3155{
3156 assert_spin_locked(&dev_priv->irq_lock);
3157
3158 if (!dev_priv->display_irqs_enabled)
3159 return;
3160
3161 dev_priv->display_irqs_enabled = false;
3162
3163 if (dev_priv->dev->irq_enabled)
3164 valleyview_display_irqs_uninstall(dev_priv);
3165}
3166
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003167static int valleyview_irq_postinstall(struct drm_device *dev)
3168{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003169 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003170 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003171
Imre Deakf8b79e52014-03-04 19:23:07 +02003172 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003173
Daniel Vetter20afbda2012-12-11 14:05:07 +01003174 I915_WRITE(PORT_HOTPLUG_EN, 0);
3175 POSTING_READ(PORT_HOTPLUG_EN);
3176
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003177 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003178 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003179 I915_WRITE(VLV_IIR, 0xffffffff);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003180 POSTING_READ(VLV_IER);
3181
Daniel Vetterb79480b2013-06-27 17:52:10 +02003182 /* Interrupt setup is already guaranteed to be single-threaded, this is
3183 * just to make the assert_spin_locked check happy. */
3184 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deakf8b79e52014-03-04 19:23:07 +02003185 if (dev_priv->display_irqs_enabled)
3186 valleyview_display_irqs_install(dev_priv);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003187 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003188
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003189 I915_WRITE(VLV_IIR, 0xffffffff);
3190 I915_WRITE(VLV_IIR, 0xffffffff);
3191
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003192 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003193
3194 /* ack & enable invalid PTE error interrupts */
3195#if 0 /* FIXME: add support to irq handler for checking these bits */
3196 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3197 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3198#endif
3199
3200 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003201
3202 return 0;
3203}
3204
Ben Widawskyabd58f02013-11-02 21:07:09 -07003205static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3206{
3207 int i;
3208
3209 /* These are interrupts we'll toggle with the ring mask register */
3210 uint32_t gt_interrupts[] = {
3211 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3212 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3213 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3214 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3215 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3216 0,
3217 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3218 };
3219
3220 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
3221 u32 tmp = I915_READ(GEN8_GT_IIR(i));
3222 if (tmp)
3223 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3224 i, tmp);
3225 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
3226 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
3227 }
3228 POSTING_READ(GEN8_GT_IER(0));
3229}
3230
3231static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3232{
3233 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003234 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
3235 GEN8_PIPE_CDCLK_CRC_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003236 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Daniel Vetter5c673b62014-03-07 20:34:46 +01003237 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3238 GEN8_PIPE_FIFO_UNDERRUN;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003239 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003240 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3241 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3242 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003243
3244 for_each_pipe(pipe) {
3245 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
3246 if (tmp)
3247 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3248 pipe, tmp);
3249 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3250 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
3251 }
3252 POSTING_READ(GEN8_DE_PIPE_ISR(0));
3253
Daniel Vetter6d766f02013-11-07 14:49:55 +01003254 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
3255 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003256 POSTING_READ(GEN8_DE_PORT_IER);
3257}
3258
3259static int gen8_irq_postinstall(struct drm_device *dev)
3260{
3261 struct drm_i915_private *dev_priv = dev->dev_private;
3262
3263 gen8_gt_irq_postinstall(dev_priv);
3264 gen8_de_irq_postinstall(dev_priv);
3265
3266 ibx_irq_postinstall(dev);
3267
3268 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3269 POSTING_READ(GEN8_MASTER_IRQ);
3270
3271 return 0;
3272}
3273
3274static void gen8_irq_uninstall(struct drm_device *dev)
3275{
3276 struct drm_i915_private *dev_priv = dev->dev_private;
3277 int pipe;
3278
3279 if (!dev_priv)
3280 return;
3281
Ben Widawskyabd58f02013-11-02 21:07:09 -07003282 I915_WRITE(GEN8_MASTER_IRQ, 0);
3283
3284#define GEN8_IRQ_FINI_NDX(type, which) do { \
3285 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3286 I915_WRITE(GEN8_##type##_IER(which), 0); \
3287 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3288 } while (0)
3289
3290#define GEN8_IRQ_FINI(type) do { \
3291 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3292 I915_WRITE(GEN8_##type##_IER, 0); \
3293 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3294 } while (0)
3295
3296 GEN8_IRQ_FINI_NDX(GT, 0);
3297 GEN8_IRQ_FINI_NDX(GT, 1);
3298 GEN8_IRQ_FINI_NDX(GT, 2);
3299 GEN8_IRQ_FINI_NDX(GT, 3);
3300
3301 for_each_pipe(pipe) {
3302 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3303 }
3304
3305 GEN8_IRQ_FINI(DE_PORT);
3306 GEN8_IRQ_FINI(DE_MISC);
3307 GEN8_IRQ_FINI(PCU);
3308#undef GEN8_IRQ_FINI
3309#undef GEN8_IRQ_FINI_NDX
3310
3311 POSTING_READ(GEN8_PCU_IIR);
3312}
3313
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003314static void valleyview_irq_uninstall(struct drm_device *dev)
3315{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003316 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakf8b79e52014-03-04 19:23:07 +02003317 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003318 int pipe;
3319
3320 if (!dev_priv)
3321 return;
3322
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003323 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003324
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003325 for_each_pipe(pipe)
3326 I915_WRITE(PIPESTAT(pipe), 0xffff);
3327
3328 I915_WRITE(HWSTAM, 0xffffffff);
3329 I915_WRITE(PORT_HOTPLUG_EN, 0);
3330 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Imre Deakf8b79e52014-03-04 19:23:07 +02003331
3332 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3333 if (dev_priv->display_irqs_enabled)
3334 valleyview_display_irqs_uninstall(dev_priv);
3335 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3336
3337 dev_priv->irq_mask = 0;
3338
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003339 I915_WRITE(VLV_IIR, 0xffffffff);
3340 I915_WRITE(VLV_IMR, 0xffffffff);
3341 I915_WRITE(VLV_IER, 0x0);
3342 POSTING_READ(VLV_IER);
3343}
3344
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003345static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003346{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003347 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003348
3349 if (!dev_priv)
3350 return;
3351
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003352 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003353
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003354 I915_WRITE(HWSTAM, 0xffffffff);
3355
3356 I915_WRITE(DEIMR, 0xffffffff);
3357 I915_WRITE(DEIER, 0x0);
3358 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003359 if (IS_GEN7(dev))
3360 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003361
3362 I915_WRITE(GTIMR, 0xffffffff);
3363 I915_WRITE(GTIER, 0x0);
3364 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003365
Ben Widawskyab5c6082013-04-05 13:12:41 -07003366 if (HAS_PCH_NOP(dev))
3367 return;
3368
Keith Packard192aac1f2011-09-20 10:12:44 -07003369 I915_WRITE(SDEIMR, 0xffffffff);
3370 I915_WRITE(SDEIER, 0x0);
3371 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003372 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3373 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003374}
3375
Chris Wilsonc2798b12012-04-22 21:13:57 +01003376static void i8xx_irq_preinstall(struct drm_device * dev)
3377{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003378 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003379 int pipe;
3380
Chris Wilsonc2798b12012-04-22 21:13:57 +01003381 for_each_pipe(pipe)
3382 I915_WRITE(PIPESTAT(pipe), 0);
3383 I915_WRITE16(IMR, 0xffff);
3384 I915_WRITE16(IER, 0x0);
3385 POSTING_READ16(IER);
3386}
3387
3388static int i8xx_irq_postinstall(struct drm_device *dev)
3389{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003390 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003391 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003392
Chris Wilsonc2798b12012-04-22 21:13:57 +01003393 I915_WRITE16(EMR,
3394 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3395
3396 /* Unmask the interrupts that we always want on. */
3397 dev_priv->irq_mask =
3398 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3399 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3400 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3401 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3402 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3403 I915_WRITE16(IMR, dev_priv->irq_mask);
3404
3405 I915_WRITE16(IER,
3406 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3407 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3408 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3409 I915_USER_INTERRUPT);
3410 POSTING_READ16(IER);
3411
Daniel Vetter379ef822013-10-16 22:55:56 +02003412 /* Interrupt setup is already guaranteed to be single-threaded, this is
3413 * just to make the assert_spin_locked check happy. */
3414 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003415 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3416 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003417 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3418
Chris Wilsonc2798b12012-04-22 21:13:57 +01003419 return 0;
3420}
3421
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003422/*
3423 * Returns true when a page flip has completed.
3424 */
3425static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003426 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003427{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003428 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003429 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003430
3431 if (!drm_handle_vblank(dev, pipe))
3432 return false;
3433
3434 if ((iir & flip_pending) == 0)
3435 return false;
3436
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003437 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003438
3439 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3440 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3441 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3442 * the flip is completed (no longer pending). Since this doesn't raise
3443 * an interrupt per se, we watch for the change at vblank.
3444 */
3445 if (I915_READ16(ISR) & flip_pending)
3446 return false;
3447
3448 intel_finish_page_flip(dev, pipe);
3449
3450 return true;
3451}
3452
Daniel Vetterff1f5252012-10-02 15:10:55 +02003453static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003454{
3455 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003456 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003457 u16 iir, new_iir;
3458 u32 pipe_stats[2];
3459 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003460 int pipe;
3461 u16 flip_mask =
3462 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3463 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3464
Chris Wilsonc2798b12012-04-22 21:13:57 +01003465 iir = I915_READ16(IIR);
3466 if (iir == 0)
3467 return IRQ_NONE;
3468
3469 while (iir & ~flip_mask) {
3470 /* Can't rely on pipestat interrupt bit in iir as it might
3471 * have been cleared after the pipestat interrupt was received.
3472 * It doesn't set the bit in iir again, but it still produces
3473 * interrupts (for non-MSI).
3474 */
3475 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3476 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003477 i915_handle_error(dev, false,
3478 "Command parser error, iir 0x%08x",
3479 iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003480
3481 for_each_pipe(pipe) {
3482 int reg = PIPESTAT(pipe);
3483 pipe_stats[pipe] = I915_READ(reg);
3484
3485 /*
3486 * Clear the PIPE*STAT regs before the IIR
3487 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003488 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003489 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003490 }
3491 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3492
3493 I915_WRITE16(IIR, iir & ~flip_mask);
3494 new_iir = I915_READ16(IIR); /* Flush posted writes */
3495
Daniel Vetterd05c6172012-04-26 23:28:09 +02003496 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003497
3498 if (iir & I915_USER_INTERRUPT)
3499 notify_ring(dev, &dev_priv->ring[RCS]);
3500
Daniel Vetter4356d582013-10-16 22:55:55 +02003501 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003502 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003503 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003504 plane = !plane;
3505
Daniel Vetter4356d582013-10-16 22:55:55 +02003506 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003507 i8xx_handle_vblank(dev, plane, pipe, iir))
3508 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003509
Daniel Vetter4356d582013-10-16 22:55:55 +02003510 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003511 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003512
3513 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3514 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003515 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003516 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003517
3518 iir = new_iir;
3519 }
3520
3521 return IRQ_HANDLED;
3522}
3523
3524static void i8xx_irq_uninstall(struct drm_device * dev)
3525{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003526 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003527 int pipe;
3528
Chris Wilsonc2798b12012-04-22 21:13:57 +01003529 for_each_pipe(pipe) {
3530 /* Clear enable bits; then clear status bits */
3531 I915_WRITE(PIPESTAT(pipe), 0);
3532 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3533 }
3534 I915_WRITE16(IMR, 0xffff);
3535 I915_WRITE16(IER, 0x0);
3536 I915_WRITE16(IIR, I915_READ16(IIR));
3537}
3538
Chris Wilsona266c7d2012-04-24 22:59:44 +01003539static void i915_irq_preinstall(struct drm_device * dev)
3540{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003541 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003542 int pipe;
3543
Chris Wilsona266c7d2012-04-24 22:59:44 +01003544 if (I915_HAS_HOTPLUG(dev)) {
3545 I915_WRITE(PORT_HOTPLUG_EN, 0);
3546 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3547 }
3548
Chris Wilson00d98eb2012-04-24 22:59:48 +01003549 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003550 for_each_pipe(pipe)
3551 I915_WRITE(PIPESTAT(pipe), 0);
3552 I915_WRITE(IMR, 0xffffffff);
3553 I915_WRITE(IER, 0x0);
3554 POSTING_READ(IER);
3555}
3556
3557static int i915_irq_postinstall(struct drm_device *dev)
3558{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003559 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003560 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003561 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003562
Chris Wilson38bde182012-04-24 22:59:50 +01003563 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3564
3565 /* Unmask the interrupts that we always want on. */
3566 dev_priv->irq_mask =
3567 ~(I915_ASLE_INTERRUPT |
3568 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3569 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3570 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3571 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3572 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3573
3574 enable_mask =
3575 I915_ASLE_INTERRUPT |
3576 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3577 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3578 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3579 I915_USER_INTERRUPT;
3580
Chris Wilsona266c7d2012-04-24 22:59:44 +01003581 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003582 I915_WRITE(PORT_HOTPLUG_EN, 0);
3583 POSTING_READ(PORT_HOTPLUG_EN);
3584
Chris Wilsona266c7d2012-04-24 22:59:44 +01003585 /* Enable in IER... */
3586 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3587 /* and unmask in IMR */
3588 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3589 }
3590
Chris Wilsona266c7d2012-04-24 22:59:44 +01003591 I915_WRITE(IMR, dev_priv->irq_mask);
3592 I915_WRITE(IER, enable_mask);
3593 POSTING_READ(IER);
3594
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003595 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003596
Daniel Vetter379ef822013-10-16 22:55:56 +02003597 /* Interrupt setup is already guaranteed to be single-threaded, this is
3598 * just to make the assert_spin_locked check happy. */
3599 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003600 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3601 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003602 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3603
Daniel Vetter20afbda2012-12-11 14:05:07 +01003604 return 0;
3605}
3606
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003607/*
3608 * Returns true when a page flip has completed.
3609 */
3610static bool i915_handle_vblank(struct drm_device *dev,
3611 int plane, int pipe, u32 iir)
3612{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003613 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003614 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3615
3616 if (!drm_handle_vblank(dev, pipe))
3617 return false;
3618
3619 if ((iir & flip_pending) == 0)
3620 return false;
3621
3622 intel_prepare_page_flip(dev, plane);
3623
3624 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3625 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3626 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3627 * the flip is completed (no longer pending). Since this doesn't raise
3628 * an interrupt per se, we watch for the change at vblank.
3629 */
3630 if (I915_READ(ISR) & flip_pending)
3631 return false;
3632
3633 intel_finish_page_flip(dev, pipe);
3634
3635 return true;
3636}
3637
Daniel Vetterff1f5252012-10-02 15:10:55 +02003638static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003639{
3640 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003641 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003642 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003643 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003644 u32 flip_mask =
3645 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3646 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003647 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003648
Chris Wilsona266c7d2012-04-24 22:59:44 +01003649 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003650 do {
3651 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003652 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003653
3654 /* Can't rely on pipestat interrupt bit in iir as it might
3655 * have been cleared after the pipestat interrupt was received.
3656 * It doesn't set the bit in iir again, but it still produces
3657 * interrupts (for non-MSI).
3658 */
3659 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3660 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003661 i915_handle_error(dev, false,
3662 "Command parser error, iir 0x%08x",
3663 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003664
3665 for_each_pipe(pipe) {
3666 int reg = PIPESTAT(pipe);
3667 pipe_stats[pipe] = I915_READ(reg);
3668
Chris Wilson38bde182012-04-24 22:59:50 +01003669 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003670 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003671 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003672 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003673 }
3674 }
3675 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3676
3677 if (!irq_received)
3678 break;
3679
Chris Wilsona266c7d2012-04-24 22:59:44 +01003680 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003681 if (I915_HAS_HOTPLUG(dev) &&
3682 iir & I915_DISPLAY_PORT_INTERRUPT)
3683 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003684
Chris Wilson38bde182012-04-24 22:59:50 +01003685 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003686 new_iir = I915_READ(IIR); /* Flush posted writes */
3687
Chris Wilsona266c7d2012-04-24 22:59:44 +01003688 if (iir & I915_USER_INTERRUPT)
3689 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003690
Chris Wilsona266c7d2012-04-24 22:59:44 +01003691 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003692 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003693 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003694 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003695
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003696 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3697 i915_handle_vblank(dev, plane, pipe, iir))
3698 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003699
3700 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3701 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003702
3703 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003704 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003705
3706 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3707 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003708 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003709 }
3710
Chris Wilsona266c7d2012-04-24 22:59:44 +01003711 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3712 intel_opregion_asle_intr(dev);
3713
3714 /* With MSI, interrupts are only generated when iir
3715 * transitions from zero to nonzero. If another bit got
3716 * set while we were handling the existing iir bits, then
3717 * we would never get another interrupt.
3718 *
3719 * This is fine on non-MSI as well, as if we hit this path
3720 * we avoid exiting the interrupt handler only to generate
3721 * another one.
3722 *
3723 * Note that for MSI this could cause a stray interrupt report
3724 * if an interrupt landed in the time between writing IIR and
3725 * the posting read. This should be rare enough to never
3726 * trigger the 99% of 100,000 interrupts test for disabling
3727 * stray interrupts.
3728 */
Chris Wilson38bde182012-04-24 22:59:50 +01003729 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003730 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003731 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003732
Daniel Vetterd05c6172012-04-26 23:28:09 +02003733 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003734
Chris Wilsona266c7d2012-04-24 22:59:44 +01003735 return ret;
3736}
3737
3738static void i915_irq_uninstall(struct drm_device * dev)
3739{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003740 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003741 int pipe;
3742
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003743 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003744
Chris Wilsona266c7d2012-04-24 22:59:44 +01003745 if (I915_HAS_HOTPLUG(dev)) {
3746 I915_WRITE(PORT_HOTPLUG_EN, 0);
3747 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3748 }
3749
Chris Wilson00d98eb2012-04-24 22:59:48 +01003750 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003751 for_each_pipe(pipe) {
3752 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003753 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003754 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3755 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003756 I915_WRITE(IMR, 0xffffffff);
3757 I915_WRITE(IER, 0x0);
3758
Chris Wilsona266c7d2012-04-24 22:59:44 +01003759 I915_WRITE(IIR, I915_READ(IIR));
3760}
3761
3762static void i965_irq_preinstall(struct drm_device * dev)
3763{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003764 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003765 int pipe;
3766
Chris Wilsonadca4732012-05-11 18:01:31 +01003767 I915_WRITE(PORT_HOTPLUG_EN, 0);
3768 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003769
3770 I915_WRITE(HWSTAM, 0xeffe);
3771 for_each_pipe(pipe)
3772 I915_WRITE(PIPESTAT(pipe), 0);
3773 I915_WRITE(IMR, 0xffffffff);
3774 I915_WRITE(IER, 0x0);
3775 POSTING_READ(IER);
3776}
3777
3778static int i965_irq_postinstall(struct drm_device *dev)
3779{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003780 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003781 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003782 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003783 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003784
Chris Wilsona266c7d2012-04-24 22:59:44 +01003785 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003786 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003787 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003788 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3789 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3790 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3791 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3792 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3793
3794 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003795 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3796 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003797 enable_mask |= I915_USER_INTERRUPT;
3798
3799 if (IS_G4X(dev))
3800 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003801
Daniel Vetterb79480b2013-06-27 17:52:10 +02003802 /* Interrupt setup is already guaranteed to be single-threaded, this is
3803 * just to make the assert_spin_locked check happy. */
3804 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003805 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3806 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3807 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003808 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003809
Chris Wilsona266c7d2012-04-24 22:59:44 +01003810 /*
3811 * Enable some error detection, note the instruction error mask
3812 * bit is reserved, so we leave it masked.
3813 */
3814 if (IS_G4X(dev)) {
3815 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3816 GM45_ERROR_MEM_PRIV |
3817 GM45_ERROR_CP_PRIV |
3818 I915_ERROR_MEMORY_REFRESH);
3819 } else {
3820 error_mask = ~(I915_ERROR_PAGE_TABLE |
3821 I915_ERROR_MEMORY_REFRESH);
3822 }
3823 I915_WRITE(EMR, error_mask);
3824
3825 I915_WRITE(IMR, dev_priv->irq_mask);
3826 I915_WRITE(IER, enable_mask);
3827 POSTING_READ(IER);
3828
Daniel Vetter20afbda2012-12-11 14:05:07 +01003829 I915_WRITE(PORT_HOTPLUG_EN, 0);
3830 POSTING_READ(PORT_HOTPLUG_EN);
3831
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003832 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003833
3834 return 0;
3835}
3836
Egbert Eichbac56d52013-02-25 12:06:51 -05003837static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003838{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003839 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003840 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003841 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003842 u32 hotplug_en;
3843
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003844 assert_spin_locked(&dev_priv->irq_lock);
3845
Egbert Eichbac56d52013-02-25 12:06:51 -05003846 if (I915_HAS_HOTPLUG(dev)) {
3847 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3848 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3849 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003850 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003851 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3852 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3853 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003854 /* Programming the CRT detection parameters tends
3855 to generate a spurious hotplug event about three
3856 seconds later. So just do it once.
3857 */
3858 if (IS_G4X(dev))
3859 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003860 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003861 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003862
Egbert Eichbac56d52013-02-25 12:06:51 -05003863 /* Ignore TV since it's buggy */
3864 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3865 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003866}
3867
Daniel Vetterff1f5252012-10-02 15:10:55 +02003868static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003869{
3870 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003871 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003872 u32 iir, new_iir;
3873 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003874 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003875 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003876 u32 flip_mask =
3877 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3878 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003879
Chris Wilsona266c7d2012-04-24 22:59:44 +01003880 iir = I915_READ(IIR);
3881
Chris Wilsona266c7d2012-04-24 22:59:44 +01003882 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003883 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003884 bool blc_event = false;
3885
Chris Wilsona266c7d2012-04-24 22:59:44 +01003886 /* Can't rely on pipestat interrupt bit in iir as it might
3887 * have been cleared after the pipestat interrupt was received.
3888 * It doesn't set the bit in iir again, but it still produces
3889 * interrupts (for non-MSI).
3890 */
3891 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3892 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003893 i915_handle_error(dev, false,
3894 "Command parser error, iir 0x%08x",
3895 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003896
3897 for_each_pipe(pipe) {
3898 int reg = PIPESTAT(pipe);
3899 pipe_stats[pipe] = I915_READ(reg);
3900
3901 /*
3902 * Clear the PIPE*STAT regs before the IIR
3903 */
3904 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003905 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003906 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003907 }
3908 }
3909 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3910
3911 if (!irq_received)
3912 break;
3913
3914 ret = IRQ_HANDLED;
3915
3916 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003917 if (iir & I915_DISPLAY_PORT_INTERRUPT)
3918 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003919
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003920 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003921 new_iir = I915_READ(IIR); /* Flush posted writes */
3922
Chris Wilsona266c7d2012-04-24 22:59:44 +01003923 if (iir & I915_USER_INTERRUPT)
3924 notify_ring(dev, &dev_priv->ring[RCS]);
3925 if (iir & I915_BSD_USER_INTERRUPT)
3926 notify_ring(dev, &dev_priv->ring[VCS]);
3927
Chris Wilsona266c7d2012-04-24 22:59:44 +01003928 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003929 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003930 i915_handle_vblank(dev, pipe, pipe, iir))
3931 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003932
3933 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3934 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003935
3936 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003937 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003938
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003939 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3940 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003941 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003942 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003943
3944 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3945 intel_opregion_asle_intr(dev);
3946
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003947 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3948 gmbus_irq_handler(dev);
3949
Chris Wilsona266c7d2012-04-24 22:59:44 +01003950 /* With MSI, interrupts are only generated when iir
3951 * transitions from zero to nonzero. If another bit got
3952 * set while we were handling the existing iir bits, then
3953 * we would never get another interrupt.
3954 *
3955 * This is fine on non-MSI as well, as if we hit this path
3956 * we avoid exiting the interrupt handler only to generate
3957 * another one.
3958 *
3959 * Note that for MSI this could cause a stray interrupt report
3960 * if an interrupt landed in the time between writing IIR and
3961 * the posting read. This should be rare enough to never
3962 * trigger the 99% of 100,000 interrupts test for disabling
3963 * stray interrupts.
3964 */
3965 iir = new_iir;
3966 }
3967
Daniel Vetterd05c6172012-04-26 23:28:09 +02003968 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003969
Chris Wilsona266c7d2012-04-24 22:59:44 +01003970 return ret;
3971}
3972
3973static void i965_irq_uninstall(struct drm_device * dev)
3974{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003975 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003976 int pipe;
3977
3978 if (!dev_priv)
3979 return;
3980
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003981 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003982
Chris Wilsonadca4732012-05-11 18:01:31 +01003983 I915_WRITE(PORT_HOTPLUG_EN, 0);
3984 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003985
3986 I915_WRITE(HWSTAM, 0xffffffff);
3987 for_each_pipe(pipe)
3988 I915_WRITE(PIPESTAT(pipe), 0);
3989 I915_WRITE(IMR, 0xffffffff);
3990 I915_WRITE(IER, 0x0);
3991
3992 for_each_pipe(pipe)
3993 I915_WRITE(PIPESTAT(pipe),
3994 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3995 I915_WRITE(IIR, I915_READ(IIR));
3996}
3997
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003998static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02003999{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004000 struct drm_i915_private *dev_priv = (struct drm_i915_private *)data;
Egbert Eichac4c16c2013-04-16 13:36:58 +02004001 struct drm_device *dev = dev_priv->dev;
4002 struct drm_mode_config *mode_config = &dev->mode_config;
4003 unsigned long irqflags;
4004 int i;
4005
4006 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4007 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4008 struct drm_connector *connector;
4009
4010 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4011 continue;
4012
4013 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4014
4015 list_for_each_entry(connector, &mode_config->connector_list, head) {
4016 struct intel_connector *intel_connector = to_intel_connector(connector);
4017
4018 if (intel_connector->encoder->hpd_pin == i) {
4019 if (connector->polled != intel_connector->polled)
4020 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
4021 drm_get_connector_name(connector));
4022 connector->polled = intel_connector->polled;
4023 if (!connector->polled)
4024 connector->polled = DRM_CONNECTOR_POLL_HPD;
4025 }
4026 }
4027 }
4028 if (dev_priv->display.hpd_irq_setup)
4029 dev_priv->display.hpd_irq_setup(dev);
4030 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4031}
4032
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004033void intel_irq_init(struct drm_device *dev)
4034{
Chris Wilson8b2e3262012-04-24 22:59:41 +01004035 struct drm_i915_private *dev_priv = dev->dev_private;
4036
4037 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004038 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004039 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004040 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004041
Deepak Sa6706b42014-03-15 20:23:22 +05304042 /* Let's track the enabled rps events */
4043 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
4044
Daniel Vetter99584db2012-11-14 17:14:04 +01004045 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4046 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004047 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004048 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02004049 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01004050
Tomas Janousek97a19a22012-12-08 13:48:13 +01004051 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004052
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004053 if (IS_GEN2(dev)) {
4054 dev->max_vblank_count = 0;
4055 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4056 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004057 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4058 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004059 } else {
4060 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4061 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004062 }
4063
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004064 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004065 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004066 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4067 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004068
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004069 if (IS_VALLEYVIEW(dev)) {
4070 dev->driver->irq_handler = valleyview_irq_handler;
4071 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4072 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4073 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4074 dev->driver->enable_vblank = valleyview_enable_vblank;
4075 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004076 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004077 } else if (IS_GEN8(dev)) {
4078 dev->driver->irq_handler = gen8_irq_handler;
4079 dev->driver->irq_preinstall = gen8_irq_preinstall;
4080 dev->driver->irq_postinstall = gen8_irq_postinstall;
4081 dev->driver->irq_uninstall = gen8_irq_uninstall;
4082 dev->driver->enable_vblank = gen8_enable_vblank;
4083 dev->driver->disable_vblank = gen8_disable_vblank;
4084 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004085 } else if (HAS_PCH_SPLIT(dev)) {
4086 dev->driver->irq_handler = ironlake_irq_handler;
4087 dev->driver->irq_preinstall = ironlake_irq_preinstall;
4088 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4089 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4090 dev->driver->enable_vblank = ironlake_enable_vblank;
4091 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004092 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004093 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004094 if (INTEL_INFO(dev)->gen == 2) {
4095 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4096 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4097 dev->driver->irq_handler = i8xx_irq_handler;
4098 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004099 } else if (INTEL_INFO(dev)->gen == 3) {
4100 dev->driver->irq_preinstall = i915_irq_preinstall;
4101 dev->driver->irq_postinstall = i915_irq_postinstall;
4102 dev->driver->irq_uninstall = i915_irq_uninstall;
4103 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004104 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004105 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004106 dev->driver->irq_preinstall = i965_irq_preinstall;
4107 dev->driver->irq_postinstall = i965_irq_postinstall;
4108 dev->driver->irq_uninstall = i965_irq_uninstall;
4109 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004110 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004111 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004112 dev->driver->enable_vblank = i915_enable_vblank;
4113 dev->driver->disable_vblank = i915_disable_vblank;
4114 }
4115}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004116
4117void intel_hpd_init(struct drm_device *dev)
4118{
4119 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02004120 struct drm_mode_config *mode_config = &dev->mode_config;
4121 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004122 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02004123 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004124
Egbert Eich821450c2013-04-16 13:36:55 +02004125 for (i = 1; i < HPD_NUM_PINS; i++) {
4126 dev_priv->hpd_stats[i].hpd_cnt = 0;
4127 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4128 }
4129 list_for_each_entry(connector, &mode_config->connector_list, head) {
4130 struct intel_connector *intel_connector = to_intel_connector(connector);
4131 connector->polled = intel_connector->polled;
4132 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4133 connector->polled = DRM_CONNECTOR_POLL_HPD;
4134 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004135
4136 /* Interrupt setup is already guaranteed to be single-threaded, this is
4137 * just to make the assert_spin_locked checks happy. */
4138 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004139 if (dev_priv->display.hpd_irq_setup)
4140 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004141 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004142}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004143
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004144/* Disable interrupts so we can allow runtime PM. */
4145void hsw_runtime_pm_disable_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004146{
4147 struct drm_i915_private *dev_priv = dev->dev_private;
4148 unsigned long irqflags;
4149
4150 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4151
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004152 dev_priv->pm.regsave.deimr = I915_READ(DEIMR);
4153 dev_priv->pm.regsave.sdeimr = I915_READ(SDEIMR);
4154 dev_priv->pm.regsave.gtimr = I915_READ(GTIMR);
4155 dev_priv->pm.regsave.gtier = I915_READ(GTIER);
4156 dev_priv->pm.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004157
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004158 ironlake_disable_display_irq(dev_priv, 0xffffffff);
4159 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004160 ilk_disable_gt_irq(dev_priv, 0xffffffff);
4161 snb_disable_pm_irq(dev_priv, 0xffffffff);
4162
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004163 dev_priv->pm.irqs_disabled = true;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004164
4165 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4166}
4167
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004168/* Restore interrupts so we can recover from runtime PM. */
4169void hsw_runtime_pm_restore_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004170{
4171 struct drm_i915_private *dev_priv = dev->dev_private;
4172 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004173 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004174
4175 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4176
4177 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004178 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004179
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004180 val = I915_READ(SDEIMR);
4181 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004182
4183 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004184 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004185
4186 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004187 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004188
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004189 dev_priv->pm.irqs_disabled = false;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004190
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004191 ironlake_enable_display_irq(dev_priv, ~dev_priv->pm.regsave.deimr);
4192 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pm.regsave.sdeimr);
4193 ilk_enable_gt_irq(dev_priv, ~dev_priv->pm.regsave.gtimr);
4194 snb_enable_pm_irq(dev_priv, ~dev_priv->pm.regsave.gen6_pmimr);
4195 I915_WRITE(GTIER, dev_priv->pm.regsave.gtier);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004196
4197 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4198}