blob: 19949e8b36c55e33299d71745c9b356e9cc65518 [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
65static const u32 hpd_status_gen4[] = {
66 [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
235static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
236 enum pipe pipe, bool enable)
237{
238 struct drm_i915_private *dev_priv = dev->dev_private;
239 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
240 DE_PIPEB_FIFO_UNDERRUN;
241
242 if (enable)
243 ironlake_enable_display_irq(dev_priv, bit);
244 else
245 ironlake_disable_display_irq(dev_priv, bit);
246}
247
248static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200249 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300250{
251 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300252 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200253 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
254
Paulo Zanoni86642812013-04-12 17:57:57 -0300255 if (!ivb_can_enable_err_int(dev))
256 return;
257
Paulo Zanoni86642812013-04-12 17:57:57 -0300258 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
259 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200260 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
261
262 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300263 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200264
265 if (!was_enabled &&
266 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
267 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
268 pipe_name(pipe));
269 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 }
271}
272
Daniel Vetterfee884e2013-07-04 23:35:21 +0200273/**
274 * ibx_display_interrupt_update - update SDEIMR
275 * @dev_priv: driver private
276 * @interrupt_mask: mask of interrupt bits to update
277 * @enabled_irq_mask: mask of interrupt bits to enable
278 */
279static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
280 uint32_t interrupt_mask,
281 uint32_t enabled_irq_mask)
282{
283 uint32_t sdeimr = I915_READ(SDEIMR);
284 sdeimr &= ~interrupt_mask;
285 sdeimr |= (~enabled_irq_mask & interrupt_mask);
286
287 assert_spin_locked(&dev_priv->irq_lock);
288
Paulo Zanonic67a4702013-08-19 13:18:09 -0300289 if (dev_priv->pc8.irqs_disabled &&
290 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
291 WARN(1, "IRQs disabled\n");
292 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
293 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
294 interrupt_mask);
295 return;
296 }
297
Daniel Vetterfee884e2013-07-04 23:35:21 +0200298 I915_WRITE(SDEIMR, sdeimr);
299 POSTING_READ(SDEIMR);
300}
301#define ibx_enable_display_interrupt(dev_priv, bits) \
302 ibx_display_interrupt_update((dev_priv), (bits), (bits))
303#define ibx_disable_display_interrupt(dev_priv, bits) \
304 ibx_display_interrupt_update((dev_priv), (bits), 0)
305
Daniel Vetterde280752013-07-04 23:35:24 +0200306static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
307 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300308 bool enable)
309{
Paulo Zanoni86642812013-04-12 17:57:57 -0300310 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200311 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
312 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300313
314 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200315 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300316 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200317 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300318}
319
320static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
321 enum transcoder pch_transcoder,
322 bool enable)
323{
324 struct drm_i915_private *dev_priv = dev->dev_private;
325
326 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200327 I915_WRITE(SERR_INT,
328 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
329
Paulo Zanoni86642812013-04-12 17:57:57 -0300330 if (!cpt_can_enable_serr_int(dev))
331 return;
332
Daniel Vetterfee884e2013-07-04 23:35:21 +0200333 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300334 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200335 uint32_t tmp = I915_READ(SERR_INT);
336 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
337
338 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200339 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200340
341 if (!was_enabled &&
342 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
343 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
344 transcoder_name(pch_transcoder));
345 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300346 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300347}
348
349/**
350 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
351 * @dev: drm device
352 * @pipe: pipe
353 * @enable: true if we want to report FIFO underrun errors, false otherwise
354 *
355 * This function makes us disable or enable CPU fifo underruns for a specific
356 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
357 * reporting for one pipe may also disable all the other CPU error interruts for
358 * the other pipes, due to the fact that there's just one interrupt mask/enable
359 * bit for all the pipes.
360 *
361 * Returns the previous state of underrun reporting.
362 */
363bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
364 enum pipe pipe, bool enable)
365{
366 struct drm_i915_private *dev_priv = dev->dev_private;
367 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
368 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
369 unsigned long flags;
370 bool ret;
371
372 spin_lock_irqsave(&dev_priv->irq_lock, flags);
373
374 ret = !intel_crtc->cpu_fifo_underrun_disabled;
375
376 if (enable == ret)
377 goto done;
378
379 intel_crtc->cpu_fifo_underrun_disabled = !enable;
380
381 if (IS_GEN5(dev) || IS_GEN6(dev))
382 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
383 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200384 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300385
386done:
387 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
388 return ret;
389}
390
391/**
392 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
393 * @dev: drm device
394 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
395 * @enable: true if we want to report FIFO underrun errors, false otherwise
396 *
397 * This function makes us disable or enable PCH fifo underruns for a specific
398 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
399 * underrun reporting for one transcoder may also disable all the other PCH
400 * error interruts for the other transcoders, due to the fact that there's just
401 * one interrupt mask/enable bit for all the transcoders.
402 *
403 * Returns the previous state of underrun reporting.
404 */
405bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
406 enum transcoder pch_transcoder,
407 bool enable)
408{
409 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200410 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
411 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300412 unsigned long flags;
413 bool ret;
414
Daniel Vetterde280752013-07-04 23:35:24 +0200415 /*
416 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
417 * has only one pch transcoder A that all pipes can use. To avoid racy
418 * pch transcoder -> pipe lookups from interrupt code simply store the
419 * underrun statistics in crtc A. Since we never expose this anywhere
420 * nor use it outside of the fifo underrun code here using the "wrong"
421 * crtc on LPT won't cause issues.
422 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300423
424 spin_lock_irqsave(&dev_priv->irq_lock, flags);
425
426 ret = !intel_crtc->pch_fifo_underrun_disabled;
427
428 if (enable == ret)
429 goto done;
430
431 intel_crtc->pch_fifo_underrun_disabled = !enable;
432
433 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200434 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300435 else
436 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
437
438done:
439 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
440 return ret;
441}
442
443
Keith Packard7c463582008-11-04 02:03:27 -0800444void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200445i915_enable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800446{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200447 u32 reg = PIPESTAT(pipe);
448 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800449
Daniel Vetterb79480b2013-06-27 17:52:10 +0200450 assert_spin_locked(&dev_priv->irq_lock);
451
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200452 if ((pipestat & mask) == mask)
453 return;
454
455 /* Enable the interrupt, clear any pending status */
456 pipestat |= mask | (mask >> 16);
457 I915_WRITE(reg, pipestat);
458 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800459}
460
461void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200462i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800463{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200464 u32 reg = PIPESTAT(pipe);
465 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800466
Daniel Vetterb79480b2013-06-27 17:52:10 +0200467 assert_spin_locked(&dev_priv->irq_lock);
468
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200469 if ((pipestat & mask) == 0)
470 return;
471
472 pipestat &= ~mask;
473 I915_WRITE(reg, pipestat);
474 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800475}
476
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000477/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300478 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000479 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300480static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000481{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000482 drm_i915_private_t *dev_priv = dev->dev_private;
483 unsigned long irqflags;
484
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300485 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
486 return;
487
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000488 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000489
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200490 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE);
Jani Nikulaf8987802013-04-29 13:02:53 +0300491 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200492 i915_enable_pipestat(dev_priv, PIPE_A,
493 PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000494
495 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000496}
497
498/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700499 * i915_pipe_enabled - check if a pipe is enabled
500 * @dev: DRM device
501 * @pipe: pipe to check
502 *
503 * Reading certain registers when the pipe is disabled can hang the chip.
504 * Use this routine to make sure the PLL is running and the pipe is active
505 * before reading such registers if unsure.
506 */
507static int
508i915_pipe_enabled(struct drm_device *dev, int pipe)
509{
510 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200511
Daniel Vettera01025a2013-05-22 00:50:23 +0200512 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
513 /* Locking is horribly broken here, but whatever. */
514 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
515 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300516
Daniel Vettera01025a2013-05-22 00:50:23 +0200517 return intel_crtc->active;
518 } else {
519 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
520 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700521}
522
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300523static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
524{
525 /* Gen2 doesn't have a hardware frame counter */
526 return 0;
527}
528
Keith Packard42f52ef2008-10-18 19:39:29 -0700529/* Called from drm generic code, passed a 'crtc', which
530 * we use as a pipe index
531 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700532static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700533{
534 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
535 unsigned long high_frame;
536 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300537 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700538
539 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800540 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800541 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700542 return 0;
543 }
544
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300545 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
546 struct intel_crtc *intel_crtc =
547 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
548 const struct drm_display_mode *mode =
549 &intel_crtc->config.adjusted_mode;
550
551 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
552 } else {
553 enum transcoder cpu_transcoder =
554 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
555 u32 htotal;
556
557 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
558 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
559
560 vbl_start *= htotal;
561 }
562
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800563 high_frame = PIPEFRAME(pipe);
564 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100565
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700566 /*
567 * High & low register fields aren't synchronized, so make sure
568 * we get a low value that's stable across two reads of the high
569 * register.
570 */
571 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100572 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300573 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100574 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700575 } while (high1 != high2);
576
Chris Wilson5eddb702010-09-11 13:48:45 +0100577 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300578 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100579 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300580
581 /*
582 * The frame counter increments at beginning of active.
583 * Cook up a vblank counter by also checking the pixel
584 * counter against vblank start.
585 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200586 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700587}
588
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700589static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800590{
591 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800592 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800593
594 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800595 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800596 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800597 return 0;
598 }
599
600 return I915_READ(reg);
601}
602
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300603static bool intel_pipe_in_vblank(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300604{
605 struct drm_i915_private *dev_priv = dev->dev_private;
606 uint32_t status;
607
608 if (IS_VALLEYVIEW(dev)) {
609 status = pipe == PIPE_A ?
610 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
611 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
612
613 return I915_READ(VLV_ISR) & status;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300614 } else if (IS_GEN2(dev)) {
615 status = pipe == PIPE_A ?
616 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
617 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
618
619 return I915_READ16(ISR) & status;
620 } else if (INTEL_INFO(dev)->gen < 5) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300621 status = pipe == PIPE_A ?
622 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
623 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
624
625 return I915_READ(ISR) & status;
626 } else if (INTEL_INFO(dev)->gen < 7) {
627 status = pipe == PIPE_A ?
628 DE_PIPEA_VBLANK :
629 DE_PIPEB_VBLANK;
630
631 return I915_READ(DEISR) & status;
632 } else {
633 switch (pipe) {
634 default:
635 case PIPE_A:
636 status = DE_PIPEA_VBLANK_IVB;
637 break;
638 case PIPE_B:
639 status = DE_PIPEB_VBLANK_IVB;
640 break;
641 case PIPE_C:
642 status = DE_PIPEC_VBLANK_IVB;
643 break;
644 }
645
646 return I915_READ(DEISR) & status;
647 }
648}
649
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700650static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100651 int *vpos, int *hpos)
652{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300653 struct drm_i915_private *dev_priv = dev->dev_private;
654 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
655 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
656 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300657 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100658 int vbl_start, vbl_end, htotal, vtotal;
659 bool in_vbl = true;
660 int ret = 0;
661
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300662 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100663 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800664 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100665 return 0;
666 }
667
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300668 htotal = mode->crtc_htotal;
669 vtotal = mode->crtc_vtotal;
670 vbl_start = mode->crtc_vblank_start;
671 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100672
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300673 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
674
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300675 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100676 /* No obvious pixelcount register. Only query vertical
677 * scanout position from Display scan line register.
678 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300679 if (IS_GEN2(dev))
680 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
681 else
682 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300683
684 /*
685 * The scanline counter increments at the leading edge
686 * of hsync, ie. it completely misses the active portion
687 * of the line. Fix up the counter at both edges of vblank
688 * to get a more accurate picture whether we're in vblank
689 * or not.
690 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300691 in_vbl = intel_pipe_in_vblank(dev, pipe);
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300692 if ((in_vbl && position == vbl_start - 1) ||
693 (!in_vbl && position == vbl_end - 1))
694 position = (position + 1) % vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100695 } else {
696 /* Have access to pixelcount since start of frame.
697 * We can split this into vertical and horizontal
698 * scanout position.
699 */
700 position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
701
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300702 /* convert to pixel counts */
703 vbl_start *= htotal;
704 vbl_end *= htotal;
705 vtotal *= htotal;
706 }
707
708 in_vbl = position >= vbl_start && position < vbl_end;
709
710 /*
711 * While in vblank, position will be negative
712 * counting up towards 0 at vbl_end. And outside
713 * vblank, position will be positive counting
714 * up since vbl_end.
715 */
716 if (position >= vbl_start)
717 position -= vbl_end;
718 else
719 position += vtotal - vbl_end;
720
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300721 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300722 *vpos = position;
723 *hpos = 0;
724 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100725 *vpos = position / htotal;
726 *hpos = position - (*vpos * htotal);
727 }
728
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100729 /* In vblank? */
730 if (in_vbl)
731 ret |= DRM_SCANOUTPOS_INVBL;
732
733 return ret;
734}
735
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700736static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100737 int *max_error,
738 struct timeval *vblank_time,
739 unsigned flags)
740{
Chris Wilson4041b852011-01-22 10:07:56 +0000741 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100742
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700743 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000744 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100745 return -EINVAL;
746 }
747
748 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000749 crtc = intel_get_crtc_for_pipe(dev, pipe);
750 if (crtc == NULL) {
751 DRM_ERROR("Invalid crtc %d\n", pipe);
752 return -EINVAL;
753 }
754
755 if (!crtc->enabled) {
756 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
757 return -EBUSY;
758 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100759
760 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000761 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
762 vblank_time, flags,
763 crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100764}
765
Jani Nikula67c347f2013-09-17 14:26:34 +0300766static bool intel_hpd_irq_event(struct drm_device *dev,
767 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200768{
769 enum drm_connector_status old_status;
770
771 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
772 old_status = connector->status;
773
774 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300775 if (old_status == connector->status)
776 return false;
777
778 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200779 connector->base.id,
780 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300781 drm_get_connector_status_name(old_status),
782 drm_get_connector_status_name(connector->status));
783
784 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200785}
786
Jesse Barnes5ca58282009-03-31 14:11:15 -0700787/*
788 * Handle hotplug events outside the interrupt handler proper.
789 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200790#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
791
Jesse Barnes5ca58282009-03-31 14:11:15 -0700792static void i915_hotplug_work_func(struct work_struct *work)
793{
794 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
795 hotplug_work);
796 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700797 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200798 struct intel_connector *intel_connector;
799 struct intel_encoder *intel_encoder;
800 struct drm_connector *connector;
801 unsigned long irqflags;
802 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200803 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200804 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700805
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100806 /* HPD irq before everything is fully set up. */
807 if (!dev_priv->enable_hotplug_processing)
808 return;
809
Keith Packarda65e34c2011-07-25 10:04:56 -0700810 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800811 DRM_DEBUG_KMS("running encoder hotplug functions\n");
812
Egbert Eichcd569ae2013-04-16 13:36:57 +0200813 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200814
815 hpd_event_bits = dev_priv->hpd_event_bits;
816 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200817 list_for_each_entry(connector, &mode_config->connector_list, head) {
818 intel_connector = to_intel_connector(connector);
819 intel_encoder = intel_connector->encoder;
820 if (intel_encoder->hpd_pin > HPD_NONE &&
821 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
822 connector->polled == DRM_CONNECTOR_POLL_HPD) {
823 DRM_INFO("HPD interrupt storm detected on connector %s: "
824 "switching from hotplug detection to polling\n",
825 drm_get_connector_name(connector));
826 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
827 connector->polled = DRM_CONNECTOR_POLL_CONNECT
828 | DRM_CONNECTOR_POLL_DISCONNECT;
829 hpd_disabled = true;
830 }
Egbert Eich142e2392013-04-11 15:57:57 +0200831 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
832 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
833 drm_get_connector_name(connector), intel_encoder->hpd_pin);
834 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200835 }
836 /* if there were no outputs to poll, poll was disabled,
837 * therefore make sure it's enabled when disabling HPD on
838 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200839 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200840 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200841 mod_timer(&dev_priv->hotplug_reenable_timer,
842 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
843 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200844
845 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
846
Egbert Eich321a1b32013-04-11 16:00:26 +0200847 list_for_each_entry(connector, &mode_config->connector_list, head) {
848 intel_connector = to_intel_connector(connector);
849 intel_encoder = intel_connector->encoder;
850 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
851 if (intel_encoder->hot_plug)
852 intel_encoder->hot_plug(intel_encoder);
853 if (intel_hpd_irq_event(dev, connector))
854 changed = true;
855 }
856 }
Keith Packard40ee3382011-07-28 15:31:19 -0700857 mutex_unlock(&mode_config->mutex);
858
Egbert Eich321a1b32013-04-11 16:00:26 +0200859 if (changed)
860 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700861}
862
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200863static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800864{
865 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000866 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200867 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200868
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200869 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800870
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200871 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
872
Daniel Vetter20e4d402012-08-08 23:35:39 +0200873 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200874
Jesse Barnes7648fa92010-05-20 14:28:11 -0700875 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000876 busy_up = I915_READ(RCPREVBSYTUPAVG);
877 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800878 max_avg = I915_READ(RCBMAXAVG);
879 min_avg = I915_READ(RCBMINAVG);
880
881 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000882 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200883 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
884 new_delay = dev_priv->ips.cur_delay - 1;
885 if (new_delay < dev_priv->ips.max_delay)
886 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000887 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200888 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
889 new_delay = dev_priv->ips.cur_delay + 1;
890 if (new_delay > dev_priv->ips.min_delay)
891 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800892 }
893
Jesse Barnes7648fa92010-05-20 14:28:11 -0700894 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200895 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800896
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200897 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200898
Jesse Barnesf97108d2010-01-29 11:27:07 -0800899 return;
900}
901
Chris Wilson549f7362010-10-19 11:19:32 +0100902static void notify_ring(struct drm_device *dev,
903 struct intel_ring_buffer *ring)
904{
Chris Wilson475553d2011-01-20 09:52:56 +0000905 if (ring->obj == NULL)
906 return;
907
Chris Wilson814e9b52013-09-23 17:33:19 -0300908 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000909
Chris Wilson549f7362010-10-19 11:19:32 +0100910 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300911 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100912}
913
Ben Widawsky4912d042011-04-25 11:25:20 -0700914static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800915{
Ben Widawsky4912d042011-04-25 11:25:20 -0700916 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200917 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300918 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100919 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800920
Daniel Vetter59cdb632013-07-04 23:35:28 +0200921 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200922 pm_iir = dev_priv->rps.pm_iir;
923 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -0700924 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300925 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200926 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700927
Paulo Zanoni60611c12013-08-15 11:50:01 -0300928 /* Make sure we didn't queue anything we're not going to process. */
929 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
930
Ben Widawsky48484052013-05-28 19:22:27 -0700931 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800932 return;
933
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700934 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100935
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100936 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300937 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100938 if (adj > 0)
939 adj *= 2;
940 else
941 adj = 1;
942 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300943
944 /*
945 * For better performance, jump directly
946 * to RPe if we're below it.
947 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100948 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +0300949 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100950 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
951 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
952 new_delay = dev_priv->rps.rpe_delay;
953 else
954 new_delay = dev_priv->rps.min_delay;
955 adj = 0;
956 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
957 if (adj < 0)
958 adj *= 2;
959 else
960 adj = -1;
961 new_delay = dev_priv->rps.cur_delay + adj;
962 } else { /* unknown event */
963 new_delay = dev_priv->rps.cur_delay;
964 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800965
Ben Widawsky79249632012-09-07 19:43:42 -0700966 /* sysfs frequency interfaces may have snuck in while servicing the
967 * interrupt
968 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +0200969 new_delay = clamp_t(int, new_delay,
970 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100971 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
972
973 if (IS_VALLEYVIEW(dev_priv->dev))
974 valleyview_set_rps(dev_priv->dev, new_delay);
975 else
976 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800977
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700978 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800979}
980
Ben Widawskye3689192012-05-25 16:56:22 -0700981
982/**
983 * ivybridge_parity_work - Workqueue called when a parity error interrupt
984 * occurred.
985 * @work: workqueue struct
986 *
987 * Doesn't actually do anything except notify userspace. As a consequence of
988 * this event, userspace should try to remap the bad rows since statistically
989 * it is likely the same row is more likely to go bad again.
990 */
991static void ivybridge_parity_work(struct work_struct *work)
992{
993 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +0100994 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -0700995 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -0700996 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -0700997 uint32_t misccpctl;
998 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -0700999 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001000
1001 /* We must turn off DOP level clock gating to access the L3 registers.
1002 * In order to prevent a get/put style interface, acquire struct mutex
1003 * any time we access those registers.
1004 */
1005 mutex_lock(&dev_priv->dev->struct_mutex);
1006
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001007 /* If we've screwed up tracking, just let the interrupt fire again */
1008 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1009 goto out;
1010
Ben Widawskye3689192012-05-25 16:56:22 -07001011 misccpctl = I915_READ(GEN7_MISCCPCTL);
1012 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1013 POSTING_READ(GEN7_MISCCPCTL);
1014
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001015 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1016 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001017
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001018 slice--;
1019 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1020 break;
1021
1022 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1023
1024 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1025
1026 error_status = I915_READ(reg);
1027 row = GEN7_PARITY_ERROR_ROW(error_status);
1028 bank = GEN7_PARITY_ERROR_BANK(error_status);
1029 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1030
1031 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1032 POSTING_READ(reg);
1033
1034 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1035 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1036 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1037 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1038 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1039 parity_event[5] = NULL;
1040
1041 kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
1042 KOBJ_CHANGE, parity_event);
1043
1044 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1045 slice, row, bank, subbank);
1046
1047 kfree(parity_event[4]);
1048 kfree(parity_event[3]);
1049 kfree(parity_event[2]);
1050 kfree(parity_event[1]);
1051 }
Ben Widawskye3689192012-05-25 16:56:22 -07001052
1053 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1054
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001055out:
1056 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001057 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001058 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001059 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1060
1061 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001062}
1063
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001064static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001065{
1066 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001067
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001068 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001069 return;
1070
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001071 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001072 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001073 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001074
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001075 iir &= GT_PARITY_ERROR(dev);
1076 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1077 dev_priv->l3_parity.which_slice |= 1 << 1;
1078
1079 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1080 dev_priv->l3_parity.which_slice |= 1 << 0;
1081
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001082 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001083}
1084
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001085static void ilk_gt_irq_handler(struct drm_device *dev,
1086 struct drm_i915_private *dev_priv,
1087 u32 gt_iir)
1088{
1089 if (gt_iir &
1090 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1091 notify_ring(dev, &dev_priv->ring[RCS]);
1092 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1093 notify_ring(dev, &dev_priv->ring[VCS]);
1094}
1095
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001096static void snb_gt_irq_handler(struct drm_device *dev,
1097 struct drm_i915_private *dev_priv,
1098 u32 gt_iir)
1099{
1100
Ben Widawskycc609d52013-05-28 19:22:29 -07001101 if (gt_iir &
1102 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001103 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001104 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001105 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001106 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001107 notify_ring(dev, &dev_priv->ring[BCS]);
1108
Ben Widawskycc609d52013-05-28 19:22:29 -07001109 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1110 GT_BSD_CS_ERROR_INTERRUPT |
1111 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001112 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1113 i915_handle_error(dev, false);
1114 }
Ben Widawskye3689192012-05-25 16:56:22 -07001115
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001116 if (gt_iir & GT_PARITY_ERROR(dev))
1117 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001118}
1119
Egbert Eichb543fb02013-04-16 13:36:54 +02001120#define HPD_STORM_DETECT_PERIOD 1000
1121#define HPD_STORM_THRESHOLD 5
1122
Daniel Vetter10a504d2013-06-27 17:52:12 +02001123static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001124 u32 hotplug_trigger,
1125 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001126{
1127 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001128 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001129 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001130
Daniel Vetter91d131d2013-06-27 17:52:14 +02001131 if (!hotplug_trigger)
1132 return;
1133
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001134 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001135 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001136
Egbert Eichb8f102e2013-07-26 14:14:24 +02001137 WARN(((hpd[i] & hotplug_trigger) &&
1138 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED),
1139 "Received HPD interrupt although disabled\n");
1140
Egbert Eichb543fb02013-04-16 13:36:54 +02001141 if (!(hpd[i] & hotplug_trigger) ||
1142 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1143 continue;
1144
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001145 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001146 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1147 dev_priv->hpd_stats[i].hpd_last_jiffies
1148 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1149 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1150 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001151 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001152 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1153 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001154 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001155 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001156 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001157 } else {
1158 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001159 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1160 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001161 }
1162 }
1163
Daniel Vetter10a504d2013-06-27 17:52:12 +02001164 if (storm_detected)
1165 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001166 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001167
Daniel Vetter645416f2013-09-02 16:22:25 +02001168 /*
1169 * Our hotplug handler can grab modeset locks (by calling down into the
1170 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1171 * queue for otherwise the flush_work in the pageflip code will
1172 * deadlock.
1173 */
1174 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001175}
1176
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001177static void gmbus_irq_handler(struct drm_device *dev)
1178{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001179 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1180
Daniel Vetter28c70f12012-12-01 13:53:45 +01001181 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001182}
1183
Daniel Vetterce99c252012-12-01 13:53:47 +01001184static void dp_aux_irq_handler(struct drm_device *dev)
1185{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001186 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1187
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001188 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001189}
1190
Shuang He8bf1e9f2013-10-15 18:55:27 +01001191#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001192static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1193 uint32_t crc0, uint32_t crc1,
1194 uint32_t crc2, uint32_t crc3,
1195 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001196{
1197 struct drm_i915_private *dev_priv = dev->dev_private;
1198 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1199 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001200 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001201
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001202 spin_lock(&pipe_crc->lock);
1203
Damien Lespiau0c912c72013-10-15 18:55:37 +01001204 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001205 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001206 DRM_ERROR("spurious interrupt\n");
1207 return;
1208 }
1209
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001210 head = pipe_crc->head;
1211 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001212
1213 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001214 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001215 DRM_ERROR("CRC buffer overflowing\n");
1216 return;
1217 }
1218
1219 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001220
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001221 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001222 entry->crc[0] = crc0;
1223 entry->crc[1] = crc1;
1224 entry->crc[2] = crc2;
1225 entry->crc[3] = crc3;
1226 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001227
1228 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001229 pipe_crc->head = head;
1230
1231 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001232
1233 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001234}
Daniel Vetter277de952013-10-18 16:37:07 +02001235#else
1236static inline void
1237display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1238 uint32_t crc0, uint32_t crc1,
1239 uint32_t crc2, uint32_t crc3,
1240 uint32_t crc4) {}
1241#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001242
Daniel Vetter277de952013-10-18 16:37:07 +02001243
1244static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001245{
1246 struct drm_i915_private *dev_priv = dev->dev_private;
1247
Daniel Vetter277de952013-10-18 16:37:07 +02001248 display_pipe_crc_irq_handler(dev, pipe,
1249 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1250 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001251}
1252
Daniel Vetter277de952013-10-18 16:37:07 +02001253static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001254{
1255 struct drm_i915_private *dev_priv = dev->dev_private;
1256
Daniel Vetter277de952013-10-18 16:37:07 +02001257 display_pipe_crc_irq_handler(dev, pipe,
1258 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1259 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1260 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1261 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1262 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001263}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001264
Daniel Vetter277de952013-10-18 16:37:07 +02001265static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001266{
1267 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001268 uint32_t res1, res2;
1269
1270 if (INTEL_INFO(dev)->gen >= 3)
1271 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1272 else
1273 res1 = 0;
1274
1275 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1276 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1277 else
1278 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001279
Daniel Vetter277de952013-10-18 16:37:07 +02001280 display_pipe_crc_irq_handler(dev, pipe,
1281 I915_READ(PIPE_CRC_RES_RED(pipe)),
1282 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1283 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1284 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001285}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001286
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001287/* The RPS events need forcewake, so we add them to a work queue and mask their
1288 * IMR bits until the work is done. Other interrupts can be processed without
1289 * the work queue. */
1290static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001291{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001292 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001293 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001294 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001295 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001296 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001297
1298 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001299 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001300
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001301 if (HAS_VEBOX(dev_priv->dev)) {
1302 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1303 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001304
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001305 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1306 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1307 i915_handle_error(dev_priv->dev, false);
1308 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001309 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001310}
1311
Daniel Vetterff1f5252012-10-02 15:10:55 +02001312static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001313{
1314 struct drm_device *dev = (struct drm_device *) arg;
1315 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1316 u32 iir, gt_iir, pm_iir;
1317 irqreturn_t ret = IRQ_NONE;
1318 unsigned long irqflags;
1319 int pipe;
1320 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001321
1322 atomic_inc(&dev_priv->irq_received);
1323
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001324 while (true) {
1325 iir = I915_READ(VLV_IIR);
1326 gt_iir = I915_READ(GTIIR);
1327 pm_iir = I915_READ(GEN6_PMIIR);
1328
1329 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1330 goto out;
1331
1332 ret = IRQ_HANDLED;
1333
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001334 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001335
1336 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1337 for_each_pipe(pipe) {
1338 int reg = PIPESTAT(pipe);
1339 pipe_stats[pipe] = I915_READ(reg);
1340
1341 /*
1342 * Clear the PIPE*STAT regs before the IIR
1343 */
1344 if (pipe_stats[pipe] & 0x8000ffff) {
1345 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1346 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1347 pipe_name(pipe));
1348 I915_WRITE(reg, pipe_stats[pipe]);
1349 }
1350 }
1351 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1352
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001353 for_each_pipe(pipe) {
1354 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1355 drm_handle_vblank(dev, pipe);
1356
1357 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1358 intel_prepare_page_flip(dev, pipe);
1359 intel_finish_page_flip(dev, pipe);
1360 }
Daniel Vetter4356d582013-10-16 22:55:55 +02001361
1362 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02001363 i9xx_pipe_crc_irq_handler(dev, pipe);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001364 }
1365
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001366 /* Consume port. Then clear IIR or we'll miss events */
1367 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1368 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001369 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001370
1371 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1372 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001373
1374 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1375
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001376 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1377 I915_READ(PORT_HOTPLUG_STAT);
1378 }
1379
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001380 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1381 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001382
Paulo Zanoni60611c12013-08-15 11:50:01 -03001383 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001384 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001385
1386 I915_WRITE(GTIIR, gt_iir);
1387 I915_WRITE(GEN6_PMIIR, pm_iir);
1388 I915_WRITE(VLV_IIR, iir);
1389 }
1390
1391out:
1392 return ret;
1393}
1394
Adam Jackson23e81d62012-06-06 15:45:44 -04001395static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001396{
1397 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001398 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001399 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001400
Daniel Vetter91d131d2013-06-27 17:52:14 +02001401 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1402
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001403 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1404 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1405 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001406 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001407 port_name(port));
1408 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001409
Daniel Vetterce99c252012-12-01 13:53:47 +01001410 if (pch_iir & SDE_AUX_MASK)
1411 dp_aux_irq_handler(dev);
1412
Jesse Barnes776ad802011-01-04 15:09:39 -08001413 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001414 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001415
1416 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1417 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1418
1419 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1420 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1421
1422 if (pch_iir & SDE_POISON)
1423 DRM_ERROR("PCH poison interrupt\n");
1424
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001425 if (pch_iir & SDE_FDI_MASK)
1426 for_each_pipe(pipe)
1427 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1428 pipe_name(pipe),
1429 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001430
1431 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1432 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1433
1434 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1435 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1436
Jesse Barnes776ad802011-01-04 15:09:39 -08001437 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001438 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1439 false))
1440 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1441
1442 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1443 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1444 false))
1445 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1446}
1447
1448static void ivb_err_int_handler(struct drm_device *dev)
1449{
1450 struct drm_i915_private *dev_priv = dev->dev_private;
1451 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001452 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001453
Paulo Zanonide032bf2013-04-12 17:57:58 -03001454 if (err_int & ERR_INT_POISON)
1455 DRM_ERROR("Poison interrupt\n");
1456
Daniel Vetter5a69b892013-10-16 22:55:52 +02001457 for_each_pipe(pipe) {
1458 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1459 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1460 false))
1461 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1462 pipe_name(pipe));
1463 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001464
Daniel Vetter5a69b892013-10-16 22:55:52 +02001465 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1466 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001467 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001468 else
Daniel Vetter277de952013-10-18 16:37:07 +02001469 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001470 }
1471 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001472
Paulo Zanoni86642812013-04-12 17:57:57 -03001473 I915_WRITE(GEN7_ERR_INT, err_int);
1474}
1475
1476static void cpt_serr_int_handler(struct drm_device *dev)
1477{
1478 struct drm_i915_private *dev_priv = dev->dev_private;
1479 u32 serr_int = I915_READ(SERR_INT);
1480
Paulo Zanonide032bf2013-04-12 17:57:58 -03001481 if (serr_int & SERR_INT_POISON)
1482 DRM_ERROR("PCH poison interrupt\n");
1483
Paulo Zanoni86642812013-04-12 17:57:57 -03001484 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1485 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1486 false))
1487 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1488
1489 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1490 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1491 false))
1492 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1493
1494 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1495 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1496 false))
1497 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1498
1499 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001500}
1501
Adam Jackson23e81d62012-06-06 15:45:44 -04001502static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1503{
1504 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1505 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001506 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001507
Daniel Vetter91d131d2013-06-27 17:52:14 +02001508 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1509
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001510 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1511 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1512 SDE_AUDIO_POWER_SHIFT_CPT);
1513 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1514 port_name(port));
1515 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001516
1517 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001518 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001519
1520 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001521 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001522
1523 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1524 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1525
1526 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1527 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1528
1529 if (pch_iir & SDE_FDI_MASK_CPT)
1530 for_each_pipe(pipe)
1531 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1532 pipe_name(pipe),
1533 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001534
1535 if (pch_iir & SDE_ERROR_CPT)
1536 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001537}
1538
Paulo Zanonic008bc62013-07-12 16:35:10 -03001539static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1540{
1541 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001542 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001543
1544 if (de_iir & DE_AUX_CHANNEL_A)
1545 dp_aux_irq_handler(dev);
1546
1547 if (de_iir & DE_GSE)
1548 intel_opregion_asle_intr(dev);
1549
Paulo Zanonic008bc62013-07-12 16:35:10 -03001550 if (de_iir & DE_POISON)
1551 DRM_ERROR("Poison interrupt\n");
1552
Daniel Vetter40da17c2013-10-21 18:04:36 +02001553 for_each_pipe(pipe) {
1554 if (de_iir & DE_PIPE_VBLANK(pipe))
1555 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001556
Daniel Vetter40da17c2013-10-21 18:04:36 +02001557 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1558 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1559 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1560 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001561
Daniel Vetter40da17c2013-10-21 18:04:36 +02001562 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1563 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001564
Daniel Vetter40da17c2013-10-21 18:04:36 +02001565 /* plane/pipes map 1:1 on ilk+ */
1566 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1567 intel_prepare_page_flip(dev, pipe);
1568 intel_finish_page_flip_plane(dev, pipe);
1569 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001570 }
1571
1572 /* check event from PCH */
1573 if (de_iir & DE_PCH_EVENT) {
1574 u32 pch_iir = I915_READ(SDEIIR);
1575
1576 if (HAS_PCH_CPT(dev))
1577 cpt_irq_handler(dev, pch_iir);
1578 else
1579 ibx_irq_handler(dev, pch_iir);
1580
1581 /* should clear PCH hotplug event before clear CPU irq */
1582 I915_WRITE(SDEIIR, pch_iir);
1583 }
1584
1585 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1586 ironlake_rps_change_irq_handler(dev);
1587}
1588
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001589static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1590{
1591 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001592 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001593
1594 if (de_iir & DE_ERR_INT_IVB)
1595 ivb_err_int_handler(dev);
1596
1597 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1598 dp_aux_irq_handler(dev);
1599
1600 if (de_iir & DE_GSE_IVB)
1601 intel_opregion_asle_intr(dev);
1602
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001603 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001604 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001605 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001606
1607 /* plane/pipes map 1:1 on ilk+ */
1608 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001609 intel_prepare_page_flip(dev, i);
1610 intel_finish_page_flip_plane(dev, i);
1611 }
1612 }
1613
1614 /* check event from PCH */
1615 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1616 u32 pch_iir = I915_READ(SDEIIR);
1617
1618 cpt_irq_handler(dev, pch_iir);
1619
1620 /* clear PCH hotplug event before clear CPU irq */
1621 I915_WRITE(SDEIIR, pch_iir);
1622 }
1623}
1624
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001625static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001626{
1627 struct drm_device *dev = (struct drm_device *) arg;
1628 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001629 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001630 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001631
1632 atomic_inc(&dev_priv->irq_received);
1633
Paulo Zanoni86642812013-04-12 17:57:57 -03001634 /* We get interrupts on unclaimed registers, so check for this before we
1635 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001636 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001637
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001638 /* disable master interrupt before clearing iir */
1639 de_ier = I915_READ(DEIER);
1640 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001641 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001642
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001643 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1644 * interrupts will will be stored on its back queue, and then we'll be
1645 * able to process them after we restore SDEIER (as soon as we restore
1646 * it, we'll get an interrupt if SDEIIR still has something to process
1647 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001648 if (!HAS_PCH_NOP(dev)) {
1649 sde_ier = I915_READ(SDEIER);
1650 I915_WRITE(SDEIER, 0);
1651 POSTING_READ(SDEIER);
1652 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001653
Chris Wilson0e434062012-05-09 21:45:44 +01001654 gt_iir = I915_READ(GTIIR);
1655 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001656 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001657 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001658 else
1659 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001660 I915_WRITE(GTIIR, gt_iir);
1661 ret = IRQ_HANDLED;
1662 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001663
1664 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001665 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001666 if (INTEL_INFO(dev)->gen >= 7)
1667 ivb_display_irq_handler(dev, de_iir);
1668 else
1669 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001670 I915_WRITE(DEIIR, de_iir);
1671 ret = IRQ_HANDLED;
1672 }
1673
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001674 if (INTEL_INFO(dev)->gen >= 6) {
1675 u32 pm_iir = I915_READ(GEN6_PMIIR);
1676 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001677 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001678 I915_WRITE(GEN6_PMIIR, pm_iir);
1679 ret = IRQ_HANDLED;
1680 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001681 }
1682
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001683 I915_WRITE(DEIER, de_ier);
1684 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001685 if (!HAS_PCH_NOP(dev)) {
1686 I915_WRITE(SDEIER, sde_ier);
1687 POSTING_READ(SDEIER);
1688 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001689
1690 return ret;
1691}
1692
Daniel Vetter17e1df02013-09-08 21:57:13 +02001693static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1694 bool reset_completed)
1695{
1696 struct intel_ring_buffer *ring;
1697 int i;
1698
1699 /*
1700 * Notify all waiters for GPU completion events that reset state has
1701 * been changed, and that they need to restart their wait after
1702 * checking for potential errors (and bail out to drop locks if there is
1703 * a gpu reset pending so that i915_error_work_func can acquire them).
1704 */
1705
1706 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1707 for_each_ring(ring, dev_priv, i)
1708 wake_up_all(&ring->irq_queue);
1709
1710 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1711 wake_up_all(&dev_priv->pending_flip_queue);
1712
1713 /*
1714 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1715 * reset state is cleared.
1716 */
1717 if (reset_completed)
1718 wake_up_all(&dev_priv->gpu_error.reset_queue);
1719}
1720
Jesse Barnes8a905232009-07-11 16:48:03 -04001721/**
1722 * i915_error_work_func - do process context error handling work
1723 * @work: work struct
1724 *
1725 * Fire an error uevent so userspace can see that a hang or error
1726 * was detected.
1727 */
1728static void i915_error_work_func(struct work_struct *work)
1729{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001730 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1731 work);
1732 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1733 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001734 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07001735 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1736 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1737 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02001738 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001739
Ben Gamarif316a422009-09-14 17:48:46 -04001740 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001741
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001742 /*
1743 * Note that there's only one work item which does gpu resets, so we
1744 * need not worry about concurrent gpu resets potentially incrementing
1745 * error->reset_counter twice. We only need to take care of another
1746 * racing irq/hangcheck declaring the gpu dead for a second time. A
1747 * quick check for that is good enough: schedule_work ensures the
1748 * correct ordering between hang detection and this work item, and since
1749 * the reset in-progress bit is only ever set by code outside of this
1750 * work we don't need to worry about any other races.
1751 */
1752 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001753 DRM_DEBUG_DRIVER("resetting chip\n");
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001754 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
1755 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001756
Daniel Vetter17e1df02013-09-08 21:57:13 +02001757 /*
1758 * All state reset _must_ be completed before we update the
1759 * reset counter, for otherwise waiters might miss the reset
1760 * pending state and not properly drop locks, resulting in
1761 * deadlocks with the reset work.
1762 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01001763 ret = i915_reset(dev);
1764
Daniel Vetter17e1df02013-09-08 21:57:13 +02001765 intel_display_handle_reset(dev);
1766
Daniel Vetterf69061b2012-12-06 09:01:42 +01001767 if (ret == 0) {
1768 /*
1769 * After all the gem state is reset, increment the reset
1770 * counter and wake up everyone waiting for the reset to
1771 * complete.
1772 *
1773 * Since unlock operations are a one-sided barrier only,
1774 * we need to insert a barrier here to order any seqno
1775 * updates before
1776 * the counter increment.
1777 */
1778 smp_mb__before_atomic_inc();
1779 atomic_inc(&dev_priv->gpu_error.reset_counter);
1780
1781 kobject_uevent_env(&dev->primary->kdev.kobj,
1782 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001783 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02001784 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04001785 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001786
Daniel Vetter17e1df02013-09-08 21:57:13 +02001787 /*
1788 * Note: The wake_up also serves as a memory barrier so that
1789 * waiters see the update value of the reset counter atomic_t.
1790 */
1791 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04001792 }
Jesse Barnes8a905232009-07-11 16:48:03 -04001793}
1794
Chris Wilson35aed2e2010-05-27 13:18:12 +01001795static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04001796{
1797 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07001798 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04001799 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07001800 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04001801
Chris Wilson35aed2e2010-05-27 13:18:12 +01001802 if (!eir)
1803 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04001804
Joe Perchesa70491c2012-03-18 13:00:11 -07001805 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04001806
Ben Widawskybd9854f2012-08-23 15:18:09 -07001807 i915_get_extra_instdone(dev, instdone);
1808
Jesse Barnes8a905232009-07-11 16:48:03 -04001809 if (IS_G4X(dev)) {
1810 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1811 u32 ipeir = I915_READ(IPEIR_I965);
1812
Joe Perchesa70491c2012-03-18 13:00:11 -07001813 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1814 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07001815 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1816 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07001817 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001818 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001819 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001820 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001821 }
1822 if (eir & GM45_ERROR_PAGE_TABLE) {
1823 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001824 pr_err("page table error\n");
1825 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001826 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001827 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001828 }
1829 }
1830
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001831 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001832 if (eir & I915_ERROR_PAGE_TABLE) {
1833 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001834 pr_err("page table error\n");
1835 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001836 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001837 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001838 }
1839 }
1840
1841 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001842 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001843 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07001844 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001845 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04001846 /* pipestat has already been acked */
1847 }
1848 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001849 pr_err("instruction error\n");
1850 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07001851 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1852 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001853 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001854 u32 ipeir = I915_READ(IPEIR);
1855
Joe Perchesa70491c2012-03-18 13:00:11 -07001856 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
1857 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07001858 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04001859 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001860 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001861 } else {
1862 u32 ipeir = I915_READ(IPEIR_I965);
1863
Joe Perchesa70491c2012-03-18 13:00:11 -07001864 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1865 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07001866 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001867 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001868 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001869 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001870 }
1871 }
1872
1873 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001874 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001875 eir = I915_READ(EIR);
1876 if (eir) {
1877 /*
1878 * some errors might have become stuck,
1879 * mask them.
1880 */
1881 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1882 I915_WRITE(EMR, I915_READ(EMR) | eir);
1883 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1884 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01001885}
1886
1887/**
1888 * i915_handle_error - handle an error interrupt
1889 * @dev: drm device
1890 *
1891 * Do some basic checking of regsiter state at error interrupt time and
1892 * dump it to the syslog. Also call i915_capture_error_state() to make
1893 * sure we get a record and make it available in debugfs. Fire a uevent
1894 * so userspace knows something bad happened (should trigger collection
1895 * of a ring dump etc.).
1896 */
Chris Wilson527f9e92010-11-11 01:16:58 +00001897void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01001898{
1899 struct drm_i915_private *dev_priv = dev->dev_private;
1900
1901 i915_capture_error_state(dev);
1902 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04001903
Ben Gamariba1234d2009-09-14 17:48:47 -04001904 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01001905 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
1906 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04001907
Ben Gamari11ed50e2009-09-14 17:48:45 -04001908 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02001909 * Wakeup waiting processes so that the reset work function
1910 * i915_error_work_func doesn't deadlock trying to grab various
1911 * locks. By bumping the reset counter first, the woken
1912 * processes will see a reset in progress and back off,
1913 * releasing their locks and then wait for the reset completion.
1914 * We must do this for _all_ gpu waiters that might hold locks
1915 * that the reset work needs to acquire.
1916 *
1917 * Note: The wake_up serves as the required memory barrier to
1918 * ensure that the waiters see the updated value of the reset
1919 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04001920 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02001921 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04001922 }
1923
Daniel Vetter122f46b2013-09-04 17:36:14 +02001924 /*
1925 * Our reset work can grab modeset locks (since it needs to reset the
1926 * state of outstanding pagelips). Hence it must not be run on our own
1927 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
1928 * code will deadlock.
1929 */
1930 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04001931}
1932
Ville Syrjälä21ad8332013-02-19 15:16:39 +02001933static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001934{
1935 drm_i915_private_t *dev_priv = dev->dev_private;
1936 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1937 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00001938 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001939 struct intel_unpin_work *work;
1940 unsigned long flags;
1941 bool stall_detected;
1942
1943 /* Ignore early vblank irqs */
1944 if (intel_crtc == NULL)
1945 return;
1946
1947 spin_lock_irqsave(&dev->event_lock, flags);
1948 work = intel_crtc->unpin_work;
1949
Chris Wilsone7d841c2012-12-03 11:36:30 +00001950 if (work == NULL ||
1951 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
1952 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001953 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1954 spin_unlock_irqrestore(&dev->event_lock, flags);
1955 return;
1956 }
1957
1958 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00001959 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001960 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001961 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07001962 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001963 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001964 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001965 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001966 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02001967 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001968 crtc->x * crtc->fb->bits_per_pixel/8);
1969 }
1970
1971 spin_unlock_irqrestore(&dev->event_lock, flags);
1972
1973 if (stall_detected) {
1974 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1975 intel_prepare_page_flip(dev, intel_crtc->plane);
1976 }
1977}
1978
Keith Packard42f52ef2008-10-18 19:39:29 -07001979/* Called from drm generic code, passed 'crtc' which
1980 * we use as a pipe index
1981 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001982static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001983{
1984 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001985 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001986
Chris Wilson5eddb702010-09-11 13:48:45 +01001987 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001988 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001989
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001990 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07001991 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08001992 i915_enable_pipestat(dev_priv, pipe,
1993 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07001994 else
Keith Packard7c463582008-11-04 02:03:27 -08001995 i915_enable_pipestat(dev_priv, pipe,
1996 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001997
1998 /* maintain vblank delivery even in deep C-states */
1999 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002000 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002001 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002002
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002003 return 0;
2004}
2005
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002006static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002007{
2008 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2009 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002010 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002011 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002012
2013 if (!i915_pipe_enabled(dev, pipe))
2014 return -EINVAL;
2015
2016 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002017 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002018 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2019
2020 return 0;
2021}
2022
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002023static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2024{
2025 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2026 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002027 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002028
2029 if (!i915_pipe_enabled(dev, pipe))
2030 return -EINVAL;
2031
2032 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002033 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002034 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002035 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002036 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002037 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002038 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002039 i915_enable_pipestat(dev_priv, pipe,
2040 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002041 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2042
2043 return 0;
2044}
2045
Keith Packard42f52ef2008-10-18 19:39:29 -07002046/* Called from drm generic code, passed 'crtc' which
2047 * we use as a pipe index
2048 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002049static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002050{
2051 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002052 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002053
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002054 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002055 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002056 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002057
Jesse Barnesf796cf82011-04-07 13:58:17 -07002058 i915_disable_pipestat(dev_priv, pipe,
2059 PIPE_VBLANK_INTERRUPT_ENABLE |
2060 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2061 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2062}
2063
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002064static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002065{
2066 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2067 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002068 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002069 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002070
2071 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002072 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002073 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2074}
2075
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002076static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2077{
2078 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2079 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002080 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002081
2082 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002083 i915_disable_pipestat(dev_priv, pipe,
2084 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002085 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002086 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002087 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002088 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002089 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002090 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002091 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2092}
2093
Chris Wilson893eead2010-10-27 14:44:35 +01002094static u32
2095ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002096{
Chris Wilson893eead2010-10-27 14:44:35 +01002097 return list_entry(ring->request_list.prev,
2098 struct drm_i915_gem_request, list)->seqno;
2099}
2100
Chris Wilson9107e9d2013-06-10 11:20:20 +01002101static bool
2102ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002103{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002104 return (list_empty(&ring->request_list) ||
2105 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002106}
2107
Chris Wilson6274f212013-06-10 11:20:21 +01002108static struct intel_ring_buffer *
2109semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002110{
2111 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002112 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002113
2114 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2115 if ((ipehr & ~(0x3 << 16)) !=
2116 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002117 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002118
2119 /* ACTHD is likely pointing to the dword after the actual command,
2120 * so scan backwards until we find the MBOX.
2121 */
Chris Wilson6274f212013-06-10 11:20:21 +01002122 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002123 acthd_min = max((int)acthd - 3 * 4, 0);
2124 do {
2125 cmd = ioread32(ring->virtual_start + acthd);
2126 if (cmd == ipehr)
2127 break;
2128
2129 acthd -= 4;
2130 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002131 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002132 } while (1);
2133
Chris Wilson6274f212013-06-10 11:20:21 +01002134 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2135 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002136}
2137
Chris Wilson6274f212013-06-10 11:20:21 +01002138static int semaphore_passed(struct intel_ring_buffer *ring)
2139{
2140 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2141 struct intel_ring_buffer *signaller;
2142 u32 seqno, ctl;
2143
2144 ring->hangcheck.deadlock = true;
2145
2146 signaller = semaphore_waits_for(ring, &seqno);
2147 if (signaller == NULL || signaller->hangcheck.deadlock)
2148 return -1;
2149
2150 /* cursory check for an unkickable deadlock */
2151 ctl = I915_READ_CTL(signaller);
2152 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2153 return -1;
2154
2155 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2156}
2157
2158static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2159{
2160 struct intel_ring_buffer *ring;
2161 int i;
2162
2163 for_each_ring(ring, dev_priv, i)
2164 ring->hangcheck.deadlock = false;
2165}
2166
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002167static enum intel_ring_hangcheck_action
2168ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002169{
2170 struct drm_device *dev = ring->dev;
2171 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002172 u32 tmp;
2173
Chris Wilson6274f212013-06-10 11:20:21 +01002174 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002175 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002176
Chris Wilson9107e9d2013-06-10 11:20:20 +01002177 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002178 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002179
2180 /* Is the chip hanging on a WAIT_FOR_EVENT?
2181 * If so we can simply poke the RB_WAIT bit
2182 * and break the hang. This should work on
2183 * all but the second generation chipsets.
2184 */
2185 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002186 if (tmp & RING_WAIT) {
2187 DRM_ERROR("Kicking stuck wait on %s\n",
2188 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002189 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002190 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002191 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002192 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002193
Chris Wilson6274f212013-06-10 11:20:21 +01002194 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2195 switch (semaphore_passed(ring)) {
2196 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002197 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002198 case 1:
2199 DRM_ERROR("Kicking stuck semaphore on %s\n",
2200 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002201 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002202 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002203 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002204 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002205 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002206 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002207 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002208
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002209 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002210}
2211
Ben Gamarif65d9422009-09-14 17:48:44 -04002212/**
2213 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002214 * batchbuffers in a long time. We keep track per ring seqno progress and
2215 * if there are no progress, hangcheck score for that ring is increased.
2216 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2217 * we kick the ring. If we see no progress on three subsequent calls
2218 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002219 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002220static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002221{
2222 struct drm_device *dev = (struct drm_device *)data;
2223 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002224 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002225 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002226 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002227 bool stuck[I915_NUM_RINGS] = { 0 };
2228#define BUSY 1
2229#define KICK 5
2230#define HUNG 20
2231#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01002232
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002233 if (!i915_enable_hangcheck)
2234 return;
2235
Chris Wilsonb4519512012-05-11 14:29:30 +01002236 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002237 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002238 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002239
Chris Wilson6274f212013-06-10 11:20:21 +01002240 semaphore_clear_deadlocks(dev_priv);
2241
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002242 seqno = ring->get_seqno(ring, false);
2243 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002244
Chris Wilson9107e9d2013-06-10 11:20:20 +01002245 if (ring->hangcheck.seqno == seqno) {
2246 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002247 ring->hangcheck.action = HANGCHECK_IDLE;
2248
Chris Wilson9107e9d2013-06-10 11:20:20 +01002249 if (waitqueue_active(&ring->irq_queue)) {
2250 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002251 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002252 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2253 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2254 ring->name);
2255 else
2256 DRM_INFO("Fake missed irq on %s\n",
2257 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002258 wake_up_all(&ring->irq_queue);
2259 }
2260 /* Safeguard against driver failure */
2261 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002262 } else
2263 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002264 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002265 /* We always increment the hangcheck score
2266 * if the ring is busy and still processing
2267 * the same request, so that no single request
2268 * can run indefinitely (such as a chain of
2269 * batches). The only time we do not increment
2270 * the hangcheck score on this ring, if this
2271 * ring is in a legitimate wait for another
2272 * ring. In that case the waiting ring is a
2273 * victim and we want to be sure we catch the
2274 * right culprit. Then every time we do kick
2275 * the ring, add a small increment to the
2276 * score so that we can catch a batch that is
2277 * being repeatedly kicked and so responsible
2278 * for stalling the machine.
2279 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002280 ring->hangcheck.action = ring_stuck(ring,
2281 acthd);
2282
2283 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002284 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002285 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002286 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002287 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002288 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002289 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002290 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002291 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002292 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002293 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002294 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002295 stuck[i] = true;
2296 break;
2297 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002298 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002299 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002300 ring->hangcheck.action = HANGCHECK_ACTIVE;
2301
Chris Wilson9107e9d2013-06-10 11:20:20 +01002302 /* Gradually reduce the count so that we catch DoS
2303 * attempts across multiple batches.
2304 */
2305 if (ring->hangcheck.score > 0)
2306 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002307 }
2308
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002309 ring->hangcheck.seqno = seqno;
2310 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002311 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002312 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002313
Mika Kuoppala92cab732013-05-24 17:16:07 +03002314 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002315 if (ring->hangcheck.score > FIRE) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002316 DRM_INFO("%s on %s\n",
2317 stuck[i] ? "stuck" : "no progress",
2318 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002319 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002320 }
2321 }
2322
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002323 if (rings_hung)
2324 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002325
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002326 if (busy_count)
2327 /* Reset timer case chip hangs without another request
2328 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002329 i915_queue_hangcheck(dev);
2330}
2331
2332void i915_queue_hangcheck(struct drm_device *dev)
2333{
2334 struct drm_i915_private *dev_priv = dev->dev_private;
2335 if (!i915_enable_hangcheck)
2336 return;
2337
2338 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2339 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002340}
2341
Paulo Zanoni91738a92013-06-05 14:21:51 -03002342static void ibx_irq_preinstall(struct drm_device *dev)
2343{
2344 struct drm_i915_private *dev_priv = dev->dev_private;
2345
2346 if (HAS_PCH_NOP(dev))
2347 return;
2348
2349 /* south display irq */
2350 I915_WRITE(SDEIMR, 0xffffffff);
2351 /*
2352 * SDEIER is also touched by the interrupt handler to work around missed
2353 * PCH interrupts. Hence we can't update it after the interrupt handler
2354 * is enabled - instead we unconditionally enable all PCH interrupt
2355 * sources here, but then only unmask them as needed with SDEIMR.
2356 */
2357 I915_WRITE(SDEIER, 0xffffffff);
2358 POSTING_READ(SDEIER);
2359}
2360
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002361static void gen5_gt_irq_preinstall(struct drm_device *dev)
2362{
2363 struct drm_i915_private *dev_priv = dev->dev_private;
2364
2365 /* and GT */
2366 I915_WRITE(GTIMR, 0xffffffff);
2367 I915_WRITE(GTIER, 0x0);
2368 POSTING_READ(GTIER);
2369
2370 if (INTEL_INFO(dev)->gen >= 6) {
2371 /* and PM */
2372 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2373 I915_WRITE(GEN6_PMIER, 0x0);
2374 POSTING_READ(GEN6_PMIER);
2375 }
2376}
2377
Linus Torvalds1da177e2005-04-16 15:20:36 -07002378/* drm_dma.h hooks
2379*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002380static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002381{
2382 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2383
Jesse Barnes46979952011-04-07 13:53:55 -07002384 atomic_set(&dev_priv->irq_received, 0);
2385
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002386 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002387
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002388 I915_WRITE(DEIMR, 0xffffffff);
2389 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002390 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002391
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002392 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002393
Paulo Zanoni91738a92013-06-05 14:21:51 -03002394 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002395}
2396
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002397static void valleyview_irq_preinstall(struct drm_device *dev)
2398{
2399 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2400 int pipe;
2401
2402 atomic_set(&dev_priv->irq_received, 0);
2403
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002404 /* VLV magic */
2405 I915_WRITE(VLV_IMR, 0);
2406 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2407 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2408 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2409
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002410 /* and GT */
2411 I915_WRITE(GTIIR, I915_READ(GTIIR));
2412 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002413
2414 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002415
2416 I915_WRITE(DPINVGTT, 0xff);
2417
2418 I915_WRITE(PORT_HOTPLUG_EN, 0);
2419 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2420 for_each_pipe(pipe)
2421 I915_WRITE(PIPESTAT(pipe), 0xffff);
2422 I915_WRITE(VLV_IIR, 0xffffffff);
2423 I915_WRITE(VLV_IMR, 0xffffffff);
2424 I915_WRITE(VLV_IER, 0x0);
2425 POSTING_READ(VLV_IER);
2426}
2427
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002428static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002429{
2430 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002431 struct drm_mode_config *mode_config = &dev->mode_config;
2432 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002433 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002434
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002435 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002436 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002437 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002438 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002439 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002440 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002441 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002442 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002443 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002444 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002445 }
2446
Daniel Vetterfee884e2013-07-04 23:35:21 +02002447 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002448
2449 /*
2450 * Enable digital hotplug on the PCH, and configure the DP short pulse
2451 * duration to 2ms (which is the minimum in the Display Port spec)
2452 *
2453 * This register is the same on all known PCH chips.
2454 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002455 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2456 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2457 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2458 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2459 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2460 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2461}
2462
Paulo Zanonid46da432013-02-08 17:35:15 -02002463static void ibx_irq_postinstall(struct drm_device *dev)
2464{
2465 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002466 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002467
Daniel Vetter692a04c2013-05-29 21:43:05 +02002468 if (HAS_PCH_NOP(dev))
2469 return;
2470
Paulo Zanoni86642812013-04-12 17:57:57 -03002471 if (HAS_PCH_IBX(dev)) {
2472 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002473 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002474 } else {
2475 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2476
2477 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2478 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002479
Paulo Zanonid46da432013-02-08 17:35:15 -02002480 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2481 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002482}
2483
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002484static void gen5_gt_irq_postinstall(struct drm_device *dev)
2485{
2486 struct drm_i915_private *dev_priv = dev->dev_private;
2487 u32 pm_irqs, gt_irqs;
2488
2489 pm_irqs = gt_irqs = 0;
2490
2491 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002492 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002493 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002494 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2495 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002496 }
2497
2498 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2499 if (IS_GEN5(dev)) {
2500 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2501 ILK_BSD_USER_INTERRUPT;
2502 } else {
2503 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2504 }
2505
2506 I915_WRITE(GTIIR, I915_READ(GTIIR));
2507 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2508 I915_WRITE(GTIER, gt_irqs);
2509 POSTING_READ(GTIER);
2510
2511 if (INTEL_INFO(dev)->gen >= 6) {
2512 pm_irqs |= GEN6_PM_RPS_EVENTS;
2513
2514 if (HAS_VEBOX(dev))
2515 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2516
Paulo Zanoni605cd252013-08-06 18:57:15 -03002517 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002518 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002519 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002520 I915_WRITE(GEN6_PMIER, pm_irqs);
2521 POSTING_READ(GEN6_PMIER);
2522 }
2523}
2524
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002525static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002526{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002527 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002528 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002529 u32 display_mask, extra_mask;
2530
2531 if (INTEL_INFO(dev)->gen >= 7) {
2532 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2533 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2534 DE_PLANEB_FLIP_DONE_IVB |
2535 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2536 DE_ERR_INT_IVB);
2537 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2538 DE_PIPEA_VBLANK_IVB);
2539
2540 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2541 } else {
2542 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2543 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002544 DE_AUX_CHANNEL_A |
2545 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2546 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2547 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002548 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2549 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002550
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002551 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002552
2553 /* should always can generate irq */
2554 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002555 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002556 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002557 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002558
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002559 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002560
Paulo Zanonid46da432013-02-08 17:35:15 -02002561 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002562
Jesse Barnesf97108d2010-01-29 11:27:07 -08002563 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002564 /* Enable PCU event interrupts
2565 *
2566 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002567 * setup is guaranteed to run in single-threaded context. But we
2568 * need it to make the assert_spin_locked happy. */
2569 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002570 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002571 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002572 }
2573
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002574 return 0;
2575}
2576
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002577static int valleyview_irq_postinstall(struct drm_device *dev)
2578{
2579 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002580 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002581 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2582 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002583 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002584
2585 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002586 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2587 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2588 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002589 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2590
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002591 /*
2592 *Leave vblank interrupts masked initially. enable/disable will
2593 * toggle them based on usage.
2594 */
2595 dev_priv->irq_mask = (~enable_mask) |
2596 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2597 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002598
Daniel Vetter20afbda2012-12-11 14:05:07 +01002599 I915_WRITE(PORT_HOTPLUG_EN, 0);
2600 POSTING_READ(PORT_HOTPLUG_EN);
2601
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002602 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2603 I915_WRITE(VLV_IER, enable_mask);
2604 I915_WRITE(VLV_IIR, 0xffffffff);
2605 I915_WRITE(PIPESTAT(0), 0xffff);
2606 I915_WRITE(PIPESTAT(1), 0xffff);
2607 POSTING_READ(VLV_IER);
2608
Daniel Vetterb79480b2013-06-27 17:52:10 +02002609 /* Interrupt setup is already guaranteed to be single-threaded, this is
2610 * just to make the assert_spin_locked check happy. */
2611 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002612 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
2613 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
2614 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002615 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002616
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002617 I915_WRITE(VLV_IIR, 0xffffffff);
2618 I915_WRITE(VLV_IIR, 0xffffffff);
2619
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002620 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002621
2622 /* ack & enable invalid PTE error interrupts */
2623#if 0 /* FIXME: add support to irq handler for checking these bits */
2624 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2625 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2626#endif
2627
2628 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002629
2630 return 0;
2631}
2632
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002633static void valleyview_irq_uninstall(struct drm_device *dev)
2634{
2635 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2636 int pipe;
2637
2638 if (!dev_priv)
2639 return;
2640
Egbert Eichac4c16c2013-04-16 13:36:58 +02002641 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2642
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002643 for_each_pipe(pipe)
2644 I915_WRITE(PIPESTAT(pipe), 0xffff);
2645
2646 I915_WRITE(HWSTAM, 0xffffffff);
2647 I915_WRITE(PORT_HOTPLUG_EN, 0);
2648 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2649 for_each_pipe(pipe)
2650 I915_WRITE(PIPESTAT(pipe), 0xffff);
2651 I915_WRITE(VLV_IIR, 0xffffffff);
2652 I915_WRITE(VLV_IMR, 0xffffffff);
2653 I915_WRITE(VLV_IER, 0x0);
2654 POSTING_READ(VLV_IER);
2655}
2656
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002657static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002658{
2659 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07002660
2661 if (!dev_priv)
2662 return;
2663
Egbert Eichac4c16c2013-04-16 13:36:58 +02002664 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2665
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002666 I915_WRITE(HWSTAM, 0xffffffff);
2667
2668 I915_WRITE(DEIMR, 0xffffffff);
2669 I915_WRITE(DEIER, 0x0);
2670 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002671 if (IS_GEN7(dev))
2672 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002673
2674 I915_WRITE(GTIMR, 0xffffffff);
2675 I915_WRITE(GTIER, 0x0);
2676 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07002677
Ben Widawskyab5c6082013-04-05 13:12:41 -07002678 if (HAS_PCH_NOP(dev))
2679 return;
2680
Keith Packard192aac1f2011-09-20 10:12:44 -07002681 I915_WRITE(SDEIMR, 0xffffffff);
2682 I915_WRITE(SDEIER, 0x0);
2683 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002684 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
2685 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002686}
2687
Chris Wilsonc2798b12012-04-22 21:13:57 +01002688static void i8xx_irq_preinstall(struct drm_device * dev)
2689{
2690 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2691 int pipe;
2692
2693 atomic_set(&dev_priv->irq_received, 0);
2694
2695 for_each_pipe(pipe)
2696 I915_WRITE(PIPESTAT(pipe), 0);
2697 I915_WRITE16(IMR, 0xffff);
2698 I915_WRITE16(IER, 0x0);
2699 POSTING_READ16(IER);
2700}
2701
2702static int i8xx_irq_postinstall(struct drm_device *dev)
2703{
2704 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02002705 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002706
Chris Wilsonc2798b12012-04-22 21:13:57 +01002707 I915_WRITE16(EMR,
2708 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2709
2710 /* Unmask the interrupts that we always want on. */
2711 dev_priv->irq_mask =
2712 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2713 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2714 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2715 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2716 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2717 I915_WRITE16(IMR, dev_priv->irq_mask);
2718
2719 I915_WRITE16(IER,
2720 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2721 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2722 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2723 I915_USER_INTERRUPT);
2724 POSTING_READ16(IER);
2725
Daniel Vetter379ef822013-10-16 22:55:56 +02002726 /* Interrupt setup is already guaranteed to be single-threaded, this is
2727 * just to make the assert_spin_locked check happy. */
2728 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002729 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
2730 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02002731 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2732
Chris Wilsonc2798b12012-04-22 21:13:57 +01002733 return 0;
2734}
2735
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002736/*
2737 * Returns true when a page flip has completed.
2738 */
2739static bool i8xx_handle_vblank(struct drm_device *dev,
2740 int pipe, u16 iir)
2741{
2742 drm_i915_private_t *dev_priv = dev->dev_private;
2743 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
2744
2745 if (!drm_handle_vblank(dev, pipe))
2746 return false;
2747
2748 if ((iir & flip_pending) == 0)
2749 return false;
2750
2751 intel_prepare_page_flip(dev, pipe);
2752
2753 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2754 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2755 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2756 * the flip is completed (no longer pending). Since this doesn't raise
2757 * an interrupt per se, we watch for the change at vblank.
2758 */
2759 if (I915_READ16(ISR) & flip_pending)
2760 return false;
2761
2762 intel_finish_page_flip(dev, pipe);
2763
2764 return true;
2765}
2766
Daniel Vetterff1f5252012-10-02 15:10:55 +02002767static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01002768{
2769 struct drm_device *dev = (struct drm_device *) arg;
2770 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002771 u16 iir, new_iir;
2772 u32 pipe_stats[2];
2773 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002774 int pipe;
2775 u16 flip_mask =
2776 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2777 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
2778
2779 atomic_inc(&dev_priv->irq_received);
2780
2781 iir = I915_READ16(IIR);
2782 if (iir == 0)
2783 return IRQ_NONE;
2784
2785 while (iir & ~flip_mask) {
2786 /* Can't rely on pipestat interrupt bit in iir as it might
2787 * have been cleared after the pipestat interrupt was received.
2788 * It doesn't set the bit in iir again, but it still produces
2789 * interrupts (for non-MSI).
2790 */
2791 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2792 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2793 i915_handle_error(dev, false);
2794
2795 for_each_pipe(pipe) {
2796 int reg = PIPESTAT(pipe);
2797 pipe_stats[pipe] = I915_READ(reg);
2798
2799 /*
2800 * Clear the PIPE*STAT regs before the IIR
2801 */
2802 if (pipe_stats[pipe] & 0x8000ffff) {
2803 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2804 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2805 pipe_name(pipe));
2806 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002807 }
2808 }
2809 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2810
2811 I915_WRITE16(IIR, iir & ~flip_mask);
2812 new_iir = I915_READ16(IIR); /* Flush posted writes */
2813
Daniel Vetterd05c6172012-04-26 23:28:09 +02002814 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002815
2816 if (iir & I915_USER_INTERRUPT)
2817 notify_ring(dev, &dev_priv->ring[RCS]);
2818
Daniel Vetter4356d582013-10-16 22:55:55 +02002819 for_each_pipe(pipe) {
2820 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
2821 i8xx_handle_vblank(dev, pipe, iir))
2822 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002823
Daniel Vetter4356d582013-10-16 22:55:55 +02002824 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02002825 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02002826 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01002827
2828 iir = new_iir;
2829 }
2830
2831 return IRQ_HANDLED;
2832}
2833
2834static void i8xx_irq_uninstall(struct drm_device * dev)
2835{
2836 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2837 int pipe;
2838
Chris Wilsonc2798b12012-04-22 21:13:57 +01002839 for_each_pipe(pipe) {
2840 /* Clear enable bits; then clear status bits */
2841 I915_WRITE(PIPESTAT(pipe), 0);
2842 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2843 }
2844 I915_WRITE16(IMR, 0xffff);
2845 I915_WRITE16(IER, 0x0);
2846 I915_WRITE16(IIR, I915_READ16(IIR));
2847}
2848
Chris Wilsona266c7d2012-04-24 22:59:44 +01002849static void i915_irq_preinstall(struct drm_device * dev)
2850{
2851 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2852 int pipe;
2853
2854 atomic_set(&dev_priv->irq_received, 0);
2855
2856 if (I915_HAS_HOTPLUG(dev)) {
2857 I915_WRITE(PORT_HOTPLUG_EN, 0);
2858 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2859 }
2860
Chris Wilson00d98eb2012-04-24 22:59:48 +01002861 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002862 for_each_pipe(pipe)
2863 I915_WRITE(PIPESTAT(pipe), 0);
2864 I915_WRITE(IMR, 0xffffffff);
2865 I915_WRITE(IER, 0x0);
2866 POSTING_READ(IER);
2867}
2868
2869static int i915_irq_postinstall(struct drm_device *dev)
2870{
2871 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01002872 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002873 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002874
Chris Wilson38bde182012-04-24 22:59:50 +01002875 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2876
2877 /* Unmask the interrupts that we always want on. */
2878 dev_priv->irq_mask =
2879 ~(I915_ASLE_INTERRUPT |
2880 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2881 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2882 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2883 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2884 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2885
2886 enable_mask =
2887 I915_ASLE_INTERRUPT |
2888 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2889 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2890 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2891 I915_USER_INTERRUPT;
2892
Chris Wilsona266c7d2012-04-24 22:59:44 +01002893 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01002894 I915_WRITE(PORT_HOTPLUG_EN, 0);
2895 POSTING_READ(PORT_HOTPLUG_EN);
2896
Chris Wilsona266c7d2012-04-24 22:59:44 +01002897 /* Enable in IER... */
2898 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
2899 /* and unmask in IMR */
2900 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
2901 }
2902
Chris Wilsona266c7d2012-04-24 22:59:44 +01002903 I915_WRITE(IMR, dev_priv->irq_mask);
2904 I915_WRITE(IER, enable_mask);
2905 POSTING_READ(IER);
2906
Jani Nikulaf49e38d2013-04-29 13:02:54 +03002907 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002908
Daniel Vetter379ef822013-10-16 22:55:56 +02002909 /* Interrupt setup is already guaranteed to be single-threaded, this is
2910 * just to make the assert_spin_locked check happy. */
2911 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002912 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
2913 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02002914 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2915
Daniel Vetter20afbda2012-12-11 14:05:07 +01002916 return 0;
2917}
2918
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002919/*
2920 * Returns true when a page flip has completed.
2921 */
2922static bool i915_handle_vblank(struct drm_device *dev,
2923 int plane, int pipe, u32 iir)
2924{
2925 drm_i915_private_t *dev_priv = dev->dev_private;
2926 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
2927
2928 if (!drm_handle_vblank(dev, pipe))
2929 return false;
2930
2931 if ((iir & flip_pending) == 0)
2932 return false;
2933
2934 intel_prepare_page_flip(dev, plane);
2935
2936 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2937 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2938 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2939 * the flip is completed (no longer pending). Since this doesn't raise
2940 * an interrupt per se, we watch for the change at vblank.
2941 */
2942 if (I915_READ(ISR) & flip_pending)
2943 return false;
2944
2945 intel_finish_page_flip(dev, pipe);
2946
2947 return true;
2948}
2949
Daniel Vetterff1f5252012-10-02 15:10:55 +02002950static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01002951{
2952 struct drm_device *dev = (struct drm_device *) arg;
2953 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01002954 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01002955 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01002956 u32 flip_mask =
2957 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2958 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01002959 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002960
2961 atomic_inc(&dev_priv->irq_received);
2962
2963 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01002964 do {
2965 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01002966 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002967
2968 /* Can't rely on pipestat interrupt bit in iir as it might
2969 * have been cleared after the pipestat interrupt was received.
2970 * It doesn't set the bit in iir again, but it still produces
2971 * interrupts (for non-MSI).
2972 */
2973 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2974 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2975 i915_handle_error(dev, false);
2976
2977 for_each_pipe(pipe) {
2978 int reg = PIPESTAT(pipe);
2979 pipe_stats[pipe] = I915_READ(reg);
2980
Chris Wilson38bde182012-04-24 22:59:50 +01002981 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01002982 if (pipe_stats[pipe] & 0x8000ffff) {
2983 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2984 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2985 pipe_name(pipe));
2986 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01002987 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002988 }
2989 }
2990 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2991
2992 if (!irq_received)
2993 break;
2994
Chris Wilsona266c7d2012-04-24 22:59:44 +01002995 /* Consume port. Then clear IIR or we'll miss events */
2996 if ((I915_HAS_HOTPLUG(dev)) &&
2997 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
2998 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02002999 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003000
3001 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3002 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003003
3004 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3005
Chris Wilsona266c7d2012-04-24 22:59:44 +01003006 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003007 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003008 }
3009
Chris Wilson38bde182012-04-24 22:59:50 +01003010 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003011 new_iir = I915_READ(IIR); /* Flush posted writes */
3012
Chris Wilsona266c7d2012-04-24 22:59:44 +01003013 if (iir & I915_USER_INTERRUPT)
3014 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003015
Chris Wilsona266c7d2012-04-24 22:59:44 +01003016 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003017 int plane = pipe;
3018 if (IS_MOBILE(dev))
3019 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003020
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003021 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3022 i915_handle_vblank(dev, plane, pipe, iir))
3023 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003024
3025 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3026 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003027
3028 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003029 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003030 }
3031
Chris Wilsona266c7d2012-04-24 22:59:44 +01003032 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3033 intel_opregion_asle_intr(dev);
3034
3035 /* With MSI, interrupts are only generated when iir
3036 * transitions from zero to nonzero. If another bit got
3037 * set while we were handling the existing iir bits, then
3038 * we would never get another interrupt.
3039 *
3040 * This is fine on non-MSI as well, as if we hit this path
3041 * we avoid exiting the interrupt handler only to generate
3042 * another one.
3043 *
3044 * Note that for MSI this could cause a stray interrupt report
3045 * if an interrupt landed in the time between writing IIR and
3046 * the posting read. This should be rare enough to never
3047 * trigger the 99% of 100,000 interrupts test for disabling
3048 * stray interrupts.
3049 */
Chris Wilson38bde182012-04-24 22:59:50 +01003050 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003051 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003052 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003053
Daniel Vetterd05c6172012-04-26 23:28:09 +02003054 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003055
Chris Wilsona266c7d2012-04-24 22:59:44 +01003056 return ret;
3057}
3058
3059static void i915_irq_uninstall(struct drm_device * dev)
3060{
3061 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3062 int pipe;
3063
Egbert Eichac4c16c2013-04-16 13:36:58 +02003064 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3065
Chris Wilsona266c7d2012-04-24 22:59:44 +01003066 if (I915_HAS_HOTPLUG(dev)) {
3067 I915_WRITE(PORT_HOTPLUG_EN, 0);
3068 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3069 }
3070
Chris Wilson00d98eb2012-04-24 22:59:48 +01003071 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003072 for_each_pipe(pipe) {
3073 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003074 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003075 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3076 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003077 I915_WRITE(IMR, 0xffffffff);
3078 I915_WRITE(IER, 0x0);
3079
Chris Wilsona266c7d2012-04-24 22:59:44 +01003080 I915_WRITE(IIR, I915_READ(IIR));
3081}
3082
3083static void i965_irq_preinstall(struct drm_device * dev)
3084{
3085 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3086 int pipe;
3087
3088 atomic_set(&dev_priv->irq_received, 0);
3089
Chris Wilsonadca4732012-05-11 18:01:31 +01003090 I915_WRITE(PORT_HOTPLUG_EN, 0);
3091 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003092
3093 I915_WRITE(HWSTAM, 0xeffe);
3094 for_each_pipe(pipe)
3095 I915_WRITE(PIPESTAT(pipe), 0);
3096 I915_WRITE(IMR, 0xffffffff);
3097 I915_WRITE(IER, 0x0);
3098 POSTING_READ(IER);
3099}
3100
3101static int i965_irq_postinstall(struct drm_device *dev)
3102{
3103 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003104 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003105 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003106 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003107
Chris Wilsona266c7d2012-04-24 22:59:44 +01003108 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003109 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003110 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003111 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3112 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3113 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3114 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3115 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3116
3117 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003118 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3119 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003120 enable_mask |= I915_USER_INTERRUPT;
3121
3122 if (IS_G4X(dev))
3123 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003124
Daniel Vetterb79480b2013-06-27 17:52:10 +02003125 /* Interrupt setup is already guaranteed to be single-threaded, this is
3126 * just to make the assert_spin_locked check happy. */
3127 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003128 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
3129 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3130 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003131 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003132
Chris Wilsona266c7d2012-04-24 22:59:44 +01003133 /*
3134 * Enable some error detection, note the instruction error mask
3135 * bit is reserved, so we leave it masked.
3136 */
3137 if (IS_G4X(dev)) {
3138 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3139 GM45_ERROR_MEM_PRIV |
3140 GM45_ERROR_CP_PRIV |
3141 I915_ERROR_MEMORY_REFRESH);
3142 } else {
3143 error_mask = ~(I915_ERROR_PAGE_TABLE |
3144 I915_ERROR_MEMORY_REFRESH);
3145 }
3146 I915_WRITE(EMR, error_mask);
3147
3148 I915_WRITE(IMR, dev_priv->irq_mask);
3149 I915_WRITE(IER, enable_mask);
3150 POSTING_READ(IER);
3151
Daniel Vetter20afbda2012-12-11 14:05:07 +01003152 I915_WRITE(PORT_HOTPLUG_EN, 0);
3153 POSTING_READ(PORT_HOTPLUG_EN);
3154
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003155 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003156
3157 return 0;
3158}
3159
Egbert Eichbac56d52013-02-25 12:06:51 -05003160static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003161{
3162 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003163 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003164 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003165 u32 hotplug_en;
3166
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003167 assert_spin_locked(&dev_priv->irq_lock);
3168
Egbert Eichbac56d52013-02-25 12:06:51 -05003169 if (I915_HAS_HOTPLUG(dev)) {
3170 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3171 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3172 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003173 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003174 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3175 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3176 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003177 /* Programming the CRT detection parameters tends
3178 to generate a spurious hotplug event about three
3179 seconds later. So just do it once.
3180 */
3181 if (IS_G4X(dev))
3182 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003183 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003184 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003185
Egbert Eichbac56d52013-02-25 12:06:51 -05003186 /* Ignore TV since it's buggy */
3187 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3188 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003189}
3190
Daniel Vetterff1f5252012-10-02 15:10:55 +02003191static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003192{
3193 struct drm_device *dev = (struct drm_device *) arg;
3194 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003195 u32 iir, new_iir;
3196 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003197 unsigned long irqflags;
3198 int irq_received;
3199 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003200 u32 flip_mask =
3201 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3202 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003203
3204 atomic_inc(&dev_priv->irq_received);
3205
3206 iir = I915_READ(IIR);
3207
Chris Wilsona266c7d2012-04-24 22:59:44 +01003208 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003209 bool blc_event = false;
3210
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003211 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003212
3213 /* Can't rely on pipestat interrupt bit in iir as it might
3214 * have been cleared after the pipestat interrupt was received.
3215 * It doesn't set the bit in iir again, but it still produces
3216 * interrupts (for non-MSI).
3217 */
3218 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3219 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3220 i915_handle_error(dev, false);
3221
3222 for_each_pipe(pipe) {
3223 int reg = PIPESTAT(pipe);
3224 pipe_stats[pipe] = I915_READ(reg);
3225
3226 /*
3227 * Clear the PIPE*STAT regs before the IIR
3228 */
3229 if (pipe_stats[pipe] & 0x8000ffff) {
3230 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3231 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3232 pipe_name(pipe));
3233 I915_WRITE(reg, pipe_stats[pipe]);
3234 irq_received = 1;
3235 }
3236 }
3237 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3238
3239 if (!irq_received)
3240 break;
3241
3242 ret = IRQ_HANDLED;
3243
3244 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003245 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003246 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003247 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3248 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003249 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003250
3251 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3252 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003253
3254 intel_hpd_irq_handler(dev, hotplug_trigger,
3255 IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
3256
Chris Wilsona266c7d2012-04-24 22:59:44 +01003257 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3258 I915_READ(PORT_HOTPLUG_STAT);
3259 }
3260
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003261 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003262 new_iir = I915_READ(IIR); /* Flush posted writes */
3263
Chris Wilsona266c7d2012-04-24 22:59:44 +01003264 if (iir & I915_USER_INTERRUPT)
3265 notify_ring(dev, &dev_priv->ring[RCS]);
3266 if (iir & I915_BSD_USER_INTERRUPT)
3267 notify_ring(dev, &dev_priv->ring[VCS]);
3268
Chris Wilsona266c7d2012-04-24 22:59:44 +01003269 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003270 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003271 i915_handle_vblank(dev, pipe, pipe, iir))
3272 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003273
3274 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3275 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003276
3277 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003278 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003279 }
3280
3281
3282 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3283 intel_opregion_asle_intr(dev);
3284
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003285 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3286 gmbus_irq_handler(dev);
3287
Chris Wilsona266c7d2012-04-24 22:59:44 +01003288 /* With MSI, interrupts are only generated when iir
3289 * transitions from zero to nonzero. If another bit got
3290 * set while we were handling the existing iir bits, then
3291 * we would never get another interrupt.
3292 *
3293 * This is fine on non-MSI as well, as if we hit this path
3294 * we avoid exiting the interrupt handler only to generate
3295 * another one.
3296 *
3297 * Note that for MSI this could cause a stray interrupt report
3298 * if an interrupt landed in the time between writing IIR and
3299 * the posting read. This should be rare enough to never
3300 * trigger the 99% of 100,000 interrupts test for disabling
3301 * stray interrupts.
3302 */
3303 iir = new_iir;
3304 }
3305
Daniel Vetterd05c6172012-04-26 23:28:09 +02003306 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003307
Chris Wilsona266c7d2012-04-24 22:59:44 +01003308 return ret;
3309}
3310
3311static void i965_irq_uninstall(struct drm_device * dev)
3312{
3313 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3314 int pipe;
3315
3316 if (!dev_priv)
3317 return;
3318
Egbert Eichac4c16c2013-04-16 13:36:58 +02003319 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3320
Chris Wilsonadca4732012-05-11 18:01:31 +01003321 I915_WRITE(PORT_HOTPLUG_EN, 0);
3322 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003323
3324 I915_WRITE(HWSTAM, 0xffffffff);
3325 for_each_pipe(pipe)
3326 I915_WRITE(PIPESTAT(pipe), 0);
3327 I915_WRITE(IMR, 0xffffffff);
3328 I915_WRITE(IER, 0x0);
3329
3330 for_each_pipe(pipe)
3331 I915_WRITE(PIPESTAT(pipe),
3332 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3333 I915_WRITE(IIR, I915_READ(IIR));
3334}
3335
Egbert Eichac4c16c2013-04-16 13:36:58 +02003336static void i915_reenable_hotplug_timer_func(unsigned long data)
3337{
3338 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3339 struct drm_device *dev = dev_priv->dev;
3340 struct drm_mode_config *mode_config = &dev->mode_config;
3341 unsigned long irqflags;
3342 int i;
3343
3344 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3345 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3346 struct drm_connector *connector;
3347
3348 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3349 continue;
3350
3351 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3352
3353 list_for_each_entry(connector, &mode_config->connector_list, head) {
3354 struct intel_connector *intel_connector = to_intel_connector(connector);
3355
3356 if (intel_connector->encoder->hpd_pin == i) {
3357 if (connector->polled != intel_connector->polled)
3358 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3359 drm_get_connector_name(connector));
3360 connector->polled = intel_connector->polled;
3361 if (!connector->polled)
3362 connector->polled = DRM_CONNECTOR_POLL_HPD;
3363 }
3364 }
3365 }
3366 if (dev_priv->display.hpd_irq_setup)
3367 dev_priv->display.hpd_irq_setup(dev);
3368 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3369}
3370
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003371void intel_irq_init(struct drm_device *dev)
3372{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003373 struct drm_i915_private *dev_priv = dev->dev_private;
3374
3375 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003376 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003377 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003378 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003379
Daniel Vetter99584db2012-11-14 17:14:04 +01003380 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3381 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003382 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003383 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3384 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003385
Tomas Janousek97a19a22012-12-08 13:48:13 +01003386 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003387
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003388 if (IS_GEN2(dev)) {
3389 dev->max_vblank_count = 0;
3390 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3391 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003392 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3393 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003394 } else {
3395 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3396 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003397 }
3398
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003399 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003400 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003401 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3402 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003403
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003404 if (IS_VALLEYVIEW(dev)) {
3405 dev->driver->irq_handler = valleyview_irq_handler;
3406 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3407 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3408 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3409 dev->driver->enable_vblank = valleyview_enable_vblank;
3410 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003411 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003412 } else if (HAS_PCH_SPLIT(dev)) {
3413 dev->driver->irq_handler = ironlake_irq_handler;
3414 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3415 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3416 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3417 dev->driver->enable_vblank = ironlake_enable_vblank;
3418 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003419 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003420 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003421 if (INTEL_INFO(dev)->gen == 2) {
3422 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3423 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3424 dev->driver->irq_handler = i8xx_irq_handler;
3425 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003426 } else if (INTEL_INFO(dev)->gen == 3) {
3427 dev->driver->irq_preinstall = i915_irq_preinstall;
3428 dev->driver->irq_postinstall = i915_irq_postinstall;
3429 dev->driver->irq_uninstall = i915_irq_uninstall;
3430 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003431 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003432 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003433 dev->driver->irq_preinstall = i965_irq_preinstall;
3434 dev->driver->irq_postinstall = i965_irq_postinstall;
3435 dev->driver->irq_uninstall = i965_irq_uninstall;
3436 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003437 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003438 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003439 dev->driver->enable_vblank = i915_enable_vblank;
3440 dev->driver->disable_vblank = i915_disable_vblank;
3441 }
3442}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003443
3444void intel_hpd_init(struct drm_device *dev)
3445{
3446 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003447 struct drm_mode_config *mode_config = &dev->mode_config;
3448 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003449 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003450 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003451
Egbert Eich821450c2013-04-16 13:36:55 +02003452 for (i = 1; i < HPD_NUM_PINS; i++) {
3453 dev_priv->hpd_stats[i].hpd_cnt = 0;
3454 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3455 }
3456 list_for_each_entry(connector, &mode_config->connector_list, head) {
3457 struct intel_connector *intel_connector = to_intel_connector(connector);
3458 connector->polled = intel_connector->polled;
3459 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3460 connector->polled = DRM_CONNECTOR_POLL_HPD;
3461 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003462
3463 /* Interrupt setup is already guaranteed to be single-threaded, this is
3464 * just to make the assert_spin_locked checks happy. */
3465 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003466 if (dev_priv->display.hpd_irq_setup)
3467 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003468 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003469}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003470
3471/* Disable interrupts so we can allow Package C8+. */
3472void hsw_pc8_disable_interrupts(struct drm_device *dev)
3473{
3474 struct drm_i915_private *dev_priv = dev->dev_private;
3475 unsigned long irqflags;
3476
3477 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3478
3479 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3480 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3481 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3482 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3483 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3484
3485 ironlake_disable_display_irq(dev_priv, ~DE_PCH_EVENT_IVB);
3486 ibx_disable_display_interrupt(dev_priv, ~SDE_HOTPLUG_MASK_CPT);
3487 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3488 snb_disable_pm_irq(dev_priv, 0xffffffff);
3489
3490 dev_priv->pc8.irqs_disabled = true;
3491
3492 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3493}
3494
3495/* Restore interrupts so we can recover from Package C8+. */
3496void hsw_pc8_restore_interrupts(struct drm_device *dev)
3497{
3498 struct drm_i915_private *dev_priv = dev->dev_private;
3499 unsigned long irqflags;
3500 uint32_t val, expected;
3501
3502 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3503
3504 val = I915_READ(DEIMR);
3505 expected = ~DE_PCH_EVENT_IVB;
3506 WARN(val != expected, "DEIMR is 0x%08x, not 0x%08x\n", val, expected);
3507
3508 val = I915_READ(SDEIMR) & ~SDE_HOTPLUG_MASK_CPT;
3509 expected = ~SDE_HOTPLUG_MASK_CPT;
3510 WARN(val != expected, "SDEIMR non-HPD bits are 0x%08x, not 0x%08x\n",
3511 val, expected);
3512
3513 val = I915_READ(GTIMR);
3514 expected = 0xffffffff;
3515 WARN(val != expected, "GTIMR is 0x%08x, not 0x%08x\n", val, expected);
3516
3517 val = I915_READ(GEN6_PMIMR);
3518 expected = 0xffffffff;
3519 WARN(val != expected, "GEN6_PMIMR is 0x%08x, not 0x%08x\n", val,
3520 expected);
3521
3522 dev_priv->pc8.irqs_disabled = false;
3523
3524 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
3525 ibx_enable_display_interrupt(dev_priv,
3526 ~dev_priv->pc8.regsave.sdeimr &
3527 ~SDE_HOTPLUG_MASK_CPT);
3528 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3529 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3530 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3531
3532 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3533}