blob: c9540dca5d23e6f187617454b2b8e3a6b75dbc39 [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
Zhenyu Wang036a4a72009-06-08 14:40:19 +080083/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010084static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050085ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080086{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020087 assert_spin_locked(&dev_priv->irq_lock);
88
Paulo Zanonic67a4702013-08-19 13:18:09 -030089 if (dev_priv->pc8.irqs_disabled) {
90 WARN(1, "IRQs disabled\n");
91 dev_priv->pc8.regsave.deimr &= ~mask;
92 return;
93 }
94
Chris Wilson1ec14ad2010-12-04 11:30:53 +000095 if ((dev_priv->irq_mask & mask) != 0) {
96 dev_priv->irq_mask &= ~mask;
97 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000098 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080099 }
100}
101
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300102static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500103ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200105 assert_spin_locked(&dev_priv->irq_lock);
106
Paulo Zanonic67a4702013-08-19 13:18:09 -0300107 if (dev_priv->pc8.irqs_disabled) {
108 WARN(1, "IRQs disabled\n");
109 dev_priv->pc8.regsave.deimr |= mask;
110 return;
111 }
112
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000113 if ((dev_priv->irq_mask & mask) != mask) {
114 dev_priv->irq_mask |= mask;
115 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000116 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800117 }
118}
119
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300120/**
121 * ilk_update_gt_irq - update GTIMR
122 * @dev_priv: driver private
123 * @interrupt_mask: mask of interrupt bits to update
124 * @enabled_irq_mask: mask of interrupt bits to enable
125 */
126static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
127 uint32_t interrupt_mask,
128 uint32_t enabled_irq_mask)
129{
130 assert_spin_locked(&dev_priv->irq_lock);
131
Paulo Zanonic67a4702013-08-19 13:18:09 -0300132 if (dev_priv->pc8.irqs_disabled) {
133 WARN(1, "IRQs disabled\n");
134 dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
135 dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
136 interrupt_mask);
137 return;
138 }
139
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300140 dev_priv->gt_irq_mask &= ~interrupt_mask;
141 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
142 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
143 POSTING_READ(GTIMR);
144}
145
146void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
147{
148 ilk_update_gt_irq(dev_priv, mask, mask);
149}
150
151void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
152{
153 ilk_update_gt_irq(dev_priv, mask, 0);
154}
155
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300156/**
157 * snb_update_pm_irq - update GEN6_PMIMR
158 * @dev_priv: driver private
159 * @interrupt_mask: mask of interrupt bits to update
160 * @enabled_irq_mask: mask of interrupt bits to enable
161 */
162static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
163 uint32_t interrupt_mask,
164 uint32_t enabled_irq_mask)
165{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300166 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300167
168 assert_spin_locked(&dev_priv->irq_lock);
169
Paulo Zanonic67a4702013-08-19 13:18:09 -0300170 if (dev_priv->pc8.irqs_disabled) {
171 WARN(1, "IRQs disabled\n");
172 dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
173 dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
174 interrupt_mask);
175 return;
176 }
177
Paulo Zanoni605cd252013-08-06 18:57:15 -0300178 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300179 new_val &= ~interrupt_mask;
180 new_val |= (~enabled_irq_mask & interrupt_mask);
181
Paulo Zanoni605cd252013-08-06 18:57:15 -0300182 if (new_val != dev_priv->pm_irq_mask) {
183 dev_priv->pm_irq_mask = new_val;
184 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300185 POSTING_READ(GEN6_PMIMR);
186 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300187}
188
189void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
190{
191 snb_update_pm_irq(dev_priv, mask, mask);
192}
193
194void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
195{
196 snb_update_pm_irq(dev_priv, mask, 0);
197}
198
Paulo Zanoni86642812013-04-12 17:57:57 -0300199static bool ivb_can_enable_err_int(struct drm_device *dev)
200{
201 struct drm_i915_private *dev_priv = dev->dev_private;
202 struct intel_crtc *crtc;
203 enum pipe pipe;
204
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200205 assert_spin_locked(&dev_priv->irq_lock);
206
Paulo Zanoni86642812013-04-12 17:57:57 -0300207 for_each_pipe(pipe) {
208 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
209
210 if (crtc->cpu_fifo_underrun_disabled)
211 return false;
212 }
213
214 return true;
215}
216
217static bool cpt_can_enable_serr_int(struct drm_device *dev)
218{
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 enum pipe pipe;
221 struct intel_crtc *crtc;
222
Daniel Vetterfee884e2013-07-04 23:35:21 +0200223 assert_spin_locked(&dev_priv->irq_lock);
224
Paulo Zanoni86642812013-04-12 17:57:57 -0300225 for_each_pipe(pipe) {
226 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
227
228 if (crtc->pch_fifo_underrun_disabled)
229 return false;
230 }
231
232 return true;
233}
234
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200235static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
236{
237 struct drm_i915_private *dev_priv = dev->dev_private;
238 u32 reg = PIPESTAT(pipe);
239 u32 pipestat = I915_READ(reg) & 0x7fff0000;
240
241 assert_spin_locked(&dev_priv->irq_lock);
242
243 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
244 POSTING_READ(reg);
245}
246
Paulo Zanoni86642812013-04-12 17:57:57 -0300247static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
248 enum pipe pipe, bool enable)
249{
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
252 DE_PIPEB_FIFO_UNDERRUN;
253
254 if (enable)
255 ironlake_enable_display_irq(dev_priv, bit);
256 else
257 ironlake_disable_display_irq(dev_priv, bit);
258}
259
260static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200261 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300262{
263 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300264 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200265 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
266
Paulo Zanoni86642812013-04-12 17:57:57 -0300267 if (!ivb_can_enable_err_int(dev))
268 return;
269
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
271 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200272 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
273
274 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300275 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200276
277 if (!was_enabled &&
278 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
279 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
280 pipe_name(pipe));
281 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300282 }
283}
284
Daniel Vetter38d83c962013-11-07 11:05:46 +0100285static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
286 enum pipe pipe, bool enable)
287{
288 struct drm_i915_private *dev_priv = dev->dev_private;
289
290 assert_spin_locked(&dev_priv->irq_lock);
291
292 if (enable)
293 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
294 else
295 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
296 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
297 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
298}
299
Daniel Vetterfee884e2013-07-04 23:35:21 +0200300/**
301 * ibx_display_interrupt_update - update SDEIMR
302 * @dev_priv: driver private
303 * @interrupt_mask: mask of interrupt bits to update
304 * @enabled_irq_mask: mask of interrupt bits to enable
305 */
306static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
307 uint32_t interrupt_mask,
308 uint32_t enabled_irq_mask)
309{
310 uint32_t sdeimr = I915_READ(SDEIMR);
311 sdeimr &= ~interrupt_mask;
312 sdeimr |= (~enabled_irq_mask & interrupt_mask);
313
314 assert_spin_locked(&dev_priv->irq_lock);
315
Paulo Zanonic67a4702013-08-19 13:18:09 -0300316 if (dev_priv->pc8.irqs_disabled &&
317 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
318 WARN(1, "IRQs disabled\n");
319 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
320 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
321 interrupt_mask);
322 return;
323 }
324
Daniel Vetterfee884e2013-07-04 23:35:21 +0200325 I915_WRITE(SDEIMR, sdeimr);
326 POSTING_READ(SDEIMR);
327}
328#define ibx_enable_display_interrupt(dev_priv, bits) \
329 ibx_display_interrupt_update((dev_priv), (bits), (bits))
330#define ibx_disable_display_interrupt(dev_priv, bits) \
331 ibx_display_interrupt_update((dev_priv), (bits), 0)
332
Daniel Vetterde280752013-07-04 23:35:24 +0200333static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
334 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300335 bool enable)
336{
Paulo Zanoni86642812013-04-12 17:57:57 -0300337 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200338 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
339 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300340
341 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200342 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300343 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200344 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300345}
346
347static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
348 enum transcoder pch_transcoder,
349 bool enable)
350{
351 struct drm_i915_private *dev_priv = dev->dev_private;
352
353 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200354 I915_WRITE(SERR_INT,
355 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
356
Paulo Zanoni86642812013-04-12 17:57:57 -0300357 if (!cpt_can_enable_serr_int(dev))
358 return;
359
Daniel Vetterfee884e2013-07-04 23:35:21 +0200360 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300361 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200362 uint32_t tmp = I915_READ(SERR_INT);
363 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
364
365 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200366 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200367
368 if (!was_enabled &&
369 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
370 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
371 transcoder_name(pch_transcoder));
372 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300373 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300374}
375
376/**
377 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
378 * @dev: drm device
379 * @pipe: pipe
380 * @enable: true if we want to report FIFO underrun errors, false otherwise
381 *
382 * This function makes us disable or enable CPU fifo underruns for a specific
383 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
384 * reporting for one pipe may also disable all the other CPU error interruts for
385 * the other pipes, due to the fact that there's just one interrupt mask/enable
386 * bit for all the pipes.
387 *
388 * Returns the previous state of underrun reporting.
389 */
390bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
391 enum pipe pipe, bool enable)
392{
393 struct drm_i915_private *dev_priv = dev->dev_private;
394 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
395 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
396 unsigned long flags;
397 bool ret;
398
399 spin_lock_irqsave(&dev_priv->irq_lock, flags);
400
401 ret = !intel_crtc->cpu_fifo_underrun_disabled;
402
403 if (enable == ret)
404 goto done;
405
406 intel_crtc->cpu_fifo_underrun_disabled = !enable;
407
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200408 if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
409 i9xx_clear_fifo_underrun(dev, pipe);
410 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300411 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
412 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200413 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100414 else if (IS_GEN8(dev))
415 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300416
417done:
418 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
419 return ret;
420}
421
422/**
423 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
424 * @dev: drm device
425 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
426 * @enable: true if we want to report FIFO underrun errors, false otherwise
427 *
428 * This function makes us disable or enable PCH fifo underruns for a specific
429 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
430 * underrun reporting for one transcoder may also disable all the other PCH
431 * error interruts for the other transcoders, due to the fact that there's just
432 * one interrupt mask/enable bit for all the transcoders.
433 *
434 * Returns the previous state of underrun reporting.
435 */
436bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
437 enum transcoder pch_transcoder,
438 bool enable)
439{
440 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200441 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
442 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300443 unsigned long flags;
444 bool ret;
445
Daniel Vetterde280752013-07-04 23:35:24 +0200446 /*
447 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
448 * has only one pch transcoder A that all pipes can use. To avoid racy
449 * pch transcoder -> pipe lookups from interrupt code simply store the
450 * underrun statistics in crtc A. Since we never expose this anywhere
451 * nor use it outside of the fifo underrun code here using the "wrong"
452 * crtc on LPT won't cause issues.
453 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300454
455 spin_lock_irqsave(&dev_priv->irq_lock, flags);
456
457 ret = !intel_crtc->pch_fifo_underrun_disabled;
458
459 if (enable == ret)
460 goto done;
461
462 intel_crtc->pch_fifo_underrun_disabled = !enable;
463
464 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200465 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300466 else
467 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
468
469done:
470 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
471 return ret;
472}
473
474
Keith Packard7c463582008-11-04 02:03:27 -0800475void
Imre Deak755e9012014-02-10 18:42:47 +0200476__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
477 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800478{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200479 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200480 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800481
Daniel Vetterb79480b2013-06-27 17:52:10 +0200482 assert_spin_locked(&dev_priv->irq_lock);
483
Imre Deak755e9012014-02-10 18:42:47 +0200484 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
485 status_mask & ~PIPESTAT_INT_STATUS_MASK))
486 return;
487
488 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200489 return;
490
491 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200492 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200493 I915_WRITE(reg, pipestat);
494 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800495}
496
497void
Imre Deak755e9012014-02-10 18:42:47 +0200498__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
499 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800500{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200501 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200502 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800503
Daniel Vetterb79480b2013-06-27 17:52:10 +0200504 assert_spin_locked(&dev_priv->irq_lock);
505
Imre Deak755e9012014-02-10 18:42:47 +0200506 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
507 status_mask & ~PIPESTAT_INT_STATUS_MASK))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200508 return;
509
Imre Deak755e9012014-02-10 18:42:47 +0200510 if ((pipestat & enable_mask) == 0)
511 return;
512
513 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200514 I915_WRITE(reg, pipestat);
515 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800516}
517
Imre Deak10c59c52014-02-10 18:42:48 +0200518static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
519{
520 u32 enable_mask = status_mask << 16;
521
522 /*
523 * On pipe A we don't support the PSR interrupt yet, on pipe B the
524 * same bit MBZ.
525 */
526 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
527 return 0;
528
529 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
530 SPRITE0_FLIP_DONE_INT_EN_VLV |
531 SPRITE1_FLIP_DONE_INT_EN_VLV);
532 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
533 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
534 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
535 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
536
537 return enable_mask;
538}
539
Imre Deak755e9012014-02-10 18:42:47 +0200540void
541i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
542 u32 status_mask)
543{
544 u32 enable_mask;
545
Imre Deak10c59c52014-02-10 18:42:48 +0200546 if (IS_VALLEYVIEW(dev_priv->dev))
547 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
548 status_mask);
549 else
550 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200551 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
552}
553
554void
555i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
556 u32 status_mask)
557{
558 u32 enable_mask;
559
Imre Deak10c59c52014-02-10 18:42:48 +0200560 if (IS_VALLEYVIEW(dev_priv->dev))
561 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
562 status_mask);
563 else
564 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200565 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
566}
567
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000568/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300569 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000570 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300571static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000572{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000573 drm_i915_private_t *dev_priv = dev->dev_private;
574 unsigned long irqflags;
575
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300576 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
577 return;
578
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000579 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000580
Imre Deak755e9012014-02-10 18:42:47 +0200581 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300582 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200583 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200584 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000585
586 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000587}
588
589/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700590 * i915_pipe_enabled - check if a pipe is enabled
591 * @dev: DRM device
592 * @pipe: pipe to check
593 *
594 * Reading certain registers when the pipe is disabled can hang the chip.
595 * Use this routine to make sure the PLL is running and the pipe is active
596 * before reading such registers if unsure.
597 */
598static int
599i915_pipe_enabled(struct drm_device *dev, int pipe)
600{
601 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200602
Daniel Vettera01025a2013-05-22 00:50:23 +0200603 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
604 /* Locking is horribly broken here, but whatever. */
605 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
606 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300607
Daniel Vettera01025a2013-05-22 00:50:23 +0200608 return intel_crtc->active;
609 } else {
610 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
611 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700612}
613
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300614static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
615{
616 /* Gen2 doesn't have a hardware frame counter */
617 return 0;
618}
619
Keith Packard42f52ef2008-10-18 19:39:29 -0700620/* Called from drm generic code, passed a 'crtc', which
621 * we use as a pipe index
622 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700623static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700624{
625 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
626 unsigned long high_frame;
627 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300628 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700629
630 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800631 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800632 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700633 return 0;
634 }
635
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300636 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
637 struct intel_crtc *intel_crtc =
638 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
639 const struct drm_display_mode *mode =
640 &intel_crtc->config.adjusted_mode;
641
642 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
643 } else {
644 enum transcoder cpu_transcoder =
645 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
646 u32 htotal;
647
648 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
649 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
650
651 vbl_start *= htotal;
652 }
653
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800654 high_frame = PIPEFRAME(pipe);
655 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100656
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700657 /*
658 * High & low register fields aren't synchronized, so make sure
659 * we get a low value that's stable across two reads of the high
660 * register.
661 */
662 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100663 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300664 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100665 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700666 } while (high1 != high2);
667
Chris Wilson5eddb702010-09-11 13:48:45 +0100668 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300669 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100670 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300671
672 /*
673 * The frame counter increments at beginning of active.
674 * Cook up a vblank counter by also checking the pixel
675 * counter against vblank start.
676 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200677 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700678}
679
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700680static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800681{
682 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800683 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800684
685 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800686 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800687 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800688 return 0;
689 }
690
691 return I915_READ(reg);
692}
693
Mario Kleinerad3543e2013-10-30 05:13:08 +0100694/* raw reads, only for fast reads of display block, no need for forcewake etc. */
695#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
696#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
697
Ville Syrjälä095163b2013-10-29 00:04:43 +0200698static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300699{
700 struct drm_i915_private *dev_priv = dev->dev_private;
701 uint32_t status;
702
Ville Syrjälä095163b2013-10-29 00:04:43 +0200703 if (INTEL_INFO(dev)->gen < 7) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300704 status = pipe == PIPE_A ?
705 DE_PIPEA_VBLANK :
706 DE_PIPEB_VBLANK;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300707 } else {
708 switch (pipe) {
709 default:
710 case PIPE_A:
711 status = DE_PIPEA_VBLANK_IVB;
712 break;
713 case PIPE_B:
714 status = DE_PIPEB_VBLANK_IVB;
715 break;
716 case PIPE_C:
717 status = DE_PIPEC_VBLANK_IVB;
718 break;
719 }
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300720 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100721
Ville Syrjälä095163b2013-10-29 00:04:43 +0200722 return __raw_i915_read32(dev_priv, DEISR) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300723}
724
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700725static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200726 unsigned int flags, int *vpos, int *hpos,
727 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100728{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300729 struct drm_i915_private *dev_priv = dev->dev_private;
730 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
731 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
732 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300733 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100734 int vbl_start, vbl_end, htotal, vtotal;
735 bool in_vbl = true;
736 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100737 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100738
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300739 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100740 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800741 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100742 return 0;
743 }
744
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300745 htotal = mode->crtc_htotal;
746 vtotal = mode->crtc_vtotal;
747 vbl_start = mode->crtc_vblank_start;
748 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100749
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200750 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
751 vbl_start = DIV_ROUND_UP(vbl_start, 2);
752 vbl_end /= 2;
753 vtotal /= 2;
754 }
755
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300756 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
757
Mario Kleinerad3543e2013-10-30 05:13:08 +0100758 /*
759 * Lock uncore.lock, as we will do multiple timing critical raw
760 * register reads, potentially with preemption disabled, so the
761 * following code must not block on uncore.lock.
762 */
763 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
764
765 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
766
767 /* Get optional system timestamp before query. */
768 if (stime)
769 *stime = ktime_get();
770
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300771 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100772 /* No obvious pixelcount register. Only query vertical
773 * scanout position from Display scan line register.
774 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300775 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100776 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300777 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100778 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300779
Ville Syrjälä095163b2013-10-29 00:04:43 +0200780 if (HAS_PCH_SPLIT(dev)) {
781 /*
782 * The scanline counter increments at the leading edge
783 * of hsync, ie. it completely misses the active portion
784 * of the line. Fix up the counter at both edges of vblank
785 * to get a more accurate picture whether we're in vblank
786 * or not.
787 */
788 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
789 if ((in_vbl && position == vbl_start - 1) ||
790 (!in_vbl && position == vbl_end - 1))
791 position = (position + 1) % vtotal;
792 } else {
793 /*
794 * ISR vblank status bits don't work the way we'd want
795 * them to work on non-PCH platforms (for
796 * ilk_pipe_in_vblank_locked()), and there doesn't
797 * appear any other way to determine if we're currently
798 * in vblank.
799 *
800 * Instead let's assume that we're already in vblank if
801 * we got called from the vblank interrupt and the
802 * scanline counter value indicates that we're on the
803 * line just prior to vblank start. This should result
804 * in the correct answer, unless the vblank interrupt
805 * delivery really got delayed for almost exactly one
806 * full frame/field.
807 */
808 if (flags & DRM_CALLED_FROM_VBLIRQ &&
809 position == vbl_start - 1) {
810 position = (position + 1) % vtotal;
811
812 /* Signal this correction as "applied". */
813 ret |= 0x8;
814 }
815 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100816 } else {
817 /* Have access to pixelcount since start of frame.
818 * We can split this into vertical and horizontal
819 * scanout position.
820 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100821 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100822
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300823 /* convert to pixel counts */
824 vbl_start *= htotal;
825 vbl_end *= htotal;
826 vtotal *= htotal;
827 }
828
Mario Kleinerad3543e2013-10-30 05:13:08 +0100829 /* Get optional system timestamp after query. */
830 if (etime)
831 *etime = ktime_get();
832
833 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
834
835 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
836
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300837 in_vbl = position >= vbl_start && position < vbl_end;
838
839 /*
840 * While in vblank, position will be negative
841 * counting up towards 0 at vbl_end. And outside
842 * vblank, position will be positive counting
843 * up since vbl_end.
844 */
845 if (position >= vbl_start)
846 position -= vbl_end;
847 else
848 position += vtotal - vbl_end;
849
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300850 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300851 *vpos = position;
852 *hpos = 0;
853 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100854 *vpos = position / htotal;
855 *hpos = position - (*vpos * htotal);
856 }
857
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100858 /* In vblank? */
859 if (in_vbl)
860 ret |= DRM_SCANOUTPOS_INVBL;
861
862 return ret;
863}
864
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700865static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100866 int *max_error,
867 struct timeval *vblank_time,
868 unsigned flags)
869{
Chris Wilson4041b852011-01-22 10:07:56 +0000870 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100871
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700872 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000873 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100874 return -EINVAL;
875 }
876
877 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000878 crtc = intel_get_crtc_for_pipe(dev, pipe);
879 if (crtc == NULL) {
880 DRM_ERROR("Invalid crtc %d\n", pipe);
881 return -EINVAL;
882 }
883
884 if (!crtc->enabled) {
885 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
886 return -EBUSY;
887 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100888
889 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000890 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
891 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300892 crtc,
893 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100894}
895
Jani Nikula67c347f2013-09-17 14:26:34 +0300896static bool intel_hpd_irq_event(struct drm_device *dev,
897 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200898{
899 enum drm_connector_status old_status;
900
901 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
902 old_status = connector->status;
903
904 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300905 if (old_status == connector->status)
906 return false;
907
908 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200909 connector->base.id,
910 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300911 drm_get_connector_status_name(old_status),
912 drm_get_connector_status_name(connector->status));
913
914 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200915}
916
Jesse Barnes5ca58282009-03-31 14:11:15 -0700917/*
918 * Handle hotplug events outside the interrupt handler proper.
919 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200920#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
921
Jesse Barnes5ca58282009-03-31 14:11:15 -0700922static void i915_hotplug_work_func(struct work_struct *work)
923{
924 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
925 hotplug_work);
926 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700927 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200928 struct intel_connector *intel_connector;
929 struct intel_encoder *intel_encoder;
930 struct drm_connector *connector;
931 unsigned long irqflags;
932 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200933 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200934 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700935
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100936 /* HPD irq before everything is fully set up. */
937 if (!dev_priv->enable_hotplug_processing)
938 return;
939
Keith Packarda65e34c2011-07-25 10:04:56 -0700940 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800941 DRM_DEBUG_KMS("running encoder hotplug functions\n");
942
Egbert Eichcd569ae2013-04-16 13:36:57 +0200943 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200944
945 hpd_event_bits = dev_priv->hpd_event_bits;
946 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200947 list_for_each_entry(connector, &mode_config->connector_list, head) {
948 intel_connector = to_intel_connector(connector);
949 intel_encoder = intel_connector->encoder;
950 if (intel_encoder->hpd_pin > HPD_NONE &&
951 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
952 connector->polled == DRM_CONNECTOR_POLL_HPD) {
953 DRM_INFO("HPD interrupt storm detected on connector %s: "
954 "switching from hotplug detection to polling\n",
955 drm_get_connector_name(connector));
956 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
957 connector->polled = DRM_CONNECTOR_POLL_CONNECT
958 | DRM_CONNECTOR_POLL_DISCONNECT;
959 hpd_disabled = true;
960 }
Egbert Eich142e2392013-04-11 15:57:57 +0200961 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
962 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
963 drm_get_connector_name(connector), intel_encoder->hpd_pin);
964 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200965 }
966 /* if there were no outputs to poll, poll was disabled,
967 * therefore make sure it's enabled when disabling HPD on
968 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200969 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200970 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200971 mod_timer(&dev_priv->hotplug_reenable_timer,
972 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
973 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200974
975 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
976
Egbert Eich321a1b32013-04-11 16:00:26 +0200977 list_for_each_entry(connector, &mode_config->connector_list, head) {
978 intel_connector = to_intel_connector(connector);
979 intel_encoder = intel_connector->encoder;
980 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
981 if (intel_encoder->hot_plug)
982 intel_encoder->hot_plug(intel_encoder);
983 if (intel_hpd_irq_event(dev, connector))
984 changed = true;
985 }
986 }
Keith Packard40ee3382011-07-28 15:31:19 -0700987 mutex_unlock(&mode_config->mutex);
988
Egbert Eich321a1b32013-04-11 16:00:26 +0200989 if (changed)
990 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700991}
992
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +0200993static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
994{
995 del_timer_sync(&dev_priv->hotplug_reenable_timer);
996}
997
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200998static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800999{
1000 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001001 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001002 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001003
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001004 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001005
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001006 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1007
Daniel Vetter20e4d402012-08-08 23:35:39 +02001008 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001009
Jesse Barnes7648fa92010-05-20 14:28:11 -07001010 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001011 busy_up = I915_READ(RCPREVBSYTUPAVG);
1012 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001013 max_avg = I915_READ(RCBMAXAVG);
1014 min_avg = I915_READ(RCBMINAVG);
1015
1016 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001017 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001018 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1019 new_delay = dev_priv->ips.cur_delay - 1;
1020 if (new_delay < dev_priv->ips.max_delay)
1021 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001022 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001023 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1024 new_delay = dev_priv->ips.cur_delay + 1;
1025 if (new_delay > dev_priv->ips.min_delay)
1026 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001027 }
1028
Jesse Barnes7648fa92010-05-20 14:28:11 -07001029 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001030 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001031
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001032 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001033
Jesse Barnesf97108d2010-01-29 11:27:07 -08001034 return;
1035}
1036
Chris Wilson549f7362010-10-19 11:19:32 +01001037static void notify_ring(struct drm_device *dev,
1038 struct intel_ring_buffer *ring)
1039{
Chris Wilson475553d2011-01-20 09:52:56 +00001040 if (ring->obj == NULL)
1041 return;
1042
Chris Wilson814e9b52013-09-23 17:33:19 -03001043 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001044
Chris Wilson549f7362010-10-19 11:19:32 +01001045 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001046 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001047}
1048
Deepak S76c3552f2014-01-30 23:08:16 +05301049void gen6_set_pm_mask(struct drm_i915_private *dev_priv,
Deepak S27544362014-01-27 21:35:05 +05301050 u32 pm_iir, int new_delay)
1051{
1052 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
1053 if (new_delay >= dev_priv->rps.max_delay) {
1054 /* Mask UP THRESHOLD Interrupts */
1055 I915_WRITE(GEN6_PMINTRMSK,
1056 I915_READ(GEN6_PMINTRMSK) |
1057 GEN6_PM_RP_UP_THRESHOLD);
1058 dev_priv->rps.rp_up_masked = true;
1059 }
1060 if (dev_priv->rps.rp_down_masked) {
1061 /* UnMask DOWN THRESHOLD Interrupts */
1062 I915_WRITE(GEN6_PMINTRMSK,
1063 I915_READ(GEN6_PMINTRMSK) &
1064 ~GEN6_PM_RP_DOWN_THRESHOLD);
1065 dev_priv->rps.rp_down_masked = false;
1066 }
1067 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1068 if (new_delay <= dev_priv->rps.min_delay) {
1069 /* Mask DOWN THRESHOLD Interrupts */
1070 I915_WRITE(GEN6_PMINTRMSK,
1071 I915_READ(GEN6_PMINTRMSK) |
1072 GEN6_PM_RP_DOWN_THRESHOLD);
1073 dev_priv->rps.rp_down_masked = true;
1074 }
1075
1076 if (dev_priv->rps.rp_up_masked) {
1077 /* UnMask UP THRESHOLD Interrupts */
1078 I915_WRITE(GEN6_PMINTRMSK,
1079 I915_READ(GEN6_PMINTRMSK) &
1080 ~GEN6_PM_RP_UP_THRESHOLD);
1081 dev_priv->rps.rp_up_masked = false;
1082 }
1083 }
1084}
1085
Ben Widawsky4912d042011-04-25 11:25:20 -07001086static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001087{
Ben Widawsky4912d042011-04-25 11:25:20 -07001088 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001089 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001090 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001091 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001092
Daniel Vetter59cdb632013-07-04 23:35:28 +02001093 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001094 pm_iir = dev_priv->rps.pm_iir;
1095 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -07001096 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001097 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001098 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001099
Paulo Zanoni60611c12013-08-15 11:50:01 -03001100 /* Make sure we didn't queue anything we're not going to process. */
1101 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
1102
Ben Widawsky48484052013-05-28 19:22:27 -07001103 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001104 return;
1105
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001106 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001107
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001108 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001109 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001110 if (adj > 0)
1111 adj *= 2;
1112 else
1113 adj = 1;
1114 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001115
1116 /*
1117 * For better performance, jump directly
1118 * to RPe if we're below it.
1119 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001120 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +03001121 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001122 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1123 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
1124 new_delay = dev_priv->rps.rpe_delay;
1125 else
1126 new_delay = dev_priv->rps.min_delay;
1127 adj = 0;
1128 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1129 if (adj < 0)
1130 adj *= 2;
1131 else
1132 adj = -1;
1133 new_delay = dev_priv->rps.cur_delay + adj;
1134 } else { /* unknown event */
1135 new_delay = dev_priv->rps.cur_delay;
1136 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001137
Ben Widawsky79249632012-09-07 19:43:42 -07001138 /* sysfs frequency interfaces may have snuck in while servicing the
1139 * interrupt
1140 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001141 new_delay = clamp_t(int, new_delay,
1142 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Deepak S27544362014-01-27 21:35:05 +05301143
1144 gen6_set_pm_mask(dev_priv, pm_iir, new_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001145 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
1146
1147 if (IS_VALLEYVIEW(dev_priv->dev))
1148 valleyview_set_rps(dev_priv->dev, new_delay);
1149 else
1150 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001152 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001153}
1154
Ben Widawskye3689192012-05-25 16:56:22 -07001155
1156/**
1157 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1158 * occurred.
1159 * @work: workqueue struct
1160 *
1161 * Doesn't actually do anything except notify userspace. As a consequence of
1162 * this event, userspace should try to remap the bad rows since statistically
1163 * it is likely the same row is more likely to go bad again.
1164 */
1165static void ivybridge_parity_work(struct work_struct *work)
1166{
1167 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001168 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001169 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001170 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001171 uint32_t misccpctl;
1172 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001173 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001174
1175 /* We must turn off DOP level clock gating to access the L3 registers.
1176 * In order to prevent a get/put style interface, acquire struct mutex
1177 * any time we access those registers.
1178 */
1179 mutex_lock(&dev_priv->dev->struct_mutex);
1180
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001181 /* If we've screwed up tracking, just let the interrupt fire again */
1182 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1183 goto out;
1184
Ben Widawskye3689192012-05-25 16:56:22 -07001185 misccpctl = I915_READ(GEN7_MISCCPCTL);
1186 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1187 POSTING_READ(GEN7_MISCCPCTL);
1188
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001189 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1190 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001191
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001192 slice--;
1193 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1194 break;
1195
1196 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1197
1198 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1199
1200 error_status = I915_READ(reg);
1201 row = GEN7_PARITY_ERROR_ROW(error_status);
1202 bank = GEN7_PARITY_ERROR_BANK(error_status);
1203 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1204
1205 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1206 POSTING_READ(reg);
1207
1208 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1209 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1210 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1211 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1212 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1213 parity_event[5] = NULL;
1214
Dave Airlie5bdebb12013-10-11 14:07:25 +10001215 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001216 KOBJ_CHANGE, parity_event);
1217
1218 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1219 slice, row, bank, subbank);
1220
1221 kfree(parity_event[4]);
1222 kfree(parity_event[3]);
1223 kfree(parity_event[2]);
1224 kfree(parity_event[1]);
1225 }
Ben Widawskye3689192012-05-25 16:56:22 -07001226
1227 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1228
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001229out:
1230 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001231 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001232 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001233 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1234
1235 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001236}
1237
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001238static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001239{
1240 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001241
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001242 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001243 return;
1244
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001245 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001246 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001247 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001248
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001249 iir &= GT_PARITY_ERROR(dev);
1250 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1251 dev_priv->l3_parity.which_slice |= 1 << 1;
1252
1253 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1254 dev_priv->l3_parity.which_slice |= 1 << 0;
1255
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001256 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001257}
1258
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001259static void ilk_gt_irq_handler(struct drm_device *dev,
1260 struct drm_i915_private *dev_priv,
1261 u32 gt_iir)
1262{
1263 if (gt_iir &
1264 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1265 notify_ring(dev, &dev_priv->ring[RCS]);
1266 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1267 notify_ring(dev, &dev_priv->ring[VCS]);
1268}
1269
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001270static void snb_gt_irq_handler(struct drm_device *dev,
1271 struct drm_i915_private *dev_priv,
1272 u32 gt_iir)
1273{
1274
Ben Widawskycc609d52013-05-28 19:22:29 -07001275 if (gt_iir &
1276 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001277 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001278 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001279 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001280 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001281 notify_ring(dev, &dev_priv->ring[BCS]);
1282
Ben Widawskycc609d52013-05-28 19:22:29 -07001283 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1284 GT_BSD_CS_ERROR_INTERRUPT |
1285 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001286 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1287 i915_handle_error(dev, false);
1288 }
Ben Widawskye3689192012-05-25 16:56:22 -07001289
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001290 if (gt_iir & GT_PARITY_ERROR(dev))
1291 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001292}
1293
Ben Widawskyabd58f02013-11-02 21:07:09 -07001294static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1295 struct drm_i915_private *dev_priv,
1296 u32 master_ctl)
1297{
1298 u32 rcs, bcs, vcs;
1299 uint32_t tmp = 0;
1300 irqreturn_t ret = IRQ_NONE;
1301
1302 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1303 tmp = I915_READ(GEN8_GT_IIR(0));
1304 if (tmp) {
1305 ret = IRQ_HANDLED;
1306 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1307 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1308 if (rcs & GT_RENDER_USER_INTERRUPT)
1309 notify_ring(dev, &dev_priv->ring[RCS]);
1310 if (bcs & GT_RENDER_USER_INTERRUPT)
1311 notify_ring(dev, &dev_priv->ring[BCS]);
1312 I915_WRITE(GEN8_GT_IIR(0), tmp);
1313 } else
1314 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1315 }
1316
1317 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1318 tmp = I915_READ(GEN8_GT_IIR(1));
1319 if (tmp) {
1320 ret = IRQ_HANDLED;
1321 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1322 if (vcs & GT_RENDER_USER_INTERRUPT)
1323 notify_ring(dev, &dev_priv->ring[VCS]);
1324 I915_WRITE(GEN8_GT_IIR(1), tmp);
1325 } else
1326 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1327 }
1328
1329 if (master_ctl & GEN8_GT_VECS_IRQ) {
1330 tmp = I915_READ(GEN8_GT_IIR(3));
1331 if (tmp) {
1332 ret = IRQ_HANDLED;
1333 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1334 if (vcs & GT_RENDER_USER_INTERRUPT)
1335 notify_ring(dev, &dev_priv->ring[VECS]);
1336 I915_WRITE(GEN8_GT_IIR(3), tmp);
1337 } else
1338 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1339 }
1340
1341 return ret;
1342}
1343
Egbert Eichb543fb02013-04-16 13:36:54 +02001344#define HPD_STORM_DETECT_PERIOD 1000
1345#define HPD_STORM_THRESHOLD 5
1346
Daniel Vetter10a504d2013-06-27 17:52:12 +02001347static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001348 u32 hotplug_trigger,
1349 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001350{
1351 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001352 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001353 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001354
Daniel Vetter91d131d2013-06-27 17:52:14 +02001355 if (!hotplug_trigger)
1356 return;
1357
Imre Deakcc9bd492014-01-16 19:56:54 +02001358 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1359 hotplug_trigger);
1360
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001361 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001362 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001363
Chris Wilson34320872014-01-10 18:49:20 +00001364 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001365 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001366 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1367 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001368
Egbert Eichb543fb02013-04-16 13:36:54 +02001369 if (!(hpd[i] & hotplug_trigger) ||
1370 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1371 continue;
1372
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001373 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001374 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1375 dev_priv->hpd_stats[i].hpd_last_jiffies
1376 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1377 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1378 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001379 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001380 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1381 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001382 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001383 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001384 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001385 } else {
1386 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001387 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1388 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001389 }
1390 }
1391
Daniel Vetter10a504d2013-06-27 17:52:12 +02001392 if (storm_detected)
1393 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001394 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001395
Daniel Vetter645416f2013-09-02 16:22:25 +02001396 /*
1397 * Our hotplug handler can grab modeset locks (by calling down into the
1398 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1399 * queue for otherwise the flush_work in the pageflip code will
1400 * deadlock.
1401 */
1402 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001403}
1404
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001405static void gmbus_irq_handler(struct drm_device *dev)
1406{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001407 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1408
Daniel Vetter28c70f12012-12-01 13:53:45 +01001409 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001410}
1411
Daniel Vetterce99c252012-12-01 13:53:47 +01001412static void dp_aux_irq_handler(struct drm_device *dev)
1413{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001414 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1415
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001416 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001417}
1418
Shuang He8bf1e9f2013-10-15 18:55:27 +01001419#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001420static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1421 uint32_t crc0, uint32_t crc1,
1422 uint32_t crc2, uint32_t crc3,
1423 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001424{
1425 struct drm_i915_private *dev_priv = dev->dev_private;
1426 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1427 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001428 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001429
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001430 spin_lock(&pipe_crc->lock);
1431
Damien Lespiau0c912c72013-10-15 18:55:37 +01001432 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001433 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001434 DRM_ERROR("spurious interrupt\n");
1435 return;
1436 }
1437
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001438 head = pipe_crc->head;
1439 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001440
1441 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001442 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001443 DRM_ERROR("CRC buffer overflowing\n");
1444 return;
1445 }
1446
1447 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001448
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001449 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001450 entry->crc[0] = crc0;
1451 entry->crc[1] = crc1;
1452 entry->crc[2] = crc2;
1453 entry->crc[3] = crc3;
1454 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001455
1456 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001457 pipe_crc->head = head;
1458
1459 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001460
1461 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001462}
Daniel Vetter277de952013-10-18 16:37:07 +02001463#else
1464static inline void
1465display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1466 uint32_t crc0, uint32_t crc1,
1467 uint32_t crc2, uint32_t crc3,
1468 uint32_t crc4) {}
1469#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001470
Daniel Vetter277de952013-10-18 16:37:07 +02001471
1472static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001473{
1474 struct drm_i915_private *dev_priv = dev->dev_private;
1475
Daniel Vetter277de952013-10-18 16:37:07 +02001476 display_pipe_crc_irq_handler(dev, pipe,
1477 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1478 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001479}
1480
Daniel Vetter277de952013-10-18 16:37:07 +02001481static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001482{
1483 struct drm_i915_private *dev_priv = dev->dev_private;
1484
Daniel Vetter277de952013-10-18 16:37:07 +02001485 display_pipe_crc_irq_handler(dev, pipe,
1486 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1487 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1488 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1489 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1490 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001491}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001492
Daniel Vetter277de952013-10-18 16:37:07 +02001493static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001494{
1495 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001496 uint32_t res1, res2;
1497
1498 if (INTEL_INFO(dev)->gen >= 3)
1499 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1500 else
1501 res1 = 0;
1502
1503 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1504 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1505 else
1506 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001507
Daniel Vetter277de952013-10-18 16:37:07 +02001508 display_pipe_crc_irq_handler(dev, pipe,
1509 I915_READ(PIPE_CRC_RES_RED(pipe)),
1510 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1511 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1512 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001513}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001514
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001515/* The RPS events need forcewake, so we add them to a work queue and mask their
1516 * IMR bits until the work is done. Other interrupts can be processed without
1517 * the work queue. */
1518static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001519{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001520 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001521 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001522 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001523 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001524 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001525
1526 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001527 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001528
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001529 if (HAS_VEBOX(dev_priv->dev)) {
1530 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1531 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001532
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001533 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1534 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1535 i915_handle_error(dev_priv->dev, false);
1536 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001537 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001538}
1539
Imre Deakc1874ed2014-02-04 21:35:46 +02001540static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1541{
1542 struct drm_i915_private *dev_priv = dev->dev_private;
1543 u32 pipe_stats[I915_MAX_PIPES];
Imre Deakc1874ed2014-02-04 21:35:46 +02001544 int pipe;
1545
Imre Deak58ead0d2014-02-04 21:35:47 +02001546 spin_lock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001547 for_each_pipe(pipe) {
1548 int reg = PIPESTAT(pipe);
1549 pipe_stats[pipe] = I915_READ(reg);
1550
1551 /*
1552 * Clear the PIPE*STAT regs before the IIR
1553 */
1554 if (pipe_stats[pipe] & 0x8000ffff)
1555 I915_WRITE(reg, pipe_stats[pipe]);
1556 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001557 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001558
1559 for_each_pipe(pipe) {
1560 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1561 drm_handle_vblank(dev, pipe);
1562
Imre Deak579a9b02014-02-04 21:35:48 +02001563 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001564 intel_prepare_page_flip(dev, pipe);
1565 intel_finish_page_flip(dev, pipe);
1566 }
1567
1568 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1569 i9xx_pipe_crc_irq_handler(dev, pipe);
1570
1571 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1572 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1573 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1574 }
1575
1576 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1577 gmbus_irq_handler(dev);
1578}
1579
Daniel Vetterff1f5252012-10-02 15:10:55 +02001580static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001581{
1582 struct drm_device *dev = (struct drm_device *) arg;
1583 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1584 u32 iir, gt_iir, pm_iir;
1585 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001586
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001587 while (true) {
1588 iir = I915_READ(VLV_IIR);
1589 gt_iir = I915_READ(GTIIR);
1590 pm_iir = I915_READ(GEN6_PMIIR);
1591
1592 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1593 goto out;
1594
1595 ret = IRQ_HANDLED;
1596
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001597 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001598
Imre Deakc1874ed2014-02-04 21:35:46 +02001599 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001600
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001601 /* Consume port. Then clear IIR or we'll miss events */
1602 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1603 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001604 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001605
Daniel Vetter91d131d2013-06-27 17:52:14 +02001606 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1607
Daniel Vetter4aeebd72013-10-31 09:53:36 +01001608 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1609 dp_aux_irq_handler(dev);
1610
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001611 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1612 I915_READ(PORT_HOTPLUG_STAT);
1613 }
1614
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001615
Paulo Zanoni60611c12013-08-15 11:50:01 -03001616 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001617 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001618
1619 I915_WRITE(GTIIR, gt_iir);
1620 I915_WRITE(GEN6_PMIIR, pm_iir);
1621 I915_WRITE(VLV_IIR, iir);
1622 }
1623
1624out:
1625 return ret;
1626}
1627
Adam Jackson23e81d62012-06-06 15:45:44 -04001628static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001629{
1630 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001631 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001632 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001633
Daniel Vetter91d131d2013-06-27 17:52:14 +02001634 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1635
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001636 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1637 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1638 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001639 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001640 port_name(port));
1641 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001642
Daniel Vetterce99c252012-12-01 13:53:47 +01001643 if (pch_iir & SDE_AUX_MASK)
1644 dp_aux_irq_handler(dev);
1645
Jesse Barnes776ad802011-01-04 15:09:39 -08001646 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001647 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001648
1649 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1650 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1651
1652 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1653 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1654
1655 if (pch_iir & SDE_POISON)
1656 DRM_ERROR("PCH poison interrupt\n");
1657
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001658 if (pch_iir & SDE_FDI_MASK)
1659 for_each_pipe(pipe)
1660 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1661 pipe_name(pipe),
1662 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001663
1664 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1665 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1666
1667 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1668 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1669
Jesse Barnes776ad802011-01-04 15:09:39 -08001670 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001671 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1672 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001673 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001674
1675 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1676 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1677 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001678 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001679}
1680
1681static void ivb_err_int_handler(struct drm_device *dev)
1682{
1683 struct drm_i915_private *dev_priv = dev->dev_private;
1684 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001685 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001686
Paulo Zanonide032bf2013-04-12 17:57:58 -03001687 if (err_int & ERR_INT_POISON)
1688 DRM_ERROR("Poison interrupt\n");
1689
Daniel Vetter5a69b892013-10-16 22:55:52 +02001690 for_each_pipe(pipe) {
1691 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1692 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1693 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001694 DRM_ERROR("Pipe %c FIFO underrun\n",
1695 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001696 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001697
Daniel Vetter5a69b892013-10-16 22:55:52 +02001698 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1699 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001700 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001701 else
Daniel Vetter277de952013-10-18 16:37:07 +02001702 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001703 }
1704 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001705
Paulo Zanoni86642812013-04-12 17:57:57 -03001706 I915_WRITE(GEN7_ERR_INT, err_int);
1707}
1708
1709static void cpt_serr_int_handler(struct drm_device *dev)
1710{
1711 struct drm_i915_private *dev_priv = dev->dev_private;
1712 u32 serr_int = I915_READ(SERR_INT);
1713
Paulo Zanonide032bf2013-04-12 17:57:58 -03001714 if (serr_int & SERR_INT_POISON)
1715 DRM_ERROR("PCH poison interrupt\n");
1716
Paulo Zanoni86642812013-04-12 17:57:57 -03001717 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1718 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1719 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001720 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001721
1722 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1723 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1724 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001725 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001726
1727 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1728 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1729 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001730 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001731
1732 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001733}
1734
Adam Jackson23e81d62012-06-06 15:45:44 -04001735static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1736{
1737 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1738 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001739 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001740
Daniel Vetter91d131d2013-06-27 17:52:14 +02001741 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1742
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001743 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1744 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1745 SDE_AUDIO_POWER_SHIFT_CPT);
1746 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1747 port_name(port));
1748 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001749
1750 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001751 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001752
1753 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001754 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001755
1756 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1757 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1758
1759 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1760 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1761
1762 if (pch_iir & SDE_FDI_MASK_CPT)
1763 for_each_pipe(pipe)
1764 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1765 pipe_name(pipe),
1766 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001767
1768 if (pch_iir & SDE_ERROR_CPT)
1769 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001770}
1771
Paulo Zanonic008bc62013-07-12 16:35:10 -03001772static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1773{
1774 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001775 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001776
1777 if (de_iir & DE_AUX_CHANNEL_A)
1778 dp_aux_irq_handler(dev);
1779
1780 if (de_iir & DE_GSE)
1781 intel_opregion_asle_intr(dev);
1782
Paulo Zanonic008bc62013-07-12 16:35:10 -03001783 if (de_iir & DE_POISON)
1784 DRM_ERROR("Poison interrupt\n");
1785
Daniel Vetter40da17c2013-10-21 18:04:36 +02001786 for_each_pipe(pipe) {
1787 if (de_iir & DE_PIPE_VBLANK(pipe))
1788 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001789
Daniel Vetter40da17c2013-10-21 18:04:36 +02001790 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1791 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001792 DRM_ERROR("Pipe %c FIFO underrun\n",
1793 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001794
Daniel Vetter40da17c2013-10-21 18:04:36 +02001795 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1796 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001797
Daniel Vetter40da17c2013-10-21 18:04:36 +02001798 /* plane/pipes map 1:1 on ilk+ */
1799 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1800 intel_prepare_page_flip(dev, pipe);
1801 intel_finish_page_flip_plane(dev, pipe);
1802 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001803 }
1804
1805 /* check event from PCH */
1806 if (de_iir & DE_PCH_EVENT) {
1807 u32 pch_iir = I915_READ(SDEIIR);
1808
1809 if (HAS_PCH_CPT(dev))
1810 cpt_irq_handler(dev, pch_iir);
1811 else
1812 ibx_irq_handler(dev, pch_iir);
1813
1814 /* should clear PCH hotplug event before clear CPU irq */
1815 I915_WRITE(SDEIIR, pch_iir);
1816 }
1817
1818 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1819 ironlake_rps_change_irq_handler(dev);
1820}
1821
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001822static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1823{
1824 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001825 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001826
1827 if (de_iir & DE_ERR_INT_IVB)
1828 ivb_err_int_handler(dev);
1829
1830 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1831 dp_aux_irq_handler(dev);
1832
1833 if (de_iir & DE_GSE_IVB)
1834 intel_opregion_asle_intr(dev);
1835
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001836 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001837 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001838 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001839
1840 /* plane/pipes map 1:1 on ilk+ */
1841 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001842 intel_prepare_page_flip(dev, i);
1843 intel_finish_page_flip_plane(dev, i);
1844 }
1845 }
1846
1847 /* check event from PCH */
1848 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1849 u32 pch_iir = I915_READ(SDEIIR);
1850
1851 cpt_irq_handler(dev, pch_iir);
1852
1853 /* clear PCH hotplug event before clear CPU irq */
1854 I915_WRITE(SDEIIR, pch_iir);
1855 }
1856}
1857
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001858static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001859{
1860 struct drm_device *dev = (struct drm_device *) arg;
1861 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001862 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001863 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001864
Paulo Zanoni86642812013-04-12 17:57:57 -03001865 /* We get interrupts on unclaimed registers, so check for this before we
1866 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001867 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001868
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001869 /* disable master interrupt before clearing iir */
1870 de_ier = I915_READ(DEIER);
1871 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001872 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001873
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001874 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1875 * interrupts will will be stored on its back queue, and then we'll be
1876 * able to process them after we restore SDEIER (as soon as we restore
1877 * it, we'll get an interrupt if SDEIIR still has something to process
1878 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001879 if (!HAS_PCH_NOP(dev)) {
1880 sde_ier = I915_READ(SDEIER);
1881 I915_WRITE(SDEIER, 0);
1882 POSTING_READ(SDEIER);
1883 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001884
Chris Wilson0e434062012-05-09 21:45:44 +01001885 gt_iir = I915_READ(GTIIR);
1886 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001887 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001888 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001889 else
1890 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001891 I915_WRITE(GTIIR, gt_iir);
1892 ret = IRQ_HANDLED;
1893 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001894
1895 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001896 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001897 if (INTEL_INFO(dev)->gen >= 7)
1898 ivb_display_irq_handler(dev, de_iir);
1899 else
1900 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001901 I915_WRITE(DEIIR, de_iir);
1902 ret = IRQ_HANDLED;
1903 }
1904
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001905 if (INTEL_INFO(dev)->gen >= 6) {
1906 u32 pm_iir = I915_READ(GEN6_PMIIR);
1907 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001908 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001909 I915_WRITE(GEN6_PMIIR, pm_iir);
1910 ret = IRQ_HANDLED;
1911 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001912 }
1913
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001914 I915_WRITE(DEIER, de_ier);
1915 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001916 if (!HAS_PCH_NOP(dev)) {
1917 I915_WRITE(SDEIER, sde_ier);
1918 POSTING_READ(SDEIER);
1919 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001920
1921 return ret;
1922}
1923
Ben Widawskyabd58f02013-11-02 21:07:09 -07001924static irqreturn_t gen8_irq_handler(int irq, void *arg)
1925{
1926 struct drm_device *dev = arg;
1927 struct drm_i915_private *dev_priv = dev->dev_private;
1928 u32 master_ctl;
1929 irqreturn_t ret = IRQ_NONE;
1930 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001931 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001932
Ben Widawskyabd58f02013-11-02 21:07:09 -07001933 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1934 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1935 if (!master_ctl)
1936 return IRQ_NONE;
1937
1938 I915_WRITE(GEN8_MASTER_IRQ, 0);
1939 POSTING_READ(GEN8_MASTER_IRQ);
1940
1941 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1942
1943 if (master_ctl & GEN8_DE_MISC_IRQ) {
1944 tmp = I915_READ(GEN8_DE_MISC_IIR);
1945 if (tmp & GEN8_DE_MISC_GSE)
1946 intel_opregion_asle_intr(dev);
1947 else if (tmp)
1948 DRM_ERROR("Unexpected DE Misc interrupt\n");
1949 else
1950 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1951
1952 if (tmp) {
1953 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1954 ret = IRQ_HANDLED;
1955 }
1956 }
1957
Daniel Vetter6d766f02013-11-07 14:49:55 +01001958 if (master_ctl & GEN8_DE_PORT_IRQ) {
1959 tmp = I915_READ(GEN8_DE_PORT_IIR);
1960 if (tmp & GEN8_AUX_CHANNEL_A)
1961 dp_aux_irq_handler(dev);
1962 else if (tmp)
1963 DRM_ERROR("Unexpected DE Port interrupt\n");
1964 else
1965 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1966
1967 if (tmp) {
1968 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1969 ret = IRQ_HANDLED;
1970 }
1971 }
1972
Daniel Vetterc42664c2013-11-07 11:05:40 +01001973 for_each_pipe(pipe) {
1974 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001975
Daniel Vetterc42664c2013-11-07 11:05:40 +01001976 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1977 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001978
Daniel Vetterc42664c2013-11-07 11:05:40 +01001979 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1980 if (pipe_iir & GEN8_PIPE_VBLANK)
1981 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001982
Daniel Vetterc42664c2013-11-07 11:05:40 +01001983 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1984 intel_prepare_page_flip(dev, pipe);
1985 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001986 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001987
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001988 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1989 hsw_pipe_crc_irq_handler(dev, pipe);
1990
Daniel Vetter38d83c962013-11-07 11:05:46 +01001991 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1992 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1993 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001994 DRM_ERROR("Pipe %c FIFO underrun\n",
1995 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01001996 }
1997
Daniel Vetter30100f22013-11-07 14:49:24 +01001998 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1999 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2000 pipe_name(pipe),
2001 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
2002 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01002003
2004 if (pipe_iir) {
2005 ret = IRQ_HANDLED;
2006 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
2007 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002008 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2009 }
2010
Daniel Vetter92d03a82013-11-07 11:05:43 +01002011 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2012 /*
2013 * FIXME(BDW): Assume for now that the new interrupt handling
2014 * scheme also closed the SDE interrupt handling race we've seen
2015 * on older pch-split platforms. But this needs testing.
2016 */
2017 u32 pch_iir = I915_READ(SDEIIR);
2018
2019 cpt_irq_handler(dev, pch_iir);
2020
2021 if (pch_iir) {
2022 I915_WRITE(SDEIIR, pch_iir);
2023 ret = IRQ_HANDLED;
2024 }
2025 }
2026
Ben Widawskyabd58f02013-11-02 21:07:09 -07002027 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2028 POSTING_READ(GEN8_MASTER_IRQ);
2029
2030 return ret;
2031}
2032
Daniel Vetter17e1df02013-09-08 21:57:13 +02002033static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2034 bool reset_completed)
2035{
2036 struct intel_ring_buffer *ring;
2037 int i;
2038
2039 /*
2040 * Notify all waiters for GPU completion events that reset state has
2041 * been changed, and that they need to restart their wait after
2042 * checking for potential errors (and bail out to drop locks if there is
2043 * a gpu reset pending so that i915_error_work_func can acquire them).
2044 */
2045
2046 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2047 for_each_ring(ring, dev_priv, i)
2048 wake_up_all(&ring->irq_queue);
2049
2050 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2051 wake_up_all(&dev_priv->pending_flip_queue);
2052
2053 /*
2054 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2055 * reset state is cleared.
2056 */
2057 if (reset_completed)
2058 wake_up_all(&dev_priv->gpu_error.reset_queue);
2059}
2060
Jesse Barnes8a905232009-07-11 16:48:03 -04002061/**
2062 * i915_error_work_func - do process context error handling work
2063 * @work: work struct
2064 *
2065 * Fire an error uevent so userspace can see that a hang or error
2066 * was detected.
2067 */
2068static void i915_error_work_func(struct work_struct *work)
2069{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002070 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2071 work);
2072 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
2073 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002074 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002075 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2076 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2077 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002078 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002079
Dave Airlie5bdebb12013-10-11 14:07:25 +10002080 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002081
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002082 /*
2083 * Note that there's only one work item which does gpu resets, so we
2084 * need not worry about concurrent gpu resets potentially incrementing
2085 * error->reset_counter twice. We only need to take care of another
2086 * racing irq/hangcheck declaring the gpu dead for a second time. A
2087 * quick check for that is good enough: schedule_work ensures the
2088 * correct ordering between hang detection and this work item, and since
2089 * the reset in-progress bit is only ever set by code outside of this
2090 * work we don't need to worry about any other races.
2091 */
2092 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002093 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002094 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002095 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002096
Daniel Vetter17e1df02013-09-08 21:57:13 +02002097 /*
2098 * All state reset _must_ be completed before we update the
2099 * reset counter, for otherwise waiters might miss the reset
2100 * pending state and not properly drop locks, resulting in
2101 * deadlocks with the reset work.
2102 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002103 ret = i915_reset(dev);
2104
Daniel Vetter17e1df02013-09-08 21:57:13 +02002105 intel_display_handle_reset(dev);
2106
Daniel Vetterf69061b2012-12-06 09:01:42 +01002107 if (ret == 0) {
2108 /*
2109 * After all the gem state is reset, increment the reset
2110 * counter and wake up everyone waiting for the reset to
2111 * complete.
2112 *
2113 * Since unlock operations are a one-sided barrier only,
2114 * we need to insert a barrier here to order any seqno
2115 * updates before
2116 * the counter increment.
2117 */
2118 smp_mb__before_atomic_inc();
2119 atomic_inc(&dev_priv->gpu_error.reset_counter);
2120
Dave Airlie5bdebb12013-10-11 14:07:25 +10002121 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002122 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002123 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002124 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002125 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002126
Daniel Vetter17e1df02013-09-08 21:57:13 +02002127 /*
2128 * Note: The wake_up also serves as a memory barrier so that
2129 * waiters see the update value of the reset counter atomic_t.
2130 */
2131 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002132 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002133}
2134
Chris Wilson35aed2e2010-05-27 13:18:12 +01002135static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002136{
2137 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002138 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002139 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002140 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002141
Chris Wilson35aed2e2010-05-27 13:18:12 +01002142 if (!eir)
2143 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002144
Joe Perchesa70491c2012-03-18 13:00:11 -07002145 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002146
Ben Widawskybd9854f2012-08-23 15:18:09 -07002147 i915_get_extra_instdone(dev, instdone);
2148
Jesse Barnes8a905232009-07-11 16:48:03 -04002149 if (IS_G4X(dev)) {
2150 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2151 u32 ipeir = I915_READ(IPEIR_I965);
2152
Joe Perchesa70491c2012-03-18 13:00:11 -07002153 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2154 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002155 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2156 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002157 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002158 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002159 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002160 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002161 }
2162 if (eir & GM45_ERROR_PAGE_TABLE) {
2163 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002164 pr_err("page table error\n");
2165 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002166 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002167 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002168 }
2169 }
2170
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002171 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002172 if (eir & I915_ERROR_PAGE_TABLE) {
2173 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002174 pr_err("page table error\n");
2175 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002176 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002177 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002178 }
2179 }
2180
2181 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002182 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002183 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002184 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002185 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002186 /* pipestat has already been acked */
2187 }
2188 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002189 pr_err("instruction error\n");
2190 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002191 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2192 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002193 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002194 u32 ipeir = I915_READ(IPEIR);
2195
Joe Perchesa70491c2012-03-18 13:00:11 -07002196 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2197 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002198 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002199 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002200 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002201 } else {
2202 u32 ipeir = I915_READ(IPEIR_I965);
2203
Joe Perchesa70491c2012-03-18 13:00:11 -07002204 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2205 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002206 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002207 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002208 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002209 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002210 }
2211 }
2212
2213 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002214 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002215 eir = I915_READ(EIR);
2216 if (eir) {
2217 /*
2218 * some errors might have become stuck,
2219 * mask them.
2220 */
2221 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2222 I915_WRITE(EMR, I915_READ(EMR) | eir);
2223 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2224 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002225}
2226
2227/**
2228 * i915_handle_error - handle an error interrupt
2229 * @dev: drm device
2230 *
2231 * Do some basic checking of regsiter state at error interrupt time and
2232 * dump it to the syslog. Also call i915_capture_error_state() to make
2233 * sure we get a record and make it available in debugfs. Fire a uevent
2234 * so userspace knows something bad happened (should trigger collection
2235 * of a ring dump etc.).
2236 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002237void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002238{
2239 struct drm_i915_private *dev_priv = dev->dev_private;
2240
2241 i915_capture_error_state(dev);
2242 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002243
Ben Gamariba1234d2009-09-14 17:48:47 -04002244 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002245 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2246 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002247
Ben Gamari11ed50e2009-09-14 17:48:45 -04002248 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002249 * Wakeup waiting processes so that the reset work function
2250 * i915_error_work_func doesn't deadlock trying to grab various
2251 * locks. By bumping the reset counter first, the woken
2252 * processes will see a reset in progress and back off,
2253 * releasing their locks and then wait for the reset completion.
2254 * We must do this for _all_ gpu waiters that might hold locks
2255 * that the reset work needs to acquire.
2256 *
2257 * Note: The wake_up serves as the required memory barrier to
2258 * ensure that the waiters see the updated value of the reset
2259 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002260 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002261 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002262 }
2263
Daniel Vetter122f46b2013-09-04 17:36:14 +02002264 /*
2265 * Our reset work can grab modeset locks (since it needs to reset the
2266 * state of outstanding pagelips). Hence it must not be run on our own
2267 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2268 * code will deadlock.
2269 */
2270 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002271}
2272
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002273static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002274{
2275 drm_i915_private_t *dev_priv = dev->dev_private;
2276 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2277 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002278 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002279 struct intel_unpin_work *work;
2280 unsigned long flags;
2281 bool stall_detected;
2282
2283 /* Ignore early vblank irqs */
2284 if (intel_crtc == NULL)
2285 return;
2286
2287 spin_lock_irqsave(&dev->event_lock, flags);
2288 work = intel_crtc->unpin_work;
2289
Chris Wilsone7d841c2012-12-03 11:36:30 +00002290 if (work == NULL ||
2291 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2292 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002293 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2294 spin_unlock_irqrestore(&dev->event_lock, flags);
2295 return;
2296 }
2297
2298 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002299 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002300 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002301 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002302 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002303 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002304 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002305 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002306 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002307 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002308 crtc->x * crtc->fb->bits_per_pixel/8);
2309 }
2310
2311 spin_unlock_irqrestore(&dev->event_lock, flags);
2312
2313 if (stall_detected) {
2314 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2315 intel_prepare_page_flip(dev, intel_crtc->plane);
2316 }
2317}
2318
Keith Packard42f52ef2008-10-18 19:39:29 -07002319/* Called from drm generic code, passed 'crtc' which
2320 * we use as a pipe index
2321 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002322static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002323{
2324 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002325 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002326
Chris Wilson5eddb702010-09-11 13:48:45 +01002327 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002328 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002329
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002330 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002331 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002332 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002333 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002334 else
Keith Packard7c463582008-11-04 02:03:27 -08002335 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002336 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002337
2338 /* maintain vblank delivery even in deep C-states */
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002339 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002340 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002341 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002342
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002343 return 0;
2344}
2345
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002346static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002347{
2348 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2349 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002350 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002351 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002352
2353 if (!i915_pipe_enabled(dev, pipe))
2354 return -EINVAL;
2355
2356 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002357 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002358 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2359
2360 return 0;
2361}
2362
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002363static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2364{
2365 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2366 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002367
2368 if (!i915_pipe_enabled(dev, pipe))
2369 return -EINVAL;
2370
2371 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002372 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002373 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002374 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2375
2376 return 0;
2377}
2378
Ben Widawskyabd58f02013-11-02 21:07:09 -07002379static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2380{
2381 struct drm_i915_private *dev_priv = dev->dev_private;
2382 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002383
2384 if (!i915_pipe_enabled(dev, pipe))
2385 return -EINVAL;
2386
2387 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002388 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2389 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2390 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002391 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2392 return 0;
2393}
2394
Keith Packard42f52ef2008-10-18 19:39:29 -07002395/* Called from drm generic code, passed 'crtc' which
2396 * we use as a pipe index
2397 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002398static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002399{
2400 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002401 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002402
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002403 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002404 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002405 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002406
Jesse Barnesf796cf82011-04-07 13:58:17 -07002407 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002408 PIPE_VBLANK_INTERRUPT_STATUS |
2409 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002410 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2411}
2412
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002413static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002414{
2415 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2416 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002417 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002418 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002419
2420 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002421 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002422 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2423}
2424
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002425static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2426{
2427 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2428 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002429
2430 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002431 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002432 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002433 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2434}
2435
Ben Widawskyabd58f02013-11-02 21:07:09 -07002436static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2437{
2438 struct drm_i915_private *dev_priv = dev->dev_private;
2439 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002440
2441 if (!i915_pipe_enabled(dev, pipe))
2442 return;
2443
2444 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002445 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2446 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2447 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002448 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2449}
2450
Chris Wilson893eead2010-10-27 14:44:35 +01002451static u32
2452ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002453{
Chris Wilson893eead2010-10-27 14:44:35 +01002454 return list_entry(ring->request_list.prev,
2455 struct drm_i915_gem_request, list)->seqno;
2456}
2457
Chris Wilson9107e9d2013-06-10 11:20:20 +01002458static bool
2459ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002460{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002461 return (list_empty(&ring->request_list) ||
2462 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002463}
2464
Chris Wilson6274f212013-06-10 11:20:21 +01002465static struct intel_ring_buffer *
2466semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002467{
2468 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002469 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002470
2471 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2472 if ((ipehr & ~(0x3 << 16)) !=
2473 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002474 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002475
2476 /* ACTHD is likely pointing to the dword after the actual command,
2477 * so scan backwards until we find the MBOX.
2478 */
Chris Wilson6274f212013-06-10 11:20:21 +01002479 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002480 acthd_min = max((int)acthd - 3 * 4, 0);
2481 do {
2482 cmd = ioread32(ring->virtual_start + acthd);
2483 if (cmd == ipehr)
2484 break;
2485
2486 acthd -= 4;
2487 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002488 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002489 } while (1);
2490
Chris Wilson6274f212013-06-10 11:20:21 +01002491 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2492 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002493}
2494
Chris Wilson6274f212013-06-10 11:20:21 +01002495static int semaphore_passed(struct intel_ring_buffer *ring)
2496{
2497 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2498 struct intel_ring_buffer *signaller;
2499 u32 seqno, ctl;
2500
2501 ring->hangcheck.deadlock = true;
2502
2503 signaller = semaphore_waits_for(ring, &seqno);
2504 if (signaller == NULL || signaller->hangcheck.deadlock)
2505 return -1;
2506
2507 /* cursory check for an unkickable deadlock */
2508 ctl = I915_READ_CTL(signaller);
2509 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2510 return -1;
2511
2512 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2513}
2514
2515static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2516{
2517 struct intel_ring_buffer *ring;
2518 int i;
2519
2520 for_each_ring(ring, dev_priv, i)
2521 ring->hangcheck.deadlock = false;
2522}
2523
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002524static enum intel_ring_hangcheck_action
2525ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002526{
2527 struct drm_device *dev = ring->dev;
2528 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002529 u32 tmp;
2530
Chris Wilson6274f212013-06-10 11:20:21 +01002531 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002532 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002533
Chris Wilson9107e9d2013-06-10 11:20:20 +01002534 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002535 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002536
2537 /* Is the chip hanging on a WAIT_FOR_EVENT?
2538 * If so we can simply poke the RB_WAIT bit
2539 * and break the hang. This should work on
2540 * all but the second generation chipsets.
2541 */
2542 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002543 if (tmp & RING_WAIT) {
2544 DRM_ERROR("Kicking stuck wait on %s\n",
2545 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002546 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002547 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002548 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002549 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002550
Chris Wilson6274f212013-06-10 11:20:21 +01002551 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2552 switch (semaphore_passed(ring)) {
2553 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002554 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002555 case 1:
2556 DRM_ERROR("Kicking stuck semaphore on %s\n",
2557 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002558 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002559 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002560 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002561 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002562 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002563 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002564 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002565
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002566 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002567}
2568
Ben Gamarif65d9422009-09-14 17:48:44 -04002569/**
2570 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002571 * batchbuffers in a long time. We keep track per ring seqno progress and
2572 * if there are no progress, hangcheck score for that ring is increased.
2573 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2574 * we kick the ring. If we see no progress on three subsequent calls
2575 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002576 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002577static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002578{
2579 struct drm_device *dev = (struct drm_device *)data;
2580 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002581 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002582 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002583 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002584 bool stuck[I915_NUM_RINGS] = { 0 };
2585#define BUSY 1
2586#define KICK 5
2587#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002588
Jani Nikulad330a952014-01-21 11:24:25 +02002589 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002590 return;
2591
Chris Wilsonb4519512012-05-11 14:29:30 +01002592 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002593 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002594 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002595
Chris Wilson6274f212013-06-10 11:20:21 +01002596 semaphore_clear_deadlocks(dev_priv);
2597
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002598 seqno = ring->get_seqno(ring, false);
2599 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002600
Chris Wilson9107e9d2013-06-10 11:20:20 +01002601 if (ring->hangcheck.seqno == seqno) {
2602 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002603 ring->hangcheck.action = HANGCHECK_IDLE;
2604
Chris Wilson9107e9d2013-06-10 11:20:20 +01002605 if (waitqueue_active(&ring->irq_queue)) {
2606 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002607 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002608 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2609 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2610 ring->name);
2611 else
2612 DRM_INFO("Fake missed irq on %s\n",
2613 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002614 wake_up_all(&ring->irq_queue);
2615 }
2616 /* Safeguard against driver failure */
2617 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002618 } else
2619 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002620 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002621 /* We always increment the hangcheck score
2622 * if the ring is busy and still processing
2623 * the same request, so that no single request
2624 * can run indefinitely (such as a chain of
2625 * batches). The only time we do not increment
2626 * the hangcheck score on this ring, if this
2627 * ring is in a legitimate wait for another
2628 * ring. In that case the waiting ring is a
2629 * victim and we want to be sure we catch the
2630 * right culprit. Then every time we do kick
2631 * the ring, add a small increment to the
2632 * score so that we can catch a batch that is
2633 * being repeatedly kicked and so responsible
2634 * for stalling the machine.
2635 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002636 ring->hangcheck.action = ring_stuck(ring,
2637 acthd);
2638
2639 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002640 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002641 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002642 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002643 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002644 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002645 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002646 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002647 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002648 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002649 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002650 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002651 stuck[i] = true;
2652 break;
2653 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002654 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002655 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002656 ring->hangcheck.action = HANGCHECK_ACTIVE;
2657
Chris Wilson9107e9d2013-06-10 11:20:20 +01002658 /* Gradually reduce the count so that we catch DoS
2659 * attempts across multiple batches.
2660 */
2661 if (ring->hangcheck.score > 0)
2662 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002663 }
2664
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002665 ring->hangcheck.seqno = seqno;
2666 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002667 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002668 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002669
Mika Kuoppala92cab732013-05-24 17:16:07 +03002670 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002671 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002672 DRM_INFO("%s on %s\n",
2673 stuck[i] ? "stuck" : "no progress",
2674 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002675 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002676 }
2677 }
2678
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002679 if (rings_hung)
2680 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002681
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002682 if (busy_count)
2683 /* Reset timer case chip hangs without another request
2684 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002685 i915_queue_hangcheck(dev);
2686}
2687
2688void i915_queue_hangcheck(struct drm_device *dev)
2689{
2690 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02002691 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002692 return;
2693
2694 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2695 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002696}
2697
Paulo Zanoni91738a92013-06-05 14:21:51 -03002698static void ibx_irq_preinstall(struct drm_device *dev)
2699{
2700 struct drm_i915_private *dev_priv = dev->dev_private;
2701
2702 if (HAS_PCH_NOP(dev))
2703 return;
2704
2705 /* south display irq */
2706 I915_WRITE(SDEIMR, 0xffffffff);
2707 /*
2708 * SDEIER is also touched by the interrupt handler to work around missed
2709 * PCH interrupts. Hence we can't update it after the interrupt handler
2710 * is enabled - instead we unconditionally enable all PCH interrupt
2711 * sources here, but then only unmask them as needed with SDEIMR.
2712 */
2713 I915_WRITE(SDEIER, 0xffffffff);
2714 POSTING_READ(SDEIER);
2715}
2716
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002717static void gen5_gt_irq_preinstall(struct drm_device *dev)
2718{
2719 struct drm_i915_private *dev_priv = dev->dev_private;
2720
2721 /* and GT */
2722 I915_WRITE(GTIMR, 0xffffffff);
2723 I915_WRITE(GTIER, 0x0);
2724 POSTING_READ(GTIER);
2725
2726 if (INTEL_INFO(dev)->gen >= 6) {
2727 /* and PM */
2728 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2729 I915_WRITE(GEN6_PMIER, 0x0);
2730 POSTING_READ(GEN6_PMIER);
2731 }
2732}
2733
Linus Torvalds1da177e2005-04-16 15:20:36 -07002734/* drm_dma.h hooks
2735*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002736static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002737{
2738 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2739
2740 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002741
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002742 I915_WRITE(DEIMR, 0xffffffff);
2743 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002744 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002745
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002746 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002747
Paulo Zanoni91738a92013-06-05 14:21:51 -03002748 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002749}
2750
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002751static void valleyview_irq_preinstall(struct drm_device *dev)
2752{
2753 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2754 int pipe;
2755
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002756 /* VLV magic */
2757 I915_WRITE(VLV_IMR, 0);
2758 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2759 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2760 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2761
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002762 /* and GT */
2763 I915_WRITE(GTIIR, I915_READ(GTIIR));
2764 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002765
2766 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002767
2768 I915_WRITE(DPINVGTT, 0xff);
2769
2770 I915_WRITE(PORT_HOTPLUG_EN, 0);
2771 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2772 for_each_pipe(pipe)
2773 I915_WRITE(PIPESTAT(pipe), 0xffff);
2774 I915_WRITE(VLV_IIR, 0xffffffff);
2775 I915_WRITE(VLV_IMR, 0xffffffff);
2776 I915_WRITE(VLV_IER, 0x0);
2777 POSTING_READ(VLV_IER);
2778}
2779
Ben Widawskyabd58f02013-11-02 21:07:09 -07002780static void gen8_irq_preinstall(struct drm_device *dev)
2781{
2782 struct drm_i915_private *dev_priv = dev->dev_private;
2783 int pipe;
2784
Ben Widawskyabd58f02013-11-02 21:07:09 -07002785 I915_WRITE(GEN8_MASTER_IRQ, 0);
2786 POSTING_READ(GEN8_MASTER_IRQ);
2787
2788 /* IIR can theoretically queue up two events. Be paranoid */
2789#define GEN8_IRQ_INIT_NDX(type, which) do { \
2790 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2791 POSTING_READ(GEN8_##type##_IMR(which)); \
2792 I915_WRITE(GEN8_##type##_IER(which), 0); \
2793 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2794 POSTING_READ(GEN8_##type##_IIR(which)); \
2795 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2796 } while (0)
2797
2798#define GEN8_IRQ_INIT(type) do { \
2799 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2800 POSTING_READ(GEN8_##type##_IMR); \
2801 I915_WRITE(GEN8_##type##_IER, 0); \
2802 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2803 POSTING_READ(GEN8_##type##_IIR); \
2804 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2805 } while (0)
2806
2807 GEN8_IRQ_INIT_NDX(GT, 0);
2808 GEN8_IRQ_INIT_NDX(GT, 1);
2809 GEN8_IRQ_INIT_NDX(GT, 2);
2810 GEN8_IRQ_INIT_NDX(GT, 3);
2811
2812 for_each_pipe(pipe) {
2813 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2814 }
2815
2816 GEN8_IRQ_INIT(DE_PORT);
2817 GEN8_IRQ_INIT(DE_MISC);
2818 GEN8_IRQ_INIT(PCU);
2819#undef GEN8_IRQ_INIT
2820#undef GEN8_IRQ_INIT_NDX
2821
2822 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002823
2824 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002825}
2826
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002827static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002828{
2829 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002830 struct drm_mode_config *mode_config = &dev->mode_config;
2831 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002832 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002833
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002834 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002835 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002836 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002837 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002838 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002839 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002840 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002841 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002842 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002843 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002844 }
2845
Daniel Vetterfee884e2013-07-04 23:35:21 +02002846 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002847
2848 /*
2849 * Enable digital hotplug on the PCH, and configure the DP short pulse
2850 * duration to 2ms (which is the minimum in the Display Port spec)
2851 *
2852 * This register is the same on all known PCH chips.
2853 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002854 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2855 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2856 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2857 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2858 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2859 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2860}
2861
Paulo Zanonid46da432013-02-08 17:35:15 -02002862static void ibx_irq_postinstall(struct drm_device *dev)
2863{
2864 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002865 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002866
Daniel Vetter692a04c2013-05-29 21:43:05 +02002867 if (HAS_PCH_NOP(dev))
2868 return;
2869
Paulo Zanoni86642812013-04-12 17:57:57 -03002870 if (HAS_PCH_IBX(dev)) {
2871 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002872 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002873 } else {
2874 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2875
2876 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2877 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002878
Paulo Zanonid46da432013-02-08 17:35:15 -02002879 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2880 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002881}
2882
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002883static void gen5_gt_irq_postinstall(struct drm_device *dev)
2884{
2885 struct drm_i915_private *dev_priv = dev->dev_private;
2886 u32 pm_irqs, gt_irqs;
2887
2888 pm_irqs = gt_irqs = 0;
2889
2890 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002891 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002892 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002893 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2894 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002895 }
2896
2897 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2898 if (IS_GEN5(dev)) {
2899 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2900 ILK_BSD_USER_INTERRUPT;
2901 } else {
2902 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2903 }
2904
2905 I915_WRITE(GTIIR, I915_READ(GTIIR));
2906 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2907 I915_WRITE(GTIER, gt_irqs);
2908 POSTING_READ(GTIER);
2909
2910 if (INTEL_INFO(dev)->gen >= 6) {
2911 pm_irqs |= GEN6_PM_RPS_EVENTS;
2912
2913 if (HAS_VEBOX(dev))
2914 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2915
Paulo Zanoni605cd252013-08-06 18:57:15 -03002916 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002917 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002918 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002919 I915_WRITE(GEN6_PMIER, pm_irqs);
2920 POSTING_READ(GEN6_PMIER);
2921 }
2922}
2923
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002924static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002925{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002926 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002927 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002928 u32 display_mask, extra_mask;
2929
2930 if (INTEL_INFO(dev)->gen >= 7) {
2931 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2932 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2933 DE_PLANEB_FLIP_DONE_IVB |
2934 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2935 DE_ERR_INT_IVB);
2936 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2937 DE_PIPEA_VBLANK_IVB);
2938
2939 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2940 } else {
2941 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2942 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002943 DE_AUX_CHANNEL_A |
2944 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2945 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2946 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002947 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2948 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002949
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002950 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002951
2952 /* should always can generate irq */
2953 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002954 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002955 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002956 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002957
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002958 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002959
Paulo Zanonid46da432013-02-08 17:35:15 -02002960 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002961
Jesse Barnesf97108d2010-01-29 11:27:07 -08002962 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002963 /* Enable PCU event interrupts
2964 *
2965 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002966 * setup is guaranteed to run in single-threaded context. But we
2967 * need it to make the assert_spin_locked happy. */
2968 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002969 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002970 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002971 }
2972
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002973 return 0;
2974}
2975
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002976static int valleyview_irq_postinstall(struct drm_device *dev)
2977{
2978 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002979 u32 enable_mask;
Imre Deak755e9012014-02-10 18:42:47 +02002980 u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
2981 PIPE_CRC_DONE_INTERRUPT_STATUS;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002982 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002983
2984 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002985 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2986 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2987 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002988 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2989
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002990 /*
2991 *Leave vblank interrupts masked initially. enable/disable will
2992 * toggle them based on usage.
2993 */
2994 dev_priv->irq_mask = (~enable_mask) |
2995 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2996 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002997
Daniel Vetter20afbda2012-12-11 14:05:07 +01002998 I915_WRITE(PORT_HOTPLUG_EN, 0);
2999 POSTING_READ(PORT_HOTPLUG_EN);
3000
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003001 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3002 I915_WRITE(VLV_IER, enable_mask);
3003 I915_WRITE(VLV_IIR, 0xffffffff);
3004 I915_WRITE(PIPESTAT(0), 0xffff);
3005 I915_WRITE(PIPESTAT(1), 0xffff);
3006 POSTING_READ(VLV_IER);
3007
Daniel Vetterb79480b2013-06-27 17:52:10 +02003008 /* Interrupt setup is already guaranteed to be single-threaded, this is
3009 * just to make the assert_spin_locked check happy. */
3010 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003011 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
Imre Deak755e9012014-02-10 18:42:47 +02003012 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003013 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003014 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07003015
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003016 I915_WRITE(VLV_IIR, 0xffffffff);
3017 I915_WRITE(VLV_IIR, 0xffffffff);
3018
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003019 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003020
3021 /* ack & enable invalid PTE error interrupts */
3022#if 0 /* FIXME: add support to irq handler for checking these bits */
3023 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3024 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3025#endif
3026
3027 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003028
3029 return 0;
3030}
3031
Ben Widawskyabd58f02013-11-02 21:07:09 -07003032static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3033{
3034 int i;
3035
3036 /* These are interrupts we'll toggle with the ring mask register */
3037 uint32_t gt_interrupts[] = {
3038 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3039 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3040 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3041 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3042 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3043 0,
3044 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3045 };
3046
3047 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
3048 u32 tmp = I915_READ(GEN8_GT_IIR(i));
3049 if (tmp)
3050 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3051 i, tmp);
3052 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
3053 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
3054 }
3055 POSTING_READ(GEN8_GT_IER(0));
3056}
3057
3058static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3059{
3060 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003061 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
3062 GEN8_PIPE_CDCLK_CRC_DONE |
3063 GEN8_PIPE_FIFO_UNDERRUN |
3064 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3065 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003066 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003067 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3068 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3069 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003070
3071 for_each_pipe(pipe) {
3072 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
3073 if (tmp)
3074 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3075 pipe, tmp);
3076 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3077 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
3078 }
3079 POSTING_READ(GEN8_DE_PIPE_ISR(0));
3080
Daniel Vetter6d766f02013-11-07 14:49:55 +01003081 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
3082 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003083 POSTING_READ(GEN8_DE_PORT_IER);
3084}
3085
3086static int gen8_irq_postinstall(struct drm_device *dev)
3087{
3088 struct drm_i915_private *dev_priv = dev->dev_private;
3089
3090 gen8_gt_irq_postinstall(dev_priv);
3091 gen8_de_irq_postinstall(dev_priv);
3092
3093 ibx_irq_postinstall(dev);
3094
3095 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3096 POSTING_READ(GEN8_MASTER_IRQ);
3097
3098 return 0;
3099}
3100
3101static void gen8_irq_uninstall(struct drm_device *dev)
3102{
3103 struct drm_i915_private *dev_priv = dev->dev_private;
3104 int pipe;
3105
3106 if (!dev_priv)
3107 return;
3108
Ben Widawskyabd58f02013-11-02 21:07:09 -07003109 I915_WRITE(GEN8_MASTER_IRQ, 0);
3110
3111#define GEN8_IRQ_FINI_NDX(type, which) do { \
3112 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3113 I915_WRITE(GEN8_##type##_IER(which), 0); \
3114 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3115 } while (0)
3116
3117#define GEN8_IRQ_FINI(type) do { \
3118 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3119 I915_WRITE(GEN8_##type##_IER, 0); \
3120 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3121 } while (0)
3122
3123 GEN8_IRQ_FINI_NDX(GT, 0);
3124 GEN8_IRQ_FINI_NDX(GT, 1);
3125 GEN8_IRQ_FINI_NDX(GT, 2);
3126 GEN8_IRQ_FINI_NDX(GT, 3);
3127
3128 for_each_pipe(pipe) {
3129 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3130 }
3131
3132 GEN8_IRQ_FINI(DE_PORT);
3133 GEN8_IRQ_FINI(DE_MISC);
3134 GEN8_IRQ_FINI(PCU);
3135#undef GEN8_IRQ_FINI
3136#undef GEN8_IRQ_FINI_NDX
3137
3138 POSTING_READ(GEN8_PCU_IIR);
3139}
3140
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003141static void valleyview_irq_uninstall(struct drm_device *dev)
3142{
3143 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3144 int pipe;
3145
3146 if (!dev_priv)
3147 return;
3148
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003149 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003150
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003151 for_each_pipe(pipe)
3152 I915_WRITE(PIPESTAT(pipe), 0xffff);
3153
3154 I915_WRITE(HWSTAM, 0xffffffff);
3155 I915_WRITE(PORT_HOTPLUG_EN, 0);
3156 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3157 for_each_pipe(pipe)
3158 I915_WRITE(PIPESTAT(pipe), 0xffff);
3159 I915_WRITE(VLV_IIR, 0xffffffff);
3160 I915_WRITE(VLV_IMR, 0xffffffff);
3161 I915_WRITE(VLV_IER, 0x0);
3162 POSTING_READ(VLV_IER);
3163}
3164
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003165static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003166{
3167 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003168
3169 if (!dev_priv)
3170 return;
3171
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003172 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003173
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003174 I915_WRITE(HWSTAM, 0xffffffff);
3175
3176 I915_WRITE(DEIMR, 0xffffffff);
3177 I915_WRITE(DEIER, 0x0);
3178 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003179 if (IS_GEN7(dev))
3180 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003181
3182 I915_WRITE(GTIMR, 0xffffffff);
3183 I915_WRITE(GTIER, 0x0);
3184 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003185
Ben Widawskyab5c6082013-04-05 13:12:41 -07003186 if (HAS_PCH_NOP(dev))
3187 return;
3188
Keith Packard192aac1f2011-09-20 10:12:44 -07003189 I915_WRITE(SDEIMR, 0xffffffff);
3190 I915_WRITE(SDEIER, 0x0);
3191 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003192 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3193 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003194}
3195
Chris Wilsonc2798b12012-04-22 21:13:57 +01003196static void i8xx_irq_preinstall(struct drm_device * dev)
3197{
3198 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3199 int pipe;
3200
Chris Wilsonc2798b12012-04-22 21:13:57 +01003201 for_each_pipe(pipe)
3202 I915_WRITE(PIPESTAT(pipe), 0);
3203 I915_WRITE16(IMR, 0xffff);
3204 I915_WRITE16(IER, 0x0);
3205 POSTING_READ16(IER);
3206}
3207
3208static int i8xx_irq_postinstall(struct drm_device *dev)
3209{
3210 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003211 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003212
Chris Wilsonc2798b12012-04-22 21:13:57 +01003213 I915_WRITE16(EMR,
3214 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3215
3216 /* Unmask the interrupts that we always want on. */
3217 dev_priv->irq_mask =
3218 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3219 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3220 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3221 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3222 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3223 I915_WRITE16(IMR, dev_priv->irq_mask);
3224
3225 I915_WRITE16(IER,
3226 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3227 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3228 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3229 I915_USER_INTERRUPT);
3230 POSTING_READ16(IER);
3231
Daniel Vetter379ef822013-10-16 22:55:56 +02003232 /* Interrupt setup is already guaranteed to be single-threaded, this is
3233 * just to make the assert_spin_locked check happy. */
3234 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003235 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3236 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003237 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3238
Chris Wilsonc2798b12012-04-22 21:13:57 +01003239 return 0;
3240}
3241
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003242/*
3243 * Returns true when a page flip has completed.
3244 */
3245static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003246 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003247{
3248 drm_i915_private_t *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003249 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003250
3251 if (!drm_handle_vblank(dev, pipe))
3252 return false;
3253
3254 if ((iir & flip_pending) == 0)
3255 return false;
3256
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003257 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003258
3259 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3260 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3261 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3262 * the flip is completed (no longer pending). Since this doesn't raise
3263 * an interrupt per se, we watch for the change at vblank.
3264 */
3265 if (I915_READ16(ISR) & flip_pending)
3266 return false;
3267
3268 intel_finish_page_flip(dev, pipe);
3269
3270 return true;
3271}
3272
Daniel Vetterff1f5252012-10-02 15:10:55 +02003273static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003274{
3275 struct drm_device *dev = (struct drm_device *) arg;
3276 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003277 u16 iir, new_iir;
3278 u32 pipe_stats[2];
3279 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003280 int pipe;
3281 u16 flip_mask =
3282 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3283 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3284
Chris Wilsonc2798b12012-04-22 21:13:57 +01003285 iir = I915_READ16(IIR);
3286 if (iir == 0)
3287 return IRQ_NONE;
3288
3289 while (iir & ~flip_mask) {
3290 /* Can't rely on pipestat interrupt bit in iir as it might
3291 * have been cleared after the pipestat interrupt was received.
3292 * It doesn't set the bit in iir again, but it still produces
3293 * interrupts (for non-MSI).
3294 */
3295 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3296 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3297 i915_handle_error(dev, false);
3298
3299 for_each_pipe(pipe) {
3300 int reg = PIPESTAT(pipe);
3301 pipe_stats[pipe] = I915_READ(reg);
3302
3303 /*
3304 * Clear the PIPE*STAT regs before the IIR
3305 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003306 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003307 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003308 }
3309 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3310
3311 I915_WRITE16(IIR, iir & ~flip_mask);
3312 new_iir = I915_READ16(IIR); /* Flush posted writes */
3313
Daniel Vetterd05c6172012-04-26 23:28:09 +02003314 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003315
3316 if (iir & I915_USER_INTERRUPT)
3317 notify_ring(dev, &dev_priv->ring[RCS]);
3318
Daniel Vetter4356d582013-10-16 22:55:55 +02003319 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003320 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003321 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003322 plane = !plane;
3323
Daniel Vetter4356d582013-10-16 22:55:55 +02003324 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003325 i8xx_handle_vblank(dev, plane, pipe, iir))
3326 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003327
Daniel Vetter4356d582013-10-16 22:55:55 +02003328 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003329 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003330
3331 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3332 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003333 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003334 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003335
3336 iir = new_iir;
3337 }
3338
3339 return IRQ_HANDLED;
3340}
3341
3342static void i8xx_irq_uninstall(struct drm_device * dev)
3343{
3344 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3345 int pipe;
3346
Chris Wilsonc2798b12012-04-22 21:13:57 +01003347 for_each_pipe(pipe) {
3348 /* Clear enable bits; then clear status bits */
3349 I915_WRITE(PIPESTAT(pipe), 0);
3350 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3351 }
3352 I915_WRITE16(IMR, 0xffff);
3353 I915_WRITE16(IER, 0x0);
3354 I915_WRITE16(IIR, I915_READ16(IIR));
3355}
3356
Chris Wilsona266c7d2012-04-24 22:59:44 +01003357static void i915_irq_preinstall(struct drm_device * dev)
3358{
3359 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3360 int pipe;
3361
Chris Wilsona266c7d2012-04-24 22:59:44 +01003362 if (I915_HAS_HOTPLUG(dev)) {
3363 I915_WRITE(PORT_HOTPLUG_EN, 0);
3364 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3365 }
3366
Chris Wilson00d98eb2012-04-24 22:59:48 +01003367 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003368 for_each_pipe(pipe)
3369 I915_WRITE(PIPESTAT(pipe), 0);
3370 I915_WRITE(IMR, 0xffffffff);
3371 I915_WRITE(IER, 0x0);
3372 POSTING_READ(IER);
3373}
3374
3375static int i915_irq_postinstall(struct drm_device *dev)
3376{
3377 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003378 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003379 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003380
Chris Wilson38bde182012-04-24 22:59:50 +01003381 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3382
3383 /* Unmask the interrupts that we always want on. */
3384 dev_priv->irq_mask =
3385 ~(I915_ASLE_INTERRUPT |
3386 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3387 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3388 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3389 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3390 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3391
3392 enable_mask =
3393 I915_ASLE_INTERRUPT |
3394 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3395 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3396 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3397 I915_USER_INTERRUPT;
3398
Chris Wilsona266c7d2012-04-24 22:59:44 +01003399 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003400 I915_WRITE(PORT_HOTPLUG_EN, 0);
3401 POSTING_READ(PORT_HOTPLUG_EN);
3402
Chris Wilsona266c7d2012-04-24 22:59:44 +01003403 /* Enable in IER... */
3404 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3405 /* and unmask in IMR */
3406 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3407 }
3408
Chris Wilsona266c7d2012-04-24 22:59:44 +01003409 I915_WRITE(IMR, dev_priv->irq_mask);
3410 I915_WRITE(IER, enable_mask);
3411 POSTING_READ(IER);
3412
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003413 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003414
Daniel Vetter379ef822013-10-16 22:55:56 +02003415 /* Interrupt setup is already guaranteed to be single-threaded, this is
3416 * just to make the assert_spin_locked check happy. */
3417 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003418 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3419 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003420 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3421
Daniel Vetter20afbda2012-12-11 14:05:07 +01003422 return 0;
3423}
3424
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003425/*
3426 * Returns true when a page flip has completed.
3427 */
3428static bool i915_handle_vblank(struct drm_device *dev,
3429 int plane, int pipe, u32 iir)
3430{
3431 drm_i915_private_t *dev_priv = dev->dev_private;
3432 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3433
3434 if (!drm_handle_vblank(dev, pipe))
3435 return false;
3436
3437 if ((iir & flip_pending) == 0)
3438 return false;
3439
3440 intel_prepare_page_flip(dev, plane);
3441
3442 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3443 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3444 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3445 * the flip is completed (no longer pending). Since this doesn't raise
3446 * an interrupt per se, we watch for the change at vblank.
3447 */
3448 if (I915_READ(ISR) & flip_pending)
3449 return false;
3450
3451 intel_finish_page_flip(dev, pipe);
3452
3453 return true;
3454}
3455
Daniel Vetterff1f5252012-10-02 15:10:55 +02003456static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003457{
3458 struct drm_device *dev = (struct drm_device *) arg;
3459 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003460 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003461 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003462 u32 flip_mask =
3463 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3464 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003465 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003466
Chris Wilsona266c7d2012-04-24 22:59:44 +01003467 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003468 do {
3469 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003470 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003471
3472 /* Can't rely on pipestat interrupt bit in iir as it might
3473 * have been cleared after the pipestat interrupt was received.
3474 * It doesn't set the bit in iir again, but it still produces
3475 * interrupts (for non-MSI).
3476 */
3477 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3478 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3479 i915_handle_error(dev, false);
3480
3481 for_each_pipe(pipe) {
3482 int reg = PIPESTAT(pipe);
3483 pipe_stats[pipe] = I915_READ(reg);
3484
Chris Wilson38bde182012-04-24 22:59:50 +01003485 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003486 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003487 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003488 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003489 }
3490 }
3491 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3492
3493 if (!irq_received)
3494 break;
3495
Chris Wilsona266c7d2012-04-24 22:59:44 +01003496 /* Consume port. Then clear IIR or we'll miss events */
3497 if ((I915_HAS_HOTPLUG(dev)) &&
3498 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3499 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003500 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003501
Daniel Vetter91d131d2013-06-27 17:52:14 +02003502 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3503
Chris Wilsona266c7d2012-04-24 22:59:44 +01003504 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003505 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003506 }
3507
Chris Wilson38bde182012-04-24 22:59:50 +01003508 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003509 new_iir = I915_READ(IIR); /* Flush posted writes */
3510
Chris Wilsona266c7d2012-04-24 22:59:44 +01003511 if (iir & I915_USER_INTERRUPT)
3512 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003513
Chris Wilsona266c7d2012-04-24 22:59:44 +01003514 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003515 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003516 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003517 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003518
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003519 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3520 i915_handle_vblank(dev, plane, pipe, iir))
3521 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003522
3523 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3524 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003525
3526 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003527 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003528
3529 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3530 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003531 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003532 }
3533
Chris Wilsona266c7d2012-04-24 22:59:44 +01003534 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3535 intel_opregion_asle_intr(dev);
3536
3537 /* With MSI, interrupts are only generated when iir
3538 * transitions from zero to nonzero. If another bit got
3539 * set while we were handling the existing iir bits, then
3540 * we would never get another interrupt.
3541 *
3542 * This is fine on non-MSI as well, as if we hit this path
3543 * we avoid exiting the interrupt handler only to generate
3544 * another one.
3545 *
3546 * Note that for MSI this could cause a stray interrupt report
3547 * if an interrupt landed in the time between writing IIR and
3548 * the posting read. This should be rare enough to never
3549 * trigger the 99% of 100,000 interrupts test for disabling
3550 * stray interrupts.
3551 */
Chris Wilson38bde182012-04-24 22:59:50 +01003552 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003553 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003554 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003555
Daniel Vetterd05c6172012-04-26 23:28:09 +02003556 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003557
Chris Wilsona266c7d2012-04-24 22:59:44 +01003558 return ret;
3559}
3560
3561static void i915_irq_uninstall(struct drm_device * dev)
3562{
3563 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3564 int pipe;
3565
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003566 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003567
Chris Wilsona266c7d2012-04-24 22:59:44 +01003568 if (I915_HAS_HOTPLUG(dev)) {
3569 I915_WRITE(PORT_HOTPLUG_EN, 0);
3570 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3571 }
3572
Chris Wilson00d98eb2012-04-24 22:59:48 +01003573 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003574 for_each_pipe(pipe) {
3575 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003576 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003577 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3578 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003579 I915_WRITE(IMR, 0xffffffff);
3580 I915_WRITE(IER, 0x0);
3581
Chris Wilsona266c7d2012-04-24 22:59:44 +01003582 I915_WRITE(IIR, I915_READ(IIR));
3583}
3584
3585static void i965_irq_preinstall(struct drm_device * dev)
3586{
3587 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3588 int pipe;
3589
Chris Wilsonadca4732012-05-11 18:01:31 +01003590 I915_WRITE(PORT_HOTPLUG_EN, 0);
3591 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003592
3593 I915_WRITE(HWSTAM, 0xeffe);
3594 for_each_pipe(pipe)
3595 I915_WRITE(PIPESTAT(pipe), 0);
3596 I915_WRITE(IMR, 0xffffffff);
3597 I915_WRITE(IER, 0x0);
3598 POSTING_READ(IER);
3599}
3600
3601static int i965_irq_postinstall(struct drm_device *dev)
3602{
3603 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003604 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003605 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003606 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003607
Chris Wilsona266c7d2012-04-24 22:59:44 +01003608 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003609 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003610 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003611 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3612 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3613 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3614 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3615 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3616
3617 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003618 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3619 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003620 enable_mask |= I915_USER_INTERRUPT;
3621
3622 if (IS_G4X(dev))
3623 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003624
Daniel Vetterb79480b2013-06-27 17:52:10 +02003625 /* Interrupt setup is already guaranteed to be single-threaded, this is
3626 * just to make the assert_spin_locked check happy. */
3627 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003628 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3629 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3630 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003631 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003632
Chris Wilsona266c7d2012-04-24 22:59:44 +01003633 /*
3634 * Enable some error detection, note the instruction error mask
3635 * bit is reserved, so we leave it masked.
3636 */
3637 if (IS_G4X(dev)) {
3638 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3639 GM45_ERROR_MEM_PRIV |
3640 GM45_ERROR_CP_PRIV |
3641 I915_ERROR_MEMORY_REFRESH);
3642 } else {
3643 error_mask = ~(I915_ERROR_PAGE_TABLE |
3644 I915_ERROR_MEMORY_REFRESH);
3645 }
3646 I915_WRITE(EMR, error_mask);
3647
3648 I915_WRITE(IMR, dev_priv->irq_mask);
3649 I915_WRITE(IER, enable_mask);
3650 POSTING_READ(IER);
3651
Daniel Vetter20afbda2012-12-11 14:05:07 +01003652 I915_WRITE(PORT_HOTPLUG_EN, 0);
3653 POSTING_READ(PORT_HOTPLUG_EN);
3654
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003655 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003656
3657 return 0;
3658}
3659
Egbert Eichbac56d52013-02-25 12:06:51 -05003660static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003661{
3662 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003663 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003664 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003665 u32 hotplug_en;
3666
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003667 assert_spin_locked(&dev_priv->irq_lock);
3668
Egbert Eichbac56d52013-02-25 12:06:51 -05003669 if (I915_HAS_HOTPLUG(dev)) {
3670 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3671 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3672 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003673 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003674 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3675 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3676 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003677 /* Programming the CRT detection parameters tends
3678 to generate a spurious hotplug event about three
3679 seconds later. So just do it once.
3680 */
3681 if (IS_G4X(dev))
3682 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003683 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003684 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003685
Egbert Eichbac56d52013-02-25 12:06:51 -05003686 /* Ignore TV since it's buggy */
3687 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3688 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003689}
3690
Daniel Vetterff1f5252012-10-02 15:10:55 +02003691static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003692{
3693 struct drm_device *dev = (struct drm_device *) arg;
3694 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003695 u32 iir, new_iir;
3696 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003697 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003698 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003699 u32 flip_mask =
3700 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3701 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003702
Chris Wilsona266c7d2012-04-24 22:59:44 +01003703 iir = I915_READ(IIR);
3704
Chris Wilsona266c7d2012-04-24 22:59:44 +01003705 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003706 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003707 bool blc_event = false;
3708
Chris Wilsona266c7d2012-04-24 22:59:44 +01003709 /* Can't rely on pipestat interrupt bit in iir as it might
3710 * have been cleared after the pipestat interrupt was received.
3711 * It doesn't set the bit in iir again, but it still produces
3712 * interrupts (for non-MSI).
3713 */
3714 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3715 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3716 i915_handle_error(dev, false);
3717
3718 for_each_pipe(pipe) {
3719 int reg = PIPESTAT(pipe);
3720 pipe_stats[pipe] = I915_READ(reg);
3721
3722 /*
3723 * Clear the PIPE*STAT regs before the IIR
3724 */
3725 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003726 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003727 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003728 }
3729 }
3730 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3731
3732 if (!irq_received)
3733 break;
3734
3735 ret = IRQ_HANDLED;
3736
3737 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003738 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003739 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003740 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3741 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003742 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003743
Daniel Vetter91d131d2013-06-27 17:52:14 +02003744 intel_hpd_irq_handler(dev, hotplug_trigger,
Daniel Vetter704cfb82013-12-18 09:08:43 +01003745 IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003746
Daniel Vetter4aeebd72013-10-31 09:53:36 +01003747 if (IS_G4X(dev) &&
3748 (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
3749 dp_aux_irq_handler(dev);
3750
Chris Wilsona266c7d2012-04-24 22:59:44 +01003751 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3752 I915_READ(PORT_HOTPLUG_STAT);
3753 }
3754
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003755 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003756 new_iir = I915_READ(IIR); /* Flush posted writes */
3757
Chris Wilsona266c7d2012-04-24 22:59:44 +01003758 if (iir & I915_USER_INTERRUPT)
3759 notify_ring(dev, &dev_priv->ring[RCS]);
3760 if (iir & I915_BSD_USER_INTERRUPT)
3761 notify_ring(dev, &dev_priv->ring[VCS]);
3762
Chris Wilsona266c7d2012-04-24 22:59:44 +01003763 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003764 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003765 i915_handle_vblank(dev, pipe, pipe, iir))
3766 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003767
3768 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3769 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003770
3771 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003772 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003773
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003774 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3775 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003776 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003777 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003778
3779 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3780 intel_opregion_asle_intr(dev);
3781
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003782 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3783 gmbus_irq_handler(dev);
3784
Chris Wilsona266c7d2012-04-24 22:59:44 +01003785 /* With MSI, interrupts are only generated when iir
3786 * transitions from zero to nonzero. If another bit got
3787 * set while we were handling the existing iir bits, then
3788 * we would never get another interrupt.
3789 *
3790 * This is fine on non-MSI as well, as if we hit this path
3791 * we avoid exiting the interrupt handler only to generate
3792 * another one.
3793 *
3794 * Note that for MSI this could cause a stray interrupt report
3795 * if an interrupt landed in the time between writing IIR and
3796 * the posting read. This should be rare enough to never
3797 * trigger the 99% of 100,000 interrupts test for disabling
3798 * stray interrupts.
3799 */
3800 iir = new_iir;
3801 }
3802
Daniel Vetterd05c6172012-04-26 23:28:09 +02003803 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003804
Chris Wilsona266c7d2012-04-24 22:59:44 +01003805 return ret;
3806}
3807
3808static void i965_irq_uninstall(struct drm_device * dev)
3809{
3810 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3811 int pipe;
3812
3813 if (!dev_priv)
3814 return;
3815
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003816 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003817
Chris Wilsonadca4732012-05-11 18:01:31 +01003818 I915_WRITE(PORT_HOTPLUG_EN, 0);
3819 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003820
3821 I915_WRITE(HWSTAM, 0xffffffff);
3822 for_each_pipe(pipe)
3823 I915_WRITE(PIPESTAT(pipe), 0);
3824 I915_WRITE(IMR, 0xffffffff);
3825 I915_WRITE(IER, 0x0);
3826
3827 for_each_pipe(pipe)
3828 I915_WRITE(PIPESTAT(pipe),
3829 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3830 I915_WRITE(IIR, I915_READ(IIR));
3831}
3832
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003833static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02003834{
3835 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3836 struct drm_device *dev = dev_priv->dev;
3837 struct drm_mode_config *mode_config = &dev->mode_config;
3838 unsigned long irqflags;
3839 int i;
3840
3841 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3842 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3843 struct drm_connector *connector;
3844
3845 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3846 continue;
3847
3848 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3849
3850 list_for_each_entry(connector, &mode_config->connector_list, head) {
3851 struct intel_connector *intel_connector = to_intel_connector(connector);
3852
3853 if (intel_connector->encoder->hpd_pin == i) {
3854 if (connector->polled != intel_connector->polled)
3855 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3856 drm_get_connector_name(connector));
3857 connector->polled = intel_connector->polled;
3858 if (!connector->polled)
3859 connector->polled = DRM_CONNECTOR_POLL_HPD;
3860 }
3861 }
3862 }
3863 if (dev_priv->display.hpd_irq_setup)
3864 dev_priv->display.hpd_irq_setup(dev);
3865 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3866}
3867
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003868void intel_irq_init(struct drm_device *dev)
3869{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003870 struct drm_i915_private *dev_priv = dev->dev_private;
3871
3872 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003873 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003874 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003875 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003876
Daniel Vetter99584db2012-11-14 17:14:04 +01003877 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3878 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003879 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003880 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02003881 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003882
Tomas Janousek97a19a22012-12-08 13:48:13 +01003883 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003884
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003885 if (IS_GEN2(dev)) {
3886 dev->max_vblank_count = 0;
3887 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3888 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003889 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3890 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003891 } else {
3892 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3893 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003894 }
3895
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003896 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003897 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003898 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3899 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003900
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003901 if (IS_VALLEYVIEW(dev)) {
3902 dev->driver->irq_handler = valleyview_irq_handler;
3903 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3904 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3905 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3906 dev->driver->enable_vblank = valleyview_enable_vblank;
3907 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003908 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003909 } else if (IS_GEN8(dev)) {
3910 dev->driver->irq_handler = gen8_irq_handler;
3911 dev->driver->irq_preinstall = gen8_irq_preinstall;
3912 dev->driver->irq_postinstall = gen8_irq_postinstall;
3913 dev->driver->irq_uninstall = gen8_irq_uninstall;
3914 dev->driver->enable_vblank = gen8_enable_vblank;
3915 dev->driver->disable_vblank = gen8_disable_vblank;
3916 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003917 } else if (HAS_PCH_SPLIT(dev)) {
3918 dev->driver->irq_handler = ironlake_irq_handler;
3919 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3920 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3921 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3922 dev->driver->enable_vblank = ironlake_enable_vblank;
3923 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003924 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003925 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003926 if (INTEL_INFO(dev)->gen == 2) {
3927 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3928 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3929 dev->driver->irq_handler = i8xx_irq_handler;
3930 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003931 } else if (INTEL_INFO(dev)->gen == 3) {
3932 dev->driver->irq_preinstall = i915_irq_preinstall;
3933 dev->driver->irq_postinstall = i915_irq_postinstall;
3934 dev->driver->irq_uninstall = i915_irq_uninstall;
3935 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003936 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003937 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003938 dev->driver->irq_preinstall = i965_irq_preinstall;
3939 dev->driver->irq_postinstall = i965_irq_postinstall;
3940 dev->driver->irq_uninstall = i965_irq_uninstall;
3941 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003942 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003943 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003944 dev->driver->enable_vblank = i915_enable_vblank;
3945 dev->driver->disable_vblank = i915_disable_vblank;
3946 }
3947}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003948
3949void intel_hpd_init(struct drm_device *dev)
3950{
3951 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003952 struct drm_mode_config *mode_config = &dev->mode_config;
3953 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003954 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003955 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003956
Egbert Eich821450c2013-04-16 13:36:55 +02003957 for (i = 1; i < HPD_NUM_PINS; i++) {
3958 dev_priv->hpd_stats[i].hpd_cnt = 0;
3959 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3960 }
3961 list_for_each_entry(connector, &mode_config->connector_list, head) {
3962 struct intel_connector *intel_connector = to_intel_connector(connector);
3963 connector->polled = intel_connector->polled;
3964 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3965 connector->polled = DRM_CONNECTOR_POLL_HPD;
3966 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003967
3968 /* Interrupt setup is already guaranteed to be single-threaded, this is
3969 * just to make the assert_spin_locked checks happy. */
3970 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003971 if (dev_priv->display.hpd_irq_setup)
3972 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003973 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003974}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003975
3976/* Disable interrupts so we can allow Package C8+. */
3977void hsw_pc8_disable_interrupts(struct drm_device *dev)
3978{
3979 struct drm_i915_private *dev_priv = dev->dev_private;
3980 unsigned long irqflags;
3981
3982 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3983
3984 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3985 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3986 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3987 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3988 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3989
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003990 ironlake_disable_display_irq(dev_priv, 0xffffffff);
3991 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003992 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3993 snb_disable_pm_irq(dev_priv, 0xffffffff);
3994
3995 dev_priv->pc8.irqs_disabled = true;
3996
3997 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3998}
3999
4000/* Restore interrupts so we can recover from Package C8+. */
4001void hsw_pc8_restore_interrupts(struct drm_device *dev)
4002{
4003 struct drm_i915_private *dev_priv = dev->dev_private;
4004 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004005 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004006
4007 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
4008
4009 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004010 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004011
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004012 val = I915_READ(SDEIMR);
4013 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004014
4015 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004016 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004017
4018 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004019 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004020
4021 dev_priv->pc8.irqs_disabled = false;
4022
4023 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02004024 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004025 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
4026 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
4027 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
4028
4029 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4030}