blob: 1ce5722c24628e0cbc98a69c71f23ed16ace718f [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 Vetter38d83c962013-11-07 11:05:46 +0100273static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
274 enum pipe pipe, bool enable)
275{
276 struct drm_i915_private *dev_priv = dev->dev_private;
277
278 assert_spin_locked(&dev_priv->irq_lock);
279
280 if (enable)
281 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
282 else
283 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
284 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
285 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
286}
287
Daniel Vetterfee884e2013-07-04 23:35:21 +0200288/**
289 * ibx_display_interrupt_update - update SDEIMR
290 * @dev_priv: driver private
291 * @interrupt_mask: mask of interrupt bits to update
292 * @enabled_irq_mask: mask of interrupt bits to enable
293 */
294static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
295 uint32_t interrupt_mask,
296 uint32_t enabled_irq_mask)
297{
298 uint32_t sdeimr = I915_READ(SDEIMR);
299 sdeimr &= ~interrupt_mask;
300 sdeimr |= (~enabled_irq_mask & interrupt_mask);
301
302 assert_spin_locked(&dev_priv->irq_lock);
303
Paulo Zanonic67a4702013-08-19 13:18:09 -0300304 if (dev_priv->pc8.irqs_disabled &&
305 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
306 WARN(1, "IRQs disabled\n");
307 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
308 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
309 interrupt_mask);
310 return;
311 }
312
Daniel Vetterfee884e2013-07-04 23:35:21 +0200313 I915_WRITE(SDEIMR, sdeimr);
314 POSTING_READ(SDEIMR);
315}
316#define ibx_enable_display_interrupt(dev_priv, bits) \
317 ibx_display_interrupt_update((dev_priv), (bits), (bits))
318#define ibx_disable_display_interrupt(dev_priv, bits) \
319 ibx_display_interrupt_update((dev_priv), (bits), 0)
320
Daniel Vetterde280752013-07-04 23:35:24 +0200321static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
322 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300323 bool enable)
324{
Paulo Zanoni86642812013-04-12 17:57:57 -0300325 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200326 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
327 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300328
329 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200330 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300331 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200332 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300333}
334
335static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
336 enum transcoder pch_transcoder,
337 bool enable)
338{
339 struct drm_i915_private *dev_priv = dev->dev_private;
340
341 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200342 I915_WRITE(SERR_INT,
343 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
344
Paulo Zanoni86642812013-04-12 17:57:57 -0300345 if (!cpt_can_enable_serr_int(dev))
346 return;
347
Daniel Vetterfee884e2013-07-04 23:35:21 +0200348 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300349 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200350 uint32_t tmp = I915_READ(SERR_INT);
351 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
352
353 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200354 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200355
356 if (!was_enabled &&
357 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
358 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
359 transcoder_name(pch_transcoder));
360 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300361 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300362}
363
364/**
365 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
366 * @dev: drm device
367 * @pipe: pipe
368 * @enable: true if we want to report FIFO underrun errors, false otherwise
369 *
370 * This function makes us disable or enable CPU fifo underruns for a specific
371 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
372 * reporting for one pipe may also disable all the other CPU error interruts for
373 * the other pipes, due to the fact that there's just one interrupt mask/enable
374 * bit for all the pipes.
375 *
376 * Returns the previous state of underrun reporting.
377 */
378bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
379 enum pipe pipe, bool enable)
380{
381 struct drm_i915_private *dev_priv = dev->dev_private;
382 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
383 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
384 unsigned long flags;
385 bool ret;
386
387 spin_lock_irqsave(&dev_priv->irq_lock, flags);
388
389 ret = !intel_crtc->cpu_fifo_underrun_disabled;
390
391 if (enable == ret)
392 goto done;
393
394 intel_crtc->cpu_fifo_underrun_disabled = !enable;
395
396 if (IS_GEN5(dev) || IS_GEN6(dev))
397 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
398 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200399 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100400 else if (IS_GEN8(dev))
401 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300402
403done:
404 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
405 return ret;
406}
407
408/**
409 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
410 * @dev: drm device
411 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
412 * @enable: true if we want to report FIFO underrun errors, false otherwise
413 *
414 * This function makes us disable or enable PCH fifo underruns for a specific
415 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
416 * underrun reporting for one transcoder may also disable all the other PCH
417 * error interruts for the other transcoders, due to the fact that there's just
418 * one interrupt mask/enable bit for all the transcoders.
419 *
420 * Returns the previous state of underrun reporting.
421 */
422bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
423 enum transcoder pch_transcoder,
424 bool enable)
425{
426 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200427 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
428 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300429 unsigned long flags;
430 bool ret;
431
Daniel Vetterde280752013-07-04 23:35:24 +0200432 /*
433 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
434 * has only one pch transcoder A that all pipes can use. To avoid racy
435 * pch transcoder -> pipe lookups from interrupt code simply store the
436 * underrun statistics in crtc A. Since we never expose this anywhere
437 * nor use it outside of the fifo underrun code here using the "wrong"
438 * crtc on LPT won't cause issues.
439 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300440
441 spin_lock_irqsave(&dev_priv->irq_lock, flags);
442
443 ret = !intel_crtc->pch_fifo_underrun_disabled;
444
445 if (enable == ret)
446 goto done;
447
448 intel_crtc->pch_fifo_underrun_disabled = !enable;
449
450 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200451 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300452 else
453 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
454
455done:
456 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
457 return ret;
458}
459
460
Keith Packard7c463582008-11-04 02:03:27 -0800461void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200462i915_enable_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) == mask)
470 return;
471
472 /* Enable the interrupt, clear any pending status */
473 pipestat |= mask | (mask >> 16);
474 I915_WRITE(reg, pipestat);
475 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800476}
477
478void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200479i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800480{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200481 u32 reg = PIPESTAT(pipe);
482 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800483
Daniel Vetterb79480b2013-06-27 17:52:10 +0200484 assert_spin_locked(&dev_priv->irq_lock);
485
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200486 if ((pipestat & mask) == 0)
487 return;
488
489 pipestat &= ~mask;
490 I915_WRITE(reg, pipestat);
491 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800492}
493
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000494/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300495 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000496 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300497static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000498{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000499 drm_i915_private_t *dev_priv = dev->dev_private;
500 unsigned long irqflags;
501
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300502 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
503 return;
504
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000505 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000506
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200507 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE);
Jani Nikulaf8987802013-04-29 13:02:53 +0300508 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200509 i915_enable_pipestat(dev_priv, PIPE_A,
510 PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000511
512 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000513}
514
515/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700516 * i915_pipe_enabled - check if a pipe is enabled
517 * @dev: DRM device
518 * @pipe: pipe to check
519 *
520 * Reading certain registers when the pipe is disabled can hang the chip.
521 * Use this routine to make sure the PLL is running and the pipe is active
522 * before reading such registers if unsure.
523 */
524static int
525i915_pipe_enabled(struct drm_device *dev, int pipe)
526{
527 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200528
Daniel Vettera01025a2013-05-22 00:50:23 +0200529 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
530 /* Locking is horribly broken here, but whatever. */
531 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
532 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300533
Daniel Vettera01025a2013-05-22 00:50:23 +0200534 return intel_crtc->active;
535 } else {
536 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
537 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700538}
539
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300540static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
541{
542 /* Gen2 doesn't have a hardware frame counter */
543 return 0;
544}
545
Keith Packard42f52ef2008-10-18 19:39:29 -0700546/* Called from drm generic code, passed a 'crtc', which
547 * we use as a pipe index
548 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700549static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700550{
551 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
552 unsigned long high_frame;
553 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300554 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700555
556 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800557 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800558 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700559 return 0;
560 }
561
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300562 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
563 struct intel_crtc *intel_crtc =
564 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
565 const struct drm_display_mode *mode =
566 &intel_crtc->config.adjusted_mode;
567
568 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
569 } else {
570 enum transcoder cpu_transcoder =
571 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
572 u32 htotal;
573
574 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
575 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
576
577 vbl_start *= htotal;
578 }
579
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800580 high_frame = PIPEFRAME(pipe);
581 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100582
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700583 /*
584 * High & low register fields aren't synchronized, so make sure
585 * we get a low value that's stable across two reads of the high
586 * register.
587 */
588 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100589 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300590 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100591 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700592 } while (high1 != high2);
593
Chris Wilson5eddb702010-09-11 13:48:45 +0100594 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300595 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100596 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300597
598 /*
599 * The frame counter increments at beginning of active.
600 * Cook up a vblank counter by also checking the pixel
601 * counter against vblank start.
602 */
603 return ((high1 << 8) | low) + (pixel >= vbl_start);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700604}
605
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700606static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800607{
608 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800609 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800610
611 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800612 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800613 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800614 return 0;
615 }
616
617 return I915_READ(reg);
618}
619
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300620static bool intel_pipe_in_vblank(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300621{
622 struct drm_i915_private *dev_priv = dev->dev_private;
623 uint32_t status;
624
625 if (IS_VALLEYVIEW(dev)) {
626 status = pipe == PIPE_A ?
627 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
628 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
629
630 return I915_READ(VLV_ISR) & status;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300631 } else if (IS_GEN2(dev)) {
632 status = pipe == PIPE_A ?
633 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
634 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
635
636 return I915_READ16(ISR) & status;
637 } else if (INTEL_INFO(dev)->gen < 5) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300638 status = pipe == PIPE_A ?
639 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
640 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
641
642 return I915_READ(ISR) & status;
643 } else if (INTEL_INFO(dev)->gen < 7) {
644 status = pipe == PIPE_A ?
645 DE_PIPEA_VBLANK :
646 DE_PIPEB_VBLANK;
647
648 return I915_READ(DEISR) & status;
649 } else {
650 switch (pipe) {
651 default:
652 case PIPE_A:
653 status = DE_PIPEA_VBLANK_IVB;
654 break;
655 case PIPE_B:
656 status = DE_PIPEB_VBLANK_IVB;
657 break;
658 case PIPE_C:
659 status = DE_PIPEC_VBLANK_IVB;
660 break;
661 }
662
663 return I915_READ(DEISR) & status;
664 }
665}
666
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700667static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100668 int *vpos, int *hpos)
669{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300670 struct drm_i915_private *dev_priv = dev->dev_private;
671 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
672 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
673 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300674 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100675 int vbl_start, vbl_end, htotal, vtotal;
676 bool in_vbl = true;
677 int ret = 0;
678
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300679 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100680 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800681 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100682 return 0;
683 }
684
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300685 htotal = mode->crtc_htotal;
686 vtotal = mode->crtc_vtotal;
687 vbl_start = mode->crtc_vblank_start;
688 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100689
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300690 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
691
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300692 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100693 /* No obvious pixelcount register. Only query vertical
694 * scanout position from Display scan line register.
695 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300696 if (IS_GEN2(dev))
697 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
698 else
699 position = I915_READ(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300700
701 /*
702 * The scanline counter increments at the leading edge
703 * of hsync, ie. it completely misses the active portion
704 * of the line. Fix up the counter at both edges of vblank
705 * to get a more accurate picture whether we're in vblank
706 * or not.
707 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300708 in_vbl = intel_pipe_in_vblank(dev, pipe);
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300709 if ((in_vbl && position == vbl_start - 1) ||
710 (!in_vbl && position == vbl_end - 1))
711 position = (position + 1) % vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100712 } else {
713 /* Have access to pixelcount since start of frame.
714 * We can split this into vertical and horizontal
715 * scanout position.
716 */
717 position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
718
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300719 /* convert to pixel counts */
720 vbl_start *= htotal;
721 vbl_end *= htotal;
722 vtotal *= htotal;
723 }
724
725 in_vbl = position >= vbl_start && position < vbl_end;
726
727 /*
728 * While in vblank, position will be negative
729 * counting up towards 0 at vbl_end. And outside
730 * vblank, position will be positive counting
731 * up since vbl_end.
732 */
733 if (position >= vbl_start)
734 position -= vbl_end;
735 else
736 position += vtotal - vbl_end;
737
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300738 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300739 *vpos = position;
740 *hpos = 0;
741 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100742 *vpos = position / htotal;
743 *hpos = position - (*vpos * htotal);
744 }
745
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100746 /* In vblank? */
747 if (in_vbl)
748 ret |= DRM_SCANOUTPOS_INVBL;
749
750 return ret;
751}
752
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700753static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100754 int *max_error,
755 struct timeval *vblank_time,
756 unsigned flags)
757{
Chris Wilson4041b852011-01-22 10:07:56 +0000758 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100759
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700760 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000761 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100762 return -EINVAL;
763 }
764
765 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000766 crtc = intel_get_crtc_for_pipe(dev, pipe);
767 if (crtc == NULL) {
768 DRM_ERROR("Invalid crtc %d\n", pipe);
769 return -EINVAL;
770 }
771
772 if (!crtc->enabled) {
773 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
774 return -EBUSY;
775 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100776
777 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000778 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
779 vblank_time, flags,
780 crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100781}
782
Jani Nikula67c347f2013-09-17 14:26:34 +0300783static bool intel_hpd_irq_event(struct drm_device *dev,
784 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200785{
786 enum drm_connector_status old_status;
787
788 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
789 old_status = connector->status;
790
791 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300792 if (old_status == connector->status)
793 return false;
794
795 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200796 connector->base.id,
797 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300798 drm_get_connector_status_name(old_status),
799 drm_get_connector_status_name(connector->status));
800
801 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200802}
803
Jesse Barnes5ca58282009-03-31 14:11:15 -0700804/*
805 * Handle hotplug events outside the interrupt handler proper.
806 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200807#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
808
Jesse Barnes5ca58282009-03-31 14:11:15 -0700809static void i915_hotplug_work_func(struct work_struct *work)
810{
811 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
812 hotplug_work);
813 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700814 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200815 struct intel_connector *intel_connector;
816 struct intel_encoder *intel_encoder;
817 struct drm_connector *connector;
818 unsigned long irqflags;
819 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200820 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200821 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700822
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100823 /* HPD irq before everything is fully set up. */
824 if (!dev_priv->enable_hotplug_processing)
825 return;
826
Keith Packarda65e34c2011-07-25 10:04:56 -0700827 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800828 DRM_DEBUG_KMS("running encoder hotplug functions\n");
829
Egbert Eichcd569ae2013-04-16 13:36:57 +0200830 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200831
832 hpd_event_bits = dev_priv->hpd_event_bits;
833 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200834 list_for_each_entry(connector, &mode_config->connector_list, head) {
835 intel_connector = to_intel_connector(connector);
836 intel_encoder = intel_connector->encoder;
837 if (intel_encoder->hpd_pin > HPD_NONE &&
838 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
839 connector->polled == DRM_CONNECTOR_POLL_HPD) {
840 DRM_INFO("HPD interrupt storm detected on connector %s: "
841 "switching from hotplug detection to polling\n",
842 drm_get_connector_name(connector));
843 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
844 connector->polled = DRM_CONNECTOR_POLL_CONNECT
845 | DRM_CONNECTOR_POLL_DISCONNECT;
846 hpd_disabled = true;
847 }
Egbert Eich142e2392013-04-11 15:57:57 +0200848 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
849 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
850 drm_get_connector_name(connector), intel_encoder->hpd_pin);
851 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200852 }
853 /* if there were no outputs to poll, poll was disabled,
854 * therefore make sure it's enabled when disabling HPD on
855 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200856 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200857 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200858 mod_timer(&dev_priv->hotplug_reenable_timer,
859 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
860 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200861
862 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
863
Egbert Eich321a1b32013-04-11 16:00:26 +0200864 list_for_each_entry(connector, &mode_config->connector_list, head) {
865 intel_connector = to_intel_connector(connector);
866 intel_encoder = intel_connector->encoder;
867 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
868 if (intel_encoder->hot_plug)
869 intel_encoder->hot_plug(intel_encoder);
870 if (intel_hpd_irq_event(dev, connector))
871 changed = true;
872 }
873 }
Keith Packard40ee3382011-07-28 15:31:19 -0700874 mutex_unlock(&mode_config->mutex);
875
Egbert Eich321a1b32013-04-11 16:00:26 +0200876 if (changed)
877 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700878}
879
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200880static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800881{
882 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000883 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200884 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200885
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200886 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800887
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200888 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
889
Daniel Vetter20e4d402012-08-08 23:35:39 +0200890 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200891
Jesse Barnes7648fa92010-05-20 14:28:11 -0700892 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000893 busy_up = I915_READ(RCPREVBSYTUPAVG);
894 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800895 max_avg = I915_READ(RCBMAXAVG);
896 min_avg = I915_READ(RCBMINAVG);
897
898 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000899 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200900 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
901 new_delay = dev_priv->ips.cur_delay - 1;
902 if (new_delay < dev_priv->ips.max_delay)
903 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000904 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200905 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
906 new_delay = dev_priv->ips.cur_delay + 1;
907 if (new_delay > dev_priv->ips.min_delay)
908 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800909 }
910
Jesse Barnes7648fa92010-05-20 14:28:11 -0700911 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200912 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800913
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200914 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200915
Jesse Barnesf97108d2010-01-29 11:27:07 -0800916 return;
917}
918
Chris Wilson549f7362010-10-19 11:19:32 +0100919static void notify_ring(struct drm_device *dev,
920 struct intel_ring_buffer *ring)
921{
Chris Wilson475553d2011-01-20 09:52:56 +0000922 if (ring->obj == NULL)
923 return;
924
Chris Wilson814e9b52013-09-23 17:33:19 -0300925 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000926
Chris Wilson549f7362010-10-19 11:19:32 +0100927 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300928 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100929}
930
Ben Widawsky4912d042011-04-25 11:25:20 -0700931static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800932{
Ben Widawsky4912d042011-04-25 11:25:20 -0700933 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200934 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300935 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100936 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800937
Daniel Vetter59cdb632013-07-04 23:35:28 +0200938 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200939 pm_iir = dev_priv->rps.pm_iir;
940 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -0700941 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300942 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200943 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700944
Paulo Zanoni60611c12013-08-15 11:50:01 -0300945 /* Make sure we didn't queue anything we're not going to process. */
946 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
947
Ben Widawsky48484052013-05-28 19:22:27 -0700948 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800949 return;
950
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700951 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100952
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100953 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300954 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100955 if (adj > 0)
956 adj *= 2;
957 else
958 adj = 1;
959 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300960
961 /*
962 * For better performance, jump directly
963 * to RPe if we're below it.
964 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100965 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +0300966 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100967 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
968 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
969 new_delay = dev_priv->rps.rpe_delay;
970 else
971 new_delay = dev_priv->rps.min_delay;
972 adj = 0;
973 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
974 if (adj < 0)
975 adj *= 2;
976 else
977 adj = -1;
978 new_delay = dev_priv->rps.cur_delay + adj;
979 } else { /* unknown event */
980 new_delay = dev_priv->rps.cur_delay;
981 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800982
Ben Widawsky79249632012-09-07 19:43:42 -0700983 /* sysfs frequency interfaces may have snuck in while servicing the
984 * interrupt
985 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100986 if (new_delay < (int)dev_priv->rps.min_delay)
987 new_delay = dev_priv->rps.min_delay;
988 if (new_delay > (int)dev_priv->rps.max_delay)
989 new_delay = dev_priv->rps.max_delay;
990 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
991
992 if (IS_VALLEYVIEW(dev_priv->dev))
993 valleyview_set_rps(dev_priv->dev, new_delay);
994 else
995 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800996
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700997 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800998}
999
Ben Widawskye3689192012-05-25 16:56:22 -07001000
1001/**
1002 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1003 * occurred.
1004 * @work: workqueue struct
1005 *
1006 * Doesn't actually do anything except notify userspace. As a consequence of
1007 * this event, userspace should try to remap the bad rows since statistically
1008 * it is likely the same row is more likely to go bad again.
1009 */
1010static void ivybridge_parity_work(struct work_struct *work)
1011{
1012 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001013 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001014 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001015 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001016 uint32_t misccpctl;
1017 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001018 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001019
1020 /* We must turn off DOP level clock gating to access the L3 registers.
1021 * In order to prevent a get/put style interface, acquire struct mutex
1022 * any time we access those registers.
1023 */
1024 mutex_lock(&dev_priv->dev->struct_mutex);
1025
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001026 /* If we've screwed up tracking, just let the interrupt fire again */
1027 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1028 goto out;
1029
Ben Widawskye3689192012-05-25 16:56:22 -07001030 misccpctl = I915_READ(GEN7_MISCCPCTL);
1031 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1032 POSTING_READ(GEN7_MISCCPCTL);
1033
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001034 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1035 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001036
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001037 slice--;
1038 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1039 break;
1040
1041 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1042
1043 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1044
1045 error_status = I915_READ(reg);
1046 row = GEN7_PARITY_ERROR_ROW(error_status);
1047 bank = GEN7_PARITY_ERROR_BANK(error_status);
1048 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1049
1050 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1051 POSTING_READ(reg);
1052
1053 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1054 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1055 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1056 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1057 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1058 parity_event[5] = NULL;
1059
1060 kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
1061 KOBJ_CHANGE, parity_event);
1062
1063 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1064 slice, row, bank, subbank);
1065
1066 kfree(parity_event[4]);
1067 kfree(parity_event[3]);
1068 kfree(parity_event[2]);
1069 kfree(parity_event[1]);
1070 }
Ben Widawskye3689192012-05-25 16:56:22 -07001071
1072 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1073
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001074out:
1075 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001076 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001077 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001078 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1079
1080 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001081}
1082
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001083static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001084{
1085 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001086
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001087 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001088 return;
1089
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001090 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001091 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001092 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001093
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001094 iir &= GT_PARITY_ERROR(dev);
1095 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1096 dev_priv->l3_parity.which_slice |= 1 << 1;
1097
1098 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1099 dev_priv->l3_parity.which_slice |= 1 << 0;
1100
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001101 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001102}
1103
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001104static void ilk_gt_irq_handler(struct drm_device *dev,
1105 struct drm_i915_private *dev_priv,
1106 u32 gt_iir)
1107{
1108 if (gt_iir &
1109 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1110 notify_ring(dev, &dev_priv->ring[RCS]);
1111 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1112 notify_ring(dev, &dev_priv->ring[VCS]);
1113}
1114
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001115static void snb_gt_irq_handler(struct drm_device *dev,
1116 struct drm_i915_private *dev_priv,
1117 u32 gt_iir)
1118{
1119
Ben Widawskycc609d52013-05-28 19:22:29 -07001120 if (gt_iir &
1121 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001122 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001123 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001124 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001125 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001126 notify_ring(dev, &dev_priv->ring[BCS]);
1127
Ben Widawskycc609d52013-05-28 19:22:29 -07001128 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1129 GT_BSD_CS_ERROR_INTERRUPT |
1130 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001131 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1132 i915_handle_error(dev, false);
1133 }
Ben Widawskye3689192012-05-25 16:56:22 -07001134
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001135 if (gt_iir & GT_PARITY_ERROR(dev))
1136 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001137}
1138
Ben Widawskyabd58f02013-11-02 21:07:09 -07001139static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1140 struct drm_i915_private *dev_priv,
1141 u32 master_ctl)
1142{
1143 u32 rcs, bcs, vcs;
1144 uint32_t tmp = 0;
1145 irqreturn_t ret = IRQ_NONE;
1146
1147 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1148 tmp = I915_READ(GEN8_GT_IIR(0));
1149 if (tmp) {
1150 ret = IRQ_HANDLED;
1151 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1152 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1153 if (rcs & GT_RENDER_USER_INTERRUPT)
1154 notify_ring(dev, &dev_priv->ring[RCS]);
1155 if (bcs & GT_RENDER_USER_INTERRUPT)
1156 notify_ring(dev, &dev_priv->ring[BCS]);
1157 I915_WRITE(GEN8_GT_IIR(0), tmp);
1158 } else
1159 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1160 }
1161
1162 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1163 tmp = I915_READ(GEN8_GT_IIR(1));
1164 if (tmp) {
1165 ret = IRQ_HANDLED;
1166 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1167 if (vcs & GT_RENDER_USER_INTERRUPT)
1168 notify_ring(dev, &dev_priv->ring[VCS]);
1169 I915_WRITE(GEN8_GT_IIR(1), tmp);
1170 } else
1171 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1172 }
1173
1174 if (master_ctl & GEN8_GT_VECS_IRQ) {
1175 tmp = I915_READ(GEN8_GT_IIR(3));
1176 if (tmp) {
1177 ret = IRQ_HANDLED;
1178 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1179 if (vcs & GT_RENDER_USER_INTERRUPT)
1180 notify_ring(dev, &dev_priv->ring[VECS]);
1181 I915_WRITE(GEN8_GT_IIR(3), tmp);
1182 } else
1183 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1184 }
1185
1186 return ret;
1187}
1188
Egbert Eichb543fb02013-04-16 13:36:54 +02001189#define HPD_STORM_DETECT_PERIOD 1000
1190#define HPD_STORM_THRESHOLD 5
1191
Daniel Vetter10a504d2013-06-27 17:52:12 +02001192static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001193 u32 hotplug_trigger,
1194 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001195{
1196 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001197 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001198 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001199
Daniel Vetter91d131d2013-06-27 17:52:14 +02001200 if (!hotplug_trigger)
1201 return;
1202
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001203 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001204 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001205
Egbert Eichb8f102e2013-07-26 14:14:24 +02001206 WARN(((hpd[i] & hotplug_trigger) &&
1207 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED),
1208 "Received HPD interrupt although disabled\n");
1209
Egbert Eichb543fb02013-04-16 13:36:54 +02001210 if (!(hpd[i] & hotplug_trigger) ||
1211 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1212 continue;
1213
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001214 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001215 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1216 dev_priv->hpd_stats[i].hpd_last_jiffies
1217 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1218 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1219 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001220 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001221 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1222 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001223 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001224 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001225 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001226 } else {
1227 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001228 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1229 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001230 }
1231 }
1232
Daniel Vetter10a504d2013-06-27 17:52:12 +02001233 if (storm_detected)
1234 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001235 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001236
Daniel Vetter645416f2013-09-02 16:22:25 +02001237 /*
1238 * Our hotplug handler can grab modeset locks (by calling down into the
1239 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1240 * queue for otherwise the flush_work in the pageflip code will
1241 * deadlock.
1242 */
1243 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001244}
1245
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001246static void gmbus_irq_handler(struct drm_device *dev)
1247{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001248 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1249
Daniel Vetter28c70f12012-12-01 13:53:45 +01001250 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001251}
1252
Daniel Vetterce99c252012-12-01 13:53:47 +01001253static void dp_aux_irq_handler(struct drm_device *dev)
1254{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001255 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1256
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001257 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001258}
1259
Shuang He8bf1e9f2013-10-15 18:55:27 +01001260#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001261static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1262 uint32_t crc0, uint32_t crc1,
1263 uint32_t crc2, uint32_t crc3,
1264 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001265{
1266 struct drm_i915_private *dev_priv = dev->dev_private;
1267 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1268 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001269 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001270
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001271 spin_lock(&pipe_crc->lock);
1272
Damien Lespiau0c912c72013-10-15 18:55:37 +01001273 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001274 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001275 DRM_ERROR("spurious interrupt\n");
1276 return;
1277 }
1278
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001279 head = pipe_crc->head;
1280 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001281
1282 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001283 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001284 DRM_ERROR("CRC buffer overflowing\n");
1285 return;
1286 }
1287
1288 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001289
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001290 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001291 entry->crc[0] = crc0;
1292 entry->crc[1] = crc1;
1293 entry->crc[2] = crc2;
1294 entry->crc[3] = crc3;
1295 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001296
1297 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001298 pipe_crc->head = head;
1299
1300 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001301
1302 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001303}
Daniel Vetter277de952013-10-18 16:37:07 +02001304#else
1305static inline void
1306display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1307 uint32_t crc0, uint32_t crc1,
1308 uint32_t crc2, uint32_t crc3,
1309 uint32_t crc4) {}
1310#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001311
Daniel Vetter277de952013-10-18 16:37:07 +02001312
1313static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001314{
1315 struct drm_i915_private *dev_priv = dev->dev_private;
1316
Daniel Vetter277de952013-10-18 16:37:07 +02001317 display_pipe_crc_irq_handler(dev, pipe,
1318 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1319 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001320}
1321
Daniel Vetter277de952013-10-18 16:37:07 +02001322static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001323{
1324 struct drm_i915_private *dev_priv = dev->dev_private;
1325
Daniel Vetter277de952013-10-18 16:37:07 +02001326 display_pipe_crc_irq_handler(dev, pipe,
1327 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1328 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1329 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1330 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1331 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001332}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001333
Daniel Vetter277de952013-10-18 16:37:07 +02001334static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001335{
1336 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001337 uint32_t res1, res2;
1338
1339 if (INTEL_INFO(dev)->gen >= 3)
1340 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1341 else
1342 res1 = 0;
1343
1344 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1345 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1346 else
1347 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001348
Daniel Vetter277de952013-10-18 16:37:07 +02001349 display_pipe_crc_irq_handler(dev, pipe,
1350 I915_READ(PIPE_CRC_RES_RED(pipe)),
1351 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1352 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1353 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001354}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001355
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001356/* The RPS events need forcewake, so we add them to a work queue and mask their
1357 * IMR bits until the work is done. Other interrupts can be processed without
1358 * the work queue. */
1359static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001360{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001361 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001362 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001363 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001364 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001365 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001366
1367 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001368 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001369
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001370 if (HAS_VEBOX(dev_priv->dev)) {
1371 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1372 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001373
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001374 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1375 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1376 i915_handle_error(dev_priv->dev, false);
1377 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001378 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001379}
1380
Daniel Vetterff1f5252012-10-02 15:10:55 +02001381static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001382{
1383 struct drm_device *dev = (struct drm_device *) arg;
1384 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1385 u32 iir, gt_iir, pm_iir;
1386 irqreturn_t ret = IRQ_NONE;
1387 unsigned long irqflags;
1388 int pipe;
1389 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001390
1391 atomic_inc(&dev_priv->irq_received);
1392
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001393 while (true) {
1394 iir = I915_READ(VLV_IIR);
1395 gt_iir = I915_READ(GTIIR);
1396 pm_iir = I915_READ(GEN6_PMIIR);
1397
1398 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1399 goto out;
1400
1401 ret = IRQ_HANDLED;
1402
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001403 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001404
1405 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1406 for_each_pipe(pipe) {
1407 int reg = PIPESTAT(pipe);
1408 pipe_stats[pipe] = I915_READ(reg);
1409
1410 /*
1411 * Clear the PIPE*STAT regs before the IIR
1412 */
1413 if (pipe_stats[pipe] & 0x8000ffff) {
1414 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1415 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1416 pipe_name(pipe));
1417 I915_WRITE(reg, pipe_stats[pipe]);
1418 }
1419 }
1420 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1421
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001422 for_each_pipe(pipe) {
1423 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1424 drm_handle_vblank(dev, pipe);
1425
1426 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1427 intel_prepare_page_flip(dev, pipe);
1428 intel_finish_page_flip(dev, pipe);
1429 }
Daniel Vetter4356d582013-10-16 22:55:55 +02001430
1431 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02001432 i9xx_pipe_crc_irq_handler(dev, pipe);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001433 }
1434
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001435 /* Consume port. Then clear IIR or we'll miss events */
1436 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1437 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001438 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001439
1440 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1441 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001442
1443 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1444
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001445 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1446 I915_READ(PORT_HOTPLUG_STAT);
1447 }
1448
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001449 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1450 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001451
Paulo Zanoni60611c12013-08-15 11:50:01 -03001452 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001453 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001454
1455 I915_WRITE(GTIIR, gt_iir);
1456 I915_WRITE(GEN6_PMIIR, pm_iir);
1457 I915_WRITE(VLV_IIR, iir);
1458 }
1459
1460out:
1461 return ret;
1462}
1463
Adam Jackson23e81d62012-06-06 15:45:44 -04001464static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001465{
1466 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001467 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001468 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001469
Daniel Vetter91d131d2013-06-27 17:52:14 +02001470 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1471
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001472 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1473 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1474 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001475 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001476 port_name(port));
1477 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001478
Daniel Vetterce99c252012-12-01 13:53:47 +01001479 if (pch_iir & SDE_AUX_MASK)
1480 dp_aux_irq_handler(dev);
1481
Jesse Barnes776ad802011-01-04 15:09:39 -08001482 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001483 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001484
1485 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1486 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1487
1488 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1489 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1490
1491 if (pch_iir & SDE_POISON)
1492 DRM_ERROR("PCH poison interrupt\n");
1493
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001494 if (pch_iir & SDE_FDI_MASK)
1495 for_each_pipe(pipe)
1496 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1497 pipe_name(pipe),
1498 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001499
1500 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1501 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1502
1503 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1504 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1505
Jesse Barnes776ad802011-01-04 15:09:39 -08001506 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001507 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1508 false))
1509 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1510
1511 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1512 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1513 false))
1514 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1515}
1516
1517static void ivb_err_int_handler(struct drm_device *dev)
1518{
1519 struct drm_i915_private *dev_priv = dev->dev_private;
1520 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001521 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001522
Paulo Zanonide032bf2013-04-12 17:57:58 -03001523 if (err_int & ERR_INT_POISON)
1524 DRM_ERROR("Poison interrupt\n");
1525
Daniel Vetter5a69b892013-10-16 22:55:52 +02001526 for_each_pipe(pipe) {
1527 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1528 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1529 false))
1530 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1531 pipe_name(pipe));
1532 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001533
Daniel Vetter5a69b892013-10-16 22:55:52 +02001534 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1535 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001536 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001537 else
Daniel Vetter277de952013-10-18 16:37:07 +02001538 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001539 }
1540 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001541
Paulo Zanoni86642812013-04-12 17:57:57 -03001542 I915_WRITE(GEN7_ERR_INT, err_int);
1543}
1544
1545static void cpt_serr_int_handler(struct drm_device *dev)
1546{
1547 struct drm_i915_private *dev_priv = dev->dev_private;
1548 u32 serr_int = I915_READ(SERR_INT);
1549
Paulo Zanonide032bf2013-04-12 17:57:58 -03001550 if (serr_int & SERR_INT_POISON)
1551 DRM_ERROR("PCH poison interrupt\n");
1552
Paulo Zanoni86642812013-04-12 17:57:57 -03001553 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1554 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1555 false))
1556 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1557
1558 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1559 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1560 false))
1561 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1562
1563 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1564 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1565 false))
1566 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1567
1568 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001569}
1570
Adam Jackson23e81d62012-06-06 15:45:44 -04001571static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1572{
1573 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1574 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001575 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001576
Daniel Vetter91d131d2013-06-27 17:52:14 +02001577 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1578
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001579 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1580 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1581 SDE_AUDIO_POWER_SHIFT_CPT);
1582 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1583 port_name(port));
1584 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001585
1586 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001587 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001588
1589 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001590 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001591
1592 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1593 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1594
1595 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1596 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1597
1598 if (pch_iir & SDE_FDI_MASK_CPT)
1599 for_each_pipe(pipe)
1600 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1601 pipe_name(pipe),
1602 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001603
1604 if (pch_iir & SDE_ERROR_CPT)
1605 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001606}
1607
Paulo Zanonic008bc62013-07-12 16:35:10 -03001608static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1609{
1610 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001611 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001612
1613 if (de_iir & DE_AUX_CHANNEL_A)
1614 dp_aux_irq_handler(dev);
1615
1616 if (de_iir & DE_GSE)
1617 intel_opregion_asle_intr(dev);
1618
Paulo Zanonic008bc62013-07-12 16:35:10 -03001619 if (de_iir & DE_POISON)
1620 DRM_ERROR("Poison interrupt\n");
1621
Daniel Vetter40da17c2013-10-21 18:04:36 +02001622 for_each_pipe(pipe) {
1623 if (de_iir & DE_PIPE_VBLANK(pipe))
1624 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001625
Daniel Vetter40da17c2013-10-21 18:04:36 +02001626 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1627 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1628 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1629 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001630
Daniel Vetter40da17c2013-10-21 18:04:36 +02001631 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1632 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001633
Daniel Vetter40da17c2013-10-21 18:04:36 +02001634 /* plane/pipes map 1:1 on ilk+ */
1635 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1636 intel_prepare_page_flip(dev, pipe);
1637 intel_finish_page_flip_plane(dev, pipe);
1638 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001639 }
1640
1641 /* check event from PCH */
1642 if (de_iir & DE_PCH_EVENT) {
1643 u32 pch_iir = I915_READ(SDEIIR);
1644
1645 if (HAS_PCH_CPT(dev))
1646 cpt_irq_handler(dev, pch_iir);
1647 else
1648 ibx_irq_handler(dev, pch_iir);
1649
1650 /* should clear PCH hotplug event before clear CPU irq */
1651 I915_WRITE(SDEIIR, pch_iir);
1652 }
1653
1654 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1655 ironlake_rps_change_irq_handler(dev);
1656}
1657
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001658static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1659{
1660 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001661 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001662
1663 if (de_iir & DE_ERR_INT_IVB)
1664 ivb_err_int_handler(dev);
1665
1666 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1667 dp_aux_irq_handler(dev);
1668
1669 if (de_iir & DE_GSE_IVB)
1670 intel_opregion_asle_intr(dev);
1671
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001672 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001673 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001674 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001675
1676 /* plane/pipes map 1:1 on ilk+ */
1677 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001678 intel_prepare_page_flip(dev, i);
1679 intel_finish_page_flip_plane(dev, i);
1680 }
1681 }
1682
1683 /* check event from PCH */
1684 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1685 u32 pch_iir = I915_READ(SDEIIR);
1686
1687 cpt_irq_handler(dev, pch_iir);
1688
1689 /* clear PCH hotplug event before clear CPU irq */
1690 I915_WRITE(SDEIIR, pch_iir);
1691 }
1692}
1693
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001694static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001695{
1696 struct drm_device *dev = (struct drm_device *) arg;
1697 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001698 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001699 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001700
1701 atomic_inc(&dev_priv->irq_received);
1702
Paulo Zanoni86642812013-04-12 17:57:57 -03001703 /* We get interrupts on unclaimed registers, so check for this before we
1704 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001705 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001706
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001707 /* disable master interrupt before clearing iir */
1708 de_ier = I915_READ(DEIER);
1709 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001710 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001711
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001712 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1713 * interrupts will will be stored on its back queue, and then we'll be
1714 * able to process them after we restore SDEIER (as soon as we restore
1715 * it, we'll get an interrupt if SDEIIR still has something to process
1716 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001717 if (!HAS_PCH_NOP(dev)) {
1718 sde_ier = I915_READ(SDEIER);
1719 I915_WRITE(SDEIER, 0);
1720 POSTING_READ(SDEIER);
1721 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001722
Chris Wilson0e434062012-05-09 21:45:44 +01001723 gt_iir = I915_READ(GTIIR);
1724 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001725 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001726 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001727 else
1728 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001729 I915_WRITE(GTIIR, gt_iir);
1730 ret = IRQ_HANDLED;
1731 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001732
1733 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001734 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001735 if (INTEL_INFO(dev)->gen >= 7)
1736 ivb_display_irq_handler(dev, de_iir);
1737 else
1738 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001739 I915_WRITE(DEIIR, de_iir);
1740 ret = IRQ_HANDLED;
1741 }
1742
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001743 if (INTEL_INFO(dev)->gen >= 6) {
1744 u32 pm_iir = I915_READ(GEN6_PMIIR);
1745 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001746 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001747 I915_WRITE(GEN6_PMIIR, pm_iir);
1748 ret = IRQ_HANDLED;
1749 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001750 }
1751
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001752 I915_WRITE(DEIER, de_ier);
1753 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001754 if (!HAS_PCH_NOP(dev)) {
1755 I915_WRITE(SDEIER, sde_ier);
1756 POSTING_READ(SDEIER);
1757 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001758
1759 return ret;
1760}
1761
Ben Widawskyabd58f02013-11-02 21:07:09 -07001762static irqreturn_t gen8_irq_handler(int irq, void *arg)
1763{
1764 struct drm_device *dev = arg;
1765 struct drm_i915_private *dev_priv = dev->dev_private;
1766 u32 master_ctl;
1767 irqreturn_t ret = IRQ_NONE;
1768 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001769 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001770
1771 atomic_inc(&dev_priv->irq_received);
1772
1773 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1774 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1775 if (!master_ctl)
1776 return IRQ_NONE;
1777
1778 I915_WRITE(GEN8_MASTER_IRQ, 0);
1779 POSTING_READ(GEN8_MASTER_IRQ);
1780
1781 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1782
1783 if (master_ctl & GEN8_DE_MISC_IRQ) {
1784 tmp = I915_READ(GEN8_DE_MISC_IIR);
1785 if (tmp & GEN8_DE_MISC_GSE)
1786 intel_opregion_asle_intr(dev);
1787 else if (tmp)
1788 DRM_ERROR("Unexpected DE Misc interrupt\n");
1789 else
1790 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1791
1792 if (tmp) {
1793 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1794 ret = IRQ_HANDLED;
1795 }
1796 }
1797
Daniel Vetter6d766f02013-11-07 14:49:55 +01001798 if (master_ctl & GEN8_DE_PORT_IRQ) {
1799 tmp = I915_READ(GEN8_DE_PORT_IIR);
1800 if (tmp & GEN8_AUX_CHANNEL_A)
1801 dp_aux_irq_handler(dev);
1802 else if (tmp)
1803 DRM_ERROR("Unexpected DE Port interrupt\n");
1804 else
1805 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1806
1807 if (tmp) {
1808 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1809 ret = IRQ_HANDLED;
1810 }
1811 }
1812
Daniel Vetterc42664c2013-11-07 11:05:40 +01001813 for_each_pipe(pipe) {
1814 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001815
Daniel Vetterc42664c2013-11-07 11:05:40 +01001816 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1817 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001818
Daniel Vetterc42664c2013-11-07 11:05:40 +01001819 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1820 if (pipe_iir & GEN8_PIPE_VBLANK)
1821 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001822
Daniel Vetterc42664c2013-11-07 11:05:40 +01001823 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1824 intel_prepare_page_flip(dev, pipe);
1825 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001826 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001827
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001828 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1829 hsw_pipe_crc_irq_handler(dev, pipe);
1830
Daniel Vetter38d83c962013-11-07 11:05:46 +01001831 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1832 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1833 false))
1834 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1835 pipe_name(pipe));
1836 }
1837
Daniel Vetter30100f22013-11-07 14:49:24 +01001838 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1839 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
1840 pipe_name(pipe),
1841 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
1842 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001843
1844 if (pipe_iir) {
1845 ret = IRQ_HANDLED;
1846 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
1847 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07001848 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
1849 }
1850
Daniel Vetter92d03a82013-11-07 11:05:43 +01001851 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
1852 /*
1853 * FIXME(BDW): Assume for now that the new interrupt handling
1854 * scheme also closed the SDE interrupt handling race we've seen
1855 * on older pch-split platforms. But this needs testing.
1856 */
1857 u32 pch_iir = I915_READ(SDEIIR);
1858
1859 cpt_irq_handler(dev, pch_iir);
1860
1861 if (pch_iir) {
1862 I915_WRITE(SDEIIR, pch_iir);
1863 ret = IRQ_HANDLED;
1864 }
1865 }
1866
Ben Widawskyabd58f02013-11-02 21:07:09 -07001867 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1868 POSTING_READ(GEN8_MASTER_IRQ);
1869
1870 return ret;
1871}
1872
Daniel Vetter17e1df02013-09-08 21:57:13 +02001873static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1874 bool reset_completed)
1875{
1876 struct intel_ring_buffer *ring;
1877 int i;
1878
1879 /*
1880 * Notify all waiters for GPU completion events that reset state has
1881 * been changed, and that they need to restart their wait after
1882 * checking for potential errors (and bail out to drop locks if there is
1883 * a gpu reset pending so that i915_error_work_func can acquire them).
1884 */
1885
1886 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1887 for_each_ring(ring, dev_priv, i)
1888 wake_up_all(&ring->irq_queue);
1889
1890 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1891 wake_up_all(&dev_priv->pending_flip_queue);
1892
1893 /*
1894 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1895 * reset state is cleared.
1896 */
1897 if (reset_completed)
1898 wake_up_all(&dev_priv->gpu_error.reset_queue);
1899}
1900
Jesse Barnes8a905232009-07-11 16:48:03 -04001901/**
1902 * i915_error_work_func - do process context error handling work
1903 * @work: work struct
1904 *
1905 * Fire an error uevent so userspace can see that a hang or error
1906 * was detected.
1907 */
1908static void i915_error_work_func(struct work_struct *work)
1909{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001910 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1911 work);
1912 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1913 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001914 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07001915 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1916 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1917 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02001918 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001919
Ben Gamarif316a422009-09-14 17:48:46 -04001920 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001921
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001922 /*
1923 * Note that there's only one work item which does gpu resets, so we
1924 * need not worry about concurrent gpu resets potentially incrementing
1925 * error->reset_counter twice. We only need to take care of another
1926 * racing irq/hangcheck declaring the gpu dead for a second time. A
1927 * quick check for that is good enough: schedule_work ensures the
1928 * correct ordering between hang detection and this work item, and since
1929 * the reset in-progress bit is only ever set by code outside of this
1930 * work we don't need to worry about any other races.
1931 */
1932 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001933 DRM_DEBUG_DRIVER("resetting chip\n");
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001934 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
1935 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001936
Daniel Vetter17e1df02013-09-08 21:57:13 +02001937 /*
1938 * All state reset _must_ be completed before we update the
1939 * reset counter, for otherwise waiters might miss the reset
1940 * pending state and not properly drop locks, resulting in
1941 * deadlocks with the reset work.
1942 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01001943 ret = i915_reset(dev);
1944
Daniel Vetter17e1df02013-09-08 21:57:13 +02001945 intel_display_handle_reset(dev);
1946
Daniel Vetterf69061b2012-12-06 09:01:42 +01001947 if (ret == 0) {
1948 /*
1949 * After all the gem state is reset, increment the reset
1950 * counter and wake up everyone waiting for the reset to
1951 * complete.
1952 *
1953 * Since unlock operations are a one-sided barrier only,
1954 * we need to insert a barrier here to order any seqno
1955 * updates before
1956 * the counter increment.
1957 */
1958 smp_mb__before_atomic_inc();
1959 atomic_inc(&dev_priv->gpu_error.reset_counter);
1960
1961 kobject_uevent_env(&dev->primary->kdev.kobj,
1962 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001963 } else {
1964 atomic_set(&error->reset_counter, I915_WEDGED);
Ben Gamarif316a422009-09-14 17:48:46 -04001965 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001966
Daniel Vetter17e1df02013-09-08 21:57:13 +02001967 /*
1968 * Note: The wake_up also serves as a memory barrier so that
1969 * waiters see the update value of the reset counter atomic_t.
1970 */
1971 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04001972 }
Jesse Barnes8a905232009-07-11 16:48:03 -04001973}
1974
Chris Wilson35aed2e2010-05-27 13:18:12 +01001975static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04001976{
1977 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07001978 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04001979 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07001980 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04001981
Chris Wilson35aed2e2010-05-27 13:18:12 +01001982 if (!eir)
1983 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04001984
Joe Perchesa70491c2012-03-18 13:00:11 -07001985 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04001986
Ben Widawskybd9854f2012-08-23 15:18:09 -07001987 i915_get_extra_instdone(dev, instdone);
1988
Jesse Barnes8a905232009-07-11 16:48:03 -04001989 if (IS_G4X(dev)) {
1990 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1991 u32 ipeir = I915_READ(IPEIR_I965);
1992
Joe Perchesa70491c2012-03-18 13:00:11 -07001993 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1994 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07001995 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1996 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07001997 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001998 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001999 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002000 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002001 }
2002 if (eir & GM45_ERROR_PAGE_TABLE) {
2003 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002004 pr_err("page table error\n");
2005 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002006 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002007 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002008 }
2009 }
2010
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002011 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002012 if (eir & I915_ERROR_PAGE_TABLE) {
2013 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002014 pr_err("page table error\n");
2015 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002016 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002017 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002018 }
2019 }
2020
2021 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002022 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002023 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002024 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002025 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002026 /* pipestat has already been acked */
2027 }
2028 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002029 pr_err("instruction error\n");
2030 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002031 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2032 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002033 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002034 u32 ipeir = I915_READ(IPEIR);
2035
Joe Perchesa70491c2012-03-18 13:00:11 -07002036 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2037 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002038 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002039 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002040 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002041 } else {
2042 u32 ipeir = I915_READ(IPEIR_I965);
2043
Joe Perchesa70491c2012-03-18 13:00:11 -07002044 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2045 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002046 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002047 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002048 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002049 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002050 }
2051 }
2052
2053 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002054 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002055 eir = I915_READ(EIR);
2056 if (eir) {
2057 /*
2058 * some errors might have become stuck,
2059 * mask them.
2060 */
2061 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2062 I915_WRITE(EMR, I915_READ(EMR) | eir);
2063 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2064 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002065}
2066
2067/**
2068 * i915_handle_error - handle an error interrupt
2069 * @dev: drm device
2070 *
2071 * Do some basic checking of regsiter state at error interrupt time and
2072 * dump it to the syslog. Also call i915_capture_error_state() to make
2073 * sure we get a record and make it available in debugfs. Fire a uevent
2074 * so userspace knows something bad happened (should trigger collection
2075 * of a ring dump etc.).
2076 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002077void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002078{
2079 struct drm_i915_private *dev_priv = dev->dev_private;
2080
2081 i915_capture_error_state(dev);
2082 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002083
Ben Gamariba1234d2009-09-14 17:48:47 -04002084 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002085 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2086 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002087
Ben Gamari11ed50e2009-09-14 17:48:45 -04002088 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002089 * Wakeup waiting processes so that the reset work function
2090 * i915_error_work_func doesn't deadlock trying to grab various
2091 * locks. By bumping the reset counter first, the woken
2092 * processes will see a reset in progress and back off,
2093 * releasing their locks and then wait for the reset completion.
2094 * We must do this for _all_ gpu waiters that might hold locks
2095 * that the reset work needs to acquire.
2096 *
2097 * Note: The wake_up serves as the required memory barrier to
2098 * ensure that the waiters see the updated value of the reset
2099 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002100 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002101 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002102 }
2103
Daniel Vetter122f46b2013-09-04 17:36:14 +02002104 /*
2105 * Our reset work can grab modeset locks (since it needs to reset the
2106 * state of outstanding pagelips). Hence it must not be run on our own
2107 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2108 * code will deadlock.
2109 */
2110 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002111}
2112
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002113static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002114{
2115 drm_i915_private_t *dev_priv = dev->dev_private;
2116 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2117 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002118 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002119 struct intel_unpin_work *work;
2120 unsigned long flags;
2121 bool stall_detected;
2122
2123 /* Ignore early vblank irqs */
2124 if (intel_crtc == NULL)
2125 return;
2126
2127 spin_lock_irqsave(&dev->event_lock, flags);
2128 work = intel_crtc->unpin_work;
2129
Chris Wilsone7d841c2012-12-03 11:36:30 +00002130 if (work == NULL ||
2131 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2132 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002133 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2134 spin_unlock_irqrestore(&dev->event_lock, flags);
2135 return;
2136 }
2137
2138 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002139 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002140 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002141 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002142 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002143 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002144 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002145 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002146 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002147 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002148 crtc->x * crtc->fb->bits_per_pixel/8);
2149 }
2150
2151 spin_unlock_irqrestore(&dev->event_lock, flags);
2152
2153 if (stall_detected) {
2154 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2155 intel_prepare_page_flip(dev, intel_crtc->plane);
2156 }
2157}
2158
Keith Packard42f52ef2008-10-18 19:39:29 -07002159/* Called from drm generic code, passed 'crtc' which
2160 * we use as a pipe index
2161 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002162static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002163{
2164 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002165 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002166
Chris Wilson5eddb702010-09-11 13:48:45 +01002167 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002168 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002169
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002170 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002171 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002172 i915_enable_pipestat(dev_priv, pipe,
2173 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07002174 else
Keith Packard7c463582008-11-04 02:03:27 -08002175 i915_enable_pipestat(dev_priv, pipe,
2176 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002177
2178 /* maintain vblank delivery even in deep C-states */
2179 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002180 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002181 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002182
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002183 return 0;
2184}
2185
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002186static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002187{
2188 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2189 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002190 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002191 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002192
2193 if (!i915_pipe_enabled(dev, pipe))
2194 return -EINVAL;
2195
2196 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002197 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002198 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2199
2200 return 0;
2201}
2202
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002203static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2204{
2205 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2206 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002207 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002208
2209 if (!i915_pipe_enabled(dev, pipe))
2210 return -EINVAL;
2211
2212 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002213 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002214 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002215 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002216 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002217 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002218 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002219 i915_enable_pipestat(dev_priv, pipe,
2220 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002221 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2222
2223 return 0;
2224}
2225
Ben Widawskyabd58f02013-11-02 21:07:09 -07002226static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2227{
2228 struct drm_i915_private *dev_priv = dev->dev_private;
2229 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002230
2231 if (!i915_pipe_enabled(dev, pipe))
2232 return -EINVAL;
2233
2234 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002235 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2236 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2237 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002238 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2239 return 0;
2240}
2241
Keith Packard42f52ef2008-10-18 19:39:29 -07002242/* Called from drm generic code, passed 'crtc' which
2243 * we use as a pipe index
2244 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002245static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002246{
2247 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002248 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002249
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002250 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002251 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002252 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002253
Jesse Barnesf796cf82011-04-07 13:58:17 -07002254 i915_disable_pipestat(dev_priv, pipe,
2255 PIPE_VBLANK_INTERRUPT_ENABLE |
2256 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2257 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2258}
2259
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002260static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002261{
2262 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2263 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002264 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002265 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002266
2267 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002268 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002269 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2270}
2271
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002272static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2273{
2274 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2275 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002276 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002277
2278 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002279 i915_disable_pipestat(dev_priv, pipe,
2280 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002281 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002282 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002283 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002284 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002285 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002286 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002287 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2288}
2289
Ben Widawskyabd58f02013-11-02 21:07:09 -07002290static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2291{
2292 struct drm_i915_private *dev_priv = dev->dev_private;
2293 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002294
2295 if (!i915_pipe_enabled(dev, pipe))
2296 return;
2297
2298 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002299 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2300 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2301 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002302 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2303}
2304
Chris Wilson893eead2010-10-27 14:44:35 +01002305static u32
2306ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002307{
Chris Wilson893eead2010-10-27 14:44:35 +01002308 return list_entry(ring->request_list.prev,
2309 struct drm_i915_gem_request, list)->seqno;
2310}
2311
Chris Wilson9107e9d2013-06-10 11:20:20 +01002312static bool
2313ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002314{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002315 return (list_empty(&ring->request_list) ||
2316 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002317}
2318
Chris Wilson6274f212013-06-10 11:20:21 +01002319static struct intel_ring_buffer *
2320semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002321{
2322 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002323 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002324
2325 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2326 if ((ipehr & ~(0x3 << 16)) !=
2327 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002328 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002329
2330 /* ACTHD is likely pointing to the dword after the actual command,
2331 * so scan backwards until we find the MBOX.
2332 */
Chris Wilson6274f212013-06-10 11:20:21 +01002333 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002334 acthd_min = max((int)acthd - 3 * 4, 0);
2335 do {
2336 cmd = ioread32(ring->virtual_start + acthd);
2337 if (cmd == ipehr)
2338 break;
2339
2340 acthd -= 4;
2341 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002342 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002343 } while (1);
2344
Chris Wilson6274f212013-06-10 11:20:21 +01002345 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2346 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002347}
2348
Chris Wilson6274f212013-06-10 11:20:21 +01002349static int semaphore_passed(struct intel_ring_buffer *ring)
2350{
2351 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2352 struct intel_ring_buffer *signaller;
2353 u32 seqno, ctl;
2354
2355 ring->hangcheck.deadlock = true;
2356
2357 signaller = semaphore_waits_for(ring, &seqno);
2358 if (signaller == NULL || signaller->hangcheck.deadlock)
2359 return -1;
2360
2361 /* cursory check for an unkickable deadlock */
2362 ctl = I915_READ_CTL(signaller);
2363 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2364 return -1;
2365
2366 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2367}
2368
2369static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2370{
2371 struct intel_ring_buffer *ring;
2372 int i;
2373
2374 for_each_ring(ring, dev_priv, i)
2375 ring->hangcheck.deadlock = false;
2376}
2377
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002378static enum intel_ring_hangcheck_action
2379ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002380{
2381 struct drm_device *dev = ring->dev;
2382 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002383 u32 tmp;
2384
Chris Wilson6274f212013-06-10 11:20:21 +01002385 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002386 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002387
Chris Wilson9107e9d2013-06-10 11:20:20 +01002388 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002389 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002390
2391 /* Is the chip hanging on a WAIT_FOR_EVENT?
2392 * If so we can simply poke the RB_WAIT bit
2393 * and break the hang. This should work on
2394 * all but the second generation chipsets.
2395 */
2396 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002397 if (tmp & RING_WAIT) {
2398 DRM_ERROR("Kicking stuck wait on %s\n",
2399 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002400 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002401 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002402 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002403 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002404
Chris Wilson6274f212013-06-10 11:20:21 +01002405 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2406 switch (semaphore_passed(ring)) {
2407 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002408 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002409 case 1:
2410 DRM_ERROR("Kicking stuck semaphore on %s\n",
2411 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002412 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002413 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002414 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002415 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002416 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002417 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002418 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002419
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002420 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002421}
2422
Ben Gamarif65d9422009-09-14 17:48:44 -04002423/**
2424 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002425 * batchbuffers in a long time. We keep track per ring seqno progress and
2426 * if there are no progress, hangcheck score for that ring is increased.
2427 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2428 * we kick the ring. If we see no progress on three subsequent calls
2429 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002430 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002431static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002432{
2433 struct drm_device *dev = (struct drm_device *)data;
2434 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002435 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002436 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002437 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002438 bool stuck[I915_NUM_RINGS] = { 0 };
2439#define BUSY 1
2440#define KICK 5
2441#define HUNG 20
2442#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01002443
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002444 if (!i915_enable_hangcheck)
2445 return;
2446
Chris Wilsonb4519512012-05-11 14:29:30 +01002447 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002448 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002449 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002450
Chris Wilson6274f212013-06-10 11:20:21 +01002451 semaphore_clear_deadlocks(dev_priv);
2452
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002453 seqno = ring->get_seqno(ring, false);
2454 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002455
Chris Wilson9107e9d2013-06-10 11:20:20 +01002456 if (ring->hangcheck.seqno == seqno) {
2457 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002458 ring->hangcheck.action = HANGCHECK_IDLE;
2459
Chris Wilson9107e9d2013-06-10 11:20:20 +01002460 if (waitqueue_active(&ring->irq_queue)) {
2461 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002462 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002463 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2464 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2465 ring->name);
2466 else
2467 DRM_INFO("Fake missed irq on %s\n",
2468 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002469 wake_up_all(&ring->irq_queue);
2470 }
2471 /* Safeguard against driver failure */
2472 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002473 } else
2474 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002475 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002476 /* We always increment the hangcheck score
2477 * if the ring is busy and still processing
2478 * the same request, so that no single request
2479 * can run indefinitely (such as a chain of
2480 * batches). The only time we do not increment
2481 * the hangcheck score on this ring, if this
2482 * ring is in a legitimate wait for another
2483 * ring. In that case the waiting ring is a
2484 * victim and we want to be sure we catch the
2485 * right culprit. Then every time we do kick
2486 * the ring, add a small increment to the
2487 * score so that we can catch a batch that is
2488 * being repeatedly kicked and so responsible
2489 * for stalling the machine.
2490 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002491 ring->hangcheck.action = ring_stuck(ring,
2492 acthd);
2493
2494 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002495 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002496 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002497 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002498 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002499 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002500 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002501 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002502 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002503 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002504 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002505 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002506 stuck[i] = true;
2507 break;
2508 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002509 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002510 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002511 ring->hangcheck.action = HANGCHECK_ACTIVE;
2512
Chris Wilson9107e9d2013-06-10 11:20:20 +01002513 /* Gradually reduce the count so that we catch DoS
2514 * attempts across multiple batches.
2515 */
2516 if (ring->hangcheck.score > 0)
2517 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002518 }
2519
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002520 ring->hangcheck.seqno = seqno;
2521 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002522 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002523 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002524
Mika Kuoppala92cab732013-05-24 17:16:07 +03002525 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002526 if (ring->hangcheck.score > FIRE) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002527 DRM_INFO("%s on %s\n",
2528 stuck[i] ? "stuck" : "no progress",
2529 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002530 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002531 }
2532 }
2533
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002534 if (rings_hung)
2535 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002536
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002537 if (busy_count)
2538 /* Reset timer case chip hangs without another request
2539 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002540 i915_queue_hangcheck(dev);
2541}
2542
2543void i915_queue_hangcheck(struct drm_device *dev)
2544{
2545 struct drm_i915_private *dev_priv = dev->dev_private;
2546 if (!i915_enable_hangcheck)
2547 return;
2548
2549 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2550 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002551}
2552
Paulo Zanoni91738a92013-06-05 14:21:51 -03002553static void ibx_irq_preinstall(struct drm_device *dev)
2554{
2555 struct drm_i915_private *dev_priv = dev->dev_private;
2556
2557 if (HAS_PCH_NOP(dev))
2558 return;
2559
2560 /* south display irq */
2561 I915_WRITE(SDEIMR, 0xffffffff);
2562 /*
2563 * SDEIER is also touched by the interrupt handler to work around missed
2564 * PCH interrupts. Hence we can't update it after the interrupt handler
2565 * is enabled - instead we unconditionally enable all PCH interrupt
2566 * sources here, but then only unmask them as needed with SDEIMR.
2567 */
2568 I915_WRITE(SDEIER, 0xffffffff);
2569 POSTING_READ(SDEIER);
2570}
2571
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002572static void gen5_gt_irq_preinstall(struct drm_device *dev)
2573{
2574 struct drm_i915_private *dev_priv = dev->dev_private;
2575
2576 /* and GT */
2577 I915_WRITE(GTIMR, 0xffffffff);
2578 I915_WRITE(GTIER, 0x0);
2579 POSTING_READ(GTIER);
2580
2581 if (INTEL_INFO(dev)->gen >= 6) {
2582 /* and PM */
2583 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2584 I915_WRITE(GEN6_PMIER, 0x0);
2585 POSTING_READ(GEN6_PMIER);
2586 }
2587}
2588
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589/* drm_dma.h hooks
2590*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002591static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002592{
2593 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2594
Jesse Barnes46979952011-04-07 13:53:55 -07002595 atomic_set(&dev_priv->irq_received, 0);
2596
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002597 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002598
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002599 I915_WRITE(DEIMR, 0xffffffff);
2600 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002601 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002602
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002603 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002604
Paulo Zanoni91738a92013-06-05 14:21:51 -03002605 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002606}
2607
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002608static void valleyview_irq_preinstall(struct drm_device *dev)
2609{
2610 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2611 int pipe;
2612
2613 atomic_set(&dev_priv->irq_received, 0);
2614
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002615 /* VLV magic */
2616 I915_WRITE(VLV_IMR, 0);
2617 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2618 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2619 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2620
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002621 /* and GT */
2622 I915_WRITE(GTIIR, I915_READ(GTIIR));
2623 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002624
2625 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002626
2627 I915_WRITE(DPINVGTT, 0xff);
2628
2629 I915_WRITE(PORT_HOTPLUG_EN, 0);
2630 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2631 for_each_pipe(pipe)
2632 I915_WRITE(PIPESTAT(pipe), 0xffff);
2633 I915_WRITE(VLV_IIR, 0xffffffff);
2634 I915_WRITE(VLV_IMR, 0xffffffff);
2635 I915_WRITE(VLV_IER, 0x0);
2636 POSTING_READ(VLV_IER);
2637}
2638
Ben Widawskyabd58f02013-11-02 21:07:09 -07002639static void gen8_irq_preinstall(struct drm_device *dev)
2640{
2641 struct drm_i915_private *dev_priv = dev->dev_private;
2642 int pipe;
2643
2644 atomic_set(&dev_priv->irq_received, 0);
2645
2646 I915_WRITE(GEN8_MASTER_IRQ, 0);
2647 POSTING_READ(GEN8_MASTER_IRQ);
2648
2649 /* IIR can theoretically queue up two events. Be paranoid */
2650#define GEN8_IRQ_INIT_NDX(type, which) do { \
2651 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2652 POSTING_READ(GEN8_##type##_IMR(which)); \
2653 I915_WRITE(GEN8_##type##_IER(which), 0); \
2654 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2655 POSTING_READ(GEN8_##type##_IIR(which)); \
2656 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2657 } while (0)
2658
2659#define GEN8_IRQ_INIT(type) do { \
2660 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2661 POSTING_READ(GEN8_##type##_IMR); \
2662 I915_WRITE(GEN8_##type##_IER, 0); \
2663 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2664 POSTING_READ(GEN8_##type##_IIR); \
2665 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2666 } while (0)
2667
2668 GEN8_IRQ_INIT_NDX(GT, 0);
2669 GEN8_IRQ_INIT_NDX(GT, 1);
2670 GEN8_IRQ_INIT_NDX(GT, 2);
2671 GEN8_IRQ_INIT_NDX(GT, 3);
2672
2673 for_each_pipe(pipe) {
2674 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2675 }
2676
2677 GEN8_IRQ_INIT(DE_PORT);
2678 GEN8_IRQ_INIT(DE_MISC);
2679 GEN8_IRQ_INIT(PCU);
2680#undef GEN8_IRQ_INIT
2681#undef GEN8_IRQ_INIT_NDX
2682
2683 POSTING_READ(GEN8_PCU_IIR);
2684}
2685
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002686static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002687{
2688 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002689 struct drm_mode_config *mode_config = &dev->mode_config;
2690 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002691 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002692
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002693 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002694 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002695 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002696 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002697 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002698 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002699 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002700 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002701 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002702 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002703 }
2704
Daniel Vetterfee884e2013-07-04 23:35:21 +02002705 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002706
2707 /*
2708 * Enable digital hotplug on the PCH, and configure the DP short pulse
2709 * duration to 2ms (which is the minimum in the Display Port spec)
2710 *
2711 * This register is the same on all known PCH chips.
2712 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002713 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2714 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2715 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2716 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2717 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2718 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2719}
2720
Paulo Zanonid46da432013-02-08 17:35:15 -02002721static void ibx_irq_postinstall(struct drm_device *dev)
2722{
2723 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002724 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002725
Daniel Vetter692a04c2013-05-29 21:43:05 +02002726 if (HAS_PCH_NOP(dev))
2727 return;
2728
Paulo Zanoni86642812013-04-12 17:57:57 -03002729 if (HAS_PCH_IBX(dev)) {
2730 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002731 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002732 } else {
2733 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2734
2735 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2736 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002737
Paulo Zanonid46da432013-02-08 17:35:15 -02002738 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2739 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002740}
2741
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002742static void gen5_gt_irq_postinstall(struct drm_device *dev)
2743{
2744 struct drm_i915_private *dev_priv = dev->dev_private;
2745 u32 pm_irqs, gt_irqs;
2746
2747 pm_irqs = gt_irqs = 0;
2748
2749 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002750 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002751 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002752 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2753 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002754 }
2755
2756 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2757 if (IS_GEN5(dev)) {
2758 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2759 ILK_BSD_USER_INTERRUPT;
2760 } else {
2761 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2762 }
2763
2764 I915_WRITE(GTIIR, I915_READ(GTIIR));
2765 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2766 I915_WRITE(GTIER, gt_irqs);
2767 POSTING_READ(GTIER);
2768
2769 if (INTEL_INFO(dev)->gen >= 6) {
2770 pm_irqs |= GEN6_PM_RPS_EVENTS;
2771
2772 if (HAS_VEBOX(dev))
2773 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2774
Paulo Zanoni605cd252013-08-06 18:57:15 -03002775 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002776 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002777 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002778 I915_WRITE(GEN6_PMIER, pm_irqs);
2779 POSTING_READ(GEN6_PMIER);
2780 }
2781}
2782
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002783static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002784{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002785 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002786 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002787 u32 display_mask, extra_mask;
2788
2789 if (INTEL_INFO(dev)->gen >= 7) {
2790 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2791 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2792 DE_PLANEB_FLIP_DONE_IVB |
2793 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2794 DE_ERR_INT_IVB);
2795 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2796 DE_PIPEA_VBLANK_IVB);
2797
2798 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2799 } else {
2800 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2801 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002802 DE_AUX_CHANNEL_A |
2803 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2804 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2805 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002806 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2807 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002808
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002809 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002810
2811 /* should always can generate irq */
2812 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002813 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002814 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002815 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002816
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002817 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002818
Paulo Zanonid46da432013-02-08 17:35:15 -02002819 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002820
Jesse Barnesf97108d2010-01-29 11:27:07 -08002821 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002822 /* Enable PCU event interrupts
2823 *
2824 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002825 * setup is guaranteed to run in single-threaded context. But we
2826 * need it to make the assert_spin_locked happy. */
2827 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002828 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002829 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002830 }
2831
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002832 return 0;
2833}
2834
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002835static int valleyview_irq_postinstall(struct drm_device *dev)
2836{
2837 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002838 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002839 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2840 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002841 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002842
2843 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002844 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2845 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2846 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002847 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2848
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002849 /*
2850 *Leave vblank interrupts masked initially. enable/disable will
2851 * toggle them based on usage.
2852 */
2853 dev_priv->irq_mask = (~enable_mask) |
2854 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2855 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002856
Daniel Vetter20afbda2012-12-11 14:05:07 +01002857 I915_WRITE(PORT_HOTPLUG_EN, 0);
2858 POSTING_READ(PORT_HOTPLUG_EN);
2859
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002860 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2861 I915_WRITE(VLV_IER, enable_mask);
2862 I915_WRITE(VLV_IIR, 0xffffffff);
2863 I915_WRITE(PIPESTAT(0), 0xffff);
2864 I915_WRITE(PIPESTAT(1), 0xffff);
2865 POSTING_READ(VLV_IER);
2866
Daniel Vetterb79480b2013-06-27 17:52:10 +02002867 /* Interrupt setup is already guaranteed to be single-threaded, this is
2868 * just to make the assert_spin_locked check happy. */
2869 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002870 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
2871 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
2872 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002873 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002874
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002875 I915_WRITE(VLV_IIR, 0xffffffff);
2876 I915_WRITE(VLV_IIR, 0xffffffff);
2877
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002878 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002879
2880 /* ack & enable invalid PTE error interrupts */
2881#if 0 /* FIXME: add support to irq handler for checking these bits */
2882 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2883 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2884#endif
2885
2886 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002887
2888 return 0;
2889}
2890
Ben Widawskyabd58f02013-11-02 21:07:09 -07002891static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
2892{
2893 int i;
2894
2895 /* These are interrupts we'll toggle with the ring mask register */
2896 uint32_t gt_interrupts[] = {
2897 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
2898 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
2899 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
2900 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
2901 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
2902 0,
2903 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
2904 };
2905
2906 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
2907 u32 tmp = I915_READ(GEN8_GT_IIR(i));
2908 if (tmp)
2909 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2910 i, tmp);
2911 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
2912 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
2913 }
2914 POSTING_READ(GEN8_GT_IER(0));
2915}
2916
2917static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
2918{
2919 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002920 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
2921 GEN8_PIPE_CDCLK_CRC_DONE |
2922 GEN8_PIPE_FIFO_UNDERRUN |
2923 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2924 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002925 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002926 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
2927 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
2928 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002929
2930 for_each_pipe(pipe) {
2931 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2932 if (tmp)
2933 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2934 pipe, tmp);
2935 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2936 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
2937 }
2938 POSTING_READ(GEN8_DE_PIPE_ISR(0));
2939
Daniel Vetter6d766f02013-11-07 14:49:55 +01002940 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
2941 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002942 POSTING_READ(GEN8_DE_PORT_IER);
2943}
2944
2945static int gen8_irq_postinstall(struct drm_device *dev)
2946{
2947 struct drm_i915_private *dev_priv = dev->dev_private;
2948
2949 gen8_gt_irq_postinstall(dev_priv);
2950 gen8_de_irq_postinstall(dev_priv);
2951
2952 ibx_irq_postinstall(dev);
2953
2954 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
2955 POSTING_READ(GEN8_MASTER_IRQ);
2956
2957 return 0;
2958}
2959
2960static void gen8_irq_uninstall(struct drm_device *dev)
2961{
2962 struct drm_i915_private *dev_priv = dev->dev_private;
2963 int pipe;
2964
2965 if (!dev_priv)
2966 return;
2967
2968 atomic_set(&dev_priv->irq_received, 0);
2969
2970 I915_WRITE(GEN8_MASTER_IRQ, 0);
2971
2972#define GEN8_IRQ_FINI_NDX(type, which) do { \
2973 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2974 I915_WRITE(GEN8_##type##_IER(which), 0); \
2975 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2976 } while (0)
2977
2978#define GEN8_IRQ_FINI(type) do { \
2979 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2980 I915_WRITE(GEN8_##type##_IER, 0); \
2981 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2982 } while (0)
2983
2984 GEN8_IRQ_FINI_NDX(GT, 0);
2985 GEN8_IRQ_FINI_NDX(GT, 1);
2986 GEN8_IRQ_FINI_NDX(GT, 2);
2987 GEN8_IRQ_FINI_NDX(GT, 3);
2988
2989 for_each_pipe(pipe) {
2990 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
2991 }
2992
2993 GEN8_IRQ_FINI(DE_PORT);
2994 GEN8_IRQ_FINI(DE_MISC);
2995 GEN8_IRQ_FINI(PCU);
2996#undef GEN8_IRQ_FINI
2997#undef GEN8_IRQ_FINI_NDX
2998
2999 POSTING_READ(GEN8_PCU_IIR);
3000}
3001
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003002static void valleyview_irq_uninstall(struct drm_device *dev)
3003{
3004 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3005 int pipe;
3006
3007 if (!dev_priv)
3008 return;
3009
Egbert Eichac4c16c2013-04-16 13:36:58 +02003010 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3011
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003012 for_each_pipe(pipe)
3013 I915_WRITE(PIPESTAT(pipe), 0xffff);
3014
3015 I915_WRITE(HWSTAM, 0xffffffff);
3016 I915_WRITE(PORT_HOTPLUG_EN, 0);
3017 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3018 for_each_pipe(pipe)
3019 I915_WRITE(PIPESTAT(pipe), 0xffff);
3020 I915_WRITE(VLV_IIR, 0xffffffff);
3021 I915_WRITE(VLV_IMR, 0xffffffff);
3022 I915_WRITE(VLV_IER, 0x0);
3023 POSTING_READ(VLV_IER);
3024}
3025
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003026static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003027{
3028 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003029
3030 if (!dev_priv)
3031 return;
3032
Egbert Eichac4c16c2013-04-16 13:36:58 +02003033 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3034
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003035 I915_WRITE(HWSTAM, 0xffffffff);
3036
3037 I915_WRITE(DEIMR, 0xffffffff);
3038 I915_WRITE(DEIER, 0x0);
3039 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003040 if (IS_GEN7(dev))
3041 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003042
3043 I915_WRITE(GTIMR, 0xffffffff);
3044 I915_WRITE(GTIER, 0x0);
3045 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003046
Ben Widawskyab5c6082013-04-05 13:12:41 -07003047 if (HAS_PCH_NOP(dev))
3048 return;
3049
Keith Packard192aac1f2011-09-20 10:12:44 -07003050 I915_WRITE(SDEIMR, 0xffffffff);
3051 I915_WRITE(SDEIER, 0x0);
3052 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003053 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3054 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003055}
3056
Chris Wilsonc2798b12012-04-22 21:13:57 +01003057static void i8xx_irq_preinstall(struct drm_device * dev)
3058{
3059 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3060 int pipe;
3061
3062 atomic_set(&dev_priv->irq_received, 0);
3063
3064 for_each_pipe(pipe)
3065 I915_WRITE(PIPESTAT(pipe), 0);
3066 I915_WRITE16(IMR, 0xffff);
3067 I915_WRITE16(IER, 0x0);
3068 POSTING_READ16(IER);
3069}
3070
3071static int i8xx_irq_postinstall(struct drm_device *dev)
3072{
3073 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003074 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003075
Chris Wilsonc2798b12012-04-22 21:13:57 +01003076 I915_WRITE16(EMR,
3077 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3078
3079 /* Unmask the interrupts that we always want on. */
3080 dev_priv->irq_mask =
3081 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3082 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3083 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3084 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3085 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3086 I915_WRITE16(IMR, dev_priv->irq_mask);
3087
3088 I915_WRITE16(IER,
3089 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3090 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3091 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3092 I915_USER_INTERRUPT);
3093 POSTING_READ16(IER);
3094
Daniel Vetter379ef822013-10-16 22:55:56 +02003095 /* Interrupt setup is already guaranteed to be single-threaded, this is
3096 * just to make the assert_spin_locked check happy. */
3097 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003098 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3099 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003100 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3101
Chris Wilsonc2798b12012-04-22 21:13:57 +01003102 return 0;
3103}
3104
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003105/*
3106 * Returns true when a page flip has completed.
3107 */
3108static bool i8xx_handle_vblank(struct drm_device *dev,
3109 int pipe, u16 iir)
3110{
3111 drm_i915_private_t *dev_priv = dev->dev_private;
3112 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
3113
3114 if (!drm_handle_vblank(dev, pipe))
3115 return false;
3116
3117 if ((iir & flip_pending) == 0)
3118 return false;
3119
3120 intel_prepare_page_flip(dev, pipe);
3121
3122 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3123 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3124 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3125 * the flip is completed (no longer pending). Since this doesn't raise
3126 * an interrupt per se, we watch for the change at vblank.
3127 */
3128 if (I915_READ16(ISR) & flip_pending)
3129 return false;
3130
3131 intel_finish_page_flip(dev, pipe);
3132
3133 return true;
3134}
3135
Daniel Vetterff1f5252012-10-02 15:10:55 +02003136static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003137{
3138 struct drm_device *dev = (struct drm_device *) arg;
3139 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003140 u16 iir, new_iir;
3141 u32 pipe_stats[2];
3142 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003143 int pipe;
3144 u16 flip_mask =
3145 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3146 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3147
3148 atomic_inc(&dev_priv->irq_received);
3149
3150 iir = I915_READ16(IIR);
3151 if (iir == 0)
3152 return IRQ_NONE;
3153
3154 while (iir & ~flip_mask) {
3155 /* Can't rely on pipestat interrupt bit in iir as it might
3156 * have been cleared after the pipestat interrupt was received.
3157 * It doesn't set the bit in iir again, but it still produces
3158 * interrupts (for non-MSI).
3159 */
3160 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3161 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3162 i915_handle_error(dev, false);
3163
3164 for_each_pipe(pipe) {
3165 int reg = PIPESTAT(pipe);
3166 pipe_stats[pipe] = I915_READ(reg);
3167
3168 /*
3169 * Clear the PIPE*STAT regs before the IIR
3170 */
3171 if (pipe_stats[pipe] & 0x8000ffff) {
3172 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3173 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3174 pipe_name(pipe));
3175 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003176 }
3177 }
3178 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3179
3180 I915_WRITE16(IIR, iir & ~flip_mask);
3181 new_iir = I915_READ16(IIR); /* Flush posted writes */
3182
Daniel Vetterd05c6172012-04-26 23:28:09 +02003183 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003184
3185 if (iir & I915_USER_INTERRUPT)
3186 notify_ring(dev, &dev_priv->ring[RCS]);
3187
Daniel Vetter4356d582013-10-16 22:55:55 +02003188 for_each_pipe(pipe) {
3189 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3190 i8xx_handle_vblank(dev, pipe, iir))
3191 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003192
Daniel Vetter4356d582013-10-16 22:55:55 +02003193 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003194 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003195 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003196
3197 iir = new_iir;
3198 }
3199
3200 return IRQ_HANDLED;
3201}
3202
3203static void i8xx_irq_uninstall(struct drm_device * dev)
3204{
3205 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3206 int pipe;
3207
Chris Wilsonc2798b12012-04-22 21:13:57 +01003208 for_each_pipe(pipe) {
3209 /* Clear enable bits; then clear status bits */
3210 I915_WRITE(PIPESTAT(pipe), 0);
3211 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3212 }
3213 I915_WRITE16(IMR, 0xffff);
3214 I915_WRITE16(IER, 0x0);
3215 I915_WRITE16(IIR, I915_READ16(IIR));
3216}
3217
Chris Wilsona266c7d2012-04-24 22:59:44 +01003218static void i915_irq_preinstall(struct drm_device * dev)
3219{
3220 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3221 int pipe;
3222
3223 atomic_set(&dev_priv->irq_received, 0);
3224
3225 if (I915_HAS_HOTPLUG(dev)) {
3226 I915_WRITE(PORT_HOTPLUG_EN, 0);
3227 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3228 }
3229
Chris Wilson00d98eb2012-04-24 22:59:48 +01003230 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003231 for_each_pipe(pipe)
3232 I915_WRITE(PIPESTAT(pipe), 0);
3233 I915_WRITE(IMR, 0xffffffff);
3234 I915_WRITE(IER, 0x0);
3235 POSTING_READ(IER);
3236}
3237
3238static int i915_irq_postinstall(struct drm_device *dev)
3239{
3240 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003241 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003242 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003243
Chris Wilson38bde182012-04-24 22:59:50 +01003244 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3245
3246 /* Unmask the interrupts that we always want on. */
3247 dev_priv->irq_mask =
3248 ~(I915_ASLE_INTERRUPT |
3249 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3250 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3251 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3252 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3253 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3254
3255 enable_mask =
3256 I915_ASLE_INTERRUPT |
3257 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3258 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3259 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3260 I915_USER_INTERRUPT;
3261
Chris Wilsona266c7d2012-04-24 22:59:44 +01003262 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003263 I915_WRITE(PORT_HOTPLUG_EN, 0);
3264 POSTING_READ(PORT_HOTPLUG_EN);
3265
Chris Wilsona266c7d2012-04-24 22:59:44 +01003266 /* Enable in IER... */
3267 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3268 /* and unmask in IMR */
3269 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3270 }
3271
Chris Wilsona266c7d2012-04-24 22:59:44 +01003272 I915_WRITE(IMR, dev_priv->irq_mask);
3273 I915_WRITE(IER, enable_mask);
3274 POSTING_READ(IER);
3275
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003276 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003277
Daniel Vetter379ef822013-10-16 22:55:56 +02003278 /* Interrupt setup is already guaranteed to be single-threaded, this is
3279 * just to make the assert_spin_locked check happy. */
3280 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003281 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3282 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003283 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3284
Daniel Vetter20afbda2012-12-11 14:05:07 +01003285 return 0;
3286}
3287
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003288/*
3289 * Returns true when a page flip has completed.
3290 */
3291static bool i915_handle_vblank(struct drm_device *dev,
3292 int plane, int pipe, u32 iir)
3293{
3294 drm_i915_private_t *dev_priv = dev->dev_private;
3295 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3296
3297 if (!drm_handle_vblank(dev, pipe))
3298 return false;
3299
3300 if ((iir & flip_pending) == 0)
3301 return false;
3302
3303 intel_prepare_page_flip(dev, plane);
3304
3305 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3306 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3307 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3308 * the flip is completed (no longer pending). Since this doesn't raise
3309 * an interrupt per se, we watch for the change at vblank.
3310 */
3311 if (I915_READ(ISR) & flip_pending)
3312 return false;
3313
3314 intel_finish_page_flip(dev, pipe);
3315
3316 return true;
3317}
3318
Daniel Vetterff1f5252012-10-02 15:10:55 +02003319static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003320{
3321 struct drm_device *dev = (struct drm_device *) arg;
3322 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003323 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003324 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003325 u32 flip_mask =
3326 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3327 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003328 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003329
3330 atomic_inc(&dev_priv->irq_received);
3331
3332 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003333 do {
3334 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003335 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003336
3337 /* Can't rely on pipestat interrupt bit in iir as it might
3338 * have been cleared after the pipestat interrupt was received.
3339 * It doesn't set the bit in iir again, but it still produces
3340 * interrupts (for non-MSI).
3341 */
3342 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3343 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3344 i915_handle_error(dev, false);
3345
3346 for_each_pipe(pipe) {
3347 int reg = PIPESTAT(pipe);
3348 pipe_stats[pipe] = I915_READ(reg);
3349
Chris Wilson38bde182012-04-24 22:59:50 +01003350 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003351 if (pipe_stats[pipe] & 0x8000ffff) {
3352 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3353 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3354 pipe_name(pipe));
3355 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003356 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003357 }
3358 }
3359 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3360
3361 if (!irq_received)
3362 break;
3363
Chris Wilsona266c7d2012-04-24 22:59:44 +01003364 /* Consume port. Then clear IIR or we'll miss events */
3365 if ((I915_HAS_HOTPLUG(dev)) &&
3366 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3367 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003368 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003369
3370 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3371 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003372
3373 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3374
Chris Wilsona266c7d2012-04-24 22:59:44 +01003375 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003376 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003377 }
3378
Chris Wilson38bde182012-04-24 22:59:50 +01003379 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003380 new_iir = I915_READ(IIR); /* Flush posted writes */
3381
Chris Wilsona266c7d2012-04-24 22:59:44 +01003382 if (iir & I915_USER_INTERRUPT)
3383 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003384
Chris Wilsona266c7d2012-04-24 22:59:44 +01003385 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003386 int plane = pipe;
3387 if (IS_MOBILE(dev))
3388 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003389
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003390 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3391 i915_handle_vblank(dev, plane, pipe, iir))
3392 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003393
3394 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3395 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003396
3397 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003398 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003399 }
3400
Chris Wilsona266c7d2012-04-24 22:59:44 +01003401 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3402 intel_opregion_asle_intr(dev);
3403
3404 /* With MSI, interrupts are only generated when iir
3405 * transitions from zero to nonzero. If another bit got
3406 * set while we were handling the existing iir bits, then
3407 * we would never get another interrupt.
3408 *
3409 * This is fine on non-MSI as well, as if we hit this path
3410 * we avoid exiting the interrupt handler only to generate
3411 * another one.
3412 *
3413 * Note that for MSI this could cause a stray interrupt report
3414 * if an interrupt landed in the time between writing IIR and
3415 * the posting read. This should be rare enough to never
3416 * trigger the 99% of 100,000 interrupts test for disabling
3417 * stray interrupts.
3418 */
Chris Wilson38bde182012-04-24 22:59:50 +01003419 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003420 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003421 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003422
Daniel Vetterd05c6172012-04-26 23:28:09 +02003423 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003424
Chris Wilsona266c7d2012-04-24 22:59:44 +01003425 return ret;
3426}
3427
3428static void i915_irq_uninstall(struct drm_device * dev)
3429{
3430 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3431 int pipe;
3432
Egbert Eichac4c16c2013-04-16 13:36:58 +02003433 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3434
Chris Wilsona266c7d2012-04-24 22:59:44 +01003435 if (I915_HAS_HOTPLUG(dev)) {
3436 I915_WRITE(PORT_HOTPLUG_EN, 0);
3437 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3438 }
3439
Chris Wilson00d98eb2012-04-24 22:59:48 +01003440 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003441 for_each_pipe(pipe) {
3442 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003443 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003444 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3445 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003446 I915_WRITE(IMR, 0xffffffff);
3447 I915_WRITE(IER, 0x0);
3448
Chris Wilsona266c7d2012-04-24 22:59:44 +01003449 I915_WRITE(IIR, I915_READ(IIR));
3450}
3451
3452static void i965_irq_preinstall(struct drm_device * dev)
3453{
3454 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3455 int pipe;
3456
3457 atomic_set(&dev_priv->irq_received, 0);
3458
Chris Wilsonadca4732012-05-11 18:01:31 +01003459 I915_WRITE(PORT_HOTPLUG_EN, 0);
3460 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003461
3462 I915_WRITE(HWSTAM, 0xeffe);
3463 for_each_pipe(pipe)
3464 I915_WRITE(PIPESTAT(pipe), 0);
3465 I915_WRITE(IMR, 0xffffffff);
3466 I915_WRITE(IER, 0x0);
3467 POSTING_READ(IER);
3468}
3469
3470static int i965_irq_postinstall(struct drm_device *dev)
3471{
3472 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003473 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003474 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003475 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003476
Chris Wilsona266c7d2012-04-24 22:59:44 +01003477 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003478 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003479 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003480 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3481 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3482 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3483 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3484 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3485
3486 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003487 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3488 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003489 enable_mask |= I915_USER_INTERRUPT;
3490
3491 if (IS_G4X(dev))
3492 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003493
Daniel Vetterb79480b2013-06-27 17:52:10 +02003494 /* Interrupt setup is already guaranteed to be single-threaded, this is
3495 * just to make the assert_spin_locked check happy. */
3496 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003497 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
3498 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3499 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003500 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003501
Chris Wilsona266c7d2012-04-24 22:59:44 +01003502 /*
3503 * Enable some error detection, note the instruction error mask
3504 * bit is reserved, so we leave it masked.
3505 */
3506 if (IS_G4X(dev)) {
3507 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3508 GM45_ERROR_MEM_PRIV |
3509 GM45_ERROR_CP_PRIV |
3510 I915_ERROR_MEMORY_REFRESH);
3511 } else {
3512 error_mask = ~(I915_ERROR_PAGE_TABLE |
3513 I915_ERROR_MEMORY_REFRESH);
3514 }
3515 I915_WRITE(EMR, error_mask);
3516
3517 I915_WRITE(IMR, dev_priv->irq_mask);
3518 I915_WRITE(IER, enable_mask);
3519 POSTING_READ(IER);
3520
Daniel Vetter20afbda2012-12-11 14:05:07 +01003521 I915_WRITE(PORT_HOTPLUG_EN, 0);
3522 POSTING_READ(PORT_HOTPLUG_EN);
3523
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003524 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003525
3526 return 0;
3527}
3528
Egbert Eichbac56d52013-02-25 12:06:51 -05003529static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003530{
3531 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003532 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003533 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003534 u32 hotplug_en;
3535
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003536 assert_spin_locked(&dev_priv->irq_lock);
3537
Egbert Eichbac56d52013-02-25 12:06:51 -05003538 if (I915_HAS_HOTPLUG(dev)) {
3539 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3540 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3541 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003542 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003543 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3544 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3545 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003546 /* Programming the CRT detection parameters tends
3547 to generate a spurious hotplug event about three
3548 seconds later. So just do it once.
3549 */
3550 if (IS_G4X(dev))
3551 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003552 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003553 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003554
Egbert Eichbac56d52013-02-25 12:06:51 -05003555 /* Ignore TV since it's buggy */
3556 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3557 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003558}
3559
Daniel Vetterff1f5252012-10-02 15:10:55 +02003560static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003561{
3562 struct drm_device *dev = (struct drm_device *) arg;
3563 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003564 u32 iir, new_iir;
3565 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003566 unsigned long irqflags;
3567 int irq_received;
3568 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003569 u32 flip_mask =
3570 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3571 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003572
3573 atomic_inc(&dev_priv->irq_received);
3574
3575 iir = I915_READ(IIR);
3576
Chris Wilsona266c7d2012-04-24 22:59:44 +01003577 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003578 bool blc_event = false;
3579
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003580 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003581
3582 /* Can't rely on pipestat interrupt bit in iir as it might
3583 * have been cleared after the pipestat interrupt was received.
3584 * It doesn't set the bit in iir again, but it still produces
3585 * interrupts (for non-MSI).
3586 */
3587 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3588 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3589 i915_handle_error(dev, false);
3590
3591 for_each_pipe(pipe) {
3592 int reg = PIPESTAT(pipe);
3593 pipe_stats[pipe] = I915_READ(reg);
3594
3595 /*
3596 * Clear the PIPE*STAT regs before the IIR
3597 */
3598 if (pipe_stats[pipe] & 0x8000ffff) {
3599 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3600 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3601 pipe_name(pipe));
3602 I915_WRITE(reg, pipe_stats[pipe]);
3603 irq_received = 1;
3604 }
3605 }
3606 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3607
3608 if (!irq_received)
3609 break;
3610
3611 ret = IRQ_HANDLED;
3612
3613 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003614 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003615 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003616 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3617 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003618 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003619
3620 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3621 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003622
3623 intel_hpd_irq_handler(dev, hotplug_trigger,
3624 IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
3625
Chris Wilsona266c7d2012-04-24 22:59:44 +01003626 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3627 I915_READ(PORT_HOTPLUG_STAT);
3628 }
3629
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003630 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003631 new_iir = I915_READ(IIR); /* Flush posted writes */
3632
Chris Wilsona266c7d2012-04-24 22:59:44 +01003633 if (iir & I915_USER_INTERRUPT)
3634 notify_ring(dev, &dev_priv->ring[RCS]);
3635 if (iir & I915_BSD_USER_INTERRUPT)
3636 notify_ring(dev, &dev_priv->ring[VCS]);
3637
Chris Wilsona266c7d2012-04-24 22:59:44 +01003638 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003639 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003640 i915_handle_vblank(dev, pipe, pipe, iir))
3641 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003642
3643 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3644 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003645
3646 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003647 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003648 }
3649
3650
3651 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3652 intel_opregion_asle_intr(dev);
3653
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003654 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3655 gmbus_irq_handler(dev);
3656
Chris Wilsona266c7d2012-04-24 22:59:44 +01003657 /* With MSI, interrupts are only generated when iir
3658 * transitions from zero to nonzero. If another bit got
3659 * set while we were handling the existing iir bits, then
3660 * we would never get another interrupt.
3661 *
3662 * This is fine on non-MSI as well, as if we hit this path
3663 * we avoid exiting the interrupt handler only to generate
3664 * another one.
3665 *
3666 * Note that for MSI this could cause a stray interrupt report
3667 * if an interrupt landed in the time between writing IIR and
3668 * the posting read. This should be rare enough to never
3669 * trigger the 99% of 100,000 interrupts test for disabling
3670 * stray interrupts.
3671 */
3672 iir = new_iir;
3673 }
3674
Daniel Vetterd05c6172012-04-26 23:28:09 +02003675 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003676
Chris Wilsona266c7d2012-04-24 22:59:44 +01003677 return ret;
3678}
3679
3680static void i965_irq_uninstall(struct drm_device * dev)
3681{
3682 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3683 int pipe;
3684
3685 if (!dev_priv)
3686 return;
3687
Egbert Eichac4c16c2013-04-16 13:36:58 +02003688 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3689
Chris Wilsonadca4732012-05-11 18:01:31 +01003690 I915_WRITE(PORT_HOTPLUG_EN, 0);
3691 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003692
3693 I915_WRITE(HWSTAM, 0xffffffff);
3694 for_each_pipe(pipe)
3695 I915_WRITE(PIPESTAT(pipe), 0);
3696 I915_WRITE(IMR, 0xffffffff);
3697 I915_WRITE(IER, 0x0);
3698
3699 for_each_pipe(pipe)
3700 I915_WRITE(PIPESTAT(pipe),
3701 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3702 I915_WRITE(IIR, I915_READ(IIR));
3703}
3704
Egbert Eichac4c16c2013-04-16 13:36:58 +02003705static void i915_reenable_hotplug_timer_func(unsigned long data)
3706{
3707 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3708 struct drm_device *dev = dev_priv->dev;
3709 struct drm_mode_config *mode_config = &dev->mode_config;
3710 unsigned long irqflags;
3711 int i;
3712
3713 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3714 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3715 struct drm_connector *connector;
3716
3717 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3718 continue;
3719
3720 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3721
3722 list_for_each_entry(connector, &mode_config->connector_list, head) {
3723 struct intel_connector *intel_connector = to_intel_connector(connector);
3724
3725 if (intel_connector->encoder->hpd_pin == i) {
3726 if (connector->polled != intel_connector->polled)
3727 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3728 drm_get_connector_name(connector));
3729 connector->polled = intel_connector->polled;
3730 if (!connector->polled)
3731 connector->polled = DRM_CONNECTOR_POLL_HPD;
3732 }
3733 }
3734 }
3735 if (dev_priv->display.hpd_irq_setup)
3736 dev_priv->display.hpd_irq_setup(dev);
3737 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3738}
3739
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003740void intel_irq_init(struct drm_device *dev)
3741{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003742 struct drm_i915_private *dev_priv = dev->dev_private;
3743
3744 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003745 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003746 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003747 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003748
Daniel Vetter99584db2012-11-14 17:14:04 +01003749 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3750 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003751 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003752 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3753 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003754
Tomas Janousek97a19a22012-12-08 13:48:13 +01003755 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003756
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003757 if (IS_GEN2(dev)) {
3758 dev->max_vblank_count = 0;
3759 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3760 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003761 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3762 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003763 } else {
3764 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3765 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003766 }
3767
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003768 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003769 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003770 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3771 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003772
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003773 if (IS_VALLEYVIEW(dev)) {
3774 dev->driver->irq_handler = valleyview_irq_handler;
3775 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3776 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3777 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3778 dev->driver->enable_vblank = valleyview_enable_vblank;
3779 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003780 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003781 } else if (IS_GEN8(dev)) {
3782 dev->driver->irq_handler = gen8_irq_handler;
3783 dev->driver->irq_preinstall = gen8_irq_preinstall;
3784 dev->driver->irq_postinstall = gen8_irq_postinstall;
3785 dev->driver->irq_uninstall = gen8_irq_uninstall;
3786 dev->driver->enable_vblank = gen8_enable_vblank;
3787 dev->driver->disable_vblank = gen8_disable_vblank;
3788 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003789 } else if (HAS_PCH_SPLIT(dev)) {
3790 dev->driver->irq_handler = ironlake_irq_handler;
3791 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3792 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3793 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3794 dev->driver->enable_vblank = ironlake_enable_vblank;
3795 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003796 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003797 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003798 if (INTEL_INFO(dev)->gen == 2) {
3799 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3800 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3801 dev->driver->irq_handler = i8xx_irq_handler;
3802 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003803 } else if (INTEL_INFO(dev)->gen == 3) {
3804 dev->driver->irq_preinstall = i915_irq_preinstall;
3805 dev->driver->irq_postinstall = i915_irq_postinstall;
3806 dev->driver->irq_uninstall = i915_irq_uninstall;
3807 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003808 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003809 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003810 dev->driver->irq_preinstall = i965_irq_preinstall;
3811 dev->driver->irq_postinstall = i965_irq_postinstall;
3812 dev->driver->irq_uninstall = i965_irq_uninstall;
3813 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003814 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003815 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003816 dev->driver->enable_vblank = i915_enable_vblank;
3817 dev->driver->disable_vblank = i915_disable_vblank;
3818 }
3819}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003820
3821void intel_hpd_init(struct drm_device *dev)
3822{
3823 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003824 struct drm_mode_config *mode_config = &dev->mode_config;
3825 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003826 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003827 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003828
Egbert Eich821450c2013-04-16 13:36:55 +02003829 for (i = 1; i < HPD_NUM_PINS; i++) {
3830 dev_priv->hpd_stats[i].hpd_cnt = 0;
3831 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3832 }
3833 list_for_each_entry(connector, &mode_config->connector_list, head) {
3834 struct intel_connector *intel_connector = to_intel_connector(connector);
3835 connector->polled = intel_connector->polled;
3836 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3837 connector->polled = DRM_CONNECTOR_POLL_HPD;
3838 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003839
3840 /* Interrupt setup is already guaranteed to be single-threaded, this is
3841 * just to make the assert_spin_locked checks happy. */
3842 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003843 if (dev_priv->display.hpd_irq_setup)
3844 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003845 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003846}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003847
3848/* Disable interrupts so we can allow Package C8+. */
3849void hsw_pc8_disable_interrupts(struct drm_device *dev)
3850{
3851 struct drm_i915_private *dev_priv = dev->dev_private;
3852 unsigned long irqflags;
3853
3854 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3855
3856 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3857 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3858 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3859 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3860 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3861
3862 ironlake_disable_display_irq(dev_priv, ~DE_PCH_EVENT_IVB);
3863 ibx_disable_display_interrupt(dev_priv, ~SDE_HOTPLUG_MASK_CPT);
3864 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3865 snb_disable_pm_irq(dev_priv, 0xffffffff);
3866
3867 dev_priv->pc8.irqs_disabled = true;
3868
3869 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3870}
3871
3872/* Restore interrupts so we can recover from Package C8+. */
3873void hsw_pc8_restore_interrupts(struct drm_device *dev)
3874{
3875 struct drm_i915_private *dev_priv = dev->dev_private;
3876 unsigned long irqflags;
3877 uint32_t val, expected;
3878
3879 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3880
3881 val = I915_READ(DEIMR);
3882 expected = ~DE_PCH_EVENT_IVB;
3883 WARN(val != expected, "DEIMR is 0x%08x, not 0x%08x\n", val, expected);
3884
3885 val = I915_READ(SDEIMR) & ~SDE_HOTPLUG_MASK_CPT;
3886 expected = ~SDE_HOTPLUG_MASK_CPT;
3887 WARN(val != expected, "SDEIMR non-HPD bits are 0x%08x, not 0x%08x\n",
3888 val, expected);
3889
3890 val = I915_READ(GTIMR);
3891 expected = 0xffffffff;
3892 WARN(val != expected, "GTIMR is 0x%08x, not 0x%08x\n", val, expected);
3893
3894 val = I915_READ(GEN6_PMIMR);
3895 expected = 0xffffffff;
3896 WARN(val != expected, "GEN6_PMIMR is 0x%08x, not 0x%08x\n", val,
3897 expected);
3898
3899 dev_priv->pc8.irqs_disabled = false;
3900
3901 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
3902 ibx_enable_display_interrupt(dev_priv,
3903 ~dev_priv->pc8.regsave.sdeimr &
3904 ~SDE_HOTPLUG_MASK_CPT);
3905 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3906 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3907 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3908
3909 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3910}