blob: 72ade87a7154f71d092e203a31f16bf89223afe9 [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Egbert Eiche5868a32013-02-28 04:17:12 -050040static const u32 hpd_ibx[] = {
41 [HPD_CRT] = SDE_CRT_HOTPLUG,
42 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
43 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
44 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
45 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
46};
47
48static const u32 hpd_cpt[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010050 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050051 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
54};
55
56static const u32 hpd_mask_i915[] = {
57 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
58 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
59 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
60 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
61 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
62 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
63};
64
Daniel Vetter704cfb82013-12-18 09:08:43 +010065static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050066 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
67 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
68 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
69 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
70 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
71 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
72};
73
Egbert Eiche5868a32013-02-28 04:17:12 -050074static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
75 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
76 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
77 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
78 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
79 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
80 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
81};
82
Zhenyu Wang036a4a72009-06-08 14:40:19 +080083/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010084static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050085ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080086{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020087 assert_spin_locked(&dev_priv->irq_lock);
88
Paulo Zanonic67a4702013-08-19 13:18:09 -030089 if (dev_priv->pc8.irqs_disabled) {
90 WARN(1, "IRQs disabled\n");
91 dev_priv->pc8.regsave.deimr &= ~mask;
92 return;
93 }
94
Chris Wilson1ec14ad2010-12-04 11:30:53 +000095 if ((dev_priv->irq_mask & mask) != 0) {
96 dev_priv->irq_mask &= ~mask;
97 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000098 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080099 }
100}
101
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300102static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500103ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200105 assert_spin_locked(&dev_priv->irq_lock);
106
Paulo Zanonic67a4702013-08-19 13:18:09 -0300107 if (dev_priv->pc8.irqs_disabled) {
108 WARN(1, "IRQs disabled\n");
109 dev_priv->pc8.regsave.deimr |= mask;
110 return;
111 }
112
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000113 if ((dev_priv->irq_mask & mask) != mask) {
114 dev_priv->irq_mask |= mask;
115 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000116 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800117 }
118}
119
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300120/**
121 * ilk_update_gt_irq - update GTIMR
122 * @dev_priv: driver private
123 * @interrupt_mask: mask of interrupt bits to update
124 * @enabled_irq_mask: mask of interrupt bits to enable
125 */
126static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
127 uint32_t interrupt_mask,
128 uint32_t enabled_irq_mask)
129{
130 assert_spin_locked(&dev_priv->irq_lock);
131
Paulo Zanonic67a4702013-08-19 13:18:09 -0300132 if (dev_priv->pc8.irqs_disabled) {
133 WARN(1, "IRQs disabled\n");
134 dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
135 dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
136 interrupt_mask);
137 return;
138 }
139
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300140 dev_priv->gt_irq_mask &= ~interrupt_mask;
141 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
142 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
143 POSTING_READ(GTIMR);
144}
145
146void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
147{
148 ilk_update_gt_irq(dev_priv, mask, mask);
149}
150
151void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
152{
153 ilk_update_gt_irq(dev_priv, mask, 0);
154}
155
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300156/**
157 * snb_update_pm_irq - update GEN6_PMIMR
158 * @dev_priv: driver private
159 * @interrupt_mask: mask of interrupt bits to update
160 * @enabled_irq_mask: mask of interrupt bits to enable
161 */
162static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
163 uint32_t interrupt_mask,
164 uint32_t enabled_irq_mask)
165{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300166 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300167
168 assert_spin_locked(&dev_priv->irq_lock);
169
Paulo Zanonic67a4702013-08-19 13:18:09 -0300170 if (dev_priv->pc8.irqs_disabled) {
171 WARN(1, "IRQs disabled\n");
172 dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
173 dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
174 interrupt_mask);
175 return;
176 }
177
Paulo Zanoni605cd252013-08-06 18:57:15 -0300178 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300179 new_val &= ~interrupt_mask;
180 new_val |= (~enabled_irq_mask & interrupt_mask);
181
Paulo Zanoni605cd252013-08-06 18:57:15 -0300182 if (new_val != dev_priv->pm_irq_mask) {
183 dev_priv->pm_irq_mask = new_val;
184 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300185 POSTING_READ(GEN6_PMIMR);
186 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300187}
188
189void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
190{
191 snb_update_pm_irq(dev_priv, mask, mask);
192}
193
194void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
195{
196 snb_update_pm_irq(dev_priv, mask, 0);
197}
198
Paulo Zanoni86642812013-04-12 17:57:57 -0300199static bool ivb_can_enable_err_int(struct drm_device *dev)
200{
201 struct drm_i915_private *dev_priv = dev->dev_private;
202 struct intel_crtc *crtc;
203 enum pipe pipe;
204
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200205 assert_spin_locked(&dev_priv->irq_lock);
206
Paulo Zanoni86642812013-04-12 17:57:57 -0300207 for_each_pipe(pipe) {
208 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
209
210 if (crtc->cpu_fifo_underrun_disabled)
211 return false;
212 }
213
214 return true;
215}
216
217static bool cpt_can_enable_serr_int(struct drm_device *dev)
218{
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 enum pipe pipe;
221 struct intel_crtc *crtc;
222
Daniel Vetterfee884e2013-07-04 23:35:21 +0200223 assert_spin_locked(&dev_priv->irq_lock);
224
Paulo Zanoni86642812013-04-12 17:57:57 -0300225 for_each_pipe(pipe) {
226 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
227
228 if (crtc->pch_fifo_underrun_disabled)
229 return false;
230 }
231
232 return true;
233}
234
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200235static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
236{
237 struct drm_i915_private *dev_priv = dev->dev_private;
238 u32 reg = PIPESTAT(pipe);
239 u32 pipestat = I915_READ(reg) & 0x7fff0000;
240
241 assert_spin_locked(&dev_priv->irq_lock);
242
243 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
244 POSTING_READ(reg);
245}
246
Paulo Zanoni86642812013-04-12 17:57:57 -0300247static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
248 enum pipe pipe, bool enable)
249{
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
252 DE_PIPEB_FIFO_UNDERRUN;
253
254 if (enable)
255 ironlake_enable_display_irq(dev_priv, bit);
256 else
257 ironlake_disable_display_irq(dev_priv, bit);
258}
259
260static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200261 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300262{
263 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300264 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200265 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
266
Paulo Zanoni86642812013-04-12 17:57:57 -0300267 if (!ivb_can_enable_err_int(dev))
268 return;
269
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
271 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200272 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
273
274 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300275 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200276
277 if (!was_enabled &&
278 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
279 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
280 pipe_name(pipe));
281 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300282 }
283}
284
Daniel Vetter38d83c962013-11-07 11:05:46 +0100285static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
286 enum pipe pipe, bool enable)
287{
288 struct drm_i915_private *dev_priv = dev->dev_private;
289
290 assert_spin_locked(&dev_priv->irq_lock);
291
292 if (enable)
293 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
294 else
295 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
296 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
297 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
298}
299
Daniel Vetterfee884e2013-07-04 23:35:21 +0200300/**
301 * ibx_display_interrupt_update - update SDEIMR
302 * @dev_priv: driver private
303 * @interrupt_mask: mask of interrupt bits to update
304 * @enabled_irq_mask: mask of interrupt bits to enable
305 */
306static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
307 uint32_t interrupt_mask,
308 uint32_t enabled_irq_mask)
309{
310 uint32_t sdeimr = I915_READ(SDEIMR);
311 sdeimr &= ~interrupt_mask;
312 sdeimr |= (~enabled_irq_mask & interrupt_mask);
313
314 assert_spin_locked(&dev_priv->irq_lock);
315
Paulo Zanonic67a4702013-08-19 13:18:09 -0300316 if (dev_priv->pc8.irqs_disabled &&
317 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
318 WARN(1, "IRQs disabled\n");
319 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
320 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
321 interrupt_mask);
322 return;
323 }
324
Daniel Vetterfee884e2013-07-04 23:35:21 +0200325 I915_WRITE(SDEIMR, sdeimr);
326 POSTING_READ(SDEIMR);
327}
328#define ibx_enable_display_interrupt(dev_priv, bits) \
329 ibx_display_interrupt_update((dev_priv), (bits), (bits))
330#define ibx_disable_display_interrupt(dev_priv, bits) \
331 ibx_display_interrupt_update((dev_priv), (bits), 0)
332
Daniel Vetterde280752013-07-04 23:35:24 +0200333static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
334 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300335 bool enable)
336{
Paulo Zanoni86642812013-04-12 17:57:57 -0300337 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200338 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
339 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300340
341 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200342 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300343 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200344 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300345}
346
347static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
348 enum transcoder pch_transcoder,
349 bool enable)
350{
351 struct drm_i915_private *dev_priv = dev->dev_private;
352
353 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200354 I915_WRITE(SERR_INT,
355 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
356
Paulo Zanoni86642812013-04-12 17:57:57 -0300357 if (!cpt_can_enable_serr_int(dev))
358 return;
359
Daniel Vetterfee884e2013-07-04 23:35:21 +0200360 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300361 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200362 uint32_t tmp = I915_READ(SERR_INT);
363 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
364
365 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200366 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200367
368 if (!was_enabled &&
369 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
370 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
371 transcoder_name(pch_transcoder));
372 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300373 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300374}
375
376/**
377 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
378 * @dev: drm device
379 * @pipe: pipe
380 * @enable: true if we want to report FIFO underrun errors, false otherwise
381 *
382 * This function makes us disable or enable CPU fifo underruns for a specific
383 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
384 * reporting for one pipe may also disable all the other CPU error interruts for
385 * the other pipes, due to the fact that there's just one interrupt mask/enable
386 * bit for all the pipes.
387 *
388 * Returns the previous state of underrun reporting.
389 */
390bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
391 enum pipe pipe, bool enable)
392{
393 struct drm_i915_private *dev_priv = dev->dev_private;
394 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
395 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
396 unsigned long flags;
397 bool ret;
398
399 spin_lock_irqsave(&dev_priv->irq_lock, flags);
400
401 ret = !intel_crtc->cpu_fifo_underrun_disabled;
402
403 if (enable == ret)
404 goto done;
405
406 intel_crtc->cpu_fifo_underrun_disabled = !enable;
407
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200408 if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
409 i9xx_clear_fifo_underrun(dev, pipe);
410 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300411 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
412 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200413 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100414 else if (IS_GEN8(dev))
415 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300416
417done:
418 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
419 return ret;
420}
421
422/**
423 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
424 * @dev: drm device
425 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
426 * @enable: true if we want to report FIFO underrun errors, false otherwise
427 *
428 * This function makes us disable or enable PCH fifo underruns for a specific
429 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
430 * underrun reporting for one transcoder may also disable all the other PCH
431 * error interruts for the other transcoders, due to the fact that there's just
432 * one interrupt mask/enable bit for all the transcoders.
433 *
434 * Returns the previous state of underrun reporting.
435 */
436bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
437 enum transcoder pch_transcoder,
438 bool enable)
439{
440 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200441 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
442 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300443 unsigned long flags;
444 bool ret;
445
Daniel Vetterde280752013-07-04 23:35:24 +0200446 /*
447 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
448 * has only one pch transcoder A that all pipes can use. To avoid racy
449 * pch transcoder -> pipe lookups from interrupt code simply store the
450 * underrun statistics in crtc A. Since we never expose this anywhere
451 * nor use it outside of the fifo underrun code here using the "wrong"
452 * crtc on LPT won't cause issues.
453 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300454
455 spin_lock_irqsave(&dev_priv->irq_lock, flags);
456
457 ret = !intel_crtc->pch_fifo_underrun_disabled;
458
459 if (enable == ret)
460 goto done;
461
462 intel_crtc->pch_fifo_underrun_disabled = !enable;
463
464 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200465 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300466 else
467 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
468
469done:
470 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
471 return ret;
472}
473
474
Keith Packard7c463582008-11-04 02:03:27 -0800475void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200476i915_enable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800477{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200478 u32 reg = PIPESTAT(pipe);
479 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800480
Daniel Vetterb79480b2013-06-27 17:52:10 +0200481 assert_spin_locked(&dev_priv->irq_lock);
482
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200483 if ((pipestat & mask) == mask)
484 return;
485
486 /* Enable the interrupt, clear any pending status */
487 pipestat |= mask | (mask >> 16);
488 I915_WRITE(reg, pipestat);
489 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800490}
491
492void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200493i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800494{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200495 u32 reg = PIPESTAT(pipe);
496 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800497
Daniel Vetterb79480b2013-06-27 17:52:10 +0200498 assert_spin_locked(&dev_priv->irq_lock);
499
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200500 if ((pipestat & mask) == 0)
501 return;
502
503 pipestat &= ~mask;
504 I915_WRITE(reg, pipestat);
505 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800506}
507
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000508/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300509 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000510 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300511static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000512{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000513 drm_i915_private_t *dev_priv = dev->dev_private;
514 unsigned long irqflags;
515
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300516 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
517 return;
518
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000519 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000520
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200521 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE);
Jani Nikulaf8987802013-04-29 13:02:53 +0300522 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200523 i915_enable_pipestat(dev_priv, PIPE_A,
524 PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000525
526 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000527}
528
529/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700530 * i915_pipe_enabled - check if a pipe is enabled
531 * @dev: DRM device
532 * @pipe: pipe to check
533 *
534 * Reading certain registers when the pipe is disabled can hang the chip.
535 * Use this routine to make sure the PLL is running and the pipe is active
536 * before reading such registers if unsure.
537 */
538static int
539i915_pipe_enabled(struct drm_device *dev, int pipe)
540{
541 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200542
Daniel Vettera01025a2013-05-22 00:50:23 +0200543 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
544 /* Locking is horribly broken here, but whatever. */
545 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
546 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300547
Daniel Vettera01025a2013-05-22 00:50:23 +0200548 return intel_crtc->active;
549 } else {
550 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
551 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700552}
553
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300554static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
555{
556 /* Gen2 doesn't have a hardware frame counter */
557 return 0;
558}
559
Keith Packard42f52ef2008-10-18 19:39:29 -0700560/* Called from drm generic code, passed a 'crtc', which
561 * we use as a pipe index
562 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700563static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700564{
565 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
566 unsigned long high_frame;
567 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300568 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700569
570 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800571 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800572 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700573 return 0;
574 }
575
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300576 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
577 struct intel_crtc *intel_crtc =
578 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
579 const struct drm_display_mode *mode =
580 &intel_crtc->config.adjusted_mode;
581
582 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
583 } else {
584 enum transcoder cpu_transcoder =
585 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
586 u32 htotal;
587
588 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
589 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
590
591 vbl_start *= htotal;
592 }
593
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800594 high_frame = PIPEFRAME(pipe);
595 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100596
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700597 /*
598 * High & low register fields aren't synchronized, so make sure
599 * we get a low value that's stable across two reads of the high
600 * register.
601 */
602 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100603 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300604 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100605 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700606 } while (high1 != high2);
607
Chris Wilson5eddb702010-09-11 13:48:45 +0100608 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300609 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100610 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300611
612 /*
613 * The frame counter increments at beginning of active.
614 * Cook up a vblank counter by also checking the pixel
615 * counter against vblank start.
616 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200617 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700618}
619
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700620static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800621{
622 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800623 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800624
625 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800626 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800627 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800628 return 0;
629 }
630
631 return I915_READ(reg);
632}
633
Mario Kleinerad3543e2013-10-30 05:13:08 +0100634/* raw reads, only for fast reads of display block, no need for forcewake etc. */
635#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
636#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
637
Ville Syrjälä095163b2013-10-29 00:04:43 +0200638static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300639{
640 struct drm_i915_private *dev_priv = dev->dev_private;
641 uint32_t status;
642
Ville Syrjälä095163b2013-10-29 00:04:43 +0200643 if (INTEL_INFO(dev)->gen < 7) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300644 status = pipe == PIPE_A ?
645 DE_PIPEA_VBLANK :
646 DE_PIPEB_VBLANK;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300647 } else {
648 switch (pipe) {
649 default:
650 case PIPE_A:
651 status = DE_PIPEA_VBLANK_IVB;
652 break;
653 case PIPE_B:
654 status = DE_PIPEB_VBLANK_IVB;
655 break;
656 case PIPE_C:
657 status = DE_PIPEC_VBLANK_IVB;
658 break;
659 }
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300660 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100661
Ville Syrjälä095163b2013-10-29 00:04:43 +0200662 return __raw_i915_read32(dev_priv, DEISR) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300663}
664
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700665static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200666 unsigned int flags, int *vpos, int *hpos,
667 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100668{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300669 struct drm_i915_private *dev_priv = dev->dev_private;
670 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
671 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
672 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300673 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100674 int vbl_start, vbl_end, htotal, vtotal;
675 bool in_vbl = true;
676 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100677 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100678
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äd31faf62013-10-28 16:31:41 +0200690 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
691 vbl_start = DIV_ROUND_UP(vbl_start, 2);
692 vbl_end /= 2;
693 vtotal /= 2;
694 }
695
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300696 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
697
Mario Kleinerad3543e2013-10-30 05:13:08 +0100698 /*
699 * Lock uncore.lock, as we will do multiple timing critical raw
700 * register reads, potentially with preemption disabled, so the
701 * following code must not block on uncore.lock.
702 */
703 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
704
705 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
706
707 /* Get optional system timestamp before query. */
708 if (stime)
709 *stime = ktime_get();
710
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300711 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100712 /* No obvious pixelcount register. Only query vertical
713 * scanout position from Display scan line register.
714 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300715 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100716 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300717 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100718 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300719
Ville Syrjälä095163b2013-10-29 00:04:43 +0200720 if (HAS_PCH_SPLIT(dev)) {
721 /*
722 * The scanline counter increments at the leading edge
723 * of hsync, ie. it completely misses the active portion
724 * of the line. Fix up the counter at both edges of vblank
725 * to get a more accurate picture whether we're in vblank
726 * or not.
727 */
728 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
729 if ((in_vbl && position == vbl_start - 1) ||
730 (!in_vbl && position == vbl_end - 1))
731 position = (position + 1) % vtotal;
732 } else {
733 /*
734 * ISR vblank status bits don't work the way we'd want
735 * them to work on non-PCH platforms (for
736 * ilk_pipe_in_vblank_locked()), and there doesn't
737 * appear any other way to determine if we're currently
738 * in vblank.
739 *
740 * Instead let's assume that we're already in vblank if
741 * we got called from the vblank interrupt and the
742 * scanline counter value indicates that we're on the
743 * line just prior to vblank start. This should result
744 * in the correct answer, unless the vblank interrupt
745 * delivery really got delayed for almost exactly one
746 * full frame/field.
747 */
748 if (flags & DRM_CALLED_FROM_VBLIRQ &&
749 position == vbl_start - 1) {
750 position = (position + 1) % vtotal;
751
752 /* Signal this correction as "applied". */
753 ret |= 0x8;
754 }
755 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100756 } else {
757 /* Have access to pixelcount since start of frame.
758 * We can split this into vertical and horizontal
759 * scanout position.
760 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100761 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100762
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300763 /* convert to pixel counts */
764 vbl_start *= htotal;
765 vbl_end *= htotal;
766 vtotal *= htotal;
767 }
768
Mario Kleinerad3543e2013-10-30 05:13:08 +0100769 /* Get optional system timestamp after query. */
770 if (etime)
771 *etime = ktime_get();
772
773 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
774
775 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
776
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300777 in_vbl = position >= vbl_start && position < vbl_end;
778
779 /*
780 * While in vblank, position will be negative
781 * counting up towards 0 at vbl_end. And outside
782 * vblank, position will be positive counting
783 * up since vbl_end.
784 */
785 if (position >= vbl_start)
786 position -= vbl_end;
787 else
788 position += vtotal - vbl_end;
789
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300790 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300791 *vpos = position;
792 *hpos = 0;
793 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100794 *vpos = position / htotal;
795 *hpos = position - (*vpos * htotal);
796 }
797
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100798 /* In vblank? */
799 if (in_vbl)
800 ret |= DRM_SCANOUTPOS_INVBL;
801
802 return ret;
803}
804
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700805static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100806 int *max_error,
807 struct timeval *vblank_time,
808 unsigned flags)
809{
Chris Wilson4041b852011-01-22 10:07:56 +0000810 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100811
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700812 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000813 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100814 return -EINVAL;
815 }
816
817 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000818 crtc = intel_get_crtc_for_pipe(dev, pipe);
819 if (crtc == NULL) {
820 DRM_ERROR("Invalid crtc %d\n", pipe);
821 return -EINVAL;
822 }
823
824 if (!crtc->enabled) {
825 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
826 return -EBUSY;
827 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100828
829 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000830 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
831 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300832 crtc,
833 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100834}
835
Jani Nikula67c347f2013-09-17 14:26:34 +0300836static bool intel_hpd_irq_event(struct drm_device *dev,
837 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200838{
839 enum drm_connector_status old_status;
840
841 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
842 old_status = connector->status;
843
844 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300845 if (old_status == connector->status)
846 return false;
847
848 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200849 connector->base.id,
850 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300851 drm_get_connector_status_name(old_status),
852 drm_get_connector_status_name(connector->status));
853
854 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200855}
856
Jesse Barnes5ca58282009-03-31 14:11:15 -0700857/*
858 * Handle hotplug events outside the interrupt handler proper.
859 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200860#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
861
Jesse Barnes5ca58282009-03-31 14:11:15 -0700862static void i915_hotplug_work_func(struct work_struct *work)
863{
864 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
865 hotplug_work);
866 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700867 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200868 struct intel_connector *intel_connector;
869 struct intel_encoder *intel_encoder;
870 struct drm_connector *connector;
871 unsigned long irqflags;
872 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200873 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200874 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700875
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100876 /* HPD irq before everything is fully set up. */
877 if (!dev_priv->enable_hotplug_processing)
878 return;
879
Keith Packarda65e34c2011-07-25 10:04:56 -0700880 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800881 DRM_DEBUG_KMS("running encoder hotplug functions\n");
882
Egbert Eichcd569ae2013-04-16 13:36:57 +0200883 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200884
885 hpd_event_bits = dev_priv->hpd_event_bits;
886 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200887 list_for_each_entry(connector, &mode_config->connector_list, head) {
888 intel_connector = to_intel_connector(connector);
889 intel_encoder = intel_connector->encoder;
890 if (intel_encoder->hpd_pin > HPD_NONE &&
891 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
892 connector->polled == DRM_CONNECTOR_POLL_HPD) {
893 DRM_INFO("HPD interrupt storm detected on connector %s: "
894 "switching from hotplug detection to polling\n",
895 drm_get_connector_name(connector));
896 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
897 connector->polled = DRM_CONNECTOR_POLL_CONNECT
898 | DRM_CONNECTOR_POLL_DISCONNECT;
899 hpd_disabled = true;
900 }
Egbert Eich142e2392013-04-11 15:57:57 +0200901 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
902 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
903 drm_get_connector_name(connector), intel_encoder->hpd_pin);
904 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200905 }
906 /* if there were no outputs to poll, poll was disabled,
907 * therefore make sure it's enabled when disabling HPD on
908 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200909 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200910 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200911 mod_timer(&dev_priv->hotplug_reenable_timer,
912 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
913 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200914
915 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
916
Egbert Eich321a1b32013-04-11 16:00:26 +0200917 list_for_each_entry(connector, &mode_config->connector_list, head) {
918 intel_connector = to_intel_connector(connector);
919 intel_encoder = intel_connector->encoder;
920 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
921 if (intel_encoder->hot_plug)
922 intel_encoder->hot_plug(intel_encoder);
923 if (intel_hpd_irq_event(dev, connector))
924 changed = true;
925 }
926 }
Keith Packard40ee3382011-07-28 15:31:19 -0700927 mutex_unlock(&mode_config->mutex);
928
Egbert Eich321a1b32013-04-11 16:00:26 +0200929 if (changed)
930 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700931}
932
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +0200933static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
934{
935 del_timer_sync(&dev_priv->hotplug_reenable_timer);
936}
937
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200938static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800939{
940 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000941 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200942 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200943
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200944 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800945
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200946 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
947
Daniel Vetter20e4d402012-08-08 23:35:39 +0200948 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200949
Jesse Barnes7648fa92010-05-20 14:28:11 -0700950 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000951 busy_up = I915_READ(RCPREVBSYTUPAVG);
952 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800953 max_avg = I915_READ(RCBMAXAVG);
954 min_avg = I915_READ(RCBMINAVG);
955
956 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000957 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200958 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
959 new_delay = dev_priv->ips.cur_delay - 1;
960 if (new_delay < dev_priv->ips.max_delay)
961 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000962 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200963 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
964 new_delay = dev_priv->ips.cur_delay + 1;
965 if (new_delay > dev_priv->ips.min_delay)
966 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800967 }
968
Jesse Barnes7648fa92010-05-20 14:28:11 -0700969 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200970 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800971
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200972 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200973
Jesse Barnesf97108d2010-01-29 11:27:07 -0800974 return;
975}
976
Chris Wilson549f7362010-10-19 11:19:32 +0100977static void notify_ring(struct drm_device *dev,
978 struct intel_ring_buffer *ring)
979{
Chris Wilson475553d2011-01-20 09:52:56 +0000980 if (ring->obj == NULL)
981 return;
982
Chris Wilson814e9b52013-09-23 17:33:19 -0300983 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000984
Chris Wilson549f7362010-10-19 11:19:32 +0100985 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300986 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100987}
988
Ben Widawsky4912d042011-04-25 11:25:20 -0700989static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800990{
Ben Widawsky4912d042011-04-25 11:25:20 -0700991 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200992 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300993 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100994 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800995
Daniel Vetter59cdb632013-07-04 23:35:28 +0200996 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200997 pm_iir = dev_priv->rps.pm_iir;
998 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -0700999 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001000 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001001 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001002
Paulo Zanoni60611c12013-08-15 11:50:01 -03001003 /* Make sure we didn't queue anything we're not going to process. */
1004 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
1005
Ben Widawsky48484052013-05-28 19:22:27 -07001006 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001007 return;
1008
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001009 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001010
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001011 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001012 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001013 if (adj > 0)
1014 adj *= 2;
1015 else
1016 adj = 1;
1017 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001018
1019 /*
1020 * For better performance, jump directly
1021 * to RPe if we're below it.
1022 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001023 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +03001024 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001025 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1026 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
1027 new_delay = dev_priv->rps.rpe_delay;
1028 else
1029 new_delay = dev_priv->rps.min_delay;
1030 adj = 0;
1031 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1032 if (adj < 0)
1033 adj *= 2;
1034 else
1035 adj = -1;
1036 new_delay = dev_priv->rps.cur_delay + adj;
1037 } else { /* unknown event */
1038 new_delay = dev_priv->rps.cur_delay;
1039 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001040
Ben Widawsky79249632012-09-07 19:43:42 -07001041 /* sysfs frequency interfaces may have snuck in while servicing the
1042 * interrupt
1043 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001044 new_delay = clamp_t(int, new_delay,
1045 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001046 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
1047
1048 if (IS_VALLEYVIEW(dev_priv->dev))
1049 valleyview_set_rps(dev_priv->dev, new_delay);
1050 else
1051 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001052
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001053 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001054}
1055
Ben Widawskye3689192012-05-25 16:56:22 -07001056
1057/**
1058 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1059 * occurred.
1060 * @work: workqueue struct
1061 *
1062 * Doesn't actually do anything except notify userspace. As a consequence of
1063 * this event, userspace should try to remap the bad rows since statistically
1064 * it is likely the same row is more likely to go bad again.
1065 */
1066static void ivybridge_parity_work(struct work_struct *work)
1067{
1068 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001069 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001070 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001071 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001072 uint32_t misccpctl;
1073 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001074 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001075
1076 /* We must turn off DOP level clock gating to access the L3 registers.
1077 * In order to prevent a get/put style interface, acquire struct mutex
1078 * any time we access those registers.
1079 */
1080 mutex_lock(&dev_priv->dev->struct_mutex);
1081
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001082 /* If we've screwed up tracking, just let the interrupt fire again */
1083 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1084 goto out;
1085
Ben Widawskye3689192012-05-25 16:56:22 -07001086 misccpctl = I915_READ(GEN7_MISCCPCTL);
1087 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1088 POSTING_READ(GEN7_MISCCPCTL);
1089
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001090 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1091 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001092
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001093 slice--;
1094 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1095 break;
1096
1097 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1098
1099 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1100
1101 error_status = I915_READ(reg);
1102 row = GEN7_PARITY_ERROR_ROW(error_status);
1103 bank = GEN7_PARITY_ERROR_BANK(error_status);
1104 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1105
1106 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1107 POSTING_READ(reg);
1108
1109 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1110 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1111 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1112 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1113 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1114 parity_event[5] = NULL;
1115
Dave Airlie5bdebb12013-10-11 14:07:25 +10001116 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001117 KOBJ_CHANGE, parity_event);
1118
1119 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1120 slice, row, bank, subbank);
1121
1122 kfree(parity_event[4]);
1123 kfree(parity_event[3]);
1124 kfree(parity_event[2]);
1125 kfree(parity_event[1]);
1126 }
Ben Widawskye3689192012-05-25 16:56:22 -07001127
1128 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1129
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001130out:
1131 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001132 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001133 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001134 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1135
1136 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001137}
1138
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001139static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001140{
1141 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001142
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001143 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001144 return;
1145
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001146 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001147 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001148 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001149
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001150 iir &= GT_PARITY_ERROR(dev);
1151 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1152 dev_priv->l3_parity.which_slice |= 1 << 1;
1153
1154 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1155 dev_priv->l3_parity.which_slice |= 1 << 0;
1156
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001157 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001158}
1159
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001160static void ilk_gt_irq_handler(struct drm_device *dev,
1161 struct drm_i915_private *dev_priv,
1162 u32 gt_iir)
1163{
1164 if (gt_iir &
1165 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1166 notify_ring(dev, &dev_priv->ring[RCS]);
1167 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1168 notify_ring(dev, &dev_priv->ring[VCS]);
1169}
1170
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001171static void snb_gt_irq_handler(struct drm_device *dev,
1172 struct drm_i915_private *dev_priv,
1173 u32 gt_iir)
1174{
1175
Ben Widawskycc609d52013-05-28 19:22:29 -07001176 if (gt_iir &
1177 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001178 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001179 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001180 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001181 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001182 notify_ring(dev, &dev_priv->ring[BCS]);
1183
Ben Widawskycc609d52013-05-28 19:22:29 -07001184 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1185 GT_BSD_CS_ERROR_INTERRUPT |
1186 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001187 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1188 i915_handle_error(dev, false);
1189 }
Ben Widawskye3689192012-05-25 16:56:22 -07001190
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001191 if (gt_iir & GT_PARITY_ERROR(dev))
1192 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001193}
1194
Ben Widawskyabd58f02013-11-02 21:07:09 -07001195static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1196 struct drm_i915_private *dev_priv,
1197 u32 master_ctl)
1198{
1199 u32 rcs, bcs, vcs;
1200 uint32_t tmp = 0;
1201 irqreturn_t ret = IRQ_NONE;
1202
1203 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1204 tmp = I915_READ(GEN8_GT_IIR(0));
1205 if (tmp) {
1206 ret = IRQ_HANDLED;
1207 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1208 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1209 if (rcs & GT_RENDER_USER_INTERRUPT)
1210 notify_ring(dev, &dev_priv->ring[RCS]);
1211 if (bcs & GT_RENDER_USER_INTERRUPT)
1212 notify_ring(dev, &dev_priv->ring[BCS]);
1213 I915_WRITE(GEN8_GT_IIR(0), tmp);
1214 } else
1215 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1216 }
1217
1218 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1219 tmp = I915_READ(GEN8_GT_IIR(1));
1220 if (tmp) {
1221 ret = IRQ_HANDLED;
1222 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1223 if (vcs & GT_RENDER_USER_INTERRUPT)
1224 notify_ring(dev, &dev_priv->ring[VCS]);
1225 I915_WRITE(GEN8_GT_IIR(1), tmp);
1226 } else
1227 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1228 }
1229
1230 if (master_ctl & GEN8_GT_VECS_IRQ) {
1231 tmp = I915_READ(GEN8_GT_IIR(3));
1232 if (tmp) {
1233 ret = IRQ_HANDLED;
1234 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1235 if (vcs & GT_RENDER_USER_INTERRUPT)
1236 notify_ring(dev, &dev_priv->ring[VECS]);
1237 I915_WRITE(GEN8_GT_IIR(3), tmp);
1238 } else
1239 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1240 }
1241
1242 return ret;
1243}
1244
Egbert Eichb543fb02013-04-16 13:36:54 +02001245#define HPD_STORM_DETECT_PERIOD 1000
1246#define HPD_STORM_THRESHOLD 5
1247
Daniel Vetter10a504d2013-06-27 17:52:12 +02001248static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001249 u32 hotplug_trigger,
1250 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001251{
1252 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001253 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001254 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001255
Daniel Vetter91d131d2013-06-27 17:52:14 +02001256 if (!hotplug_trigger)
1257 return;
1258
Imre Deakcc9bd492014-01-16 19:56:54 +02001259 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1260 hotplug_trigger);
1261
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001262 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001263 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001264
Chris Wilson34320872014-01-10 18:49:20 +00001265 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001266 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001267 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1268 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001269
Egbert Eichb543fb02013-04-16 13:36:54 +02001270 if (!(hpd[i] & hotplug_trigger) ||
1271 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1272 continue;
1273
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001274 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001275 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1276 dev_priv->hpd_stats[i].hpd_last_jiffies
1277 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1278 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1279 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001280 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001281 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1282 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001283 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001284 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001285 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001286 } else {
1287 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001288 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1289 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001290 }
1291 }
1292
Daniel Vetter10a504d2013-06-27 17:52:12 +02001293 if (storm_detected)
1294 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001295 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001296
Daniel Vetter645416f2013-09-02 16:22:25 +02001297 /*
1298 * Our hotplug handler can grab modeset locks (by calling down into the
1299 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1300 * queue for otherwise the flush_work in the pageflip code will
1301 * deadlock.
1302 */
1303 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001304}
1305
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001306static void gmbus_irq_handler(struct drm_device *dev)
1307{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001308 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1309
Daniel Vetter28c70f12012-12-01 13:53:45 +01001310 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001311}
1312
Daniel Vetterce99c252012-12-01 13:53:47 +01001313static void dp_aux_irq_handler(struct drm_device *dev)
1314{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001315 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1316
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001317 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001318}
1319
Shuang He8bf1e9f2013-10-15 18:55:27 +01001320#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001321static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1322 uint32_t crc0, uint32_t crc1,
1323 uint32_t crc2, uint32_t crc3,
1324 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001325{
1326 struct drm_i915_private *dev_priv = dev->dev_private;
1327 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1328 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001329 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001330
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001331 spin_lock(&pipe_crc->lock);
1332
Damien Lespiau0c912c72013-10-15 18:55:37 +01001333 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001334 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001335 DRM_ERROR("spurious interrupt\n");
1336 return;
1337 }
1338
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001339 head = pipe_crc->head;
1340 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001341
1342 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001343 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001344 DRM_ERROR("CRC buffer overflowing\n");
1345 return;
1346 }
1347
1348 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001349
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001350 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001351 entry->crc[0] = crc0;
1352 entry->crc[1] = crc1;
1353 entry->crc[2] = crc2;
1354 entry->crc[3] = crc3;
1355 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001356
1357 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001358 pipe_crc->head = head;
1359
1360 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001361
1362 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001363}
Daniel Vetter277de952013-10-18 16:37:07 +02001364#else
1365static inline void
1366display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1367 uint32_t crc0, uint32_t crc1,
1368 uint32_t crc2, uint32_t crc3,
1369 uint32_t crc4) {}
1370#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001371
Daniel Vetter277de952013-10-18 16:37:07 +02001372
1373static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001374{
1375 struct drm_i915_private *dev_priv = dev->dev_private;
1376
Daniel Vetter277de952013-10-18 16:37:07 +02001377 display_pipe_crc_irq_handler(dev, pipe,
1378 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1379 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001380}
1381
Daniel Vetter277de952013-10-18 16:37:07 +02001382static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001383{
1384 struct drm_i915_private *dev_priv = dev->dev_private;
1385
Daniel Vetter277de952013-10-18 16:37:07 +02001386 display_pipe_crc_irq_handler(dev, pipe,
1387 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1388 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1389 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1390 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1391 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001392}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001393
Daniel Vetter277de952013-10-18 16:37:07 +02001394static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001395{
1396 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001397 uint32_t res1, res2;
1398
1399 if (INTEL_INFO(dev)->gen >= 3)
1400 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1401 else
1402 res1 = 0;
1403
1404 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1405 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1406 else
1407 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001408
Daniel Vetter277de952013-10-18 16:37:07 +02001409 display_pipe_crc_irq_handler(dev, pipe,
1410 I915_READ(PIPE_CRC_RES_RED(pipe)),
1411 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1412 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1413 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001414}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001415
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001416/* The RPS events need forcewake, so we add them to a work queue and mask their
1417 * IMR bits until the work is done. Other interrupts can be processed without
1418 * the work queue. */
1419static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001420{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001421 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001422 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001423 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001424 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001425 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001426
1427 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001428 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001429
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001430 if (HAS_VEBOX(dev_priv->dev)) {
1431 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1432 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001433
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001434 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1435 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1436 i915_handle_error(dev_priv->dev, false);
1437 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001438 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001439}
1440
Daniel Vetterff1f5252012-10-02 15:10:55 +02001441static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001442{
1443 struct drm_device *dev = (struct drm_device *) arg;
1444 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1445 u32 iir, gt_iir, pm_iir;
1446 irqreturn_t ret = IRQ_NONE;
1447 unsigned long irqflags;
1448 int pipe;
1449 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001450
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001451 while (true) {
1452 iir = I915_READ(VLV_IIR);
1453 gt_iir = I915_READ(GTIIR);
1454 pm_iir = I915_READ(GEN6_PMIIR);
1455
1456 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1457 goto out;
1458
1459 ret = IRQ_HANDLED;
1460
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001461 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001462
1463 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1464 for_each_pipe(pipe) {
1465 int reg = PIPESTAT(pipe);
1466 pipe_stats[pipe] = I915_READ(reg);
1467
1468 /*
1469 * Clear the PIPE*STAT regs before the IIR
1470 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02001471 if (pipe_stats[pipe] & 0x8000ffff)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001472 I915_WRITE(reg, pipe_stats[pipe]);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001473 }
1474 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1475
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001476 for_each_pipe(pipe) {
Jesse Barnes7b5562d2013-11-05 15:48:01 -08001477 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001478 drm_handle_vblank(dev, pipe);
1479
1480 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1481 intel_prepare_page_flip(dev, pipe);
1482 intel_finish_page_flip(dev, pipe);
1483 }
Daniel Vetter4356d582013-10-16 22:55:55 +02001484
1485 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02001486 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02001487
1488 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1489 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001490 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001491 }
1492
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001493 /* Consume port. Then clear IIR or we'll miss events */
1494 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1495 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001496 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001497
Daniel Vetter91d131d2013-06-27 17:52:14 +02001498 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1499
Daniel Vetter4aeebd72013-10-31 09:53:36 +01001500 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1501 dp_aux_irq_handler(dev);
1502
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001503 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1504 I915_READ(PORT_HOTPLUG_STAT);
1505 }
1506
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001507 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1508 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001509
Paulo Zanoni60611c12013-08-15 11:50:01 -03001510 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001511 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001512
1513 I915_WRITE(GTIIR, gt_iir);
1514 I915_WRITE(GEN6_PMIIR, pm_iir);
1515 I915_WRITE(VLV_IIR, iir);
1516 }
1517
1518out:
1519 return ret;
1520}
1521
Adam Jackson23e81d62012-06-06 15:45:44 -04001522static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001523{
1524 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001525 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001526 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001527
Daniel Vetter91d131d2013-06-27 17:52:14 +02001528 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1529
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001530 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1531 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1532 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001533 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001534 port_name(port));
1535 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001536
Daniel Vetterce99c252012-12-01 13:53:47 +01001537 if (pch_iir & SDE_AUX_MASK)
1538 dp_aux_irq_handler(dev);
1539
Jesse Barnes776ad802011-01-04 15:09:39 -08001540 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001541 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001542
1543 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1544 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1545
1546 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1547 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1548
1549 if (pch_iir & SDE_POISON)
1550 DRM_ERROR("PCH poison interrupt\n");
1551
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001552 if (pch_iir & SDE_FDI_MASK)
1553 for_each_pipe(pipe)
1554 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1555 pipe_name(pipe),
1556 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001557
1558 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1559 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1560
1561 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1562 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1563
Jesse Barnes776ad802011-01-04 15:09:39 -08001564 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001565 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1566 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001567 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001568
1569 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1570 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1571 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001572 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001573}
1574
1575static void ivb_err_int_handler(struct drm_device *dev)
1576{
1577 struct drm_i915_private *dev_priv = dev->dev_private;
1578 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001579 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001580
Paulo Zanonide032bf2013-04-12 17:57:58 -03001581 if (err_int & ERR_INT_POISON)
1582 DRM_ERROR("Poison interrupt\n");
1583
Daniel Vetter5a69b892013-10-16 22:55:52 +02001584 for_each_pipe(pipe) {
1585 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1586 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1587 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001588 DRM_ERROR("Pipe %c FIFO underrun\n",
1589 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001590 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001591
Daniel Vetter5a69b892013-10-16 22:55:52 +02001592 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1593 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001594 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001595 else
Daniel Vetter277de952013-10-18 16:37:07 +02001596 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001597 }
1598 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001599
Paulo Zanoni86642812013-04-12 17:57:57 -03001600 I915_WRITE(GEN7_ERR_INT, err_int);
1601}
1602
1603static void cpt_serr_int_handler(struct drm_device *dev)
1604{
1605 struct drm_i915_private *dev_priv = dev->dev_private;
1606 u32 serr_int = I915_READ(SERR_INT);
1607
Paulo Zanonide032bf2013-04-12 17:57:58 -03001608 if (serr_int & SERR_INT_POISON)
1609 DRM_ERROR("PCH poison interrupt\n");
1610
Paulo Zanoni86642812013-04-12 17:57:57 -03001611 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1612 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1613 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001614 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001615
1616 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1617 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1618 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001619 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001620
1621 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1622 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1623 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001624 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001625
1626 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001627}
1628
Adam Jackson23e81d62012-06-06 15:45:44 -04001629static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1630{
1631 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1632 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001633 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001634
Daniel Vetter91d131d2013-06-27 17:52:14 +02001635 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1636
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001637 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1638 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1639 SDE_AUDIO_POWER_SHIFT_CPT);
1640 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1641 port_name(port));
1642 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001643
1644 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001645 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001646
1647 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001648 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001649
1650 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1651 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1652
1653 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1654 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1655
1656 if (pch_iir & SDE_FDI_MASK_CPT)
1657 for_each_pipe(pipe)
1658 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1659 pipe_name(pipe),
1660 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001661
1662 if (pch_iir & SDE_ERROR_CPT)
1663 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001664}
1665
Paulo Zanonic008bc62013-07-12 16:35:10 -03001666static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1667{
1668 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001669 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001670
1671 if (de_iir & DE_AUX_CHANNEL_A)
1672 dp_aux_irq_handler(dev);
1673
1674 if (de_iir & DE_GSE)
1675 intel_opregion_asle_intr(dev);
1676
Paulo Zanonic008bc62013-07-12 16:35:10 -03001677 if (de_iir & DE_POISON)
1678 DRM_ERROR("Poison interrupt\n");
1679
Daniel Vetter40da17c2013-10-21 18:04:36 +02001680 for_each_pipe(pipe) {
1681 if (de_iir & DE_PIPE_VBLANK(pipe))
1682 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001683
Daniel Vetter40da17c2013-10-21 18:04:36 +02001684 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1685 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001686 DRM_ERROR("Pipe %c FIFO underrun\n",
1687 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001688
Daniel Vetter40da17c2013-10-21 18:04:36 +02001689 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1690 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001691
Daniel Vetter40da17c2013-10-21 18:04:36 +02001692 /* plane/pipes map 1:1 on ilk+ */
1693 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1694 intel_prepare_page_flip(dev, pipe);
1695 intel_finish_page_flip_plane(dev, pipe);
1696 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001697 }
1698
1699 /* check event from PCH */
1700 if (de_iir & DE_PCH_EVENT) {
1701 u32 pch_iir = I915_READ(SDEIIR);
1702
1703 if (HAS_PCH_CPT(dev))
1704 cpt_irq_handler(dev, pch_iir);
1705 else
1706 ibx_irq_handler(dev, pch_iir);
1707
1708 /* should clear PCH hotplug event before clear CPU irq */
1709 I915_WRITE(SDEIIR, pch_iir);
1710 }
1711
1712 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1713 ironlake_rps_change_irq_handler(dev);
1714}
1715
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001716static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1717{
1718 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001719 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001720
1721 if (de_iir & DE_ERR_INT_IVB)
1722 ivb_err_int_handler(dev);
1723
1724 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1725 dp_aux_irq_handler(dev);
1726
1727 if (de_iir & DE_GSE_IVB)
1728 intel_opregion_asle_intr(dev);
1729
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001730 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001731 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001732 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001733
1734 /* plane/pipes map 1:1 on ilk+ */
1735 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001736 intel_prepare_page_flip(dev, i);
1737 intel_finish_page_flip_plane(dev, i);
1738 }
1739 }
1740
1741 /* check event from PCH */
1742 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1743 u32 pch_iir = I915_READ(SDEIIR);
1744
1745 cpt_irq_handler(dev, pch_iir);
1746
1747 /* clear PCH hotplug event before clear CPU irq */
1748 I915_WRITE(SDEIIR, pch_iir);
1749 }
1750}
1751
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001752static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001753{
1754 struct drm_device *dev = (struct drm_device *) arg;
1755 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001756 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001757 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001758
Paulo Zanoni86642812013-04-12 17:57:57 -03001759 /* We get interrupts on unclaimed registers, so check for this before we
1760 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001761 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001762
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001763 /* disable master interrupt before clearing iir */
1764 de_ier = I915_READ(DEIER);
1765 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001766 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001767
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001768 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1769 * interrupts will will be stored on its back queue, and then we'll be
1770 * able to process them after we restore SDEIER (as soon as we restore
1771 * it, we'll get an interrupt if SDEIIR still has something to process
1772 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001773 if (!HAS_PCH_NOP(dev)) {
1774 sde_ier = I915_READ(SDEIER);
1775 I915_WRITE(SDEIER, 0);
1776 POSTING_READ(SDEIER);
1777 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001778
Chris Wilson0e434062012-05-09 21:45:44 +01001779 gt_iir = I915_READ(GTIIR);
1780 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001781 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001782 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001783 else
1784 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001785 I915_WRITE(GTIIR, gt_iir);
1786 ret = IRQ_HANDLED;
1787 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001788
1789 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001790 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001791 if (INTEL_INFO(dev)->gen >= 7)
1792 ivb_display_irq_handler(dev, de_iir);
1793 else
1794 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001795 I915_WRITE(DEIIR, de_iir);
1796 ret = IRQ_HANDLED;
1797 }
1798
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001799 if (INTEL_INFO(dev)->gen >= 6) {
1800 u32 pm_iir = I915_READ(GEN6_PMIIR);
1801 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001802 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001803 I915_WRITE(GEN6_PMIIR, pm_iir);
1804 ret = IRQ_HANDLED;
1805 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001806 }
1807
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001808 I915_WRITE(DEIER, de_ier);
1809 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001810 if (!HAS_PCH_NOP(dev)) {
1811 I915_WRITE(SDEIER, sde_ier);
1812 POSTING_READ(SDEIER);
1813 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001814
1815 return ret;
1816}
1817
Ben Widawskyabd58f02013-11-02 21:07:09 -07001818static irqreturn_t gen8_irq_handler(int irq, void *arg)
1819{
1820 struct drm_device *dev = arg;
1821 struct drm_i915_private *dev_priv = dev->dev_private;
1822 u32 master_ctl;
1823 irqreturn_t ret = IRQ_NONE;
1824 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001825 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001826
Ben Widawskyabd58f02013-11-02 21:07:09 -07001827 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1828 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1829 if (!master_ctl)
1830 return IRQ_NONE;
1831
1832 I915_WRITE(GEN8_MASTER_IRQ, 0);
1833 POSTING_READ(GEN8_MASTER_IRQ);
1834
1835 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1836
1837 if (master_ctl & GEN8_DE_MISC_IRQ) {
1838 tmp = I915_READ(GEN8_DE_MISC_IIR);
1839 if (tmp & GEN8_DE_MISC_GSE)
1840 intel_opregion_asle_intr(dev);
1841 else if (tmp)
1842 DRM_ERROR("Unexpected DE Misc interrupt\n");
1843 else
1844 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1845
1846 if (tmp) {
1847 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1848 ret = IRQ_HANDLED;
1849 }
1850 }
1851
Daniel Vetter6d766f02013-11-07 14:49:55 +01001852 if (master_ctl & GEN8_DE_PORT_IRQ) {
1853 tmp = I915_READ(GEN8_DE_PORT_IIR);
1854 if (tmp & GEN8_AUX_CHANNEL_A)
1855 dp_aux_irq_handler(dev);
1856 else if (tmp)
1857 DRM_ERROR("Unexpected DE Port interrupt\n");
1858 else
1859 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1860
1861 if (tmp) {
1862 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1863 ret = IRQ_HANDLED;
1864 }
1865 }
1866
Daniel Vetterc42664c2013-11-07 11:05:40 +01001867 for_each_pipe(pipe) {
1868 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001869
Daniel Vetterc42664c2013-11-07 11:05:40 +01001870 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1871 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001872
Daniel Vetterc42664c2013-11-07 11:05:40 +01001873 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1874 if (pipe_iir & GEN8_PIPE_VBLANK)
1875 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001876
Daniel Vetterc42664c2013-11-07 11:05:40 +01001877 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1878 intel_prepare_page_flip(dev, pipe);
1879 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001880 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001881
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001882 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1883 hsw_pipe_crc_irq_handler(dev, pipe);
1884
Daniel Vetter38d83c962013-11-07 11:05:46 +01001885 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1886 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1887 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001888 DRM_ERROR("Pipe %c FIFO underrun\n",
1889 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01001890 }
1891
Daniel Vetter30100f22013-11-07 14:49:24 +01001892 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1893 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
1894 pipe_name(pipe),
1895 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
1896 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001897
1898 if (pipe_iir) {
1899 ret = IRQ_HANDLED;
1900 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
1901 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07001902 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
1903 }
1904
Daniel Vetter92d03a82013-11-07 11:05:43 +01001905 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
1906 /*
1907 * FIXME(BDW): Assume for now that the new interrupt handling
1908 * scheme also closed the SDE interrupt handling race we've seen
1909 * on older pch-split platforms. But this needs testing.
1910 */
1911 u32 pch_iir = I915_READ(SDEIIR);
1912
1913 cpt_irq_handler(dev, pch_iir);
1914
1915 if (pch_iir) {
1916 I915_WRITE(SDEIIR, pch_iir);
1917 ret = IRQ_HANDLED;
1918 }
1919 }
1920
Ben Widawskyabd58f02013-11-02 21:07:09 -07001921 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1922 POSTING_READ(GEN8_MASTER_IRQ);
1923
1924 return ret;
1925}
1926
Daniel Vetter17e1df02013-09-08 21:57:13 +02001927static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1928 bool reset_completed)
1929{
1930 struct intel_ring_buffer *ring;
1931 int i;
1932
1933 /*
1934 * Notify all waiters for GPU completion events that reset state has
1935 * been changed, and that they need to restart their wait after
1936 * checking for potential errors (and bail out to drop locks if there is
1937 * a gpu reset pending so that i915_error_work_func can acquire them).
1938 */
1939
1940 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1941 for_each_ring(ring, dev_priv, i)
1942 wake_up_all(&ring->irq_queue);
1943
1944 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1945 wake_up_all(&dev_priv->pending_flip_queue);
1946
1947 /*
1948 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1949 * reset state is cleared.
1950 */
1951 if (reset_completed)
1952 wake_up_all(&dev_priv->gpu_error.reset_queue);
1953}
1954
Jesse Barnes8a905232009-07-11 16:48:03 -04001955/**
1956 * i915_error_work_func - do process context error handling work
1957 * @work: work struct
1958 *
1959 * Fire an error uevent so userspace can see that a hang or error
1960 * was detected.
1961 */
1962static void i915_error_work_func(struct work_struct *work)
1963{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001964 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1965 work);
1966 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1967 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001968 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07001969 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1970 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1971 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02001972 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001973
Dave Airlie5bdebb12013-10-11 14:07:25 +10001974 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001975
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001976 /*
1977 * Note that there's only one work item which does gpu resets, so we
1978 * need not worry about concurrent gpu resets potentially incrementing
1979 * error->reset_counter twice. We only need to take care of another
1980 * racing irq/hangcheck declaring the gpu dead for a second time. A
1981 * quick check for that is good enough: schedule_work ensures the
1982 * correct ordering between hang detection and this work item, and since
1983 * the reset in-progress bit is only ever set by code outside of this
1984 * work we don't need to worry about any other races.
1985 */
1986 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001987 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10001988 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001989 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001990
Daniel Vetter17e1df02013-09-08 21:57:13 +02001991 /*
1992 * All state reset _must_ be completed before we update the
1993 * reset counter, for otherwise waiters might miss the reset
1994 * pending state and not properly drop locks, resulting in
1995 * deadlocks with the reset work.
1996 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01001997 ret = i915_reset(dev);
1998
Daniel Vetter17e1df02013-09-08 21:57:13 +02001999 intel_display_handle_reset(dev);
2000
Daniel Vetterf69061b2012-12-06 09:01:42 +01002001 if (ret == 0) {
2002 /*
2003 * After all the gem state is reset, increment the reset
2004 * counter and wake up everyone waiting for the reset to
2005 * complete.
2006 *
2007 * Since unlock operations are a one-sided barrier only,
2008 * we need to insert a barrier here to order any seqno
2009 * updates before
2010 * the counter increment.
2011 */
2012 smp_mb__before_atomic_inc();
2013 atomic_inc(&dev_priv->gpu_error.reset_counter);
2014
Dave Airlie5bdebb12013-10-11 14:07:25 +10002015 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002016 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002017 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002018 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002019 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002020
Daniel Vetter17e1df02013-09-08 21:57:13 +02002021 /*
2022 * Note: The wake_up also serves as a memory barrier so that
2023 * waiters see the update value of the reset counter atomic_t.
2024 */
2025 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002026 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002027}
2028
Chris Wilson35aed2e2010-05-27 13:18:12 +01002029static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002030{
2031 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002032 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002033 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002034 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002035
Chris Wilson35aed2e2010-05-27 13:18:12 +01002036 if (!eir)
2037 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002038
Joe Perchesa70491c2012-03-18 13:00:11 -07002039 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002040
Ben Widawskybd9854f2012-08-23 15:18:09 -07002041 i915_get_extra_instdone(dev, instdone);
2042
Jesse Barnes8a905232009-07-11 16:48:03 -04002043 if (IS_G4X(dev)) {
2044 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2045 u32 ipeir = I915_READ(IPEIR_I965);
2046
Joe Perchesa70491c2012-03-18 13:00:11 -07002047 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2048 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002049 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2050 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002051 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002052 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002053 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002054 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002055 }
2056 if (eir & GM45_ERROR_PAGE_TABLE) {
2057 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002058 pr_err("page table error\n");
2059 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002060 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002061 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002062 }
2063 }
2064
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002065 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002066 if (eir & I915_ERROR_PAGE_TABLE) {
2067 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002068 pr_err("page table error\n");
2069 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002070 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002071 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002072 }
2073 }
2074
2075 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002076 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002077 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002078 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002079 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002080 /* pipestat has already been acked */
2081 }
2082 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002083 pr_err("instruction error\n");
2084 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002085 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2086 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002087 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002088 u32 ipeir = I915_READ(IPEIR);
2089
Joe Perchesa70491c2012-03-18 13:00:11 -07002090 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2091 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002092 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002093 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002094 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002095 } else {
2096 u32 ipeir = I915_READ(IPEIR_I965);
2097
Joe Perchesa70491c2012-03-18 13:00:11 -07002098 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2099 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002100 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002101 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002102 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002103 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002104 }
2105 }
2106
2107 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002108 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002109 eir = I915_READ(EIR);
2110 if (eir) {
2111 /*
2112 * some errors might have become stuck,
2113 * mask them.
2114 */
2115 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2116 I915_WRITE(EMR, I915_READ(EMR) | eir);
2117 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2118 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002119}
2120
2121/**
2122 * i915_handle_error - handle an error interrupt
2123 * @dev: drm device
2124 *
2125 * Do some basic checking of regsiter state at error interrupt time and
2126 * dump it to the syslog. Also call i915_capture_error_state() to make
2127 * sure we get a record and make it available in debugfs. Fire a uevent
2128 * so userspace knows something bad happened (should trigger collection
2129 * of a ring dump etc.).
2130 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002131void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002132{
2133 struct drm_i915_private *dev_priv = dev->dev_private;
2134
2135 i915_capture_error_state(dev);
2136 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002137
Ben Gamariba1234d2009-09-14 17:48:47 -04002138 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002139 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2140 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002141
Ben Gamari11ed50e2009-09-14 17:48:45 -04002142 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002143 * Wakeup waiting processes so that the reset work function
2144 * i915_error_work_func doesn't deadlock trying to grab various
2145 * locks. By bumping the reset counter first, the woken
2146 * processes will see a reset in progress and back off,
2147 * releasing their locks and then wait for the reset completion.
2148 * We must do this for _all_ gpu waiters that might hold locks
2149 * that the reset work needs to acquire.
2150 *
2151 * Note: The wake_up serves as the required memory barrier to
2152 * ensure that the waiters see the updated value of the reset
2153 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002154 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002155 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002156 }
2157
Daniel Vetter122f46b2013-09-04 17:36:14 +02002158 /*
2159 * Our reset work can grab modeset locks (since it needs to reset the
2160 * state of outstanding pagelips). Hence it must not be run on our own
2161 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2162 * code will deadlock.
2163 */
2164 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002165}
2166
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002167static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002168{
2169 drm_i915_private_t *dev_priv = dev->dev_private;
2170 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2171 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002172 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002173 struct intel_unpin_work *work;
2174 unsigned long flags;
2175 bool stall_detected;
2176
2177 /* Ignore early vblank irqs */
2178 if (intel_crtc == NULL)
2179 return;
2180
2181 spin_lock_irqsave(&dev->event_lock, flags);
2182 work = intel_crtc->unpin_work;
2183
Chris Wilsone7d841c2012-12-03 11:36:30 +00002184 if (work == NULL ||
2185 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2186 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002187 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2188 spin_unlock_irqrestore(&dev->event_lock, flags);
2189 return;
2190 }
2191
2192 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002193 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002194 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002195 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002196 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002197 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002198 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002199 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002200 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002201 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002202 crtc->x * crtc->fb->bits_per_pixel/8);
2203 }
2204
2205 spin_unlock_irqrestore(&dev->event_lock, flags);
2206
2207 if (stall_detected) {
2208 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2209 intel_prepare_page_flip(dev, intel_crtc->plane);
2210 }
2211}
2212
Keith Packard42f52ef2008-10-18 19:39:29 -07002213/* Called from drm generic code, passed 'crtc' which
2214 * we use as a pipe index
2215 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002216static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002217{
2218 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002219 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002220
Chris Wilson5eddb702010-09-11 13:48:45 +01002221 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002222 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002223
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002224 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002225 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002226 i915_enable_pipestat(dev_priv, pipe,
2227 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07002228 else
Keith Packard7c463582008-11-04 02:03:27 -08002229 i915_enable_pipestat(dev_priv, pipe,
2230 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002231
2232 /* maintain vblank delivery even in deep C-states */
2233 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002234 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002235 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002236
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002237 return 0;
2238}
2239
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002240static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002241{
2242 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2243 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002244 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002245 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002246
2247 if (!i915_pipe_enabled(dev, pipe))
2248 return -EINVAL;
2249
2250 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002251 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002252 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2253
2254 return 0;
2255}
2256
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002257static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2258{
2259 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2260 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002261 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002262
2263 if (!i915_pipe_enabled(dev, pipe))
2264 return -EINVAL;
2265
2266 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002267 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002268 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002269 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002270 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002271 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002272 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002273 i915_enable_pipestat(dev_priv, pipe,
2274 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002275 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2276
2277 return 0;
2278}
2279
Ben Widawskyabd58f02013-11-02 21:07:09 -07002280static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2281{
2282 struct drm_i915_private *dev_priv = dev->dev_private;
2283 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002284
2285 if (!i915_pipe_enabled(dev, pipe))
2286 return -EINVAL;
2287
2288 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002289 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2290 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2291 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002292 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2293 return 0;
2294}
2295
Keith Packard42f52ef2008-10-18 19:39:29 -07002296/* Called from drm generic code, passed 'crtc' which
2297 * we use as a pipe index
2298 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002299static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002300{
2301 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002302 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002303
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002304 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002305 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002306 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002307
Jesse Barnesf796cf82011-04-07 13:58:17 -07002308 i915_disable_pipestat(dev_priv, pipe,
2309 PIPE_VBLANK_INTERRUPT_ENABLE |
2310 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2311 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2312}
2313
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002314static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002315{
2316 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2317 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002318 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002319 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002320
2321 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002322 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002323 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2324}
2325
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002326static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2327{
2328 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2329 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002330 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002331
2332 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002333 i915_disable_pipestat(dev_priv, pipe,
2334 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002335 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002336 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002337 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002338 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002339 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002340 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002341 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2342}
2343
Ben Widawskyabd58f02013-11-02 21:07:09 -07002344static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2345{
2346 struct drm_i915_private *dev_priv = dev->dev_private;
2347 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002348
2349 if (!i915_pipe_enabled(dev, pipe))
2350 return;
2351
2352 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002353 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2354 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2355 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002356 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2357}
2358
Chris Wilson893eead2010-10-27 14:44:35 +01002359static u32
2360ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002361{
Chris Wilson893eead2010-10-27 14:44:35 +01002362 return list_entry(ring->request_list.prev,
2363 struct drm_i915_gem_request, list)->seqno;
2364}
2365
Chris Wilson9107e9d2013-06-10 11:20:20 +01002366static bool
2367ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002368{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002369 return (list_empty(&ring->request_list) ||
2370 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002371}
2372
Chris Wilson6274f212013-06-10 11:20:21 +01002373static struct intel_ring_buffer *
2374semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002375{
2376 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002377 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002378
2379 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2380 if ((ipehr & ~(0x3 << 16)) !=
2381 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002382 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002383
2384 /* ACTHD is likely pointing to the dword after the actual command,
2385 * so scan backwards until we find the MBOX.
2386 */
Chris Wilson6274f212013-06-10 11:20:21 +01002387 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002388 acthd_min = max((int)acthd - 3 * 4, 0);
2389 do {
2390 cmd = ioread32(ring->virtual_start + acthd);
2391 if (cmd == ipehr)
2392 break;
2393
2394 acthd -= 4;
2395 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002396 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002397 } while (1);
2398
Chris Wilson6274f212013-06-10 11:20:21 +01002399 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2400 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002401}
2402
Chris Wilson6274f212013-06-10 11:20:21 +01002403static int semaphore_passed(struct intel_ring_buffer *ring)
2404{
2405 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2406 struct intel_ring_buffer *signaller;
2407 u32 seqno, ctl;
2408
2409 ring->hangcheck.deadlock = true;
2410
2411 signaller = semaphore_waits_for(ring, &seqno);
2412 if (signaller == NULL || signaller->hangcheck.deadlock)
2413 return -1;
2414
2415 /* cursory check for an unkickable deadlock */
2416 ctl = I915_READ_CTL(signaller);
2417 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2418 return -1;
2419
2420 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2421}
2422
2423static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2424{
2425 struct intel_ring_buffer *ring;
2426 int i;
2427
2428 for_each_ring(ring, dev_priv, i)
2429 ring->hangcheck.deadlock = false;
2430}
2431
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002432static enum intel_ring_hangcheck_action
2433ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002434{
2435 struct drm_device *dev = ring->dev;
2436 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002437 u32 tmp;
2438
Chris Wilson6274f212013-06-10 11:20:21 +01002439 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002440 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002441
Chris Wilson9107e9d2013-06-10 11:20:20 +01002442 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002443 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002444
2445 /* Is the chip hanging on a WAIT_FOR_EVENT?
2446 * If so we can simply poke the RB_WAIT bit
2447 * and break the hang. This should work on
2448 * all but the second generation chipsets.
2449 */
2450 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002451 if (tmp & RING_WAIT) {
2452 DRM_ERROR("Kicking stuck wait on %s\n",
2453 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002454 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002455 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002456 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002457 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002458
Chris Wilson6274f212013-06-10 11:20:21 +01002459 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2460 switch (semaphore_passed(ring)) {
2461 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002462 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002463 case 1:
2464 DRM_ERROR("Kicking stuck semaphore on %s\n",
2465 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002466 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002467 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002468 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002469 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002470 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002471 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002472 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002473
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002474 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002475}
2476
Ben Gamarif65d9422009-09-14 17:48:44 -04002477/**
2478 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002479 * batchbuffers in a long time. We keep track per ring seqno progress and
2480 * if there are no progress, hangcheck score for that ring is increased.
2481 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2482 * we kick the ring. If we see no progress on three subsequent calls
2483 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002484 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002485static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002486{
2487 struct drm_device *dev = (struct drm_device *)data;
2488 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002489 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002490 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002491 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002492 bool stuck[I915_NUM_RINGS] = { 0 };
2493#define BUSY 1
2494#define KICK 5
2495#define HUNG 20
2496#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01002497
Jani Nikulad330a952014-01-21 11:24:25 +02002498 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002499 return;
2500
Chris Wilsonb4519512012-05-11 14:29:30 +01002501 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002502 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002503 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002504
Chris Wilson6274f212013-06-10 11:20:21 +01002505 semaphore_clear_deadlocks(dev_priv);
2506
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002507 seqno = ring->get_seqno(ring, false);
2508 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002509
Chris Wilson9107e9d2013-06-10 11:20:20 +01002510 if (ring->hangcheck.seqno == seqno) {
2511 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002512 ring->hangcheck.action = HANGCHECK_IDLE;
2513
Chris Wilson9107e9d2013-06-10 11:20:20 +01002514 if (waitqueue_active(&ring->irq_queue)) {
2515 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002516 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002517 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2518 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2519 ring->name);
2520 else
2521 DRM_INFO("Fake missed irq on %s\n",
2522 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002523 wake_up_all(&ring->irq_queue);
2524 }
2525 /* Safeguard against driver failure */
2526 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002527 } else
2528 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002529 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002530 /* We always increment the hangcheck score
2531 * if the ring is busy and still processing
2532 * the same request, so that no single request
2533 * can run indefinitely (such as a chain of
2534 * batches). The only time we do not increment
2535 * the hangcheck score on this ring, if this
2536 * ring is in a legitimate wait for another
2537 * ring. In that case the waiting ring is a
2538 * victim and we want to be sure we catch the
2539 * right culprit. Then every time we do kick
2540 * the ring, add a small increment to the
2541 * score so that we can catch a batch that is
2542 * being repeatedly kicked and so responsible
2543 * for stalling the machine.
2544 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002545 ring->hangcheck.action = ring_stuck(ring,
2546 acthd);
2547
2548 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002549 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002550 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002551 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002552 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002553 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002554 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002555 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002556 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002557 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002558 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002559 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002560 stuck[i] = true;
2561 break;
2562 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002563 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002564 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002565 ring->hangcheck.action = HANGCHECK_ACTIVE;
2566
Chris Wilson9107e9d2013-06-10 11:20:20 +01002567 /* Gradually reduce the count so that we catch DoS
2568 * attempts across multiple batches.
2569 */
2570 if (ring->hangcheck.score > 0)
2571 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002572 }
2573
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002574 ring->hangcheck.seqno = seqno;
2575 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002576 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002577 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002578
Mika Kuoppala92cab732013-05-24 17:16:07 +03002579 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002580 if (ring->hangcheck.score > FIRE) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002581 DRM_INFO("%s on %s\n",
2582 stuck[i] ? "stuck" : "no progress",
2583 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002584 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002585 }
2586 }
2587
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002588 if (rings_hung)
2589 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002590
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002591 if (busy_count)
2592 /* Reset timer case chip hangs without another request
2593 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002594 i915_queue_hangcheck(dev);
2595}
2596
2597void i915_queue_hangcheck(struct drm_device *dev)
2598{
2599 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02002600 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002601 return;
2602
2603 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2604 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002605}
2606
Paulo Zanoni91738a92013-06-05 14:21:51 -03002607static void ibx_irq_preinstall(struct drm_device *dev)
2608{
2609 struct drm_i915_private *dev_priv = dev->dev_private;
2610
2611 if (HAS_PCH_NOP(dev))
2612 return;
2613
2614 /* south display irq */
2615 I915_WRITE(SDEIMR, 0xffffffff);
2616 /*
2617 * SDEIER is also touched by the interrupt handler to work around missed
2618 * PCH interrupts. Hence we can't update it after the interrupt handler
2619 * is enabled - instead we unconditionally enable all PCH interrupt
2620 * sources here, but then only unmask them as needed with SDEIMR.
2621 */
2622 I915_WRITE(SDEIER, 0xffffffff);
2623 POSTING_READ(SDEIER);
2624}
2625
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002626static void gen5_gt_irq_preinstall(struct drm_device *dev)
2627{
2628 struct drm_i915_private *dev_priv = dev->dev_private;
2629
2630 /* and GT */
2631 I915_WRITE(GTIMR, 0xffffffff);
2632 I915_WRITE(GTIER, 0x0);
2633 POSTING_READ(GTIER);
2634
2635 if (INTEL_INFO(dev)->gen >= 6) {
2636 /* and PM */
2637 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2638 I915_WRITE(GEN6_PMIER, 0x0);
2639 POSTING_READ(GEN6_PMIER);
2640 }
2641}
2642
Linus Torvalds1da177e2005-04-16 15:20:36 -07002643/* drm_dma.h hooks
2644*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002645static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002646{
2647 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2648
2649 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002650
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002651 I915_WRITE(DEIMR, 0xffffffff);
2652 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002653 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002654
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002655 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002656
Paulo Zanoni91738a92013-06-05 14:21:51 -03002657 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002658}
2659
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002660static void valleyview_irq_preinstall(struct drm_device *dev)
2661{
2662 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2663 int pipe;
2664
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002665 /* VLV magic */
2666 I915_WRITE(VLV_IMR, 0);
2667 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2668 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2669 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2670
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002671 /* and GT */
2672 I915_WRITE(GTIIR, I915_READ(GTIIR));
2673 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002674
2675 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002676
2677 I915_WRITE(DPINVGTT, 0xff);
2678
2679 I915_WRITE(PORT_HOTPLUG_EN, 0);
2680 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2681 for_each_pipe(pipe)
2682 I915_WRITE(PIPESTAT(pipe), 0xffff);
2683 I915_WRITE(VLV_IIR, 0xffffffff);
2684 I915_WRITE(VLV_IMR, 0xffffffff);
2685 I915_WRITE(VLV_IER, 0x0);
2686 POSTING_READ(VLV_IER);
2687}
2688
Ben Widawskyabd58f02013-11-02 21:07:09 -07002689static void gen8_irq_preinstall(struct drm_device *dev)
2690{
2691 struct drm_i915_private *dev_priv = dev->dev_private;
2692 int pipe;
2693
Ben Widawskyabd58f02013-11-02 21:07:09 -07002694 I915_WRITE(GEN8_MASTER_IRQ, 0);
2695 POSTING_READ(GEN8_MASTER_IRQ);
2696
2697 /* IIR can theoretically queue up two events. Be paranoid */
2698#define GEN8_IRQ_INIT_NDX(type, which) do { \
2699 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2700 POSTING_READ(GEN8_##type##_IMR(which)); \
2701 I915_WRITE(GEN8_##type##_IER(which), 0); \
2702 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2703 POSTING_READ(GEN8_##type##_IIR(which)); \
2704 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2705 } while (0)
2706
2707#define GEN8_IRQ_INIT(type) do { \
2708 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2709 POSTING_READ(GEN8_##type##_IMR); \
2710 I915_WRITE(GEN8_##type##_IER, 0); \
2711 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2712 POSTING_READ(GEN8_##type##_IIR); \
2713 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2714 } while (0)
2715
2716 GEN8_IRQ_INIT_NDX(GT, 0);
2717 GEN8_IRQ_INIT_NDX(GT, 1);
2718 GEN8_IRQ_INIT_NDX(GT, 2);
2719 GEN8_IRQ_INIT_NDX(GT, 3);
2720
2721 for_each_pipe(pipe) {
2722 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2723 }
2724
2725 GEN8_IRQ_INIT(DE_PORT);
2726 GEN8_IRQ_INIT(DE_MISC);
2727 GEN8_IRQ_INIT(PCU);
2728#undef GEN8_IRQ_INIT
2729#undef GEN8_IRQ_INIT_NDX
2730
2731 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002732
2733 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002734}
2735
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002736static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002737{
2738 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002739 struct drm_mode_config *mode_config = &dev->mode_config;
2740 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002741 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002742
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002743 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002744 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002745 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002746 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002747 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002748 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002749 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002750 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002751 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002752 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002753 }
2754
Daniel Vetterfee884e2013-07-04 23:35:21 +02002755 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002756
2757 /*
2758 * Enable digital hotplug on the PCH, and configure the DP short pulse
2759 * duration to 2ms (which is the minimum in the Display Port spec)
2760 *
2761 * This register is the same on all known PCH chips.
2762 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002763 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2764 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2765 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2766 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2767 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2768 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2769}
2770
Paulo Zanonid46da432013-02-08 17:35:15 -02002771static void ibx_irq_postinstall(struct drm_device *dev)
2772{
2773 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002774 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002775
Daniel Vetter692a04c2013-05-29 21:43:05 +02002776 if (HAS_PCH_NOP(dev))
2777 return;
2778
Paulo Zanoni86642812013-04-12 17:57:57 -03002779 if (HAS_PCH_IBX(dev)) {
2780 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002781 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002782 } else {
2783 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2784
2785 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2786 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002787
Paulo Zanonid46da432013-02-08 17:35:15 -02002788 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2789 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002790}
2791
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002792static void gen5_gt_irq_postinstall(struct drm_device *dev)
2793{
2794 struct drm_i915_private *dev_priv = dev->dev_private;
2795 u32 pm_irqs, gt_irqs;
2796
2797 pm_irqs = gt_irqs = 0;
2798
2799 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002800 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002801 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002802 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2803 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002804 }
2805
2806 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2807 if (IS_GEN5(dev)) {
2808 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2809 ILK_BSD_USER_INTERRUPT;
2810 } else {
2811 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2812 }
2813
2814 I915_WRITE(GTIIR, I915_READ(GTIIR));
2815 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2816 I915_WRITE(GTIER, gt_irqs);
2817 POSTING_READ(GTIER);
2818
2819 if (INTEL_INFO(dev)->gen >= 6) {
2820 pm_irqs |= GEN6_PM_RPS_EVENTS;
2821
2822 if (HAS_VEBOX(dev))
2823 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2824
Paulo Zanoni605cd252013-08-06 18:57:15 -03002825 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002826 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002827 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002828 I915_WRITE(GEN6_PMIER, pm_irqs);
2829 POSTING_READ(GEN6_PMIER);
2830 }
2831}
2832
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002833static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002834{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002835 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002836 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002837 u32 display_mask, extra_mask;
2838
2839 if (INTEL_INFO(dev)->gen >= 7) {
2840 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2841 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2842 DE_PLANEB_FLIP_DONE_IVB |
2843 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2844 DE_ERR_INT_IVB);
2845 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2846 DE_PIPEA_VBLANK_IVB);
2847
2848 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2849 } else {
2850 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2851 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002852 DE_AUX_CHANNEL_A |
2853 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2854 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2855 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002856 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2857 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002858
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002859 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002860
2861 /* should always can generate irq */
2862 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002863 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002864 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002865 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002866
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002867 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002868
Paulo Zanonid46da432013-02-08 17:35:15 -02002869 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002870
Jesse Barnesf97108d2010-01-29 11:27:07 -08002871 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002872 /* Enable PCU event interrupts
2873 *
2874 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002875 * setup is guaranteed to run in single-threaded context. But we
2876 * need it to make the assert_spin_locked happy. */
2877 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002878 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002879 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002880 }
2881
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002882 return 0;
2883}
2884
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002885static int valleyview_irq_postinstall(struct drm_device *dev)
2886{
2887 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002888 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002889 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2890 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002891 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002892
2893 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002894 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2895 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2896 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002897 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2898
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002899 /*
2900 *Leave vblank interrupts masked initially. enable/disable will
2901 * toggle them based on usage.
2902 */
2903 dev_priv->irq_mask = (~enable_mask) |
2904 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2905 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002906
Daniel Vetter20afbda2012-12-11 14:05:07 +01002907 I915_WRITE(PORT_HOTPLUG_EN, 0);
2908 POSTING_READ(PORT_HOTPLUG_EN);
2909
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002910 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2911 I915_WRITE(VLV_IER, enable_mask);
2912 I915_WRITE(VLV_IIR, 0xffffffff);
2913 I915_WRITE(PIPESTAT(0), 0xffff);
2914 I915_WRITE(PIPESTAT(1), 0xffff);
2915 POSTING_READ(VLV_IER);
2916
Daniel Vetterb79480b2013-06-27 17:52:10 +02002917 /* Interrupt setup is already guaranteed to be single-threaded, this is
2918 * just to make the assert_spin_locked check happy. */
2919 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002920 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
2921 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
2922 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002923 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002924
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002925 I915_WRITE(VLV_IIR, 0xffffffff);
2926 I915_WRITE(VLV_IIR, 0xffffffff);
2927
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002928 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002929
2930 /* ack & enable invalid PTE error interrupts */
2931#if 0 /* FIXME: add support to irq handler for checking these bits */
2932 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2933 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2934#endif
2935
2936 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002937
2938 return 0;
2939}
2940
Ben Widawskyabd58f02013-11-02 21:07:09 -07002941static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
2942{
2943 int i;
2944
2945 /* These are interrupts we'll toggle with the ring mask register */
2946 uint32_t gt_interrupts[] = {
2947 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
2948 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
2949 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
2950 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
2951 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
2952 0,
2953 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
2954 };
2955
2956 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
2957 u32 tmp = I915_READ(GEN8_GT_IIR(i));
2958 if (tmp)
2959 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2960 i, tmp);
2961 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
2962 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
2963 }
2964 POSTING_READ(GEN8_GT_IER(0));
2965}
2966
2967static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
2968{
2969 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002970 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
2971 GEN8_PIPE_CDCLK_CRC_DONE |
2972 GEN8_PIPE_FIFO_UNDERRUN |
2973 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2974 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002975 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002976 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
2977 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
2978 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002979
2980 for_each_pipe(pipe) {
2981 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2982 if (tmp)
2983 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2984 pipe, tmp);
2985 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2986 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
2987 }
2988 POSTING_READ(GEN8_DE_PIPE_ISR(0));
2989
Daniel Vetter6d766f02013-11-07 14:49:55 +01002990 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
2991 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002992 POSTING_READ(GEN8_DE_PORT_IER);
2993}
2994
2995static int gen8_irq_postinstall(struct drm_device *dev)
2996{
2997 struct drm_i915_private *dev_priv = dev->dev_private;
2998
2999 gen8_gt_irq_postinstall(dev_priv);
3000 gen8_de_irq_postinstall(dev_priv);
3001
3002 ibx_irq_postinstall(dev);
3003
3004 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3005 POSTING_READ(GEN8_MASTER_IRQ);
3006
3007 return 0;
3008}
3009
3010static void gen8_irq_uninstall(struct drm_device *dev)
3011{
3012 struct drm_i915_private *dev_priv = dev->dev_private;
3013 int pipe;
3014
3015 if (!dev_priv)
3016 return;
3017
Ben Widawskyabd58f02013-11-02 21:07:09 -07003018 I915_WRITE(GEN8_MASTER_IRQ, 0);
3019
3020#define GEN8_IRQ_FINI_NDX(type, which) do { \
3021 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3022 I915_WRITE(GEN8_##type##_IER(which), 0); \
3023 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3024 } while (0)
3025
3026#define GEN8_IRQ_FINI(type) do { \
3027 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3028 I915_WRITE(GEN8_##type##_IER, 0); \
3029 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3030 } while (0)
3031
3032 GEN8_IRQ_FINI_NDX(GT, 0);
3033 GEN8_IRQ_FINI_NDX(GT, 1);
3034 GEN8_IRQ_FINI_NDX(GT, 2);
3035 GEN8_IRQ_FINI_NDX(GT, 3);
3036
3037 for_each_pipe(pipe) {
3038 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3039 }
3040
3041 GEN8_IRQ_FINI(DE_PORT);
3042 GEN8_IRQ_FINI(DE_MISC);
3043 GEN8_IRQ_FINI(PCU);
3044#undef GEN8_IRQ_FINI
3045#undef GEN8_IRQ_FINI_NDX
3046
3047 POSTING_READ(GEN8_PCU_IIR);
3048}
3049
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003050static void valleyview_irq_uninstall(struct drm_device *dev)
3051{
3052 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3053 int pipe;
3054
3055 if (!dev_priv)
3056 return;
3057
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003058 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003059
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003060 for_each_pipe(pipe)
3061 I915_WRITE(PIPESTAT(pipe), 0xffff);
3062
3063 I915_WRITE(HWSTAM, 0xffffffff);
3064 I915_WRITE(PORT_HOTPLUG_EN, 0);
3065 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3066 for_each_pipe(pipe)
3067 I915_WRITE(PIPESTAT(pipe), 0xffff);
3068 I915_WRITE(VLV_IIR, 0xffffffff);
3069 I915_WRITE(VLV_IMR, 0xffffffff);
3070 I915_WRITE(VLV_IER, 0x0);
3071 POSTING_READ(VLV_IER);
3072}
3073
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003074static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003075{
3076 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003077
3078 if (!dev_priv)
3079 return;
3080
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003081 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003082
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003083 I915_WRITE(HWSTAM, 0xffffffff);
3084
3085 I915_WRITE(DEIMR, 0xffffffff);
3086 I915_WRITE(DEIER, 0x0);
3087 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003088 if (IS_GEN7(dev))
3089 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003090
3091 I915_WRITE(GTIMR, 0xffffffff);
3092 I915_WRITE(GTIER, 0x0);
3093 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003094
Ben Widawskyab5c6082013-04-05 13:12:41 -07003095 if (HAS_PCH_NOP(dev))
3096 return;
3097
Keith Packard192aac1f2011-09-20 10:12:44 -07003098 I915_WRITE(SDEIMR, 0xffffffff);
3099 I915_WRITE(SDEIER, 0x0);
3100 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003101 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3102 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003103}
3104
Chris Wilsonc2798b12012-04-22 21:13:57 +01003105static void i8xx_irq_preinstall(struct drm_device * dev)
3106{
3107 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3108 int pipe;
3109
Chris Wilsonc2798b12012-04-22 21:13:57 +01003110 for_each_pipe(pipe)
3111 I915_WRITE(PIPESTAT(pipe), 0);
3112 I915_WRITE16(IMR, 0xffff);
3113 I915_WRITE16(IER, 0x0);
3114 POSTING_READ16(IER);
3115}
3116
3117static int i8xx_irq_postinstall(struct drm_device *dev)
3118{
3119 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003120 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003121
Chris Wilsonc2798b12012-04-22 21:13:57 +01003122 I915_WRITE16(EMR,
3123 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3124
3125 /* Unmask the interrupts that we always want on. */
3126 dev_priv->irq_mask =
3127 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3128 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3129 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3130 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3131 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3132 I915_WRITE16(IMR, dev_priv->irq_mask);
3133
3134 I915_WRITE16(IER,
3135 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3136 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3137 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3138 I915_USER_INTERRUPT);
3139 POSTING_READ16(IER);
3140
Daniel Vetter379ef822013-10-16 22:55:56 +02003141 /* Interrupt setup is already guaranteed to be single-threaded, this is
3142 * just to make the assert_spin_locked check happy. */
3143 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003144 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3145 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003146 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3147
Chris Wilsonc2798b12012-04-22 21:13:57 +01003148 return 0;
3149}
3150
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003151/*
3152 * Returns true when a page flip has completed.
3153 */
3154static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003155 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003156{
3157 drm_i915_private_t *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003158 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003159
3160 if (!drm_handle_vblank(dev, pipe))
3161 return false;
3162
3163 if ((iir & flip_pending) == 0)
3164 return false;
3165
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003166 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003167
3168 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3169 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3170 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3171 * the flip is completed (no longer pending). Since this doesn't raise
3172 * an interrupt per se, we watch for the change at vblank.
3173 */
3174 if (I915_READ16(ISR) & flip_pending)
3175 return false;
3176
3177 intel_finish_page_flip(dev, pipe);
3178
3179 return true;
3180}
3181
Daniel Vetterff1f5252012-10-02 15:10:55 +02003182static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003183{
3184 struct drm_device *dev = (struct drm_device *) arg;
3185 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003186 u16 iir, new_iir;
3187 u32 pipe_stats[2];
3188 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003189 int pipe;
3190 u16 flip_mask =
3191 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3192 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3193
Chris Wilsonc2798b12012-04-22 21:13:57 +01003194 iir = I915_READ16(IIR);
3195 if (iir == 0)
3196 return IRQ_NONE;
3197
3198 while (iir & ~flip_mask) {
3199 /* Can't rely on pipestat interrupt bit in iir as it might
3200 * have been cleared after the pipestat interrupt was received.
3201 * It doesn't set the bit in iir again, but it still produces
3202 * interrupts (for non-MSI).
3203 */
3204 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3205 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3206 i915_handle_error(dev, false);
3207
3208 for_each_pipe(pipe) {
3209 int reg = PIPESTAT(pipe);
3210 pipe_stats[pipe] = I915_READ(reg);
3211
3212 /*
3213 * Clear the PIPE*STAT regs before the IIR
3214 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003215 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003216 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003217 }
3218 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3219
3220 I915_WRITE16(IIR, iir & ~flip_mask);
3221 new_iir = I915_READ16(IIR); /* Flush posted writes */
3222
Daniel Vetterd05c6172012-04-26 23:28:09 +02003223 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003224
3225 if (iir & I915_USER_INTERRUPT)
3226 notify_ring(dev, &dev_priv->ring[RCS]);
3227
Daniel Vetter4356d582013-10-16 22:55:55 +02003228 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003229 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003230 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003231 plane = !plane;
3232
Daniel Vetter4356d582013-10-16 22:55:55 +02003233 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003234 i8xx_handle_vblank(dev, plane, pipe, iir))
3235 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003236
Daniel Vetter4356d582013-10-16 22:55:55 +02003237 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003238 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003239
3240 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3241 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003242 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003243 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003244
3245 iir = new_iir;
3246 }
3247
3248 return IRQ_HANDLED;
3249}
3250
3251static void i8xx_irq_uninstall(struct drm_device * dev)
3252{
3253 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3254 int pipe;
3255
Chris Wilsonc2798b12012-04-22 21:13:57 +01003256 for_each_pipe(pipe) {
3257 /* Clear enable bits; then clear status bits */
3258 I915_WRITE(PIPESTAT(pipe), 0);
3259 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3260 }
3261 I915_WRITE16(IMR, 0xffff);
3262 I915_WRITE16(IER, 0x0);
3263 I915_WRITE16(IIR, I915_READ16(IIR));
3264}
3265
Chris Wilsona266c7d2012-04-24 22:59:44 +01003266static void i915_irq_preinstall(struct drm_device * dev)
3267{
3268 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3269 int pipe;
3270
Chris Wilsona266c7d2012-04-24 22:59:44 +01003271 if (I915_HAS_HOTPLUG(dev)) {
3272 I915_WRITE(PORT_HOTPLUG_EN, 0);
3273 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3274 }
3275
Chris Wilson00d98eb2012-04-24 22:59:48 +01003276 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003277 for_each_pipe(pipe)
3278 I915_WRITE(PIPESTAT(pipe), 0);
3279 I915_WRITE(IMR, 0xffffffff);
3280 I915_WRITE(IER, 0x0);
3281 POSTING_READ(IER);
3282}
3283
3284static int i915_irq_postinstall(struct drm_device *dev)
3285{
3286 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003287 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003288 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003289
Chris Wilson38bde182012-04-24 22:59:50 +01003290 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3291
3292 /* Unmask the interrupts that we always want on. */
3293 dev_priv->irq_mask =
3294 ~(I915_ASLE_INTERRUPT |
3295 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3296 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3297 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3298 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3299 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3300
3301 enable_mask =
3302 I915_ASLE_INTERRUPT |
3303 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3304 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3305 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3306 I915_USER_INTERRUPT;
3307
Chris Wilsona266c7d2012-04-24 22:59:44 +01003308 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003309 I915_WRITE(PORT_HOTPLUG_EN, 0);
3310 POSTING_READ(PORT_HOTPLUG_EN);
3311
Chris Wilsona266c7d2012-04-24 22:59:44 +01003312 /* Enable in IER... */
3313 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3314 /* and unmask in IMR */
3315 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3316 }
3317
Chris Wilsona266c7d2012-04-24 22:59:44 +01003318 I915_WRITE(IMR, dev_priv->irq_mask);
3319 I915_WRITE(IER, enable_mask);
3320 POSTING_READ(IER);
3321
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003322 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003323
Daniel Vetter379ef822013-10-16 22:55:56 +02003324 /* Interrupt setup is already guaranteed to be single-threaded, this is
3325 * just to make the assert_spin_locked check happy. */
3326 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003327 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3328 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003329 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3330
Daniel Vetter20afbda2012-12-11 14:05:07 +01003331 return 0;
3332}
3333
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003334/*
3335 * Returns true when a page flip has completed.
3336 */
3337static bool i915_handle_vblank(struct drm_device *dev,
3338 int plane, int pipe, u32 iir)
3339{
3340 drm_i915_private_t *dev_priv = dev->dev_private;
3341 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3342
3343 if (!drm_handle_vblank(dev, pipe))
3344 return false;
3345
3346 if ((iir & flip_pending) == 0)
3347 return false;
3348
3349 intel_prepare_page_flip(dev, plane);
3350
3351 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3352 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3353 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3354 * the flip is completed (no longer pending). Since this doesn't raise
3355 * an interrupt per se, we watch for the change at vblank.
3356 */
3357 if (I915_READ(ISR) & flip_pending)
3358 return false;
3359
3360 intel_finish_page_flip(dev, pipe);
3361
3362 return true;
3363}
3364
Daniel Vetterff1f5252012-10-02 15:10:55 +02003365static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003366{
3367 struct drm_device *dev = (struct drm_device *) arg;
3368 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003369 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003370 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003371 u32 flip_mask =
3372 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3373 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003374 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003375
Chris Wilsona266c7d2012-04-24 22:59:44 +01003376 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003377 do {
3378 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003379 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003380
3381 /* Can't rely on pipestat interrupt bit in iir as it might
3382 * have been cleared after the pipestat interrupt was received.
3383 * It doesn't set the bit in iir again, but it still produces
3384 * interrupts (for non-MSI).
3385 */
3386 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3387 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3388 i915_handle_error(dev, false);
3389
3390 for_each_pipe(pipe) {
3391 int reg = PIPESTAT(pipe);
3392 pipe_stats[pipe] = I915_READ(reg);
3393
Chris Wilson38bde182012-04-24 22:59:50 +01003394 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003395 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003396 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003397 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003398 }
3399 }
3400 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3401
3402 if (!irq_received)
3403 break;
3404
Chris Wilsona266c7d2012-04-24 22:59:44 +01003405 /* Consume port. Then clear IIR or we'll miss events */
3406 if ((I915_HAS_HOTPLUG(dev)) &&
3407 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3408 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003409 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003410
Daniel Vetter91d131d2013-06-27 17:52:14 +02003411 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3412
Chris Wilsona266c7d2012-04-24 22:59:44 +01003413 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003414 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003415 }
3416
Chris Wilson38bde182012-04-24 22:59:50 +01003417 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003418 new_iir = I915_READ(IIR); /* Flush posted writes */
3419
Chris Wilsona266c7d2012-04-24 22:59:44 +01003420 if (iir & I915_USER_INTERRUPT)
3421 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003422
Chris Wilsona266c7d2012-04-24 22:59:44 +01003423 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003424 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003425 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003426 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003427
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003428 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3429 i915_handle_vblank(dev, plane, pipe, iir))
3430 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003431
3432 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3433 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003434
3435 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003436 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003437
3438 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3439 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003440 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003441 }
3442
Chris Wilsona266c7d2012-04-24 22:59:44 +01003443 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3444 intel_opregion_asle_intr(dev);
3445
3446 /* With MSI, interrupts are only generated when iir
3447 * transitions from zero to nonzero. If another bit got
3448 * set while we were handling the existing iir bits, then
3449 * we would never get another interrupt.
3450 *
3451 * This is fine on non-MSI as well, as if we hit this path
3452 * we avoid exiting the interrupt handler only to generate
3453 * another one.
3454 *
3455 * Note that for MSI this could cause a stray interrupt report
3456 * if an interrupt landed in the time between writing IIR and
3457 * the posting read. This should be rare enough to never
3458 * trigger the 99% of 100,000 interrupts test for disabling
3459 * stray interrupts.
3460 */
Chris Wilson38bde182012-04-24 22:59:50 +01003461 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003462 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003463 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003464
Daniel Vetterd05c6172012-04-26 23:28:09 +02003465 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003466
Chris Wilsona266c7d2012-04-24 22:59:44 +01003467 return ret;
3468}
3469
3470static void i915_irq_uninstall(struct drm_device * dev)
3471{
3472 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3473 int pipe;
3474
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003475 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003476
Chris Wilsona266c7d2012-04-24 22:59:44 +01003477 if (I915_HAS_HOTPLUG(dev)) {
3478 I915_WRITE(PORT_HOTPLUG_EN, 0);
3479 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3480 }
3481
Chris Wilson00d98eb2012-04-24 22:59:48 +01003482 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003483 for_each_pipe(pipe) {
3484 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003485 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003486 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3487 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003488 I915_WRITE(IMR, 0xffffffff);
3489 I915_WRITE(IER, 0x0);
3490
Chris Wilsona266c7d2012-04-24 22:59:44 +01003491 I915_WRITE(IIR, I915_READ(IIR));
3492}
3493
3494static void i965_irq_preinstall(struct drm_device * dev)
3495{
3496 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3497 int pipe;
3498
Chris Wilsonadca4732012-05-11 18:01:31 +01003499 I915_WRITE(PORT_HOTPLUG_EN, 0);
3500 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003501
3502 I915_WRITE(HWSTAM, 0xeffe);
3503 for_each_pipe(pipe)
3504 I915_WRITE(PIPESTAT(pipe), 0);
3505 I915_WRITE(IMR, 0xffffffff);
3506 I915_WRITE(IER, 0x0);
3507 POSTING_READ(IER);
3508}
3509
3510static int i965_irq_postinstall(struct drm_device *dev)
3511{
3512 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003513 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003514 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003515 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003516
Chris Wilsona266c7d2012-04-24 22:59:44 +01003517 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003518 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003519 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003520 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3521 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3522 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3523 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3524 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3525
3526 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003527 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3528 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003529 enable_mask |= I915_USER_INTERRUPT;
3530
3531 if (IS_G4X(dev))
3532 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003533
Daniel Vetterb79480b2013-06-27 17:52:10 +02003534 /* Interrupt setup is already guaranteed to be single-threaded, this is
3535 * just to make the assert_spin_locked check happy. */
3536 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003537 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
3538 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3539 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003540 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003541
Chris Wilsona266c7d2012-04-24 22:59:44 +01003542 /*
3543 * Enable some error detection, note the instruction error mask
3544 * bit is reserved, so we leave it masked.
3545 */
3546 if (IS_G4X(dev)) {
3547 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3548 GM45_ERROR_MEM_PRIV |
3549 GM45_ERROR_CP_PRIV |
3550 I915_ERROR_MEMORY_REFRESH);
3551 } else {
3552 error_mask = ~(I915_ERROR_PAGE_TABLE |
3553 I915_ERROR_MEMORY_REFRESH);
3554 }
3555 I915_WRITE(EMR, error_mask);
3556
3557 I915_WRITE(IMR, dev_priv->irq_mask);
3558 I915_WRITE(IER, enable_mask);
3559 POSTING_READ(IER);
3560
Daniel Vetter20afbda2012-12-11 14:05:07 +01003561 I915_WRITE(PORT_HOTPLUG_EN, 0);
3562 POSTING_READ(PORT_HOTPLUG_EN);
3563
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003564 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003565
3566 return 0;
3567}
3568
Egbert Eichbac56d52013-02-25 12:06:51 -05003569static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003570{
3571 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003572 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003573 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003574 u32 hotplug_en;
3575
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003576 assert_spin_locked(&dev_priv->irq_lock);
3577
Egbert Eichbac56d52013-02-25 12:06:51 -05003578 if (I915_HAS_HOTPLUG(dev)) {
3579 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3580 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3581 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003582 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003583 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3584 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3585 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003586 /* Programming the CRT detection parameters tends
3587 to generate a spurious hotplug event about three
3588 seconds later. So just do it once.
3589 */
3590 if (IS_G4X(dev))
3591 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003592 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003593 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003594
Egbert Eichbac56d52013-02-25 12:06:51 -05003595 /* Ignore TV since it's buggy */
3596 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3597 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003598}
3599
Daniel Vetterff1f5252012-10-02 15:10:55 +02003600static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003601{
3602 struct drm_device *dev = (struct drm_device *) arg;
3603 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003604 u32 iir, new_iir;
3605 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003606 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003607 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003608 u32 flip_mask =
3609 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3610 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003611
Chris Wilsona266c7d2012-04-24 22:59:44 +01003612 iir = I915_READ(IIR);
3613
Chris Wilsona266c7d2012-04-24 22:59:44 +01003614 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003615 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003616 bool blc_event = false;
3617
Chris Wilsona266c7d2012-04-24 22:59:44 +01003618 /* Can't rely on pipestat interrupt bit in iir as it might
3619 * have been cleared after the pipestat interrupt was received.
3620 * It doesn't set the bit in iir again, but it still produces
3621 * interrupts (for non-MSI).
3622 */
3623 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3624 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3625 i915_handle_error(dev, false);
3626
3627 for_each_pipe(pipe) {
3628 int reg = PIPESTAT(pipe);
3629 pipe_stats[pipe] = I915_READ(reg);
3630
3631 /*
3632 * Clear the PIPE*STAT regs before the IIR
3633 */
3634 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003635 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003636 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003637 }
3638 }
3639 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3640
3641 if (!irq_received)
3642 break;
3643
3644 ret = IRQ_HANDLED;
3645
3646 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003647 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003648 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003649 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3650 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003651 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003652
Daniel Vetter91d131d2013-06-27 17:52:14 +02003653 intel_hpd_irq_handler(dev, hotplug_trigger,
Daniel Vetter704cfb82013-12-18 09:08:43 +01003654 IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003655
Daniel Vetter4aeebd72013-10-31 09:53:36 +01003656 if (IS_G4X(dev) &&
3657 (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
3658 dp_aux_irq_handler(dev);
3659
Chris Wilsona266c7d2012-04-24 22:59:44 +01003660 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3661 I915_READ(PORT_HOTPLUG_STAT);
3662 }
3663
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003664 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003665 new_iir = I915_READ(IIR); /* Flush posted writes */
3666
Chris Wilsona266c7d2012-04-24 22:59:44 +01003667 if (iir & I915_USER_INTERRUPT)
3668 notify_ring(dev, &dev_priv->ring[RCS]);
3669 if (iir & I915_BSD_USER_INTERRUPT)
3670 notify_ring(dev, &dev_priv->ring[VCS]);
3671
Chris Wilsona266c7d2012-04-24 22:59:44 +01003672 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003673 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003674 i915_handle_vblank(dev, pipe, pipe, iir))
3675 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003676
3677 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3678 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003679
3680 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003681 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003682
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003683 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3684 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003685 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003686 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003687
3688 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3689 intel_opregion_asle_intr(dev);
3690
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003691 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3692 gmbus_irq_handler(dev);
3693
Chris Wilsona266c7d2012-04-24 22:59:44 +01003694 /* With MSI, interrupts are only generated when iir
3695 * transitions from zero to nonzero. If another bit got
3696 * set while we were handling the existing iir bits, then
3697 * we would never get another interrupt.
3698 *
3699 * This is fine on non-MSI as well, as if we hit this path
3700 * we avoid exiting the interrupt handler only to generate
3701 * another one.
3702 *
3703 * Note that for MSI this could cause a stray interrupt report
3704 * if an interrupt landed in the time between writing IIR and
3705 * the posting read. This should be rare enough to never
3706 * trigger the 99% of 100,000 interrupts test for disabling
3707 * stray interrupts.
3708 */
3709 iir = new_iir;
3710 }
3711
Daniel Vetterd05c6172012-04-26 23:28:09 +02003712 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003713
Chris Wilsona266c7d2012-04-24 22:59:44 +01003714 return ret;
3715}
3716
3717static void i965_irq_uninstall(struct drm_device * dev)
3718{
3719 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3720 int pipe;
3721
3722 if (!dev_priv)
3723 return;
3724
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003725 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003726
Chris Wilsonadca4732012-05-11 18:01:31 +01003727 I915_WRITE(PORT_HOTPLUG_EN, 0);
3728 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003729
3730 I915_WRITE(HWSTAM, 0xffffffff);
3731 for_each_pipe(pipe)
3732 I915_WRITE(PIPESTAT(pipe), 0);
3733 I915_WRITE(IMR, 0xffffffff);
3734 I915_WRITE(IER, 0x0);
3735
3736 for_each_pipe(pipe)
3737 I915_WRITE(PIPESTAT(pipe),
3738 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3739 I915_WRITE(IIR, I915_READ(IIR));
3740}
3741
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003742static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02003743{
3744 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3745 struct drm_device *dev = dev_priv->dev;
3746 struct drm_mode_config *mode_config = &dev->mode_config;
3747 unsigned long irqflags;
3748 int i;
3749
3750 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3751 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3752 struct drm_connector *connector;
3753
3754 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3755 continue;
3756
3757 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3758
3759 list_for_each_entry(connector, &mode_config->connector_list, head) {
3760 struct intel_connector *intel_connector = to_intel_connector(connector);
3761
3762 if (intel_connector->encoder->hpd_pin == i) {
3763 if (connector->polled != intel_connector->polled)
3764 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3765 drm_get_connector_name(connector));
3766 connector->polled = intel_connector->polled;
3767 if (!connector->polled)
3768 connector->polled = DRM_CONNECTOR_POLL_HPD;
3769 }
3770 }
3771 }
3772 if (dev_priv->display.hpd_irq_setup)
3773 dev_priv->display.hpd_irq_setup(dev);
3774 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3775}
3776
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003777void intel_irq_init(struct drm_device *dev)
3778{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003779 struct drm_i915_private *dev_priv = dev->dev_private;
3780
3781 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003782 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003783 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003784 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003785
Daniel Vetter99584db2012-11-14 17:14:04 +01003786 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3787 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003788 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003789 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02003790 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003791
Tomas Janousek97a19a22012-12-08 13:48:13 +01003792 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003793
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003794 if (IS_GEN2(dev)) {
3795 dev->max_vblank_count = 0;
3796 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3797 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003798 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3799 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003800 } else {
3801 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3802 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003803 }
3804
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003805 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003806 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003807 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3808 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003809
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003810 if (IS_VALLEYVIEW(dev)) {
3811 dev->driver->irq_handler = valleyview_irq_handler;
3812 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3813 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3814 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3815 dev->driver->enable_vblank = valleyview_enable_vblank;
3816 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003817 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003818 } else if (IS_GEN8(dev)) {
3819 dev->driver->irq_handler = gen8_irq_handler;
3820 dev->driver->irq_preinstall = gen8_irq_preinstall;
3821 dev->driver->irq_postinstall = gen8_irq_postinstall;
3822 dev->driver->irq_uninstall = gen8_irq_uninstall;
3823 dev->driver->enable_vblank = gen8_enable_vblank;
3824 dev->driver->disable_vblank = gen8_disable_vblank;
3825 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003826 } else if (HAS_PCH_SPLIT(dev)) {
3827 dev->driver->irq_handler = ironlake_irq_handler;
3828 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3829 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3830 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3831 dev->driver->enable_vblank = ironlake_enable_vblank;
3832 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003833 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003834 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003835 if (INTEL_INFO(dev)->gen == 2) {
3836 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3837 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3838 dev->driver->irq_handler = i8xx_irq_handler;
3839 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003840 } else if (INTEL_INFO(dev)->gen == 3) {
3841 dev->driver->irq_preinstall = i915_irq_preinstall;
3842 dev->driver->irq_postinstall = i915_irq_postinstall;
3843 dev->driver->irq_uninstall = i915_irq_uninstall;
3844 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003845 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003846 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003847 dev->driver->irq_preinstall = i965_irq_preinstall;
3848 dev->driver->irq_postinstall = i965_irq_postinstall;
3849 dev->driver->irq_uninstall = i965_irq_uninstall;
3850 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003851 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003852 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003853 dev->driver->enable_vblank = i915_enable_vblank;
3854 dev->driver->disable_vblank = i915_disable_vblank;
3855 }
3856}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003857
3858void intel_hpd_init(struct drm_device *dev)
3859{
3860 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003861 struct drm_mode_config *mode_config = &dev->mode_config;
3862 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003863 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003864 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003865
Egbert Eich821450c2013-04-16 13:36:55 +02003866 for (i = 1; i < HPD_NUM_PINS; i++) {
3867 dev_priv->hpd_stats[i].hpd_cnt = 0;
3868 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3869 }
3870 list_for_each_entry(connector, &mode_config->connector_list, head) {
3871 struct intel_connector *intel_connector = to_intel_connector(connector);
3872 connector->polled = intel_connector->polled;
3873 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3874 connector->polled = DRM_CONNECTOR_POLL_HPD;
3875 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003876
3877 /* Interrupt setup is already guaranteed to be single-threaded, this is
3878 * just to make the assert_spin_locked checks happy. */
3879 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003880 if (dev_priv->display.hpd_irq_setup)
3881 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003882 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003883}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003884
3885/* Disable interrupts so we can allow Package C8+. */
3886void hsw_pc8_disable_interrupts(struct drm_device *dev)
3887{
3888 struct drm_i915_private *dev_priv = dev->dev_private;
3889 unsigned long irqflags;
3890
3891 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3892
3893 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3894 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3895 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3896 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3897 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3898
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003899 ironlake_disable_display_irq(dev_priv, 0xffffffff);
3900 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003901 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3902 snb_disable_pm_irq(dev_priv, 0xffffffff);
3903
3904 dev_priv->pc8.irqs_disabled = true;
3905
3906 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3907}
3908
3909/* Restore interrupts so we can recover from Package C8+. */
3910void hsw_pc8_restore_interrupts(struct drm_device *dev)
3911{
3912 struct drm_i915_private *dev_priv = dev->dev_private;
3913 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003914 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03003915
3916 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3917
3918 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003919 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003920
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003921 val = I915_READ(SDEIMR);
3922 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003923
3924 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003925 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003926
3927 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003928 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003929
3930 dev_priv->pc8.irqs_disabled = false;
3931
3932 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003933 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003934 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3935 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3936 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3937
3938 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3939}