blob: f487068e8f5a2ecdfda6d9956367f879b2f99288 [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 Zanonia9d356a2014-04-01 15:37:09 -030083#define GEN5_IRQ_INIT(type) do { \
84 I915_WRITE(type##IMR, 0xffffffff); \
85 I915_WRITE(type##IER, 0); \
86 POSTING_READ(type##IER); \
87} while (0)
88
Zhenyu Wang036a4a72009-06-08 14:40:19 +080089/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010090static void
Jani Nikula2d1013d2014-03-31 14:27:17 +030091ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080092{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020093 assert_spin_locked(&dev_priv->irq_lock);
94
Paulo Zanoni5d584b22014-03-07 20:08:15 -030095 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -030096 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -030097 dev_priv->pm.regsave.deimr &= ~mask;
Paulo Zanonic67a4702013-08-19 13:18:09 -030098 return;
99 }
100
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000101 if ((dev_priv->irq_mask & mask) != 0) {
102 dev_priv->irq_mask &= ~mask;
103 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000104 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800105 }
106}
107
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300108static void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300109ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800110{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200111 assert_spin_locked(&dev_priv->irq_lock);
112
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300113 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300114 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300115 dev_priv->pm.regsave.deimr |= mask;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300116 return;
117 }
118
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000119 if ((dev_priv->irq_mask & mask) != mask) {
120 dev_priv->irq_mask |= mask;
121 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000122 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800123 }
124}
125
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300126/**
127 * ilk_update_gt_irq - update GTIMR
128 * @dev_priv: driver private
129 * @interrupt_mask: mask of interrupt bits to update
130 * @enabled_irq_mask: mask of interrupt bits to enable
131 */
132static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
133 uint32_t interrupt_mask,
134 uint32_t enabled_irq_mask)
135{
136 assert_spin_locked(&dev_priv->irq_lock);
137
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300138 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300139 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300140 dev_priv->pm.regsave.gtimr &= ~interrupt_mask;
141 dev_priv->pm.regsave.gtimr |= (~enabled_irq_mask &
Paulo Zanonic67a4702013-08-19 13:18:09 -0300142 interrupt_mask);
143 return;
144 }
145
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300146 dev_priv->gt_irq_mask &= ~interrupt_mask;
147 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
148 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
149 POSTING_READ(GTIMR);
150}
151
152void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
153{
154 ilk_update_gt_irq(dev_priv, mask, mask);
155}
156
157void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
158{
159 ilk_update_gt_irq(dev_priv, mask, 0);
160}
161
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300162/**
163 * snb_update_pm_irq - update GEN6_PMIMR
164 * @dev_priv: driver private
165 * @interrupt_mask: mask of interrupt bits to update
166 * @enabled_irq_mask: mask of interrupt bits to enable
167 */
168static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
169 uint32_t interrupt_mask,
170 uint32_t enabled_irq_mask)
171{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300172 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300173
174 assert_spin_locked(&dev_priv->irq_lock);
175
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300176 if (dev_priv->pm.irqs_disabled) {
Paulo Zanonic67a4702013-08-19 13:18:09 -0300177 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300178 dev_priv->pm.regsave.gen6_pmimr &= ~interrupt_mask;
179 dev_priv->pm.regsave.gen6_pmimr |= (~enabled_irq_mask &
Paulo Zanonic67a4702013-08-19 13:18:09 -0300180 interrupt_mask);
181 return;
182 }
183
Paulo Zanoni605cd252013-08-06 18:57:15 -0300184 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300185 new_val &= ~interrupt_mask;
186 new_val |= (~enabled_irq_mask & interrupt_mask);
187
Paulo Zanoni605cd252013-08-06 18:57:15 -0300188 if (new_val != dev_priv->pm_irq_mask) {
189 dev_priv->pm_irq_mask = new_val;
190 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300191 POSTING_READ(GEN6_PMIMR);
192 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300193}
194
195void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
196{
197 snb_update_pm_irq(dev_priv, mask, mask);
198}
199
200void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
201{
202 snb_update_pm_irq(dev_priv, mask, 0);
203}
204
Paulo Zanoni86642812013-04-12 17:57:57 -0300205static bool ivb_can_enable_err_int(struct drm_device *dev)
206{
207 struct drm_i915_private *dev_priv = dev->dev_private;
208 struct intel_crtc *crtc;
209 enum pipe pipe;
210
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200211 assert_spin_locked(&dev_priv->irq_lock);
212
Paulo Zanoni86642812013-04-12 17:57:57 -0300213 for_each_pipe(pipe) {
214 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
215
216 if (crtc->cpu_fifo_underrun_disabled)
217 return false;
218 }
219
220 return true;
221}
222
223static bool cpt_can_enable_serr_int(struct drm_device *dev)
224{
225 struct drm_i915_private *dev_priv = dev->dev_private;
226 enum pipe pipe;
227 struct intel_crtc *crtc;
228
Daniel Vetterfee884e2013-07-04 23:35:21 +0200229 assert_spin_locked(&dev_priv->irq_lock);
230
Paulo Zanoni86642812013-04-12 17:57:57 -0300231 for_each_pipe(pipe) {
232 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
233
234 if (crtc->pch_fifo_underrun_disabled)
235 return false;
236 }
237
238 return true;
239}
240
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200241static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
242{
243 struct drm_i915_private *dev_priv = dev->dev_private;
244 u32 reg = PIPESTAT(pipe);
245 u32 pipestat = I915_READ(reg) & 0x7fff0000;
246
247 assert_spin_locked(&dev_priv->irq_lock);
248
249 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
250 POSTING_READ(reg);
251}
252
Paulo Zanoni86642812013-04-12 17:57:57 -0300253static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
254 enum pipe pipe, bool enable)
255{
256 struct drm_i915_private *dev_priv = dev->dev_private;
257 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
258 DE_PIPEB_FIFO_UNDERRUN;
259
260 if (enable)
261 ironlake_enable_display_irq(dev_priv, bit);
262 else
263 ironlake_disable_display_irq(dev_priv, bit);
264}
265
266static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200267 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300268{
269 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200271 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
272
Paulo Zanoni86642812013-04-12 17:57:57 -0300273 if (!ivb_can_enable_err_int(dev))
274 return;
275
Paulo Zanoni86642812013-04-12 17:57:57 -0300276 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
277 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200278 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
279
280 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300281 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200282
283 if (!was_enabled &&
284 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
285 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
286 pipe_name(pipe));
287 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300288 }
289}
290
Daniel Vetter38d83c962013-11-07 11:05:46 +0100291static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
292 enum pipe pipe, bool enable)
293{
294 struct drm_i915_private *dev_priv = dev->dev_private;
295
296 assert_spin_locked(&dev_priv->irq_lock);
297
298 if (enable)
299 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
300 else
301 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
302 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
303 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
304}
305
Daniel Vetterfee884e2013-07-04 23:35:21 +0200306/**
307 * ibx_display_interrupt_update - update SDEIMR
308 * @dev_priv: driver private
309 * @interrupt_mask: mask of interrupt bits to update
310 * @enabled_irq_mask: mask of interrupt bits to enable
311 */
312static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
313 uint32_t interrupt_mask,
314 uint32_t enabled_irq_mask)
315{
316 uint32_t sdeimr = I915_READ(SDEIMR);
317 sdeimr &= ~interrupt_mask;
318 sdeimr |= (~enabled_irq_mask & interrupt_mask);
319
320 assert_spin_locked(&dev_priv->irq_lock);
321
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300322 if (dev_priv->pm.irqs_disabled &&
Paulo Zanonic67a4702013-08-19 13:18:09 -0300323 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
324 WARN(1, "IRQs disabled\n");
Paulo Zanoni5d584b22014-03-07 20:08:15 -0300325 dev_priv->pm.regsave.sdeimr &= ~interrupt_mask;
326 dev_priv->pm.regsave.sdeimr |= (~enabled_irq_mask &
Paulo Zanonic67a4702013-08-19 13:18:09 -0300327 interrupt_mask);
328 return;
329 }
330
Daniel Vetterfee884e2013-07-04 23:35:21 +0200331 I915_WRITE(SDEIMR, sdeimr);
332 POSTING_READ(SDEIMR);
333}
334#define ibx_enable_display_interrupt(dev_priv, bits) \
335 ibx_display_interrupt_update((dev_priv), (bits), (bits))
336#define ibx_disable_display_interrupt(dev_priv, bits) \
337 ibx_display_interrupt_update((dev_priv), (bits), 0)
338
Daniel Vetterde280752013-07-04 23:35:24 +0200339static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
340 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300341 bool enable)
342{
Paulo Zanoni86642812013-04-12 17:57:57 -0300343 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200344 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
345 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300346
347 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200348 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300349 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200350 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300351}
352
353static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
354 enum transcoder pch_transcoder,
355 bool enable)
356{
357 struct drm_i915_private *dev_priv = dev->dev_private;
358
359 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200360 I915_WRITE(SERR_INT,
361 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
362
Paulo Zanoni86642812013-04-12 17:57:57 -0300363 if (!cpt_can_enable_serr_int(dev))
364 return;
365
Daniel Vetterfee884e2013-07-04 23:35:21 +0200366 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300367 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200368 uint32_t tmp = I915_READ(SERR_INT);
369 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
370
371 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200372 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200373
374 if (!was_enabled &&
375 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
376 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
377 transcoder_name(pch_transcoder));
378 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300379 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300380}
381
382/**
383 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
384 * @dev: drm device
385 * @pipe: pipe
386 * @enable: true if we want to report FIFO underrun errors, false otherwise
387 *
388 * This function makes us disable or enable CPU fifo underruns for a specific
389 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
390 * reporting for one pipe may also disable all the other CPU error interruts for
391 * the other pipes, due to the fact that there's just one interrupt mask/enable
392 * bit for all the pipes.
393 *
394 * Returns the previous state of underrun reporting.
395 */
Imre Deakf88d42f2014-03-04 19:23:09 +0200396bool __intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
397 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300398{
399 struct drm_i915_private *dev_priv = dev->dev_private;
400 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
401 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300402 bool ret;
403
Imre Deak77961eb2014-03-05 16:20:56 +0200404 assert_spin_locked(&dev_priv->irq_lock);
405
Paulo Zanoni86642812013-04-12 17:57:57 -0300406 ret = !intel_crtc->cpu_fifo_underrun_disabled;
407
408 if (enable == ret)
409 goto done;
410
411 intel_crtc->cpu_fifo_underrun_disabled = !enable;
412
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200413 if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
414 i9xx_clear_fifo_underrun(dev, pipe);
415 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300416 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
417 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200418 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100419 else if (IS_GEN8(dev))
420 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300421
422done:
Imre Deakf88d42f2014-03-04 19:23:09 +0200423 return ret;
424}
425
426bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
427 enum pipe pipe, bool enable)
428{
429 struct drm_i915_private *dev_priv = dev->dev_private;
430 unsigned long flags;
431 bool ret;
432
433 spin_lock_irqsave(&dev_priv->irq_lock, flags);
434 ret = __intel_set_cpu_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300435 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
Imre Deakf88d42f2014-03-04 19:23:09 +0200436
Paulo Zanoni86642812013-04-12 17:57:57 -0300437 return ret;
438}
439
Imre Deak91d181d2014-02-10 18:42:49 +0200440static bool __cpu_fifo_underrun_reporting_enabled(struct drm_device *dev,
441 enum pipe pipe)
442{
443 struct drm_i915_private *dev_priv = dev->dev_private;
444 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
445 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
446
447 return !intel_crtc->cpu_fifo_underrun_disabled;
448}
449
Paulo Zanoni86642812013-04-12 17:57:57 -0300450/**
451 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
452 * @dev: drm device
453 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
454 * @enable: true if we want to report FIFO underrun errors, false otherwise
455 *
456 * This function makes us disable or enable PCH fifo underruns for a specific
457 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
458 * underrun reporting for one transcoder may also disable all the other PCH
459 * error interruts for the other transcoders, due to the fact that there's just
460 * one interrupt mask/enable bit for all the transcoders.
461 *
462 * Returns the previous state of underrun reporting.
463 */
464bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
465 enum transcoder pch_transcoder,
466 bool enable)
467{
468 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200469 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
470 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300471 unsigned long flags;
472 bool ret;
473
Daniel Vetterde280752013-07-04 23:35:24 +0200474 /*
475 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
476 * has only one pch transcoder A that all pipes can use. To avoid racy
477 * pch transcoder -> pipe lookups from interrupt code simply store the
478 * underrun statistics in crtc A. Since we never expose this anywhere
479 * nor use it outside of the fifo underrun code here using the "wrong"
480 * crtc on LPT won't cause issues.
481 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300482
483 spin_lock_irqsave(&dev_priv->irq_lock, flags);
484
485 ret = !intel_crtc->pch_fifo_underrun_disabled;
486
487 if (enable == ret)
488 goto done;
489
490 intel_crtc->pch_fifo_underrun_disabled = !enable;
491
492 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200493 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300494 else
495 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
496
497done:
498 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
499 return ret;
500}
501
502
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100503static void
Imre Deak755e9012014-02-10 18:42:47 +0200504__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
505 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800506{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200507 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200508 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800509
Daniel Vetterb79480b2013-06-27 17:52:10 +0200510 assert_spin_locked(&dev_priv->irq_lock);
511
Imre Deak755e9012014-02-10 18:42:47 +0200512 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
513 status_mask & ~PIPESTAT_INT_STATUS_MASK))
514 return;
515
516 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200517 return;
518
Imre Deak91d181d2014-02-10 18:42:49 +0200519 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
520
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200521 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200522 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200523 I915_WRITE(reg, pipestat);
524 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800525}
526
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100527static void
Imre Deak755e9012014-02-10 18:42:47 +0200528__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
529 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800530{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200531 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200532 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800533
Daniel Vetterb79480b2013-06-27 17:52:10 +0200534 assert_spin_locked(&dev_priv->irq_lock);
535
Imre Deak755e9012014-02-10 18:42:47 +0200536 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
537 status_mask & ~PIPESTAT_INT_STATUS_MASK))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200538 return;
539
Imre Deak755e9012014-02-10 18:42:47 +0200540 if ((pipestat & enable_mask) == 0)
541 return;
542
Imre Deak91d181d2014-02-10 18:42:49 +0200543 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
544
Imre Deak755e9012014-02-10 18:42:47 +0200545 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200546 I915_WRITE(reg, pipestat);
547 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800548}
549
Imre Deak10c59c52014-02-10 18:42:48 +0200550static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
551{
552 u32 enable_mask = status_mask << 16;
553
554 /*
555 * On pipe A we don't support the PSR interrupt yet, on pipe B the
556 * same bit MBZ.
557 */
558 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
559 return 0;
560
561 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
562 SPRITE0_FLIP_DONE_INT_EN_VLV |
563 SPRITE1_FLIP_DONE_INT_EN_VLV);
564 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
565 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
566 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
567 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
568
569 return enable_mask;
570}
571
Imre Deak755e9012014-02-10 18:42:47 +0200572void
573i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
574 u32 status_mask)
575{
576 u32 enable_mask;
577
Imre Deak10c59c52014-02-10 18:42:48 +0200578 if (IS_VALLEYVIEW(dev_priv->dev))
579 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
580 status_mask);
581 else
582 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200583 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
584}
585
586void
587i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
588 u32 status_mask)
589{
590 u32 enable_mask;
591
Imre Deak10c59c52014-02-10 18:42:48 +0200592 if (IS_VALLEYVIEW(dev_priv->dev))
593 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
594 status_mask);
595 else
596 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200597 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
598}
599
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000600/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300601 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000602 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300603static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000604{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300605 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000606 unsigned long irqflags;
607
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300608 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
609 return;
610
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000611 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000612
Imre Deak755e9012014-02-10 18:42:47 +0200613 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300614 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200615 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200616 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000617
618 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000619}
620
621/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700622 * i915_pipe_enabled - check if a pipe is enabled
623 * @dev: DRM device
624 * @pipe: pipe to check
625 *
626 * Reading certain registers when the pipe is disabled can hang the chip.
627 * Use this routine to make sure the PLL is running and the pipe is active
628 * before reading such registers if unsure.
629 */
630static int
631i915_pipe_enabled(struct drm_device *dev, int pipe)
632{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300633 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200634
Daniel Vettera01025a2013-05-22 00:50:23 +0200635 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
636 /* Locking is horribly broken here, but whatever. */
637 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
638 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300639
Daniel Vettera01025a2013-05-22 00:50:23 +0200640 return intel_crtc->active;
641 } else {
642 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
643 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700644}
645
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300646static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
647{
648 /* Gen2 doesn't have a hardware frame counter */
649 return 0;
650}
651
Keith Packard42f52ef2008-10-18 19:39:29 -0700652/* Called from drm generic code, passed a 'crtc', which
653 * we use as a pipe index
654 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700655static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700656{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300657 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700658 unsigned long high_frame;
659 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300660 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700661
662 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800663 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800664 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700665 return 0;
666 }
667
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300668 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
669 struct intel_crtc *intel_crtc =
670 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
671 const struct drm_display_mode *mode =
672 &intel_crtc->config.adjusted_mode;
673
674 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
675 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100676 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300677 u32 htotal;
678
679 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
680 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
681
682 vbl_start *= htotal;
683 }
684
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800685 high_frame = PIPEFRAME(pipe);
686 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100687
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700688 /*
689 * High & low register fields aren't synchronized, so make sure
690 * we get a low value that's stable across two reads of the high
691 * register.
692 */
693 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100694 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300695 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100696 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700697 } while (high1 != high2);
698
Chris Wilson5eddb702010-09-11 13:48:45 +0100699 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300700 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100701 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300702
703 /*
704 * The frame counter increments at beginning of active.
705 * Cook up a vblank counter by also checking the pixel
706 * counter against vblank start.
707 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200708 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700709}
710
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700711static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800712{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300713 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800714 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800715
716 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800717 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800718 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800719 return 0;
720 }
721
722 return I915_READ(reg);
723}
724
Mario Kleinerad3543e2013-10-30 05:13:08 +0100725/* raw reads, only for fast reads of display block, no need for forcewake etc. */
726#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100727
Ville Syrjälä095163b2013-10-29 00:04:43 +0200728static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300729{
730 struct drm_i915_private *dev_priv = dev->dev_private;
731 uint32_t status;
Ville Syrjälä24302622014-03-11 12:58:46 +0200732 int reg;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300733
Ville Syrjälä24302622014-03-11 12:58:46 +0200734 if (INTEL_INFO(dev)->gen >= 8) {
735 status = GEN8_PIPE_VBLANK;
736 reg = GEN8_DE_PIPE_ISR(pipe);
737 } else if (INTEL_INFO(dev)->gen >= 7) {
738 status = DE_PIPE_VBLANK_IVB(pipe);
739 reg = DEISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300740 } else {
Ville Syrjälä24302622014-03-11 12:58:46 +0200741 status = DE_PIPE_VBLANK(pipe);
742 reg = DEISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300743 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100744
Ville Syrjälä24302622014-03-11 12:58:46 +0200745 return __raw_i915_read32(dev_priv, reg) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300746}
747
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700748static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200749 unsigned int flags, int *vpos, int *hpos,
750 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100751{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300752 struct drm_i915_private *dev_priv = dev->dev_private;
753 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
754 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
755 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300756 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100757 int vbl_start, vbl_end, htotal, vtotal;
758 bool in_vbl = true;
759 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100760 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100761
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300762 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100763 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800764 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100765 return 0;
766 }
767
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300768 htotal = mode->crtc_htotal;
769 vtotal = mode->crtc_vtotal;
770 vbl_start = mode->crtc_vblank_start;
771 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100772
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200773 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
774 vbl_start = DIV_ROUND_UP(vbl_start, 2);
775 vbl_end /= 2;
776 vtotal /= 2;
777 }
778
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300779 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
780
Mario Kleinerad3543e2013-10-30 05:13:08 +0100781 /*
782 * Lock uncore.lock, as we will do multiple timing critical raw
783 * register reads, potentially with preemption disabled, so the
784 * following code must not block on uncore.lock.
785 */
786 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
787
788 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
789
790 /* Get optional system timestamp before query. */
791 if (stime)
792 *stime = ktime_get();
793
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300794 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100795 /* No obvious pixelcount register. Only query vertical
796 * scanout position from Display scan line register.
797 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300798 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100799 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300800 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100801 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300802
Ville Syrjäläfcb81822014-03-11 12:58:45 +0200803 if (HAS_DDI(dev)) {
804 /*
805 * On HSW HDMI outputs there seems to be a 2 line
806 * difference, whereas eDP has the normal 1 line
807 * difference that earlier platforms have. External
808 * DP is unknown. For now just check for the 2 line
809 * difference case on all output types on HSW+.
810 *
811 * This might misinterpret the scanline counter being
812 * one line too far along on eDP, but that's less
813 * dangerous than the alternative since that would lead
814 * the vblank timestamp code astray when it sees a
815 * scanline count before vblank_start during a vblank
816 * interrupt.
817 */
818 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
819 if ((in_vbl && (position == vbl_start - 2 ||
820 position == vbl_start - 1)) ||
821 (!in_vbl && (position == vbl_end - 2 ||
822 position == vbl_end - 1)))
823 position = (position + 2) % vtotal;
824 } else if (HAS_PCH_SPLIT(dev)) {
Ville Syrjälä095163b2013-10-29 00:04:43 +0200825 /*
826 * The scanline counter increments at the leading edge
827 * of hsync, ie. it completely misses the active portion
828 * of the line. Fix up the counter at both edges of vblank
829 * to get a more accurate picture whether we're in vblank
830 * or not.
831 */
832 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
833 if ((in_vbl && position == vbl_start - 1) ||
834 (!in_vbl && position == vbl_end - 1))
835 position = (position + 1) % vtotal;
836 } else {
837 /*
838 * ISR vblank status bits don't work the way we'd want
839 * them to work on non-PCH platforms (for
840 * ilk_pipe_in_vblank_locked()), and there doesn't
841 * appear any other way to determine if we're currently
842 * in vblank.
843 *
844 * Instead let's assume that we're already in vblank if
845 * we got called from the vblank interrupt and the
846 * scanline counter value indicates that we're on the
847 * line just prior to vblank start. This should result
848 * in the correct answer, unless the vblank interrupt
849 * delivery really got delayed for almost exactly one
850 * full frame/field.
851 */
852 if (flags & DRM_CALLED_FROM_VBLIRQ &&
853 position == vbl_start - 1) {
854 position = (position + 1) % vtotal;
855
856 /* Signal this correction as "applied". */
857 ret |= 0x8;
858 }
859 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100860 } else {
861 /* Have access to pixelcount since start of frame.
862 * We can split this into vertical and horizontal
863 * scanout position.
864 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100865 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100866
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300867 /* convert to pixel counts */
868 vbl_start *= htotal;
869 vbl_end *= htotal;
870 vtotal *= htotal;
871 }
872
Mario Kleinerad3543e2013-10-30 05:13:08 +0100873 /* Get optional system timestamp after query. */
874 if (etime)
875 *etime = ktime_get();
876
877 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
878
879 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
880
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300881 in_vbl = position >= vbl_start && position < vbl_end;
882
883 /*
884 * While in vblank, position will be negative
885 * counting up towards 0 at vbl_end. And outside
886 * vblank, position will be positive counting
887 * up since vbl_end.
888 */
889 if (position >= vbl_start)
890 position -= vbl_end;
891 else
892 position += vtotal - vbl_end;
893
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300894 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300895 *vpos = position;
896 *hpos = 0;
897 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100898 *vpos = position / htotal;
899 *hpos = position - (*vpos * htotal);
900 }
901
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100902 /* In vblank? */
903 if (in_vbl)
904 ret |= DRM_SCANOUTPOS_INVBL;
905
906 return ret;
907}
908
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700909static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100910 int *max_error,
911 struct timeval *vblank_time,
912 unsigned flags)
913{
Chris Wilson4041b852011-01-22 10:07:56 +0000914 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100915
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700916 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000917 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100918 return -EINVAL;
919 }
920
921 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000922 crtc = intel_get_crtc_for_pipe(dev, pipe);
923 if (crtc == NULL) {
924 DRM_ERROR("Invalid crtc %d\n", pipe);
925 return -EINVAL;
926 }
927
928 if (!crtc->enabled) {
929 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
930 return -EBUSY;
931 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100932
933 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000934 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
935 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300936 crtc,
937 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100938}
939
Jani Nikula67c347f2013-09-17 14:26:34 +0300940static bool intel_hpd_irq_event(struct drm_device *dev,
941 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200942{
943 enum drm_connector_status old_status;
944
945 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
946 old_status = connector->status;
947
948 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300949 if (old_status == connector->status)
950 return false;
951
952 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200953 connector->base.id,
954 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300955 drm_get_connector_status_name(old_status),
956 drm_get_connector_status_name(connector->status));
957
958 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200959}
960
Jesse Barnes5ca58282009-03-31 14:11:15 -0700961/*
962 * Handle hotplug events outside the interrupt handler proper.
963 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200964#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
965
Jesse Barnes5ca58282009-03-31 14:11:15 -0700966static void i915_hotplug_work_func(struct work_struct *work)
967{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300968 struct drm_i915_private *dev_priv =
969 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700970 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700971 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200972 struct intel_connector *intel_connector;
973 struct intel_encoder *intel_encoder;
974 struct drm_connector *connector;
975 unsigned long irqflags;
976 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200977 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200978 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700979
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100980 /* HPD irq before everything is fully set up. */
981 if (!dev_priv->enable_hotplug_processing)
982 return;
983
Keith Packarda65e34c2011-07-25 10:04:56 -0700984 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800985 DRM_DEBUG_KMS("running encoder hotplug functions\n");
986
Egbert Eichcd569ae2013-04-16 13:36:57 +0200987 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200988
989 hpd_event_bits = dev_priv->hpd_event_bits;
990 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200991 list_for_each_entry(connector, &mode_config->connector_list, head) {
992 intel_connector = to_intel_connector(connector);
993 intel_encoder = intel_connector->encoder;
994 if (intel_encoder->hpd_pin > HPD_NONE &&
995 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
996 connector->polled == DRM_CONNECTOR_POLL_HPD) {
997 DRM_INFO("HPD interrupt storm detected on connector %s: "
998 "switching from hotplug detection to polling\n",
999 drm_get_connector_name(connector));
1000 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
1001 connector->polled = DRM_CONNECTOR_POLL_CONNECT
1002 | DRM_CONNECTOR_POLL_DISCONNECT;
1003 hpd_disabled = true;
1004 }
Egbert Eich142e2392013-04-11 15:57:57 +02001005 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1006 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
1007 drm_get_connector_name(connector), intel_encoder->hpd_pin);
1008 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001009 }
1010 /* if there were no outputs to poll, poll was disabled,
1011 * therefore make sure it's enabled when disabling HPD on
1012 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +02001013 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +02001014 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02001015 mod_timer(&dev_priv->hotplug_reenable_timer,
1016 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
1017 }
Egbert Eichcd569ae2013-04-16 13:36:57 +02001018
1019 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1020
Egbert Eich321a1b32013-04-11 16:00:26 +02001021 list_for_each_entry(connector, &mode_config->connector_list, head) {
1022 intel_connector = to_intel_connector(connector);
1023 intel_encoder = intel_connector->encoder;
1024 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
1025 if (intel_encoder->hot_plug)
1026 intel_encoder->hot_plug(intel_encoder);
1027 if (intel_hpd_irq_event(dev, connector))
1028 changed = true;
1029 }
1030 }
Keith Packard40ee3382011-07-28 15:31:19 -07001031 mutex_unlock(&mode_config->mutex);
1032
Egbert Eich321a1b32013-04-11 16:00:26 +02001033 if (changed)
1034 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -07001035}
1036
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02001037static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
1038{
1039 del_timer_sync(&dev_priv->hotplug_reenable_timer);
1040}
1041
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001042static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001043{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001044 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001045 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001046 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001047
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001048 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001049
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001050 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1051
Daniel Vetter20e4d402012-08-08 23:35:39 +02001052 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001053
Jesse Barnes7648fa92010-05-20 14:28:11 -07001054 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001055 busy_up = I915_READ(RCPREVBSYTUPAVG);
1056 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001057 max_avg = I915_READ(RCBMAXAVG);
1058 min_avg = I915_READ(RCBMINAVG);
1059
1060 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001061 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001062 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1063 new_delay = dev_priv->ips.cur_delay - 1;
1064 if (new_delay < dev_priv->ips.max_delay)
1065 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001066 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001067 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1068 new_delay = dev_priv->ips.cur_delay + 1;
1069 if (new_delay > dev_priv->ips.min_delay)
1070 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001071 }
1072
Jesse Barnes7648fa92010-05-20 14:28:11 -07001073 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001074 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001075
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001076 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001077
Jesse Barnesf97108d2010-01-29 11:27:07 -08001078 return;
1079}
1080
Chris Wilson549f7362010-10-19 11:19:32 +01001081static void notify_ring(struct drm_device *dev,
1082 struct intel_ring_buffer *ring)
1083{
Chris Wilson475553d2011-01-20 09:52:56 +00001084 if (ring->obj == NULL)
1085 return;
1086
Chris Wilson814e9b52013-09-23 17:33:19 -03001087 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001088
Chris Wilson549f7362010-10-19 11:19:32 +01001089 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001090 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001091}
1092
Ben Widawsky4912d042011-04-25 11:25:20 -07001093static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001094{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001095 struct drm_i915_private *dev_priv =
1096 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001097 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001098 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001099
Daniel Vetter59cdb632013-07-04 23:35:28 +02001100 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001101 pm_iir = dev_priv->rps.pm_iir;
1102 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -07001103 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Deepak Sa6706b42014-03-15 20:23:22 +05301104 snb_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001105 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001106
Paulo Zanoni60611c12013-08-15 11:50:01 -03001107 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301108 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001109
Deepak Sa6706b42014-03-15 20:23:22 +05301110 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001111 return;
1112
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001113 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001114
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001115 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001116 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001117 if (adj > 0)
1118 adj *= 2;
1119 else
1120 adj = 1;
Ben Widawskyb39fb292014-03-19 18:31:11 -07001121 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001122
1123 /*
1124 * For better performance, jump directly
1125 * to RPe if we're below it.
1126 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001127 if (new_delay < dev_priv->rps.efficient_freq)
1128 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001129 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001130 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1131 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001132 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001133 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001134 adj = 0;
1135 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1136 if (adj < 0)
1137 adj *= 2;
1138 else
1139 adj = -1;
Ben Widawskyb39fb292014-03-19 18:31:11 -07001140 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001141 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001142 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001143 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001144
Ben Widawsky79249632012-09-07 19:43:42 -07001145 /* sysfs frequency interfaces may have snuck in while servicing the
1146 * interrupt
1147 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001148 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001149 dev_priv->rps.min_freq_softlimit,
1150 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301151
Ben Widawskyb39fb292014-03-19 18:31:11 -07001152 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001153
1154 if (IS_VALLEYVIEW(dev_priv->dev))
1155 valleyview_set_rps(dev_priv->dev, new_delay);
1156 else
1157 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001158
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001159 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001160}
1161
Ben Widawskye3689192012-05-25 16:56:22 -07001162
1163/**
1164 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1165 * occurred.
1166 * @work: workqueue struct
1167 *
1168 * Doesn't actually do anything except notify userspace. As a consequence of
1169 * this event, userspace should try to remap the bad rows since statistically
1170 * it is likely the same row is more likely to go bad again.
1171 */
1172static void ivybridge_parity_work(struct work_struct *work)
1173{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001174 struct drm_i915_private *dev_priv =
1175 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001176 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001177 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001178 uint32_t misccpctl;
1179 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001180 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001181
1182 /* We must turn off DOP level clock gating to access the L3 registers.
1183 * In order to prevent a get/put style interface, acquire struct mutex
1184 * any time we access those registers.
1185 */
1186 mutex_lock(&dev_priv->dev->struct_mutex);
1187
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001188 /* If we've screwed up tracking, just let the interrupt fire again */
1189 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1190 goto out;
1191
Ben Widawskye3689192012-05-25 16:56:22 -07001192 misccpctl = I915_READ(GEN7_MISCCPCTL);
1193 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1194 POSTING_READ(GEN7_MISCCPCTL);
1195
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001196 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1197 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001198
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001199 slice--;
1200 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1201 break;
1202
1203 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1204
1205 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1206
1207 error_status = I915_READ(reg);
1208 row = GEN7_PARITY_ERROR_ROW(error_status);
1209 bank = GEN7_PARITY_ERROR_BANK(error_status);
1210 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1211
1212 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1213 POSTING_READ(reg);
1214
1215 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1216 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1217 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1218 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1219 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1220 parity_event[5] = NULL;
1221
Dave Airlie5bdebb12013-10-11 14:07:25 +10001222 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001223 KOBJ_CHANGE, parity_event);
1224
1225 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1226 slice, row, bank, subbank);
1227
1228 kfree(parity_event[4]);
1229 kfree(parity_event[3]);
1230 kfree(parity_event[2]);
1231 kfree(parity_event[1]);
1232 }
Ben Widawskye3689192012-05-25 16:56:22 -07001233
1234 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1235
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001236out:
1237 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001238 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001239 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001240 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1241
1242 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001243}
1244
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001245static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001246{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001247 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001248
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001249 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001250 return;
1251
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001252 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001253 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001254 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001255
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001256 iir &= GT_PARITY_ERROR(dev);
1257 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1258 dev_priv->l3_parity.which_slice |= 1 << 1;
1259
1260 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1261 dev_priv->l3_parity.which_slice |= 1 << 0;
1262
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001263 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001264}
1265
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001266static void ilk_gt_irq_handler(struct drm_device *dev,
1267 struct drm_i915_private *dev_priv,
1268 u32 gt_iir)
1269{
1270 if (gt_iir &
1271 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1272 notify_ring(dev, &dev_priv->ring[RCS]);
1273 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1274 notify_ring(dev, &dev_priv->ring[VCS]);
1275}
1276
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001277static void snb_gt_irq_handler(struct drm_device *dev,
1278 struct drm_i915_private *dev_priv,
1279 u32 gt_iir)
1280{
1281
Ben Widawskycc609d52013-05-28 19:22:29 -07001282 if (gt_iir &
1283 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001284 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001285 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001286 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001287 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001288 notify_ring(dev, &dev_priv->ring[BCS]);
1289
Ben Widawskycc609d52013-05-28 19:22:29 -07001290 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1291 GT_BSD_CS_ERROR_INTERRUPT |
1292 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001293 i915_handle_error(dev, false, "GT error interrupt 0x%08x",
1294 gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001295 }
Ben Widawskye3689192012-05-25 16:56:22 -07001296
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001297 if (gt_iir & GT_PARITY_ERROR(dev))
1298 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001299}
1300
Ben Widawskyabd58f02013-11-02 21:07:09 -07001301static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1302 struct drm_i915_private *dev_priv,
1303 u32 master_ctl)
1304{
1305 u32 rcs, bcs, vcs;
1306 uint32_t tmp = 0;
1307 irqreturn_t ret = IRQ_NONE;
1308
1309 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1310 tmp = I915_READ(GEN8_GT_IIR(0));
1311 if (tmp) {
1312 ret = IRQ_HANDLED;
1313 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1314 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1315 if (rcs & GT_RENDER_USER_INTERRUPT)
1316 notify_ring(dev, &dev_priv->ring[RCS]);
1317 if (bcs & GT_RENDER_USER_INTERRUPT)
1318 notify_ring(dev, &dev_priv->ring[BCS]);
1319 I915_WRITE(GEN8_GT_IIR(0), tmp);
1320 } else
1321 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1322 }
1323
1324 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1325 tmp = I915_READ(GEN8_GT_IIR(1));
1326 if (tmp) {
1327 ret = IRQ_HANDLED;
1328 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1329 if (vcs & GT_RENDER_USER_INTERRUPT)
1330 notify_ring(dev, &dev_priv->ring[VCS]);
1331 I915_WRITE(GEN8_GT_IIR(1), tmp);
1332 } else
1333 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1334 }
1335
1336 if (master_ctl & GEN8_GT_VECS_IRQ) {
1337 tmp = I915_READ(GEN8_GT_IIR(3));
1338 if (tmp) {
1339 ret = IRQ_HANDLED;
1340 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1341 if (vcs & GT_RENDER_USER_INTERRUPT)
1342 notify_ring(dev, &dev_priv->ring[VECS]);
1343 I915_WRITE(GEN8_GT_IIR(3), tmp);
1344 } else
1345 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1346 }
1347
1348 return ret;
1349}
1350
Egbert Eichb543fb02013-04-16 13:36:54 +02001351#define HPD_STORM_DETECT_PERIOD 1000
1352#define HPD_STORM_THRESHOLD 5
1353
Daniel Vetter10a504d2013-06-27 17:52:12 +02001354static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001355 u32 hotplug_trigger,
1356 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001357{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001358 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001359 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001360 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001361
Daniel Vetter91d131d2013-06-27 17:52:14 +02001362 if (!hotplug_trigger)
1363 return;
1364
Imre Deakcc9bd492014-01-16 19:56:54 +02001365 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1366 hotplug_trigger);
1367
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001368 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001369 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001370
Chris Wilson34320872014-01-10 18:49:20 +00001371 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001372 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001373 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1374 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001375
Egbert Eichb543fb02013-04-16 13:36:54 +02001376 if (!(hpd[i] & hotplug_trigger) ||
1377 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1378 continue;
1379
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001380 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001381 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1382 dev_priv->hpd_stats[i].hpd_last_jiffies
1383 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1384 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1385 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001386 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001387 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1388 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001389 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001390 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001391 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001392 } else {
1393 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001394 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1395 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001396 }
1397 }
1398
Daniel Vetter10a504d2013-06-27 17:52:12 +02001399 if (storm_detected)
1400 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001401 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001402
Daniel Vetter645416f2013-09-02 16:22:25 +02001403 /*
1404 * Our hotplug handler can grab modeset locks (by calling down into the
1405 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1406 * queue for otherwise the flush_work in the pageflip code will
1407 * deadlock.
1408 */
1409 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001410}
1411
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001412static void gmbus_irq_handler(struct drm_device *dev)
1413{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001414 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001415
Daniel Vetter28c70f12012-12-01 13:53:45 +01001416 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001417}
1418
Daniel Vetterce99c252012-12-01 13:53:47 +01001419static void dp_aux_irq_handler(struct drm_device *dev)
1420{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001421 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001422
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001423 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001424}
1425
Shuang He8bf1e9f2013-10-15 18:55:27 +01001426#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001427static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1428 uint32_t crc0, uint32_t crc1,
1429 uint32_t crc2, uint32_t crc3,
1430 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001431{
1432 struct drm_i915_private *dev_priv = dev->dev_private;
1433 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1434 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001435 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001436
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001437 spin_lock(&pipe_crc->lock);
1438
Damien Lespiau0c912c72013-10-15 18:55:37 +01001439 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001440 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001441 DRM_ERROR("spurious interrupt\n");
1442 return;
1443 }
1444
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001445 head = pipe_crc->head;
1446 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001447
1448 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001449 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001450 DRM_ERROR("CRC buffer overflowing\n");
1451 return;
1452 }
1453
1454 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001455
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001456 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001457 entry->crc[0] = crc0;
1458 entry->crc[1] = crc1;
1459 entry->crc[2] = crc2;
1460 entry->crc[3] = crc3;
1461 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001462
1463 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001464 pipe_crc->head = head;
1465
1466 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001467
1468 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001469}
Daniel Vetter277de952013-10-18 16:37:07 +02001470#else
1471static inline void
1472display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1473 uint32_t crc0, uint32_t crc1,
1474 uint32_t crc2, uint32_t crc3,
1475 uint32_t crc4) {}
1476#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001477
Daniel Vetter277de952013-10-18 16:37:07 +02001478
1479static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001480{
1481 struct drm_i915_private *dev_priv = dev->dev_private;
1482
Daniel Vetter277de952013-10-18 16:37:07 +02001483 display_pipe_crc_irq_handler(dev, pipe,
1484 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1485 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001486}
1487
Daniel Vetter277de952013-10-18 16:37:07 +02001488static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001489{
1490 struct drm_i915_private *dev_priv = dev->dev_private;
1491
Daniel Vetter277de952013-10-18 16:37:07 +02001492 display_pipe_crc_irq_handler(dev, pipe,
1493 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1494 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1495 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1496 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1497 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001498}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001499
Daniel Vetter277de952013-10-18 16:37:07 +02001500static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001501{
1502 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001503 uint32_t res1, res2;
1504
1505 if (INTEL_INFO(dev)->gen >= 3)
1506 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1507 else
1508 res1 = 0;
1509
1510 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1511 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1512 else
1513 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001514
Daniel Vetter277de952013-10-18 16:37:07 +02001515 display_pipe_crc_irq_handler(dev, pipe,
1516 I915_READ(PIPE_CRC_RES_RED(pipe)),
1517 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1518 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1519 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001520}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001521
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001522/* The RPS events need forcewake, so we add them to a work queue and mask their
1523 * IMR bits until the work is done. Other interrupts can be processed without
1524 * the work queue. */
1525static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001526{
Deepak Sa6706b42014-03-15 20:23:22 +05301527 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001528 spin_lock(&dev_priv->irq_lock);
Deepak Sa6706b42014-03-15 20:23:22 +05301529 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1530 snb_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001531 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001532
1533 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001534 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001535
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001536 if (HAS_VEBOX(dev_priv->dev)) {
1537 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1538 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001539
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001540 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02001541 i915_handle_error(dev_priv->dev, false,
1542 "VEBOX CS error interrupt 0x%08x",
1543 pm_iir);
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001544 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001545 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001546}
1547
Imre Deakc1874ed2014-02-04 21:35:46 +02001548static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1549{
1550 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001551 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001552 int pipe;
1553
Imre Deak58ead0d2014-02-04 21:35:47 +02001554 spin_lock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001555 for_each_pipe(pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001556 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001557 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001558
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001559 /*
1560 * PIPESTAT bits get signalled even when the interrupt is
1561 * disabled with the mask bits, and some of the status bits do
1562 * not generate interrupts at all (like the underrun bit). Hence
1563 * we need to be careful that we only handle what we want to
1564 * handle.
1565 */
1566 mask = 0;
1567 if (__cpu_fifo_underrun_reporting_enabled(dev, pipe))
1568 mask |= PIPE_FIFO_UNDERRUN_STATUS;
1569
1570 switch (pipe) {
1571 case PIPE_A:
1572 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1573 break;
1574 case PIPE_B:
1575 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1576 break;
1577 }
1578 if (iir & iir_bit)
1579 mask |= dev_priv->pipestat_irq_mask[pipe];
1580
1581 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001582 continue;
1583
1584 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001585 mask |= PIPESTAT_INT_ENABLE_MASK;
1586 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001587
1588 /*
1589 * Clear the PIPE*STAT regs before the IIR
1590 */
Imre Deak91d181d2014-02-10 18:42:49 +02001591 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1592 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001593 I915_WRITE(reg, pipe_stats[pipe]);
1594 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001595 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001596
1597 for_each_pipe(pipe) {
1598 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1599 drm_handle_vblank(dev, pipe);
1600
Imre Deak579a9b02014-02-04 21:35:48 +02001601 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001602 intel_prepare_page_flip(dev, pipe);
1603 intel_finish_page_flip(dev, pipe);
1604 }
1605
1606 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1607 i9xx_pipe_crc_irq_handler(dev, pipe);
1608
1609 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1610 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1611 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1612 }
1613
1614 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1615 gmbus_irq_handler(dev);
1616}
1617
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001618static void i9xx_hpd_irq_handler(struct drm_device *dev)
1619{
1620 struct drm_i915_private *dev_priv = dev->dev_private;
1621 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1622
1623 if (IS_G4X(dev)) {
1624 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
1625
1626 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_g4x);
1627 } else {
1628 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1629
1630 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1631 }
1632
1633 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
1634 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1635 dp_aux_irq_handler(dev);
1636
1637 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1638 /*
1639 * Make sure hotplug status is cleared before we clear IIR, or else we
1640 * may miss hotplug events.
1641 */
1642 POSTING_READ(PORT_HOTPLUG_STAT);
1643}
1644
Daniel Vetterff1f5252012-10-02 15:10:55 +02001645static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001646{
1647 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001648 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001649 u32 iir, gt_iir, pm_iir;
1650 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001651
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001652 while (true) {
1653 iir = I915_READ(VLV_IIR);
1654 gt_iir = I915_READ(GTIIR);
1655 pm_iir = I915_READ(GEN6_PMIIR);
1656
1657 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1658 goto out;
1659
1660 ret = IRQ_HANDLED;
1661
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001662 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001663
Imre Deakc1874ed2014-02-04 21:35:46 +02001664 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001665
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001666 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001667 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1668 i9xx_hpd_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001669
Paulo Zanoni60611c12013-08-15 11:50:01 -03001670 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001671 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001672
1673 I915_WRITE(GTIIR, gt_iir);
1674 I915_WRITE(GEN6_PMIIR, pm_iir);
1675 I915_WRITE(VLV_IIR, iir);
1676 }
1677
1678out:
1679 return ret;
1680}
1681
Adam Jackson23e81d62012-06-06 15:45:44 -04001682static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001683{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001684 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001685 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001686 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001687
Daniel Vetter91d131d2013-06-27 17:52:14 +02001688 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1689
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001690 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1691 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1692 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001693 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001694 port_name(port));
1695 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001696
Daniel Vetterce99c252012-12-01 13:53:47 +01001697 if (pch_iir & SDE_AUX_MASK)
1698 dp_aux_irq_handler(dev);
1699
Jesse Barnes776ad802011-01-04 15:09:39 -08001700 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001701 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001702
1703 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1704 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1705
1706 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1707 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1708
1709 if (pch_iir & SDE_POISON)
1710 DRM_ERROR("PCH poison interrupt\n");
1711
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001712 if (pch_iir & SDE_FDI_MASK)
1713 for_each_pipe(pipe)
1714 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1715 pipe_name(pipe),
1716 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001717
1718 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1719 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1720
1721 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1722 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1723
Jesse Barnes776ad802011-01-04 15:09:39 -08001724 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001725 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1726 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001727 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001728
1729 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1730 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1731 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001732 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001733}
1734
1735static void ivb_err_int_handler(struct drm_device *dev)
1736{
1737 struct drm_i915_private *dev_priv = dev->dev_private;
1738 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001739 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001740
Paulo Zanonide032bf2013-04-12 17:57:58 -03001741 if (err_int & ERR_INT_POISON)
1742 DRM_ERROR("Poison interrupt\n");
1743
Daniel Vetter5a69b892013-10-16 22:55:52 +02001744 for_each_pipe(pipe) {
1745 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1746 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1747 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001748 DRM_ERROR("Pipe %c FIFO underrun\n",
1749 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001750 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001751
Daniel Vetter5a69b892013-10-16 22:55:52 +02001752 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1753 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001754 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001755 else
Daniel Vetter277de952013-10-18 16:37:07 +02001756 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001757 }
1758 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001759
Paulo Zanoni86642812013-04-12 17:57:57 -03001760 I915_WRITE(GEN7_ERR_INT, err_int);
1761}
1762
1763static void cpt_serr_int_handler(struct drm_device *dev)
1764{
1765 struct drm_i915_private *dev_priv = dev->dev_private;
1766 u32 serr_int = I915_READ(SERR_INT);
1767
Paulo Zanonide032bf2013-04-12 17:57:58 -03001768 if (serr_int & SERR_INT_POISON)
1769 DRM_ERROR("PCH poison interrupt\n");
1770
Paulo Zanoni86642812013-04-12 17:57:57 -03001771 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1772 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1773 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001774 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001775
1776 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1777 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1778 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001779 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001780
1781 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1782 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1783 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001784 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001785
1786 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001787}
1788
Adam Jackson23e81d62012-06-06 15:45:44 -04001789static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1790{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001791 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04001792 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001793 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001794
Daniel Vetter91d131d2013-06-27 17:52:14 +02001795 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1796
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001797 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1798 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1799 SDE_AUDIO_POWER_SHIFT_CPT);
1800 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1801 port_name(port));
1802 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001803
1804 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001805 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001806
1807 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001808 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001809
1810 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1811 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1812
1813 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1814 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1815
1816 if (pch_iir & SDE_FDI_MASK_CPT)
1817 for_each_pipe(pipe)
1818 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1819 pipe_name(pipe),
1820 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001821
1822 if (pch_iir & SDE_ERROR_CPT)
1823 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001824}
1825
Paulo Zanonic008bc62013-07-12 16:35:10 -03001826static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1827{
1828 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001829 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001830
1831 if (de_iir & DE_AUX_CHANNEL_A)
1832 dp_aux_irq_handler(dev);
1833
1834 if (de_iir & DE_GSE)
1835 intel_opregion_asle_intr(dev);
1836
Paulo Zanonic008bc62013-07-12 16:35:10 -03001837 if (de_iir & DE_POISON)
1838 DRM_ERROR("Poison interrupt\n");
1839
Daniel Vetter40da17c2013-10-21 18:04:36 +02001840 for_each_pipe(pipe) {
1841 if (de_iir & DE_PIPE_VBLANK(pipe))
1842 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001843
Daniel Vetter40da17c2013-10-21 18:04:36 +02001844 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1845 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001846 DRM_ERROR("Pipe %c FIFO underrun\n",
1847 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001848
Daniel Vetter40da17c2013-10-21 18:04:36 +02001849 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1850 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001851
Daniel Vetter40da17c2013-10-21 18:04:36 +02001852 /* plane/pipes map 1:1 on ilk+ */
1853 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1854 intel_prepare_page_flip(dev, pipe);
1855 intel_finish_page_flip_plane(dev, pipe);
1856 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001857 }
1858
1859 /* check event from PCH */
1860 if (de_iir & DE_PCH_EVENT) {
1861 u32 pch_iir = I915_READ(SDEIIR);
1862
1863 if (HAS_PCH_CPT(dev))
1864 cpt_irq_handler(dev, pch_iir);
1865 else
1866 ibx_irq_handler(dev, pch_iir);
1867
1868 /* should clear PCH hotplug event before clear CPU irq */
1869 I915_WRITE(SDEIIR, pch_iir);
1870 }
1871
1872 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1873 ironlake_rps_change_irq_handler(dev);
1874}
1875
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001876static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1877{
1878 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00001879 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001880
1881 if (de_iir & DE_ERR_INT_IVB)
1882 ivb_err_int_handler(dev);
1883
1884 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1885 dp_aux_irq_handler(dev);
1886
1887 if (de_iir & DE_GSE_IVB)
1888 intel_opregion_asle_intr(dev);
1889
Damien Lespiau07d27e22014-03-03 17:31:46 +00001890 for_each_pipe(pipe) {
1891 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
1892 drm_handle_vblank(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001893
1894 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00001895 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
1896 intel_prepare_page_flip(dev, pipe);
1897 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001898 }
1899 }
1900
1901 /* check event from PCH */
1902 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1903 u32 pch_iir = I915_READ(SDEIIR);
1904
1905 cpt_irq_handler(dev, pch_iir);
1906
1907 /* clear PCH hotplug event before clear CPU irq */
1908 I915_WRITE(SDEIIR, pch_iir);
1909 }
1910}
1911
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001912static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001913{
1914 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001915 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001916 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001917 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001918
Paulo Zanoni86642812013-04-12 17:57:57 -03001919 /* We get interrupts on unclaimed registers, so check for this before we
1920 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001921 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001922
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001923 /* disable master interrupt before clearing iir */
1924 de_ier = I915_READ(DEIER);
1925 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001926 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001927
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001928 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1929 * interrupts will will be stored on its back queue, and then we'll be
1930 * able to process them after we restore SDEIER (as soon as we restore
1931 * it, we'll get an interrupt if SDEIIR still has something to process
1932 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001933 if (!HAS_PCH_NOP(dev)) {
1934 sde_ier = I915_READ(SDEIER);
1935 I915_WRITE(SDEIER, 0);
1936 POSTING_READ(SDEIER);
1937 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001938
Chris Wilson0e434062012-05-09 21:45:44 +01001939 gt_iir = I915_READ(GTIIR);
1940 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001941 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001942 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001943 else
1944 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001945 I915_WRITE(GTIIR, gt_iir);
1946 ret = IRQ_HANDLED;
1947 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001948
1949 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001950 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001951 if (INTEL_INFO(dev)->gen >= 7)
1952 ivb_display_irq_handler(dev, de_iir);
1953 else
1954 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001955 I915_WRITE(DEIIR, de_iir);
1956 ret = IRQ_HANDLED;
1957 }
1958
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001959 if (INTEL_INFO(dev)->gen >= 6) {
1960 u32 pm_iir = I915_READ(GEN6_PMIIR);
1961 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001962 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001963 I915_WRITE(GEN6_PMIIR, pm_iir);
1964 ret = IRQ_HANDLED;
1965 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001966 }
1967
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001968 I915_WRITE(DEIER, de_ier);
1969 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001970 if (!HAS_PCH_NOP(dev)) {
1971 I915_WRITE(SDEIER, sde_ier);
1972 POSTING_READ(SDEIER);
1973 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001974
1975 return ret;
1976}
1977
Ben Widawskyabd58f02013-11-02 21:07:09 -07001978static irqreturn_t gen8_irq_handler(int irq, void *arg)
1979{
1980 struct drm_device *dev = arg;
1981 struct drm_i915_private *dev_priv = dev->dev_private;
1982 u32 master_ctl;
1983 irqreturn_t ret = IRQ_NONE;
1984 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001985 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001986
Ben Widawskyabd58f02013-11-02 21:07:09 -07001987 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1988 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1989 if (!master_ctl)
1990 return IRQ_NONE;
1991
1992 I915_WRITE(GEN8_MASTER_IRQ, 0);
1993 POSTING_READ(GEN8_MASTER_IRQ);
1994
1995 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1996
1997 if (master_ctl & GEN8_DE_MISC_IRQ) {
1998 tmp = I915_READ(GEN8_DE_MISC_IIR);
1999 if (tmp & GEN8_DE_MISC_GSE)
2000 intel_opregion_asle_intr(dev);
2001 else if (tmp)
2002 DRM_ERROR("Unexpected DE Misc interrupt\n");
2003 else
2004 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
2005
2006 if (tmp) {
2007 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2008 ret = IRQ_HANDLED;
2009 }
2010 }
2011
Daniel Vetter6d766f02013-11-07 14:49:55 +01002012 if (master_ctl & GEN8_DE_PORT_IRQ) {
2013 tmp = I915_READ(GEN8_DE_PORT_IIR);
2014 if (tmp & GEN8_AUX_CHANNEL_A)
2015 dp_aux_irq_handler(dev);
2016 else if (tmp)
2017 DRM_ERROR("Unexpected DE Port interrupt\n");
2018 else
2019 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
2020
2021 if (tmp) {
2022 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2023 ret = IRQ_HANDLED;
2024 }
2025 }
2026
Daniel Vetterc42664c2013-11-07 11:05:40 +01002027 for_each_pipe(pipe) {
2028 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002029
Daniel Vetterc42664c2013-11-07 11:05:40 +01002030 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2031 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002032
Daniel Vetterc42664c2013-11-07 11:05:40 +01002033 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2034 if (pipe_iir & GEN8_PIPE_VBLANK)
2035 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002036
Daniel Vetterc42664c2013-11-07 11:05:40 +01002037 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
2038 intel_prepare_page_flip(dev, pipe);
2039 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002040 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002041
Daniel Vetter0fbe7872013-11-07 11:05:44 +01002042 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2043 hsw_pipe_crc_irq_handler(dev, pipe);
2044
Daniel Vetter38d83c962013-11-07 11:05:46 +01002045 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
2046 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
2047 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02002048 DRM_ERROR("Pipe %c FIFO underrun\n",
2049 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01002050 }
2051
Daniel Vetter30100f22013-11-07 14:49:24 +01002052 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
2053 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2054 pipe_name(pipe),
2055 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2056 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002057
2058 if (pipe_iir) {
2059 ret = IRQ_HANDLED;
2060 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
2061 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002062 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2063 }
2064
Daniel Vetter92d03a82013-11-07 11:05:43 +01002065 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2066 /*
2067 * FIXME(BDW): Assume for now that the new interrupt handling
2068 * scheme also closed the SDE interrupt handling race we've seen
2069 * on older pch-split platforms. But this needs testing.
2070 */
2071 u32 pch_iir = I915_READ(SDEIIR);
2072
2073 cpt_irq_handler(dev, pch_iir);
2074
2075 if (pch_iir) {
2076 I915_WRITE(SDEIIR, pch_iir);
2077 ret = IRQ_HANDLED;
2078 }
2079 }
2080
Ben Widawskyabd58f02013-11-02 21:07:09 -07002081 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2082 POSTING_READ(GEN8_MASTER_IRQ);
2083
2084 return ret;
2085}
2086
Daniel Vetter17e1df02013-09-08 21:57:13 +02002087static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2088 bool reset_completed)
2089{
2090 struct intel_ring_buffer *ring;
2091 int i;
2092
2093 /*
2094 * Notify all waiters for GPU completion events that reset state has
2095 * been changed, and that they need to restart their wait after
2096 * checking for potential errors (and bail out to drop locks if there is
2097 * a gpu reset pending so that i915_error_work_func can acquire them).
2098 */
2099
2100 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2101 for_each_ring(ring, dev_priv, i)
2102 wake_up_all(&ring->irq_queue);
2103
2104 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2105 wake_up_all(&dev_priv->pending_flip_queue);
2106
2107 /*
2108 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2109 * reset state is cleared.
2110 */
2111 if (reset_completed)
2112 wake_up_all(&dev_priv->gpu_error.reset_queue);
2113}
2114
Jesse Barnes8a905232009-07-11 16:48:03 -04002115/**
2116 * i915_error_work_func - do process context error handling work
2117 * @work: work struct
2118 *
2119 * Fire an error uevent so userspace can see that a hang or error
2120 * was detected.
2121 */
2122static void i915_error_work_func(struct work_struct *work)
2123{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002124 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2125 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002126 struct drm_i915_private *dev_priv =
2127 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002128 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002129 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2130 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2131 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002132 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002133
Dave Airlie5bdebb12013-10-11 14:07:25 +10002134 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002135
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002136 /*
2137 * Note that there's only one work item which does gpu resets, so we
2138 * need not worry about concurrent gpu resets potentially incrementing
2139 * error->reset_counter twice. We only need to take care of another
2140 * racing irq/hangcheck declaring the gpu dead for a second time. A
2141 * quick check for that is good enough: schedule_work ensures the
2142 * correct ordering between hang detection and this work item, and since
2143 * the reset in-progress bit is only ever set by code outside of this
2144 * work we don't need to worry about any other races.
2145 */
2146 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002147 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002148 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002149 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002150
Daniel Vetter17e1df02013-09-08 21:57:13 +02002151 /*
2152 * All state reset _must_ be completed before we update the
2153 * reset counter, for otherwise waiters might miss the reset
2154 * pending state and not properly drop locks, resulting in
2155 * deadlocks with the reset work.
2156 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002157 ret = i915_reset(dev);
2158
Daniel Vetter17e1df02013-09-08 21:57:13 +02002159 intel_display_handle_reset(dev);
2160
Daniel Vetterf69061b2012-12-06 09:01:42 +01002161 if (ret == 0) {
2162 /*
2163 * After all the gem state is reset, increment the reset
2164 * counter and wake up everyone waiting for the reset to
2165 * complete.
2166 *
2167 * Since unlock operations are a one-sided barrier only,
2168 * we need to insert a barrier here to order any seqno
2169 * updates before
2170 * the counter increment.
2171 */
2172 smp_mb__before_atomic_inc();
2173 atomic_inc(&dev_priv->gpu_error.reset_counter);
2174
Dave Airlie5bdebb12013-10-11 14:07:25 +10002175 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002176 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002177 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002178 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002179 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002180
Daniel Vetter17e1df02013-09-08 21:57:13 +02002181 /*
2182 * Note: The wake_up also serves as a memory barrier so that
2183 * waiters see the update value of the reset counter atomic_t.
2184 */
2185 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002186 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002187}
2188
Chris Wilson35aed2e2010-05-27 13:18:12 +01002189static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002190{
2191 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002192 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002193 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002194 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002195
Chris Wilson35aed2e2010-05-27 13:18:12 +01002196 if (!eir)
2197 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002198
Joe Perchesa70491c2012-03-18 13:00:11 -07002199 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002200
Ben Widawskybd9854f2012-08-23 15:18:09 -07002201 i915_get_extra_instdone(dev, instdone);
2202
Jesse Barnes8a905232009-07-11 16:48:03 -04002203 if (IS_G4X(dev)) {
2204 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2205 u32 ipeir = I915_READ(IPEIR_I965);
2206
Joe Perchesa70491c2012-03-18 13:00:11 -07002207 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2208 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002209 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2210 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002211 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002212 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002213 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002214 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002215 }
2216 if (eir & GM45_ERROR_PAGE_TABLE) {
2217 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002218 pr_err("page table error\n");
2219 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002220 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002221 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002222 }
2223 }
2224
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002225 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002226 if (eir & I915_ERROR_PAGE_TABLE) {
2227 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002228 pr_err("page table error\n");
2229 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002230 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002231 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002232 }
2233 }
2234
2235 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002236 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002237 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002238 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002239 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002240 /* pipestat has already been acked */
2241 }
2242 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002243 pr_err("instruction error\n");
2244 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002245 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2246 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002247 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002248 u32 ipeir = I915_READ(IPEIR);
2249
Joe Perchesa70491c2012-03-18 13:00:11 -07002250 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2251 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002252 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002253 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002254 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002255 } else {
2256 u32 ipeir = I915_READ(IPEIR_I965);
2257
Joe Perchesa70491c2012-03-18 13:00:11 -07002258 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2259 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002260 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002261 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002262 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002263 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002264 }
2265 }
2266
2267 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002268 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002269 eir = I915_READ(EIR);
2270 if (eir) {
2271 /*
2272 * some errors might have become stuck,
2273 * mask them.
2274 */
2275 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2276 I915_WRITE(EMR, I915_READ(EMR) | eir);
2277 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2278 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002279}
2280
2281/**
2282 * i915_handle_error - handle an error interrupt
2283 * @dev: drm device
2284 *
2285 * Do some basic checking of regsiter state at error interrupt time and
2286 * dump it to the syslog. Also call i915_capture_error_state() to make
2287 * sure we get a record and make it available in debugfs. Fire a uevent
2288 * so userspace knows something bad happened (should trigger collection
2289 * of a ring dump etc.).
2290 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002291void i915_handle_error(struct drm_device *dev, bool wedged,
2292 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002293{
2294 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002295 va_list args;
2296 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002297
Mika Kuoppala58174462014-02-25 17:11:26 +02002298 va_start(args, fmt);
2299 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2300 va_end(args);
2301
2302 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002303 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002304
Ben Gamariba1234d2009-09-14 17:48:47 -04002305 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002306 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2307 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002308
Ben Gamari11ed50e2009-09-14 17:48:45 -04002309 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002310 * Wakeup waiting processes so that the reset work function
2311 * i915_error_work_func doesn't deadlock trying to grab various
2312 * locks. By bumping the reset counter first, the woken
2313 * processes will see a reset in progress and back off,
2314 * releasing their locks and then wait for the reset completion.
2315 * We must do this for _all_ gpu waiters that might hold locks
2316 * that the reset work needs to acquire.
2317 *
2318 * Note: The wake_up serves as the required memory barrier to
2319 * ensure that the waiters see the updated value of the reset
2320 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002321 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002322 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002323 }
2324
Daniel Vetter122f46b2013-09-04 17:36:14 +02002325 /*
2326 * Our reset work can grab modeset locks (since it needs to reset the
2327 * state of outstanding pagelips). Hence it must not be run on our own
2328 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2329 * code will deadlock.
2330 */
2331 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002332}
2333
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002334static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002335{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002336 struct drm_i915_private *dev_priv = dev->dev_private;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002337 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2338 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002339 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002340 struct intel_unpin_work *work;
2341 unsigned long flags;
2342 bool stall_detected;
2343
2344 /* Ignore early vblank irqs */
2345 if (intel_crtc == NULL)
2346 return;
2347
2348 spin_lock_irqsave(&dev->event_lock, flags);
2349 work = intel_crtc->unpin_work;
2350
Chris Wilsone7d841c2012-12-03 11:36:30 +00002351 if (work == NULL ||
2352 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2353 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002354 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2355 spin_unlock_irqrestore(&dev->event_lock, flags);
2356 return;
2357 }
2358
2359 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002360 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002361 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002362 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002363 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002364 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002365 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002366 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002367 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002368 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002369 crtc->x * crtc->fb->bits_per_pixel/8);
2370 }
2371
2372 spin_unlock_irqrestore(&dev->event_lock, flags);
2373
2374 if (stall_detected) {
2375 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2376 intel_prepare_page_flip(dev, intel_crtc->plane);
2377 }
2378}
2379
Keith Packard42f52ef2008-10-18 19:39:29 -07002380/* Called from drm generic code, passed 'crtc' which
2381 * we use as a pipe index
2382 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002383static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002384{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002385 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002386 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002387
Chris Wilson5eddb702010-09-11 13:48:45 +01002388 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002389 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002390
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002391 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002392 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002393 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002394 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002395 else
Keith Packard7c463582008-11-04 02:03:27 -08002396 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002397 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002398
2399 /* maintain vblank delivery even in deep C-states */
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002400 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002401 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002402 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002403
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002404 return 0;
2405}
2406
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002407static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002408{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002409 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002410 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002411 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002412 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002413
2414 if (!i915_pipe_enabled(dev, pipe))
2415 return -EINVAL;
2416
2417 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002418 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002419 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2420
2421 return 0;
2422}
2423
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002424static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2425{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002426 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002427 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002428
2429 if (!i915_pipe_enabled(dev, pipe))
2430 return -EINVAL;
2431
2432 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002433 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002434 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002435 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2436
2437 return 0;
2438}
2439
Ben Widawskyabd58f02013-11-02 21:07:09 -07002440static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2441{
2442 struct drm_i915_private *dev_priv = dev->dev_private;
2443 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002444
2445 if (!i915_pipe_enabled(dev, pipe))
2446 return -EINVAL;
2447
2448 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002449 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2450 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2451 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002452 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2453 return 0;
2454}
2455
Keith Packard42f52ef2008-10-18 19:39:29 -07002456/* Called from drm generic code, passed 'crtc' which
2457 * we use as a pipe index
2458 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002459static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002460{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002461 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002462 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002463
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002464 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002465 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002466 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002467
Jesse Barnesf796cf82011-04-07 13:58:17 -07002468 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002469 PIPE_VBLANK_INTERRUPT_STATUS |
2470 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002471 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2472}
2473
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002474static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002475{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002476 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002477 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002478 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002479 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002480
2481 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002482 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002483 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2484}
2485
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002486static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2487{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002488 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002489 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002490
2491 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002492 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002493 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002494 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2495}
2496
Ben Widawskyabd58f02013-11-02 21:07:09 -07002497static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2498{
2499 struct drm_i915_private *dev_priv = dev->dev_private;
2500 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002501
2502 if (!i915_pipe_enabled(dev, pipe))
2503 return;
2504
2505 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002506 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2507 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2508 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002509 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2510}
2511
Chris Wilson893eead2010-10-27 14:44:35 +01002512static u32
2513ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002514{
Chris Wilson893eead2010-10-27 14:44:35 +01002515 return list_entry(ring->request_list.prev,
2516 struct drm_i915_gem_request, list)->seqno;
2517}
2518
Chris Wilson9107e9d2013-06-10 11:20:20 +01002519static bool
2520ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002521{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002522 return (list_empty(&ring->request_list) ||
2523 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002524}
2525
Daniel Vettera028c4b2014-03-15 00:08:56 +01002526static bool
2527ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2528{
2529 if (INTEL_INFO(dev)->gen >= 8) {
2530 /*
2531 * FIXME: gen8 semaphore support - currently we don't emit
2532 * semaphores on bdw anyway, but this needs to be addressed when
2533 * we merge that code.
2534 */
2535 return false;
2536 } else {
2537 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2538 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2539 MI_SEMAPHORE_REGISTER);
2540 }
2541}
2542
Chris Wilson6274f212013-06-10 11:20:21 +01002543static struct intel_ring_buffer *
Daniel Vetter921d42e2014-03-18 10:26:04 +01002544semaphore_wait_to_signaller_ring(struct intel_ring_buffer *ring, u32 ipehr)
2545{
2546 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2547 struct intel_ring_buffer *signaller;
2548 int i;
2549
2550 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
2551 /*
2552 * FIXME: gen8 semaphore support - currently we don't emit
2553 * semaphores on bdw anyway, but this needs to be addressed when
2554 * we merge that code.
2555 */
2556 return NULL;
2557 } else {
2558 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2559
2560 for_each_ring(signaller, dev_priv, i) {
2561 if(ring == signaller)
2562 continue;
2563
2564 if (sync_bits ==
2565 signaller->semaphore_register[ring->id])
2566 return signaller;
2567 }
2568 }
2569
2570 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x\n",
2571 ring->id, ipehr);
2572
2573 return NULL;
2574}
2575
2576static struct intel_ring_buffer *
Chris Wilson6274f212013-06-10 11:20:21 +01002577semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002578{
2579 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002580 u32 cmd, ipehr, head;
2581 int i;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002582
2583 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002584 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002585 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002586
Daniel Vetter88fe4292014-03-15 00:08:55 +01002587 /*
2588 * HEAD is likely pointing to the dword after the actual command,
2589 * so scan backwards until we find the MBOX. But limit it to just 3
2590 * dwords. Note that we don't care about ACTHD here since that might
2591 * point at at batch, and semaphores are always emitted into the
2592 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002593 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002594 head = I915_READ_HEAD(ring) & HEAD_ADDR;
2595
2596 for (i = 4; i; --i) {
2597 /*
2598 * Be paranoid and presume the hw has gone off into the wild -
2599 * our ring is smaller than what the hardware (and hence
2600 * HEAD_ADDR) allows. Also handles wrap-around.
2601 */
2602 head &= ring->size - 1;
2603
2604 /* This here seems to blow up */
2605 cmd = ioread32(ring->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002606 if (cmd == ipehr)
2607 break;
2608
Daniel Vetter88fe4292014-03-15 00:08:55 +01002609 head -= 4;
2610 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002611
Daniel Vetter88fe4292014-03-15 00:08:55 +01002612 if (!i)
2613 return NULL;
2614
2615 *seqno = ioread32(ring->virtual_start + head + 4) + 1;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002616 return semaphore_wait_to_signaller_ring(ring, ipehr);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002617}
2618
Chris Wilson6274f212013-06-10 11:20:21 +01002619static int semaphore_passed(struct intel_ring_buffer *ring)
2620{
2621 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2622 struct intel_ring_buffer *signaller;
2623 u32 seqno, ctl;
2624
2625 ring->hangcheck.deadlock = true;
2626
2627 signaller = semaphore_waits_for(ring, &seqno);
2628 if (signaller == NULL || signaller->hangcheck.deadlock)
2629 return -1;
2630
2631 /* cursory check for an unkickable deadlock */
2632 ctl = I915_READ_CTL(signaller);
2633 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2634 return -1;
2635
2636 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2637}
2638
2639static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2640{
2641 struct intel_ring_buffer *ring;
2642 int i;
2643
2644 for_each_ring(ring, dev_priv, i)
2645 ring->hangcheck.deadlock = false;
2646}
2647
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002648static enum intel_ring_hangcheck_action
Chris Wilson50877442014-03-21 12:41:53 +00002649ring_stuck(struct intel_ring_buffer *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002650{
2651 struct drm_device *dev = ring->dev;
2652 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002653 u32 tmp;
2654
Chris Wilson6274f212013-06-10 11:20:21 +01002655 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002656 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002657
Chris Wilson9107e9d2013-06-10 11:20:20 +01002658 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002659 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002660
2661 /* Is the chip hanging on a WAIT_FOR_EVENT?
2662 * If so we can simply poke the RB_WAIT bit
2663 * and break the hang. This should work on
2664 * all but the second generation chipsets.
2665 */
2666 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002667 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002668 i915_handle_error(dev, false,
2669 "Kicking stuck wait on %s",
2670 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002671 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002672 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002673 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002674
Chris Wilson6274f212013-06-10 11:20:21 +01002675 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2676 switch (semaphore_passed(ring)) {
2677 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002678 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002679 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002680 i915_handle_error(dev, false,
2681 "Kicking stuck semaphore on %s",
2682 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002683 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002684 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002685 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002686 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002687 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002688 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002689
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002690 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002691}
2692
Ben Gamarif65d9422009-09-14 17:48:44 -04002693/**
2694 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002695 * batchbuffers in a long time. We keep track per ring seqno progress and
2696 * if there are no progress, hangcheck score for that ring is increased.
2697 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2698 * we kick the ring. If we see no progress on three subsequent calls
2699 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002700 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002701static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002702{
2703 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002704 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002705 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002706 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002707 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002708 bool stuck[I915_NUM_RINGS] = { 0 };
2709#define BUSY 1
2710#define KICK 5
2711#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002712
Jani Nikulad330a952014-01-21 11:24:25 +02002713 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002714 return;
2715
Chris Wilsonb4519512012-05-11 14:29:30 +01002716 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002717 u64 acthd;
2718 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002719 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002720
Chris Wilson6274f212013-06-10 11:20:21 +01002721 semaphore_clear_deadlocks(dev_priv);
2722
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002723 seqno = ring->get_seqno(ring, false);
2724 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002725
Chris Wilson9107e9d2013-06-10 11:20:20 +01002726 if (ring->hangcheck.seqno == seqno) {
2727 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002728 ring->hangcheck.action = HANGCHECK_IDLE;
2729
Chris Wilson9107e9d2013-06-10 11:20:20 +01002730 if (waitqueue_active(&ring->irq_queue)) {
2731 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002732 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002733 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2734 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2735 ring->name);
2736 else
2737 DRM_INFO("Fake missed irq on %s\n",
2738 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002739 wake_up_all(&ring->irq_queue);
2740 }
2741 /* Safeguard against driver failure */
2742 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002743 } else
2744 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002745 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002746 /* We always increment the hangcheck score
2747 * if the ring is busy and still processing
2748 * the same request, so that no single request
2749 * can run indefinitely (such as a chain of
2750 * batches). The only time we do not increment
2751 * the hangcheck score on this ring, if this
2752 * ring is in a legitimate wait for another
2753 * ring. In that case the waiting ring is a
2754 * victim and we want to be sure we catch the
2755 * right culprit. Then every time we do kick
2756 * the ring, add a small increment to the
2757 * score so that we can catch a batch that is
2758 * being repeatedly kicked and so responsible
2759 * for stalling the machine.
2760 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002761 ring->hangcheck.action = ring_stuck(ring,
2762 acthd);
2763
2764 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002765 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002766 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002767 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002768 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002769 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002770 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002771 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002772 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002773 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002774 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002775 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002776 stuck[i] = true;
2777 break;
2778 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002779 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002780 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002781 ring->hangcheck.action = HANGCHECK_ACTIVE;
2782
Chris Wilson9107e9d2013-06-10 11:20:20 +01002783 /* Gradually reduce the count so that we catch DoS
2784 * attempts across multiple batches.
2785 */
2786 if (ring->hangcheck.score > 0)
2787 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002788 }
2789
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002790 ring->hangcheck.seqno = seqno;
2791 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002792 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002793 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002794
Mika Kuoppala92cab732013-05-24 17:16:07 +03002795 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002796 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002797 DRM_INFO("%s on %s\n",
2798 stuck[i] ? "stuck" : "no progress",
2799 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002800 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002801 }
2802 }
2803
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002804 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02002805 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04002806
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002807 if (busy_count)
2808 /* Reset timer case chip hangs without another request
2809 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002810 i915_queue_hangcheck(dev);
2811}
2812
2813void i915_queue_hangcheck(struct drm_device *dev)
2814{
2815 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02002816 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002817 return;
2818
2819 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2820 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002821}
2822
Paulo Zanoni91738a92013-06-05 14:21:51 -03002823static void ibx_irq_preinstall(struct drm_device *dev)
2824{
2825 struct drm_i915_private *dev_priv = dev->dev_private;
2826
2827 if (HAS_PCH_NOP(dev))
2828 return;
2829
2830 /* south display irq */
2831 I915_WRITE(SDEIMR, 0xffffffff);
2832 /*
2833 * SDEIER is also touched by the interrupt handler to work around missed
2834 * PCH interrupts. Hence we can't update it after the interrupt handler
2835 * is enabled - instead we unconditionally enable all PCH interrupt
2836 * sources here, but then only unmask them as needed with SDEIMR.
2837 */
2838 I915_WRITE(SDEIER, 0xffffffff);
2839 POSTING_READ(SDEIER);
2840}
2841
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002842static void gen5_gt_irq_preinstall(struct drm_device *dev)
2843{
2844 struct drm_i915_private *dev_priv = dev->dev_private;
2845
Paulo Zanonia9d356a2014-04-01 15:37:09 -03002846 GEN5_IRQ_INIT(GT);
2847 if (INTEL_INFO(dev)->gen >= 6)
2848 GEN5_IRQ_INIT(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002849}
2850
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851/* drm_dma.h hooks
2852*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002853static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002854{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002855 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002856
2857 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002858
Paulo Zanonia9d356a2014-04-01 15:37:09 -03002859 GEN5_IRQ_INIT(DE);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002860
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002861 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002862
Paulo Zanoni91738a92013-06-05 14:21:51 -03002863 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002864}
2865
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002866static void valleyview_irq_preinstall(struct drm_device *dev)
2867{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002868 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002869 int pipe;
2870
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002871 /* VLV magic */
2872 I915_WRITE(VLV_IMR, 0);
2873 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2874 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2875 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2876
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002877 /* and GT */
2878 I915_WRITE(GTIIR, I915_READ(GTIIR));
2879 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002880
2881 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002882
2883 I915_WRITE(DPINVGTT, 0xff);
2884
2885 I915_WRITE(PORT_HOTPLUG_EN, 0);
2886 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2887 for_each_pipe(pipe)
2888 I915_WRITE(PIPESTAT(pipe), 0xffff);
2889 I915_WRITE(VLV_IIR, 0xffffffff);
2890 I915_WRITE(VLV_IMR, 0xffffffff);
2891 I915_WRITE(VLV_IER, 0x0);
2892 POSTING_READ(VLV_IER);
2893}
2894
Ben Widawskyabd58f02013-11-02 21:07:09 -07002895static void gen8_irq_preinstall(struct drm_device *dev)
2896{
2897 struct drm_i915_private *dev_priv = dev->dev_private;
2898 int pipe;
2899
Ben Widawskyabd58f02013-11-02 21:07:09 -07002900 I915_WRITE(GEN8_MASTER_IRQ, 0);
2901 POSTING_READ(GEN8_MASTER_IRQ);
2902
2903 /* IIR can theoretically queue up two events. Be paranoid */
2904#define GEN8_IRQ_INIT_NDX(type, which) do { \
2905 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2906 POSTING_READ(GEN8_##type##_IMR(which)); \
2907 I915_WRITE(GEN8_##type##_IER(which), 0); \
2908 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2909 POSTING_READ(GEN8_##type##_IIR(which)); \
2910 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2911 } while (0)
2912
2913#define GEN8_IRQ_INIT(type) do { \
2914 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2915 POSTING_READ(GEN8_##type##_IMR); \
2916 I915_WRITE(GEN8_##type##_IER, 0); \
2917 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2918 POSTING_READ(GEN8_##type##_IIR); \
2919 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2920 } while (0)
2921
2922 GEN8_IRQ_INIT_NDX(GT, 0);
2923 GEN8_IRQ_INIT_NDX(GT, 1);
2924 GEN8_IRQ_INIT_NDX(GT, 2);
2925 GEN8_IRQ_INIT_NDX(GT, 3);
2926
2927 for_each_pipe(pipe) {
2928 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2929 }
2930
2931 GEN8_IRQ_INIT(DE_PORT);
2932 GEN8_IRQ_INIT(DE_MISC);
2933 GEN8_IRQ_INIT(PCU);
2934#undef GEN8_IRQ_INIT
2935#undef GEN8_IRQ_INIT_NDX
2936
2937 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002938
2939 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002940}
2941
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002942static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002943{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002944 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002945 struct drm_mode_config *mode_config = &dev->mode_config;
2946 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002947 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002948
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002949 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002950 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002951 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002952 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002953 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002954 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002955 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002956 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002957 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002958 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002959 }
2960
Daniel Vetterfee884e2013-07-04 23:35:21 +02002961 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002962
2963 /*
2964 * Enable digital hotplug on the PCH, and configure the DP short pulse
2965 * duration to 2ms (which is the minimum in the Display Port spec)
2966 *
2967 * This register is the same on all known PCH chips.
2968 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002969 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2970 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2971 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2972 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2973 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2974 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2975}
2976
Paulo Zanonid46da432013-02-08 17:35:15 -02002977static void ibx_irq_postinstall(struct drm_device *dev)
2978{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002979 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002980 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002981
Daniel Vetter692a04c2013-05-29 21:43:05 +02002982 if (HAS_PCH_NOP(dev))
2983 return;
2984
Paulo Zanoni86642812013-04-12 17:57:57 -03002985 if (HAS_PCH_IBX(dev)) {
Daniel Vetter5c673b62014-03-07 20:34:46 +01002986 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002987 } else {
Daniel Vetter5c673b62014-03-07 20:34:46 +01002988 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03002989
2990 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2991 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002992
Paulo Zanonid46da432013-02-08 17:35:15 -02002993 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2994 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002995}
2996
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002997static void gen5_gt_irq_postinstall(struct drm_device *dev)
2998{
2999 struct drm_i915_private *dev_priv = dev->dev_private;
3000 u32 pm_irqs, gt_irqs;
3001
3002 pm_irqs = gt_irqs = 0;
3003
3004 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003005 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003006 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003007 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3008 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003009 }
3010
3011 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3012 if (IS_GEN5(dev)) {
3013 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3014 ILK_BSD_USER_INTERRUPT;
3015 } else {
3016 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3017 }
3018
3019 I915_WRITE(GTIIR, I915_READ(GTIIR));
3020 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
3021 I915_WRITE(GTIER, gt_irqs);
3022 POSTING_READ(GTIER);
3023
3024 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303025 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003026
3027 if (HAS_VEBOX(dev))
3028 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3029
Paulo Zanoni605cd252013-08-06 18:57:15 -03003030 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003031 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03003032 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003033 I915_WRITE(GEN6_PMIER, pm_irqs);
3034 POSTING_READ(GEN6_PMIER);
3035 }
3036}
3037
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003038static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003039{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003040 unsigned long irqflags;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003041 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003042 u32 display_mask, extra_mask;
3043
3044 if (INTEL_INFO(dev)->gen >= 7) {
3045 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3046 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3047 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003048 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003049 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003050 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003051
3052 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
3053 } else {
3054 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3055 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003056 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003057 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3058 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003059 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3060 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003061 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003062
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003063 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003064
3065 /* should always can generate irq */
3066 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003067 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003068 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00003069 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003070
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003071 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003072
Paulo Zanonid46da432013-02-08 17:35:15 -02003073 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003074
Jesse Barnesf97108d2010-01-29 11:27:07 -08003075 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003076 /* Enable PCU event interrupts
3077 *
3078 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003079 * setup is guaranteed to run in single-threaded context. But we
3080 * need it to make the assert_spin_locked happy. */
3081 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003082 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003083 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003084 }
3085
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003086 return 0;
3087}
3088
Imre Deakf8b79e52014-03-04 19:23:07 +02003089static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3090{
3091 u32 pipestat_mask;
3092 u32 iir_mask;
3093
3094 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3095 PIPE_FIFO_UNDERRUN_STATUS;
3096
3097 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3098 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3099 POSTING_READ(PIPESTAT(PIPE_A));
3100
3101 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3102 PIPE_CRC_DONE_INTERRUPT_STATUS;
3103
3104 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3105 PIPE_GMBUS_INTERRUPT_STATUS);
3106 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3107
3108 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3109 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3110 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
3111 dev_priv->irq_mask &= ~iir_mask;
3112
3113 I915_WRITE(VLV_IIR, iir_mask);
3114 I915_WRITE(VLV_IIR, iir_mask);
3115 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3116 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3117 POSTING_READ(VLV_IER);
3118}
3119
3120static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3121{
3122 u32 pipestat_mask;
3123 u32 iir_mask;
3124
3125 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3126 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003127 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003128
3129 dev_priv->irq_mask |= iir_mask;
3130 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3131 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3132 I915_WRITE(VLV_IIR, iir_mask);
3133 I915_WRITE(VLV_IIR, iir_mask);
3134 POSTING_READ(VLV_IIR);
3135
3136 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3137 PIPE_CRC_DONE_INTERRUPT_STATUS;
3138
3139 i915_disable_pipestat(dev_priv, PIPE_A, pipestat_mask |
3140 PIPE_GMBUS_INTERRUPT_STATUS);
3141 i915_disable_pipestat(dev_priv, PIPE_B, pipestat_mask);
3142
3143 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3144 PIPE_FIFO_UNDERRUN_STATUS;
3145 I915_WRITE(PIPESTAT(PIPE_A), pipestat_mask);
3146 I915_WRITE(PIPESTAT(PIPE_B), pipestat_mask);
3147 POSTING_READ(PIPESTAT(PIPE_A));
3148}
3149
3150void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3151{
3152 assert_spin_locked(&dev_priv->irq_lock);
3153
3154 if (dev_priv->display_irqs_enabled)
3155 return;
3156
3157 dev_priv->display_irqs_enabled = true;
3158
3159 if (dev_priv->dev->irq_enabled)
3160 valleyview_display_irqs_install(dev_priv);
3161}
3162
3163void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3164{
3165 assert_spin_locked(&dev_priv->irq_lock);
3166
3167 if (!dev_priv->display_irqs_enabled)
3168 return;
3169
3170 dev_priv->display_irqs_enabled = false;
3171
3172 if (dev_priv->dev->irq_enabled)
3173 valleyview_display_irqs_uninstall(dev_priv);
3174}
3175
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003176static int valleyview_irq_postinstall(struct drm_device *dev)
3177{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003178 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003179 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003180
Imre Deakf8b79e52014-03-04 19:23:07 +02003181 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003182
Daniel Vetter20afbda2012-12-11 14:05:07 +01003183 I915_WRITE(PORT_HOTPLUG_EN, 0);
3184 POSTING_READ(PORT_HOTPLUG_EN);
3185
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003186 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003187 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003188 I915_WRITE(VLV_IIR, 0xffffffff);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003189 POSTING_READ(VLV_IER);
3190
Daniel Vetterb79480b2013-06-27 17:52:10 +02003191 /* Interrupt setup is already guaranteed to be single-threaded, this is
3192 * just to make the assert_spin_locked check happy. */
3193 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deakf8b79e52014-03-04 19:23:07 +02003194 if (dev_priv->display_irqs_enabled)
3195 valleyview_display_irqs_install(dev_priv);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003196 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003197
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003198 I915_WRITE(VLV_IIR, 0xffffffff);
3199 I915_WRITE(VLV_IIR, 0xffffffff);
3200
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003201 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003202
3203 /* ack & enable invalid PTE error interrupts */
3204#if 0 /* FIXME: add support to irq handler for checking these bits */
3205 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3206 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3207#endif
3208
3209 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003210
3211 return 0;
3212}
3213
Ben Widawskyabd58f02013-11-02 21:07:09 -07003214static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3215{
3216 int i;
3217
3218 /* These are interrupts we'll toggle with the ring mask register */
3219 uint32_t gt_interrupts[] = {
3220 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3221 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3222 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3223 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3224 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3225 0,
3226 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3227 };
3228
3229 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
3230 u32 tmp = I915_READ(GEN8_GT_IIR(i));
3231 if (tmp)
3232 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3233 i, tmp);
3234 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
3235 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
3236 }
3237 POSTING_READ(GEN8_GT_IER(0));
3238}
3239
3240static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3241{
3242 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003243 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
3244 GEN8_PIPE_CDCLK_CRC_DONE |
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003245 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Daniel Vetter5c673b62014-03-07 20:34:46 +01003246 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3247 GEN8_PIPE_FIFO_UNDERRUN;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003248 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003249 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3250 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3251 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003252
3253 for_each_pipe(pipe) {
3254 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
3255 if (tmp)
3256 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3257 pipe, tmp);
3258 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3259 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
3260 }
3261 POSTING_READ(GEN8_DE_PIPE_ISR(0));
3262
Daniel Vetter6d766f02013-11-07 14:49:55 +01003263 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
3264 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003265 POSTING_READ(GEN8_DE_PORT_IER);
3266}
3267
3268static int gen8_irq_postinstall(struct drm_device *dev)
3269{
3270 struct drm_i915_private *dev_priv = dev->dev_private;
3271
3272 gen8_gt_irq_postinstall(dev_priv);
3273 gen8_de_irq_postinstall(dev_priv);
3274
3275 ibx_irq_postinstall(dev);
3276
3277 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3278 POSTING_READ(GEN8_MASTER_IRQ);
3279
3280 return 0;
3281}
3282
3283static void gen8_irq_uninstall(struct drm_device *dev)
3284{
3285 struct drm_i915_private *dev_priv = dev->dev_private;
3286 int pipe;
3287
3288 if (!dev_priv)
3289 return;
3290
Ben Widawskyabd58f02013-11-02 21:07:09 -07003291 I915_WRITE(GEN8_MASTER_IRQ, 0);
3292
3293#define GEN8_IRQ_FINI_NDX(type, which) do { \
3294 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3295 I915_WRITE(GEN8_##type##_IER(which), 0); \
3296 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3297 } while (0)
3298
3299#define GEN8_IRQ_FINI(type) do { \
3300 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3301 I915_WRITE(GEN8_##type##_IER, 0); \
3302 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3303 } while (0)
3304
3305 GEN8_IRQ_FINI_NDX(GT, 0);
3306 GEN8_IRQ_FINI_NDX(GT, 1);
3307 GEN8_IRQ_FINI_NDX(GT, 2);
3308 GEN8_IRQ_FINI_NDX(GT, 3);
3309
3310 for_each_pipe(pipe) {
3311 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3312 }
3313
3314 GEN8_IRQ_FINI(DE_PORT);
3315 GEN8_IRQ_FINI(DE_MISC);
3316 GEN8_IRQ_FINI(PCU);
3317#undef GEN8_IRQ_FINI
3318#undef GEN8_IRQ_FINI_NDX
3319
3320 POSTING_READ(GEN8_PCU_IIR);
3321}
3322
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003323static void valleyview_irq_uninstall(struct drm_device *dev)
3324{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003325 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deakf8b79e52014-03-04 19:23:07 +02003326 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003327 int pipe;
3328
3329 if (!dev_priv)
3330 return;
3331
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003332 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003333
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003334 for_each_pipe(pipe)
3335 I915_WRITE(PIPESTAT(pipe), 0xffff);
3336
3337 I915_WRITE(HWSTAM, 0xffffffff);
3338 I915_WRITE(PORT_HOTPLUG_EN, 0);
3339 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Imre Deakf8b79e52014-03-04 19:23:07 +02003340
3341 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3342 if (dev_priv->display_irqs_enabled)
3343 valleyview_display_irqs_uninstall(dev_priv);
3344 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3345
3346 dev_priv->irq_mask = 0;
3347
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003348 I915_WRITE(VLV_IIR, 0xffffffff);
3349 I915_WRITE(VLV_IMR, 0xffffffff);
3350 I915_WRITE(VLV_IER, 0x0);
3351 POSTING_READ(VLV_IER);
3352}
3353
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003354static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003355{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003356 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003357
3358 if (!dev_priv)
3359 return;
3360
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003361 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003362
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003363 I915_WRITE(HWSTAM, 0xffffffff);
3364
3365 I915_WRITE(DEIMR, 0xffffffff);
3366 I915_WRITE(DEIER, 0x0);
3367 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003368 if (IS_GEN7(dev))
3369 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003370
3371 I915_WRITE(GTIMR, 0xffffffff);
3372 I915_WRITE(GTIER, 0x0);
3373 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003374
Ben Widawskyab5c6082013-04-05 13:12:41 -07003375 if (HAS_PCH_NOP(dev))
3376 return;
3377
Keith Packard192aac1f2011-09-20 10:12:44 -07003378 I915_WRITE(SDEIMR, 0xffffffff);
3379 I915_WRITE(SDEIER, 0x0);
3380 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003381 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3382 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003383}
3384
Chris Wilsonc2798b12012-04-22 21:13:57 +01003385static void i8xx_irq_preinstall(struct drm_device * dev)
3386{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003387 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003388 int pipe;
3389
Chris Wilsonc2798b12012-04-22 21:13:57 +01003390 for_each_pipe(pipe)
3391 I915_WRITE(PIPESTAT(pipe), 0);
3392 I915_WRITE16(IMR, 0xffff);
3393 I915_WRITE16(IER, 0x0);
3394 POSTING_READ16(IER);
3395}
3396
3397static int i8xx_irq_postinstall(struct drm_device *dev)
3398{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003399 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003400 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003401
Chris Wilsonc2798b12012-04-22 21:13:57 +01003402 I915_WRITE16(EMR,
3403 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3404
3405 /* Unmask the interrupts that we always want on. */
3406 dev_priv->irq_mask =
3407 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3408 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3409 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3410 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3411 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3412 I915_WRITE16(IMR, dev_priv->irq_mask);
3413
3414 I915_WRITE16(IER,
3415 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3416 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3417 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3418 I915_USER_INTERRUPT);
3419 POSTING_READ16(IER);
3420
Daniel Vetter379ef822013-10-16 22:55:56 +02003421 /* Interrupt setup is already guaranteed to be single-threaded, this is
3422 * just to make the assert_spin_locked check happy. */
3423 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003424 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3425 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003426 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3427
Chris Wilsonc2798b12012-04-22 21:13:57 +01003428 return 0;
3429}
3430
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003431/*
3432 * Returns true when a page flip has completed.
3433 */
3434static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003435 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003436{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003437 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003438 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003439
3440 if (!drm_handle_vblank(dev, pipe))
3441 return false;
3442
3443 if ((iir & flip_pending) == 0)
3444 return false;
3445
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003446 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003447
3448 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3449 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3450 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3451 * the flip is completed (no longer pending). Since this doesn't raise
3452 * an interrupt per se, we watch for the change at vblank.
3453 */
3454 if (I915_READ16(ISR) & flip_pending)
3455 return false;
3456
3457 intel_finish_page_flip(dev, pipe);
3458
3459 return true;
3460}
3461
Daniel Vetterff1f5252012-10-02 15:10:55 +02003462static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003463{
3464 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003465 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003466 u16 iir, new_iir;
3467 u32 pipe_stats[2];
3468 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003469 int pipe;
3470 u16 flip_mask =
3471 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3472 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3473
Chris Wilsonc2798b12012-04-22 21:13:57 +01003474 iir = I915_READ16(IIR);
3475 if (iir == 0)
3476 return IRQ_NONE;
3477
3478 while (iir & ~flip_mask) {
3479 /* Can't rely on pipestat interrupt bit in iir as it might
3480 * have been cleared after the pipestat interrupt was received.
3481 * It doesn't set the bit in iir again, but it still produces
3482 * interrupts (for non-MSI).
3483 */
3484 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3485 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003486 i915_handle_error(dev, false,
3487 "Command parser error, iir 0x%08x",
3488 iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003489
3490 for_each_pipe(pipe) {
3491 int reg = PIPESTAT(pipe);
3492 pipe_stats[pipe] = I915_READ(reg);
3493
3494 /*
3495 * Clear the PIPE*STAT regs before the IIR
3496 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003497 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003498 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003499 }
3500 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3501
3502 I915_WRITE16(IIR, iir & ~flip_mask);
3503 new_iir = I915_READ16(IIR); /* Flush posted writes */
3504
Daniel Vetterd05c6172012-04-26 23:28:09 +02003505 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003506
3507 if (iir & I915_USER_INTERRUPT)
3508 notify_ring(dev, &dev_priv->ring[RCS]);
3509
Daniel Vetter4356d582013-10-16 22:55:55 +02003510 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003511 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003512 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003513 plane = !plane;
3514
Daniel Vetter4356d582013-10-16 22:55:55 +02003515 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003516 i8xx_handle_vblank(dev, plane, pipe, iir))
3517 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003518
Daniel Vetter4356d582013-10-16 22:55:55 +02003519 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003520 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003521
3522 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3523 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003524 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003525 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003526
3527 iir = new_iir;
3528 }
3529
3530 return IRQ_HANDLED;
3531}
3532
3533static void i8xx_irq_uninstall(struct drm_device * dev)
3534{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003535 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003536 int pipe;
3537
Chris Wilsonc2798b12012-04-22 21:13:57 +01003538 for_each_pipe(pipe) {
3539 /* Clear enable bits; then clear status bits */
3540 I915_WRITE(PIPESTAT(pipe), 0);
3541 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3542 }
3543 I915_WRITE16(IMR, 0xffff);
3544 I915_WRITE16(IER, 0x0);
3545 I915_WRITE16(IIR, I915_READ16(IIR));
3546}
3547
Chris Wilsona266c7d2012-04-24 22:59:44 +01003548static void i915_irq_preinstall(struct drm_device * dev)
3549{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003550 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003551 int pipe;
3552
Chris Wilsona266c7d2012-04-24 22:59:44 +01003553 if (I915_HAS_HOTPLUG(dev)) {
3554 I915_WRITE(PORT_HOTPLUG_EN, 0);
3555 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3556 }
3557
Chris Wilson00d98eb2012-04-24 22:59:48 +01003558 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003559 for_each_pipe(pipe)
3560 I915_WRITE(PIPESTAT(pipe), 0);
3561 I915_WRITE(IMR, 0xffffffff);
3562 I915_WRITE(IER, 0x0);
3563 POSTING_READ(IER);
3564}
3565
3566static int i915_irq_postinstall(struct drm_device *dev)
3567{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003568 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003569 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003570 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003571
Chris Wilson38bde182012-04-24 22:59:50 +01003572 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3573
3574 /* Unmask the interrupts that we always want on. */
3575 dev_priv->irq_mask =
3576 ~(I915_ASLE_INTERRUPT |
3577 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3578 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3579 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3580 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3581 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3582
3583 enable_mask =
3584 I915_ASLE_INTERRUPT |
3585 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3586 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3587 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3588 I915_USER_INTERRUPT;
3589
Chris Wilsona266c7d2012-04-24 22:59:44 +01003590 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003591 I915_WRITE(PORT_HOTPLUG_EN, 0);
3592 POSTING_READ(PORT_HOTPLUG_EN);
3593
Chris Wilsona266c7d2012-04-24 22:59:44 +01003594 /* Enable in IER... */
3595 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3596 /* and unmask in IMR */
3597 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3598 }
3599
Chris Wilsona266c7d2012-04-24 22:59:44 +01003600 I915_WRITE(IMR, dev_priv->irq_mask);
3601 I915_WRITE(IER, enable_mask);
3602 POSTING_READ(IER);
3603
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003604 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003605
Daniel Vetter379ef822013-10-16 22:55:56 +02003606 /* Interrupt setup is already guaranteed to be single-threaded, this is
3607 * just to make the assert_spin_locked check happy. */
3608 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003609 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3610 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003611 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3612
Daniel Vetter20afbda2012-12-11 14:05:07 +01003613 return 0;
3614}
3615
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003616/*
3617 * Returns true when a page flip has completed.
3618 */
3619static bool i915_handle_vblank(struct drm_device *dev,
3620 int plane, int pipe, u32 iir)
3621{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003622 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003623 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3624
3625 if (!drm_handle_vblank(dev, pipe))
3626 return false;
3627
3628 if ((iir & flip_pending) == 0)
3629 return false;
3630
3631 intel_prepare_page_flip(dev, plane);
3632
3633 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3634 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3635 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3636 * the flip is completed (no longer pending). Since this doesn't raise
3637 * an interrupt per se, we watch for the change at vblank.
3638 */
3639 if (I915_READ(ISR) & flip_pending)
3640 return false;
3641
3642 intel_finish_page_flip(dev, pipe);
3643
3644 return true;
3645}
3646
Daniel Vetterff1f5252012-10-02 15:10:55 +02003647static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003648{
3649 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003650 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003651 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003652 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003653 u32 flip_mask =
3654 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3655 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003656 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003657
Chris Wilsona266c7d2012-04-24 22:59:44 +01003658 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003659 do {
3660 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003661 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003662
3663 /* Can't rely on pipestat interrupt bit in iir as it might
3664 * have been cleared after the pipestat interrupt was received.
3665 * It doesn't set the bit in iir again, but it still produces
3666 * interrupts (for non-MSI).
3667 */
3668 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3669 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003670 i915_handle_error(dev, false,
3671 "Command parser error, iir 0x%08x",
3672 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003673
3674 for_each_pipe(pipe) {
3675 int reg = PIPESTAT(pipe);
3676 pipe_stats[pipe] = I915_READ(reg);
3677
Chris Wilson38bde182012-04-24 22:59:50 +01003678 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003679 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003680 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003681 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003682 }
3683 }
3684 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3685
3686 if (!irq_received)
3687 break;
3688
Chris Wilsona266c7d2012-04-24 22:59:44 +01003689 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003690 if (I915_HAS_HOTPLUG(dev) &&
3691 iir & I915_DISPLAY_PORT_INTERRUPT)
3692 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003693
Chris Wilson38bde182012-04-24 22:59:50 +01003694 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003695 new_iir = I915_READ(IIR); /* Flush posted writes */
3696
Chris Wilsona266c7d2012-04-24 22:59:44 +01003697 if (iir & I915_USER_INTERRUPT)
3698 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003699
Chris Wilsona266c7d2012-04-24 22:59:44 +01003700 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003701 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003702 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003703 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003704
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003705 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3706 i915_handle_vblank(dev, plane, pipe, iir))
3707 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003708
3709 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3710 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003711
3712 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003713 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003714
3715 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3716 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003717 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003718 }
3719
Chris Wilsona266c7d2012-04-24 22:59:44 +01003720 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3721 intel_opregion_asle_intr(dev);
3722
3723 /* With MSI, interrupts are only generated when iir
3724 * transitions from zero to nonzero. If another bit got
3725 * set while we were handling the existing iir bits, then
3726 * we would never get another interrupt.
3727 *
3728 * This is fine on non-MSI as well, as if we hit this path
3729 * we avoid exiting the interrupt handler only to generate
3730 * another one.
3731 *
3732 * Note that for MSI this could cause a stray interrupt report
3733 * if an interrupt landed in the time between writing IIR and
3734 * the posting read. This should be rare enough to never
3735 * trigger the 99% of 100,000 interrupts test for disabling
3736 * stray interrupts.
3737 */
Chris Wilson38bde182012-04-24 22:59:50 +01003738 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003739 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003740 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003741
Daniel Vetterd05c6172012-04-26 23:28:09 +02003742 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003743
Chris Wilsona266c7d2012-04-24 22:59:44 +01003744 return ret;
3745}
3746
3747static void i915_irq_uninstall(struct drm_device * dev)
3748{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003749 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003750 int pipe;
3751
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003752 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003753
Chris Wilsona266c7d2012-04-24 22:59:44 +01003754 if (I915_HAS_HOTPLUG(dev)) {
3755 I915_WRITE(PORT_HOTPLUG_EN, 0);
3756 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3757 }
3758
Chris Wilson00d98eb2012-04-24 22:59:48 +01003759 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003760 for_each_pipe(pipe) {
3761 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003762 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003763 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3764 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003765 I915_WRITE(IMR, 0xffffffff);
3766 I915_WRITE(IER, 0x0);
3767
Chris Wilsona266c7d2012-04-24 22:59:44 +01003768 I915_WRITE(IIR, I915_READ(IIR));
3769}
3770
3771static void i965_irq_preinstall(struct drm_device * dev)
3772{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003773 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003774 int pipe;
3775
Chris Wilsonadca4732012-05-11 18:01:31 +01003776 I915_WRITE(PORT_HOTPLUG_EN, 0);
3777 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003778
3779 I915_WRITE(HWSTAM, 0xeffe);
3780 for_each_pipe(pipe)
3781 I915_WRITE(PIPESTAT(pipe), 0);
3782 I915_WRITE(IMR, 0xffffffff);
3783 I915_WRITE(IER, 0x0);
3784 POSTING_READ(IER);
3785}
3786
3787static int i965_irq_postinstall(struct drm_device *dev)
3788{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003789 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003790 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003791 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003792 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003793
Chris Wilsona266c7d2012-04-24 22:59:44 +01003794 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003795 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003796 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003797 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3798 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3799 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3800 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3801 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3802
3803 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003804 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3805 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003806 enable_mask |= I915_USER_INTERRUPT;
3807
3808 if (IS_G4X(dev))
3809 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003810
Daniel Vetterb79480b2013-06-27 17:52:10 +02003811 /* Interrupt setup is already guaranteed to be single-threaded, this is
3812 * just to make the assert_spin_locked check happy. */
3813 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003814 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3815 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3816 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003817 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003818
Chris Wilsona266c7d2012-04-24 22:59:44 +01003819 /*
3820 * Enable some error detection, note the instruction error mask
3821 * bit is reserved, so we leave it masked.
3822 */
3823 if (IS_G4X(dev)) {
3824 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3825 GM45_ERROR_MEM_PRIV |
3826 GM45_ERROR_CP_PRIV |
3827 I915_ERROR_MEMORY_REFRESH);
3828 } else {
3829 error_mask = ~(I915_ERROR_PAGE_TABLE |
3830 I915_ERROR_MEMORY_REFRESH);
3831 }
3832 I915_WRITE(EMR, error_mask);
3833
3834 I915_WRITE(IMR, dev_priv->irq_mask);
3835 I915_WRITE(IER, enable_mask);
3836 POSTING_READ(IER);
3837
Daniel Vetter20afbda2012-12-11 14:05:07 +01003838 I915_WRITE(PORT_HOTPLUG_EN, 0);
3839 POSTING_READ(PORT_HOTPLUG_EN);
3840
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003841 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003842
3843 return 0;
3844}
3845
Egbert Eichbac56d52013-02-25 12:06:51 -05003846static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003847{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003848 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003849 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003850 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003851 u32 hotplug_en;
3852
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003853 assert_spin_locked(&dev_priv->irq_lock);
3854
Egbert Eichbac56d52013-02-25 12:06:51 -05003855 if (I915_HAS_HOTPLUG(dev)) {
3856 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3857 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3858 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003859 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003860 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3861 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3862 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003863 /* Programming the CRT detection parameters tends
3864 to generate a spurious hotplug event about three
3865 seconds later. So just do it once.
3866 */
3867 if (IS_G4X(dev))
3868 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003869 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003870 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003871
Egbert Eichbac56d52013-02-25 12:06:51 -05003872 /* Ignore TV since it's buggy */
3873 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3874 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003875}
3876
Daniel Vetterff1f5252012-10-02 15:10:55 +02003877static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003878{
3879 struct drm_device *dev = (struct drm_device *) arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003880 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003881 u32 iir, new_iir;
3882 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003883 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003884 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003885 u32 flip_mask =
3886 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3887 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003888
Chris Wilsona266c7d2012-04-24 22:59:44 +01003889 iir = I915_READ(IIR);
3890
Chris Wilsona266c7d2012-04-24 22:59:44 +01003891 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003892 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003893 bool blc_event = false;
3894
Chris Wilsona266c7d2012-04-24 22:59:44 +01003895 /* Can't rely on pipestat interrupt bit in iir as it might
3896 * have been cleared after the pipestat interrupt was received.
3897 * It doesn't set the bit in iir again, but it still produces
3898 * interrupts (for non-MSI).
3899 */
3900 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3901 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Mika Kuoppala58174462014-02-25 17:11:26 +02003902 i915_handle_error(dev, false,
3903 "Command parser error, iir 0x%08x",
3904 iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003905
3906 for_each_pipe(pipe) {
3907 int reg = PIPESTAT(pipe);
3908 pipe_stats[pipe] = I915_READ(reg);
3909
3910 /*
3911 * Clear the PIPE*STAT regs before the IIR
3912 */
3913 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003914 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003915 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003916 }
3917 }
3918 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3919
3920 if (!irq_received)
3921 break;
3922
3923 ret = IRQ_HANDLED;
3924
3925 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003926 if (iir & I915_DISPLAY_PORT_INTERRUPT)
3927 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003928
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003929 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003930 new_iir = I915_READ(IIR); /* Flush posted writes */
3931
Chris Wilsona266c7d2012-04-24 22:59:44 +01003932 if (iir & I915_USER_INTERRUPT)
3933 notify_ring(dev, &dev_priv->ring[RCS]);
3934 if (iir & I915_BSD_USER_INTERRUPT)
3935 notify_ring(dev, &dev_priv->ring[VCS]);
3936
Chris Wilsona266c7d2012-04-24 22:59:44 +01003937 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003938 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003939 i915_handle_vblank(dev, pipe, pipe, iir))
3940 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003941
3942 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3943 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003944
3945 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003946 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003947
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003948 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3949 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003950 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003951 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003952
3953 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3954 intel_opregion_asle_intr(dev);
3955
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003956 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3957 gmbus_irq_handler(dev);
3958
Chris Wilsona266c7d2012-04-24 22:59:44 +01003959 /* With MSI, interrupts are only generated when iir
3960 * transitions from zero to nonzero. If another bit got
3961 * set while we were handling the existing iir bits, then
3962 * we would never get another interrupt.
3963 *
3964 * This is fine on non-MSI as well, as if we hit this path
3965 * we avoid exiting the interrupt handler only to generate
3966 * another one.
3967 *
3968 * Note that for MSI this could cause a stray interrupt report
3969 * if an interrupt landed in the time between writing IIR and
3970 * the posting read. This should be rare enough to never
3971 * trigger the 99% of 100,000 interrupts test for disabling
3972 * stray interrupts.
3973 */
3974 iir = new_iir;
3975 }
3976
Daniel Vetterd05c6172012-04-26 23:28:09 +02003977 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003978
Chris Wilsona266c7d2012-04-24 22:59:44 +01003979 return ret;
3980}
3981
3982static void i965_irq_uninstall(struct drm_device * dev)
3983{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003984 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003985 int pipe;
3986
3987 if (!dev_priv)
3988 return;
3989
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003990 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003991
Chris Wilsonadca4732012-05-11 18:01:31 +01003992 I915_WRITE(PORT_HOTPLUG_EN, 0);
3993 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003994
3995 I915_WRITE(HWSTAM, 0xffffffff);
3996 for_each_pipe(pipe)
3997 I915_WRITE(PIPESTAT(pipe), 0);
3998 I915_WRITE(IMR, 0xffffffff);
3999 I915_WRITE(IER, 0x0);
4000
4001 for_each_pipe(pipe)
4002 I915_WRITE(PIPESTAT(pipe),
4003 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4004 I915_WRITE(IIR, I915_READ(IIR));
4005}
4006
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004007static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02004008{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004009 struct drm_i915_private *dev_priv = (struct drm_i915_private *)data;
Egbert Eichac4c16c2013-04-16 13:36:58 +02004010 struct drm_device *dev = dev_priv->dev;
4011 struct drm_mode_config *mode_config = &dev->mode_config;
4012 unsigned long irqflags;
4013 int i;
4014
4015 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4016 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4017 struct drm_connector *connector;
4018
4019 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4020 continue;
4021
4022 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4023
4024 list_for_each_entry(connector, &mode_config->connector_list, head) {
4025 struct intel_connector *intel_connector = to_intel_connector(connector);
4026
4027 if (intel_connector->encoder->hpd_pin == i) {
4028 if (connector->polled != intel_connector->polled)
4029 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
4030 drm_get_connector_name(connector));
4031 connector->polled = intel_connector->polled;
4032 if (!connector->polled)
4033 connector->polled = DRM_CONNECTOR_POLL_HPD;
4034 }
4035 }
4036 }
4037 if (dev_priv->display.hpd_irq_setup)
4038 dev_priv->display.hpd_irq_setup(dev);
4039 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4040}
4041
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004042void intel_irq_init(struct drm_device *dev)
4043{
Chris Wilson8b2e3262012-04-24 22:59:41 +01004044 struct drm_i915_private *dev_priv = dev->dev_private;
4045
4046 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004047 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004048 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004049 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004050
Deepak Sa6706b42014-03-15 20:23:22 +05304051 /* Let's track the enabled rps events */
4052 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
4053
Daniel Vetter99584db2012-11-14 17:14:04 +01004054 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4055 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004056 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02004057 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02004058 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01004059
Tomas Janousek97a19a22012-12-08 13:48:13 +01004060 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004061
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004062 if (IS_GEN2(dev)) {
4063 dev->max_vblank_count = 0;
4064 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
4065 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004066 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4067 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004068 } else {
4069 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4070 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004071 }
4072
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004073 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004074 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004075 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4076 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004077
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004078 if (IS_VALLEYVIEW(dev)) {
4079 dev->driver->irq_handler = valleyview_irq_handler;
4080 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4081 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4082 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4083 dev->driver->enable_vblank = valleyview_enable_vblank;
4084 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004085 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004086 } else if (IS_GEN8(dev)) {
4087 dev->driver->irq_handler = gen8_irq_handler;
4088 dev->driver->irq_preinstall = gen8_irq_preinstall;
4089 dev->driver->irq_postinstall = gen8_irq_postinstall;
4090 dev->driver->irq_uninstall = gen8_irq_uninstall;
4091 dev->driver->enable_vblank = gen8_enable_vblank;
4092 dev->driver->disable_vblank = gen8_disable_vblank;
4093 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004094 } else if (HAS_PCH_SPLIT(dev)) {
4095 dev->driver->irq_handler = ironlake_irq_handler;
4096 dev->driver->irq_preinstall = ironlake_irq_preinstall;
4097 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4098 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4099 dev->driver->enable_vblank = ironlake_enable_vblank;
4100 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004101 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004102 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004103 if (INTEL_INFO(dev)->gen == 2) {
4104 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4105 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4106 dev->driver->irq_handler = i8xx_irq_handler;
4107 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004108 } else if (INTEL_INFO(dev)->gen == 3) {
4109 dev->driver->irq_preinstall = i915_irq_preinstall;
4110 dev->driver->irq_postinstall = i915_irq_postinstall;
4111 dev->driver->irq_uninstall = i915_irq_uninstall;
4112 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004113 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004114 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004115 dev->driver->irq_preinstall = i965_irq_preinstall;
4116 dev->driver->irq_postinstall = i965_irq_postinstall;
4117 dev->driver->irq_uninstall = i965_irq_uninstall;
4118 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004119 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004120 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004121 dev->driver->enable_vblank = i915_enable_vblank;
4122 dev->driver->disable_vblank = i915_disable_vblank;
4123 }
4124}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004125
4126void intel_hpd_init(struct drm_device *dev)
4127{
4128 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02004129 struct drm_mode_config *mode_config = &dev->mode_config;
4130 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004131 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02004132 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004133
Egbert Eich821450c2013-04-16 13:36:55 +02004134 for (i = 1; i < HPD_NUM_PINS; i++) {
4135 dev_priv->hpd_stats[i].hpd_cnt = 0;
4136 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4137 }
4138 list_for_each_entry(connector, &mode_config->connector_list, head) {
4139 struct intel_connector *intel_connector = to_intel_connector(connector);
4140 connector->polled = intel_connector->polled;
4141 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4142 connector->polled = DRM_CONNECTOR_POLL_HPD;
4143 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004144
4145 /* Interrupt setup is already guaranteed to be single-threaded, this is
4146 * just to make the assert_spin_locked checks happy. */
4147 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004148 if (dev_priv->display.hpd_irq_setup)
4149 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004150 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004151}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004152
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004153/* Disable interrupts so we can allow runtime PM. */
4154void hsw_runtime_pm_disable_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004155{
4156 struct drm_i915_private *dev_priv = dev->dev_private;
4157 unsigned long irqflags;
4158
4159 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4160
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004161 dev_priv->pm.regsave.deimr = I915_READ(DEIMR);
4162 dev_priv->pm.regsave.sdeimr = I915_READ(SDEIMR);
4163 dev_priv->pm.regsave.gtimr = I915_READ(GTIMR);
4164 dev_priv->pm.regsave.gtier = I915_READ(GTIER);
4165 dev_priv->pm.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004166
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004167 ironlake_disable_display_irq(dev_priv, 0xffffffff);
4168 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004169 ilk_disable_gt_irq(dev_priv, 0xffffffff);
4170 snb_disable_pm_irq(dev_priv, 0xffffffff);
4171
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004172 dev_priv->pm.irqs_disabled = true;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004173
4174 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4175}
4176
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004177/* Restore interrupts so we can recover from runtime PM. */
4178void hsw_runtime_pm_restore_interrupts(struct drm_device *dev)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004179{
4180 struct drm_i915_private *dev_priv = dev->dev_private;
4181 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004182 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004183
4184 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4185
4186 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004187 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004188
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004189 val = I915_READ(SDEIMR);
4190 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004191
4192 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004193 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004194
4195 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004196 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004197
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004198 dev_priv->pm.irqs_disabled = false;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004199
Paulo Zanoni5d584b22014-03-07 20:08:15 -03004200 ironlake_enable_display_irq(dev_priv, ~dev_priv->pm.regsave.deimr);
4201 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pm.regsave.sdeimr);
4202 ilk_enable_gt_irq(dev_priv, ~dev_priv->pm.regsave.gtimr);
4203 snb_enable_pm_irq(dev_priv, ~dev_priv->pm.regsave.gen6_pmimr);
4204 I915_WRITE(GTIER, dev_priv->pm.regsave.gtier);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004205
4206 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4207}