blob: cdb158d1bfdeefd119e8347a5bd90787a0ddbca7 [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Egbert Eiche5868a32013-02-28 04:17:12 -050040static const u32 hpd_ibx[] = {
41 [HPD_CRT] = SDE_CRT_HOTPLUG,
42 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
43 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
44 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
45 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
46};
47
48static const u32 hpd_cpt[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010050 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050051 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
54};
55
56static const u32 hpd_mask_i915[] = {
57 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
58 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
59 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
60 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
61 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
62 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
63};
64
Daniel Vetter704cfb82013-12-18 09:08:43 +010065static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050066 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
67 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
68 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
69 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
70 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
71 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
72};
73
Egbert Eiche5868a32013-02-28 04:17:12 -050074static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
75 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
76 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
77 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
78 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
79 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
80 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
81};
82
Zhenyu Wang036a4a72009-06-08 14:40:19 +080083/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010084static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050085ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080086{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020087 assert_spin_locked(&dev_priv->irq_lock);
88
Paulo Zanonic67a4702013-08-19 13:18:09 -030089 if (dev_priv->pc8.irqs_disabled) {
90 WARN(1, "IRQs disabled\n");
91 dev_priv->pc8.regsave.deimr &= ~mask;
92 return;
93 }
94
Chris Wilson1ec14ad2010-12-04 11:30:53 +000095 if ((dev_priv->irq_mask & mask) != 0) {
96 dev_priv->irq_mask &= ~mask;
97 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000098 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080099 }
100}
101
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300102static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500103ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200105 assert_spin_locked(&dev_priv->irq_lock);
106
Paulo Zanonic67a4702013-08-19 13:18:09 -0300107 if (dev_priv->pc8.irqs_disabled) {
108 WARN(1, "IRQs disabled\n");
109 dev_priv->pc8.regsave.deimr |= mask;
110 return;
111 }
112
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000113 if ((dev_priv->irq_mask & mask) != mask) {
114 dev_priv->irq_mask |= mask;
115 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000116 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800117 }
118}
119
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300120/**
121 * ilk_update_gt_irq - update GTIMR
122 * @dev_priv: driver private
123 * @interrupt_mask: mask of interrupt bits to update
124 * @enabled_irq_mask: mask of interrupt bits to enable
125 */
126static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
127 uint32_t interrupt_mask,
128 uint32_t enabled_irq_mask)
129{
130 assert_spin_locked(&dev_priv->irq_lock);
131
Paulo Zanonic67a4702013-08-19 13:18:09 -0300132 if (dev_priv->pc8.irqs_disabled) {
133 WARN(1, "IRQs disabled\n");
134 dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
135 dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
136 interrupt_mask);
137 return;
138 }
139
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300140 dev_priv->gt_irq_mask &= ~interrupt_mask;
141 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
142 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
143 POSTING_READ(GTIMR);
144}
145
146void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
147{
148 ilk_update_gt_irq(dev_priv, mask, mask);
149}
150
151void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
152{
153 ilk_update_gt_irq(dev_priv, mask, 0);
154}
155
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300156/**
157 * snb_update_pm_irq - update GEN6_PMIMR
158 * @dev_priv: driver private
159 * @interrupt_mask: mask of interrupt bits to update
160 * @enabled_irq_mask: mask of interrupt bits to enable
161 */
162static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
163 uint32_t interrupt_mask,
164 uint32_t enabled_irq_mask)
165{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300166 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300167
168 assert_spin_locked(&dev_priv->irq_lock);
169
Paulo Zanonic67a4702013-08-19 13:18:09 -0300170 if (dev_priv->pc8.irqs_disabled) {
171 WARN(1, "IRQs disabled\n");
172 dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
173 dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
174 interrupt_mask);
175 return;
176 }
177
Paulo Zanoni605cd252013-08-06 18:57:15 -0300178 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300179 new_val &= ~interrupt_mask;
180 new_val |= (~enabled_irq_mask & interrupt_mask);
181
Paulo Zanoni605cd252013-08-06 18:57:15 -0300182 if (new_val != dev_priv->pm_irq_mask) {
183 dev_priv->pm_irq_mask = new_val;
184 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300185 POSTING_READ(GEN6_PMIMR);
186 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300187}
188
189void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
190{
191 snb_update_pm_irq(dev_priv, mask, mask);
192}
193
194void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
195{
196 snb_update_pm_irq(dev_priv, mask, 0);
197}
198
Paulo Zanoni86642812013-04-12 17:57:57 -0300199static bool ivb_can_enable_err_int(struct drm_device *dev)
200{
201 struct drm_i915_private *dev_priv = dev->dev_private;
202 struct intel_crtc *crtc;
203 enum pipe pipe;
204
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200205 assert_spin_locked(&dev_priv->irq_lock);
206
Paulo Zanoni86642812013-04-12 17:57:57 -0300207 for_each_pipe(pipe) {
208 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
209
210 if (crtc->cpu_fifo_underrun_disabled)
211 return false;
212 }
213
214 return true;
215}
216
217static bool cpt_can_enable_serr_int(struct drm_device *dev)
218{
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 enum pipe pipe;
221 struct intel_crtc *crtc;
222
Daniel Vetterfee884e2013-07-04 23:35:21 +0200223 assert_spin_locked(&dev_priv->irq_lock);
224
Paulo Zanoni86642812013-04-12 17:57:57 -0300225 for_each_pipe(pipe) {
226 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
227
228 if (crtc->pch_fifo_underrun_disabled)
229 return false;
230 }
231
232 return true;
233}
234
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200235static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
236{
237 struct drm_i915_private *dev_priv = dev->dev_private;
238 u32 reg = PIPESTAT(pipe);
239 u32 pipestat = I915_READ(reg) & 0x7fff0000;
240
241 assert_spin_locked(&dev_priv->irq_lock);
242
243 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
244 POSTING_READ(reg);
245}
246
Paulo Zanoni86642812013-04-12 17:57:57 -0300247static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
248 enum pipe pipe, bool enable)
249{
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
252 DE_PIPEB_FIFO_UNDERRUN;
253
254 if (enable)
255 ironlake_enable_display_irq(dev_priv, bit);
256 else
257 ironlake_disable_display_irq(dev_priv, bit);
258}
259
260static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200261 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300262{
263 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300264 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200265 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
266
Paulo Zanoni86642812013-04-12 17:57:57 -0300267 if (!ivb_can_enable_err_int(dev))
268 return;
269
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
271 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200272 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
273
274 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300275 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200276
277 if (!was_enabled &&
278 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
279 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
280 pipe_name(pipe));
281 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300282 }
283}
284
Daniel Vetter38d83c962013-11-07 11:05:46 +0100285static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
286 enum pipe pipe, bool enable)
287{
288 struct drm_i915_private *dev_priv = dev->dev_private;
289
290 assert_spin_locked(&dev_priv->irq_lock);
291
292 if (enable)
293 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
294 else
295 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
296 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
297 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
298}
299
Daniel Vetterfee884e2013-07-04 23:35:21 +0200300/**
301 * ibx_display_interrupt_update - update SDEIMR
302 * @dev_priv: driver private
303 * @interrupt_mask: mask of interrupt bits to update
304 * @enabled_irq_mask: mask of interrupt bits to enable
305 */
306static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
307 uint32_t interrupt_mask,
308 uint32_t enabled_irq_mask)
309{
310 uint32_t sdeimr = I915_READ(SDEIMR);
311 sdeimr &= ~interrupt_mask;
312 sdeimr |= (~enabled_irq_mask & interrupt_mask);
313
314 assert_spin_locked(&dev_priv->irq_lock);
315
Paulo Zanonic67a4702013-08-19 13:18:09 -0300316 if (dev_priv->pc8.irqs_disabled &&
317 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
318 WARN(1, "IRQs disabled\n");
319 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
320 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
321 interrupt_mask);
322 return;
323 }
324
Daniel Vetterfee884e2013-07-04 23:35:21 +0200325 I915_WRITE(SDEIMR, sdeimr);
326 POSTING_READ(SDEIMR);
327}
328#define ibx_enable_display_interrupt(dev_priv, bits) \
329 ibx_display_interrupt_update((dev_priv), (bits), (bits))
330#define ibx_disable_display_interrupt(dev_priv, bits) \
331 ibx_display_interrupt_update((dev_priv), (bits), 0)
332
Daniel Vetterde280752013-07-04 23:35:24 +0200333static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
334 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300335 bool enable)
336{
Paulo Zanoni86642812013-04-12 17:57:57 -0300337 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200338 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
339 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300340
341 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200342 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300343 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200344 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300345}
346
347static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
348 enum transcoder pch_transcoder,
349 bool enable)
350{
351 struct drm_i915_private *dev_priv = dev->dev_private;
352
353 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200354 I915_WRITE(SERR_INT,
355 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
356
Paulo Zanoni86642812013-04-12 17:57:57 -0300357 if (!cpt_can_enable_serr_int(dev))
358 return;
359
Daniel Vetterfee884e2013-07-04 23:35:21 +0200360 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300361 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200362 uint32_t tmp = I915_READ(SERR_INT);
363 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
364
365 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200366 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200367
368 if (!was_enabled &&
369 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
370 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
371 transcoder_name(pch_transcoder));
372 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300373 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300374}
375
376/**
377 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
378 * @dev: drm device
379 * @pipe: pipe
380 * @enable: true if we want to report FIFO underrun errors, false otherwise
381 *
382 * This function makes us disable or enable CPU fifo underruns for a specific
383 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
384 * reporting for one pipe may also disable all the other CPU error interruts for
385 * the other pipes, due to the fact that there's just one interrupt mask/enable
386 * bit for all the pipes.
387 *
388 * Returns the previous state of underrun reporting.
389 */
390bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
391 enum pipe pipe, bool enable)
392{
393 struct drm_i915_private *dev_priv = dev->dev_private;
394 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
395 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
396 unsigned long flags;
397 bool ret;
398
399 spin_lock_irqsave(&dev_priv->irq_lock, flags);
400
401 ret = !intel_crtc->cpu_fifo_underrun_disabled;
402
403 if (enable == ret)
404 goto done;
405
406 intel_crtc->cpu_fifo_underrun_disabled = !enable;
407
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200408 if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
409 i9xx_clear_fifo_underrun(dev, pipe);
410 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300411 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
412 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200413 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100414 else if (IS_GEN8(dev))
415 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300416
417done:
418 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
419 return ret;
420}
421
422/**
423 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
424 * @dev: drm device
425 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
426 * @enable: true if we want to report FIFO underrun errors, false otherwise
427 *
428 * This function makes us disable or enable PCH fifo underruns for a specific
429 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
430 * underrun reporting for one transcoder may also disable all the other PCH
431 * error interruts for the other transcoders, due to the fact that there's just
432 * one interrupt mask/enable bit for all the transcoders.
433 *
434 * Returns the previous state of underrun reporting.
435 */
436bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
437 enum transcoder pch_transcoder,
438 bool enable)
439{
440 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200441 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
442 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300443 unsigned long flags;
444 bool ret;
445
Daniel Vetterde280752013-07-04 23:35:24 +0200446 /*
447 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
448 * has only one pch transcoder A that all pipes can use. To avoid racy
449 * pch transcoder -> pipe lookups from interrupt code simply store the
450 * underrun statistics in crtc A. Since we never expose this anywhere
451 * nor use it outside of the fifo underrun code here using the "wrong"
452 * crtc on LPT won't cause issues.
453 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300454
455 spin_lock_irqsave(&dev_priv->irq_lock, flags);
456
457 ret = !intel_crtc->pch_fifo_underrun_disabled;
458
459 if (enable == ret)
460 goto done;
461
462 intel_crtc->pch_fifo_underrun_disabled = !enable;
463
464 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200465 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300466 else
467 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
468
469done:
470 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
471 return ret;
472}
473
474
Keith Packard7c463582008-11-04 02:03:27 -0800475void
Imre Deak755e9012014-02-10 18:42:47 +0200476__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
477 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800478{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200479 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200480 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800481
Daniel Vetterb79480b2013-06-27 17:52:10 +0200482 assert_spin_locked(&dev_priv->irq_lock);
483
Imre Deak755e9012014-02-10 18:42:47 +0200484 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
485 status_mask & ~PIPESTAT_INT_STATUS_MASK))
486 return;
487
488 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200489 return;
490
491 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200492 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200493 I915_WRITE(reg, pipestat);
494 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800495}
496
497void
Imre Deak755e9012014-02-10 18:42:47 +0200498__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
499 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800500{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200501 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200502 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800503
Daniel Vetterb79480b2013-06-27 17:52:10 +0200504 assert_spin_locked(&dev_priv->irq_lock);
505
Imre Deak755e9012014-02-10 18:42:47 +0200506 if (WARN_ON_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
507 status_mask & ~PIPESTAT_INT_STATUS_MASK))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200508 return;
509
Imre Deak755e9012014-02-10 18:42:47 +0200510 if ((pipestat & enable_mask) == 0)
511 return;
512
513 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200514 I915_WRITE(reg, pipestat);
515 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800516}
517
Imre Deak755e9012014-02-10 18:42:47 +0200518void
519i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
520 u32 status_mask)
521{
522 u32 enable_mask;
523
524 enable_mask = status_mask << 16;
525 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
526}
527
528void
529i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
530 u32 status_mask)
531{
532 u32 enable_mask;
533
534 enable_mask = status_mask << 16;
535 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
536}
537
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000538/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300539 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000540 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300541static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000542{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000543 drm_i915_private_t *dev_priv = dev->dev_private;
544 unsigned long irqflags;
545
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300546 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
547 return;
548
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000549 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000550
Imre Deak755e9012014-02-10 18:42:47 +0200551 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300552 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200553 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200554 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000555
556 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000557}
558
559/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700560 * i915_pipe_enabled - check if a pipe is enabled
561 * @dev: DRM device
562 * @pipe: pipe to check
563 *
564 * Reading certain registers when the pipe is disabled can hang the chip.
565 * Use this routine to make sure the PLL is running and the pipe is active
566 * before reading such registers if unsure.
567 */
568static int
569i915_pipe_enabled(struct drm_device *dev, int pipe)
570{
571 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200572
Daniel Vettera01025a2013-05-22 00:50:23 +0200573 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
574 /* Locking is horribly broken here, but whatever. */
575 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
576 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300577
Daniel Vettera01025a2013-05-22 00:50:23 +0200578 return intel_crtc->active;
579 } else {
580 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
581 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700582}
583
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300584static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
585{
586 /* Gen2 doesn't have a hardware frame counter */
587 return 0;
588}
589
Keith Packard42f52ef2008-10-18 19:39:29 -0700590/* Called from drm generic code, passed a 'crtc', which
591 * we use as a pipe index
592 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700593static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700594{
595 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
596 unsigned long high_frame;
597 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300598 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700599
600 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800601 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800602 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700603 return 0;
604 }
605
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300606 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
607 struct intel_crtc *intel_crtc =
608 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
609 const struct drm_display_mode *mode =
610 &intel_crtc->config.adjusted_mode;
611
612 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
613 } else {
614 enum transcoder cpu_transcoder =
615 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
616 u32 htotal;
617
618 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
619 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
620
621 vbl_start *= htotal;
622 }
623
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800624 high_frame = PIPEFRAME(pipe);
625 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100626
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700627 /*
628 * High & low register fields aren't synchronized, so make sure
629 * we get a low value that's stable across two reads of the high
630 * register.
631 */
632 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100633 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300634 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100635 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700636 } while (high1 != high2);
637
Chris Wilson5eddb702010-09-11 13:48:45 +0100638 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300639 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100640 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300641
642 /*
643 * The frame counter increments at beginning of active.
644 * Cook up a vblank counter by also checking the pixel
645 * counter against vblank start.
646 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200647 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700648}
649
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700650static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800651{
652 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800653 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800654
655 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800656 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800657 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800658 return 0;
659 }
660
661 return I915_READ(reg);
662}
663
Mario Kleinerad3543e2013-10-30 05:13:08 +0100664/* raw reads, only for fast reads of display block, no need for forcewake etc. */
665#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
666#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
667
Ville Syrjälä095163b2013-10-29 00:04:43 +0200668static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300669{
670 struct drm_i915_private *dev_priv = dev->dev_private;
671 uint32_t status;
672
Ville Syrjälä095163b2013-10-29 00:04:43 +0200673 if (INTEL_INFO(dev)->gen < 7) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300674 status = pipe == PIPE_A ?
675 DE_PIPEA_VBLANK :
676 DE_PIPEB_VBLANK;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300677 } else {
678 switch (pipe) {
679 default:
680 case PIPE_A:
681 status = DE_PIPEA_VBLANK_IVB;
682 break;
683 case PIPE_B:
684 status = DE_PIPEB_VBLANK_IVB;
685 break;
686 case PIPE_C:
687 status = DE_PIPEC_VBLANK_IVB;
688 break;
689 }
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300690 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100691
Ville Syrjälä095163b2013-10-29 00:04:43 +0200692 return __raw_i915_read32(dev_priv, DEISR) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300693}
694
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700695static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200696 unsigned int flags, int *vpos, int *hpos,
697 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100698{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300699 struct drm_i915_private *dev_priv = dev->dev_private;
700 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
701 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
702 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300703 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100704 int vbl_start, vbl_end, htotal, vtotal;
705 bool in_vbl = true;
706 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100707 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100708
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300709 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100710 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800711 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100712 return 0;
713 }
714
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300715 htotal = mode->crtc_htotal;
716 vtotal = mode->crtc_vtotal;
717 vbl_start = mode->crtc_vblank_start;
718 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100719
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200720 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
721 vbl_start = DIV_ROUND_UP(vbl_start, 2);
722 vbl_end /= 2;
723 vtotal /= 2;
724 }
725
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300726 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
727
Mario Kleinerad3543e2013-10-30 05:13:08 +0100728 /*
729 * Lock uncore.lock, as we will do multiple timing critical raw
730 * register reads, potentially with preemption disabled, so the
731 * following code must not block on uncore.lock.
732 */
733 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
734
735 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
736
737 /* Get optional system timestamp before query. */
738 if (stime)
739 *stime = ktime_get();
740
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300741 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100742 /* No obvious pixelcount register. Only query vertical
743 * scanout position from Display scan line register.
744 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300745 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100746 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300747 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100748 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300749
Ville Syrjälä095163b2013-10-29 00:04:43 +0200750 if (HAS_PCH_SPLIT(dev)) {
751 /*
752 * The scanline counter increments at the leading edge
753 * of hsync, ie. it completely misses the active portion
754 * of the line. Fix up the counter at both edges of vblank
755 * to get a more accurate picture whether we're in vblank
756 * or not.
757 */
758 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
759 if ((in_vbl && position == vbl_start - 1) ||
760 (!in_vbl && position == vbl_end - 1))
761 position = (position + 1) % vtotal;
762 } else {
763 /*
764 * ISR vblank status bits don't work the way we'd want
765 * them to work on non-PCH platforms (for
766 * ilk_pipe_in_vblank_locked()), and there doesn't
767 * appear any other way to determine if we're currently
768 * in vblank.
769 *
770 * Instead let's assume that we're already in vblank if
771 * we got called from the vblank interrupt and the
772 * scanline counter value indicates that we're on the
773 * line just prior to vblank start. This should result
774 * in the correct answer, unless the vblank interrupt
775 * delivery really got delayed for almost exactly one
776 * full frame/field.
777 */
778 if (flags & DRM_CALLED_FROM_VBLIRQ &&
779 position == vbl_start - 1) {
780 position = (position + 1) % vtotal;
781
782 /* Signal this correction as "applied". */
783 ret |= 0x8;
784 }
785 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100786 } else {
787 /* Have access to pixelcount since start of frame.
788 * We can split this into vertical and horizontal
789 * scanout position.
790 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100791 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100792
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300793 /* convert to pixel counts */
794 vbl_start *= htotal;
795 vbl_end *= htotal;
796 vtotal *= htotal;
797 }
798
Mario Kleinerad3543e2013-10-30 05:13:08 +0100799 /* Get optional system timestamp after query. */
800 if (etime)
801 *etime = ktime_get();
802
803 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
804
805 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
806
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300807 in_vbl = position >= vbl_start && position < vbl_end;
808
809 /*
810 * While in vblank, position will be negative
811 * counting up towards 0 at vbl_end. And outside
812 * vblank, position will be positive counting
813 * up since vbl_end.
814 */
815 if (position >= vbl_start)
816 position -= vbl_end;
817 else
818 position += vtotal - vbl_end;
819
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300820 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300821 *vpos = position;
822 *hpos = 0;
823 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100824 *vpos = position / htotal;
825 *hpos = position - (*vpos * htotal);
826 }
827
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100828 /* In vblank? */
829 if (in_vbl)
830 ret |= DRM_SCANOUTPOS_INVBL;
831
832 return ret;
833}
834
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700835static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100836 int *max_error,
837 struct timeval *vblank_time,
838 unsigned flags)
839{
Chris Wilson4041b852011-01-22 10:07:56 +0000840 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100841
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700842 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000843 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100844 return -EINVAL;
845 }
846
847 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000848 crtc = intel_get_crtc_for_pipe(dev, pipe);
849 if (crtc == NULL) {
850 DRM_ERROR("Invalid crtc %d\n", pipe);
851 return -EINVAL;
852 }
853
854 if (!crtc->enabled) {
855 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
856 return -EBUSY;
857 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100858
859 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000860 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
861 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300862 crtc,
863 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100864}
865
Jani Nikula67c347f2013-09-17 14:26:34 +0300866static bool intel_hpd_irq_event(struct drm_device *dev,
867 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200868{
869 enum drm_connector_status old_status;
870
871 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
872 old_status = connector->status;
873
874 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300875 if (old_status == connector->status)
876 return false;
877
878 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200879 connector->base.id,
880 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300881 drm_get_connector_status_name(old_status),
882 drm_get_connector_status_name(connector->status));
883
884 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200885}
886
Jesse Barnes5ca58282009-03-31 14:11:15 -0700887/*
888 * Handle hotplug events outside the interrupt handler proper.
889 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200890#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
891
Jesse Barnes5ca58282009-03-31 14:11:15 -0700892static void i915_hotplug_work_func(struct work_struct *work)
893{
894 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
895 hotplug_work);
896 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700897 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200898 struct intel_connector *intel_connector;
899 struct intel_encoder *intel_encoder;
900 struct drm_connector *connector;
901 unsigned long irqflags;
902 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200903 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200904 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700905
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100906 /* HPD irq before everything is fully set up. */
907 if (!dev_priv->enable_hotplug_processing)
908 return;
909
Keith Packarda65e34c2011-07-25 10:04:56 -0700910 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800911 DRM_DEBUG_KMS("running encoder hotplug functions\n");
912
Egbert Eichcd569ae2013-04-16 13:36:57 +0200913 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200914
915 hpd_event_bits = dev_priv->hpd_event_bits;
916 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +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 (intel_encoder->hpd_pin > HPD_NONE &&
921 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
922 connector->polled == DRM_CONNECTOR_POLL_HPD) {
923 DRM_INFO("HPD interrupt storm detected on connector %s: "
924 "switching from hotplug detection to polling\n",
925 drm_get_connector_name(connector));
926 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
927 connector->polled = DRM_CONNECTOR_POLL_CONNECT
928 | DRM_CONNECTOR_POLL_DISCONNECT;
929 hpd_disabled = true;
930 }
Egbert Eich142e2392013-04-11 15:57:57 +0200931 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
932 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
933 drm_get_connector_name(connector), intel_encoder->hpd_pin);
934 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200935 }
936 /* if there were no outputs to poll, poll was disabled,
937 * therefore make sure it's enabled when disabling HPD on
938 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200939 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200940 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200941 mod_timer(&dev_priv->hotplug_reenable_timer,
942 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
943 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200944
945 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
946
Egbert Eich321a1b32013-04-11 16:00:26 +0200947 list_for_each_entry(connector, &mode_config->connector_list, head) {
948 intel_connector = to_intel_connector(connector);
949 intel_encoder = intel_connector->encoder;
950 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
951 if (intel_encoder->hot_plug)
952 intel_encoder->hot_plug(intel_encoder);
953 if (intel_hpd_irq_event(dev, connector))
954 changed = true;
955 }
956 }
Keith Packard40ee3382011-07-28 15:31:19 -0700957 mutex_unlock(&mode_config->mutex);
958
Egbert Eich321a1b32013-04-11 16:00:26 +0200959 if (changed)
960 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700961}
962
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +0200963static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
964{
965 del_timer_sync(&dev_priv->hotplug_reenable_timer);
966}
967
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200968static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800969{
970 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000971 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200972 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200973
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200974 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800975
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200976 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
977
Daniel Vetter20e4d402012-08-08 23:35:39 +0200978 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200979
Jesse Barnes7648fa92010-05-20 14:28:11 -0700980 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000981 busy_up = I915_READ(RCPREVBSYTUPAVG);
982 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800983 max_avg = I915_READ(RCBMAXAVG);
984 min_avg = I915_READ(RCBMINAVG);
985
986 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000987 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200988 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
989 new_delay = dev_priv->ips.cur_delay - 1;
990 if (new_delay < dev_priv->ips.max_delay)
991 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000992 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200993 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
994 new_delay = dev_priv->ips.cur_delay + 1;
995 if (new_delay > dev_priv->ips.min_delay)
996 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800997 }
998
Jesse Barnes7648fa92010-05-20 14:28:11 -0700999 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001000 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001001
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001002 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001003
Jesse Barnesf97108d2010-01-29 11:27:07 -08001004 return;
1005}
1006
Chris Wilson549f7362010-10-19 11:19:32 +01001007static void notify_ring(struct drm_device *dev,
1008 struct intel_ring_buffer *ring)
1009{
Chris Wilson475553d2011-01-20 09:52:56 +00001010 if (ring->obj == NULL)
1011 return;
1012
Chris Wilson814e9b52013-09-23 17:33:19 -03001013 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001014
Chris Wilson549f7362010-10-19 11:19:32 +01001015 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001016 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +01001017}
1018
Deepak S76c3552f2014-01-30 23:08:16 +05301019void gen6_set_pm_mask(struct drm_i915_private *dev_priv,
Deepak S27544362014-01-27 21:35:05 +05301020 u32 pm_iir, int new_delay)
1021{
1022 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
1023 if (new_delay >= dev_priv->rps.max_delay) {
1024 /* Mask UP THRESHOLD Interrupts */
1025 I915_WRITE(GEN6_PMINTRMSK,
1026 I915_READ(GEN6_PMINTRMSK) |
1027 GEN6_PM_RP_UP_THRESHOLD);
1028 dev_priv->rps.rp_up_masked = true;
1029 }
1030 if (dev_priv->rps.rp_down_masked) {
1031 /* UnMask DOWN THRESHOLD Interrupts */
1032 I915_WRITE(GEN6_PMINTRMSK,
1033 I915_READ(GEN6_PMINTRMSK) &
1034 ~GEN6_PM_RP_DOWN_THRESHOLD);
1035 dev_priv->rps.rp_down_masked = false;
1036 }
1037 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1038 if (new_delay <= dev_priv->rps.min_delay) {
1039 /* Mask DOWN THRESHOLD Interrupts */
1040 I915_WRITE(GEN6_PMINTRMSK,
1041 I915_READ(GEN6_PMINTRMSK) |
1042 GEN6_PM_RP_DOWN_THRESHOLD);
1043 dev_priv->rps.rp_down_masked = true;
1044 }
1045
1046 if (dev_priv->rps.rp_up_masked) {
1047 /* UnMask UP THRESHOLD Interrupts */
1048 I915_WRITE(GEN6_PMINTRMSK,
1049 I915_READ(GEN6_PMINTRMSK) &
1050 ~GEN6_PM_RP_UP_THRESHOLD);
1051 dev_priv->rps.rp_up_masked = false;
1052 }
1053 }
1054}
1055
Ben Widawsky4912d042011-04-25 11:25:20 -07001056static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001057{
Ben Widawsky4912d042011-04-25 11:25:20 -07001058 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001059 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001060 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001061 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001062
Daniel Vetter59cdb632013-07-04 23:35:28 +02001063 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001064 pm_iir = dev_priv->rps.pm_iir;
1065 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -07001066 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001067 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001068 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001069
Paulo Zanoni60611c12013-08-15 11:50:01 -03001070 /* Make sure we didn't queue anything we're not going to process. */
1071 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
1072
Ben Widawsky48484052013-05-28 19:22:27 -07001073 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001074 return;
1075
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001076 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001077
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001078 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001079 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001080 if (adj > 0)
1081 adj *= 2;
1082 else
1083 adj = 1;
1084 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001085
1086 /*
1087 * For better performance, jump directly
1088 * to RPe if we're below it.
1089 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001090 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +03001091 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001092 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1093 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
1094 new_delay = dev_priv->rps.rpe_delay;
1095 else
1096 new_delay = dev_priv->rps.min_delay;
1097 adj = 0;
1098 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1099 if (adj < 0)
1100 adj *= 2;
1101 else
1102 adj = -1;
1103 new_delay = dev_priv->rps.cur_delay + adj;
1104 } else { /* unknown event */
1105 new_delay = dev_priv->rps.cur_delay;
1106 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001107
Ben Widawsky79249632012-09-07 19:43:42 -07001108 /* sysfs frequency interfaces may have snuck in while servicing the
1109 * interrupt
1110 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001111 new_delay = clamp_t(int, new_delay,
1112 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Deepak S27544362014-01-27 21:35:05 +05301113
1114 gen6_set_pm_mask(dev_priv, pm_iir, new_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001115 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
1116
1117 if (IS_VALLEYVIEW(dev_priv->dev))
1118 valleyview_set_rps(dev_priv->dev, new_delay);
1119 else
1120 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001121
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001122 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001123}
1124
Ben Widawskye3689192012-05-25 16:56:22 -07001125
1126/**
1127 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1128 * occurred.
1129 * @work: workqueue struct
1130 *
1131 * Doesn't actually do anything except notify userspace. As a consequence of
1132 * this event, userspace should try to remap the bad rows since statistically
1133 * it is likely the same row is more likely to go bad again.
1134 */
1135static void ivybridge_parity_work(struct work_struct *work)
1136{
1137 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001138 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001139 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001140 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001141 uint32_t misccpctl;
1142 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001143 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001144
1145 /* We must turn off DOP level clock gating to access the L3 registers.
1146 * In order to prevent a get/put style interface, acquire struct mutex
1147 * any time we access those registers.
1148 */
1149 mutex_lock(&dev_priv->dev->struct_mutex);
1150
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001151 /* If we've screwed up tracking, just let the interrupt fire again */
1152 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1153 goto out;
1154
Ben Widawskye3689192012-05-25 16:56:22 -07001155 misccpctl = I915_READ(GEN7_MISCCPCTL);
1156 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1157 POSTING_READ(GEN7_MISCCPCTL);
1158
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001159 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1160 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001161
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001162 slice--;
1163 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1164 break;
1165
1166 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1167
1168 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1169
1170 error_status = I915_READ(reg);
1171 row = GEN7_PARITY_ERROR_ROW(error_status);
1172 bank = GEN7_PARITY_ERROR_BANK(error_status);
1173 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1174
1175 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1176 POSTING_READ(reg);
1177
1178 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1179 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1180 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1181 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1182 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1183 parity_event[5] = NULL;
1184
Dave Airlie5bdebb12013-10-11 14:07:25 +10001185 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001186 KOBJ_CHANGE, parity_event);
1187
1188 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1189 slice, row, bank, subbank);
1190
1191 kfree(parity_event[4]);
1192 kfree(parity_event[3]);
1193 kfree(parity_event[2]);
1194 kfree(parity_event[1]);
1195 }
Ben Widawskye3689192012-05-25 16:56:22 -07001196
1197 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1198
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001199out:
1200 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001201 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001202 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001203 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1204
1205 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001206}
1207
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001208static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001209{
1210 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001211
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001212 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001213 return;
1214
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001215 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001216 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001217 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001218
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001219 iir &= GT_PARITY_ERROR(dev);
1220 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1221 dev_priv->l3_parity.which_slice |= 1 << 1;
1222
1223 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1224 dev_priv->l3_parity.which_slice |= 1 << 0;
1225
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001226 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001227}
1228
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001229static void ilk_gt_irq_handler(struct drm_device *dev,
1230 struct drm_i915_private *dev_priv,
1231 u32 gt_iir)
1232{
1233 if (gt_iir &
1234 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1235 notify_ring(dev, &dev_priv->ring[RCS]);
1236 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1237 notify_ring(dev, &dev_priv->ring[VCS]);
1238}
1239
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001240static void snb_gt_irq_handler(struct drm_device *dev,
1241 struct drm_i915_private *dev_priv,
1242 u32 gt_iir)
1243{
1244
Ben Widawskycc609d52013-05-28 19:22:29 -07001245 if (gt_iir &
1246 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001247 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001248 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001249 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001250 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001251 notify_ring(dev, &dev_priv->ring[BCS]);
1252
Ben Widawskycc609d52013-05-28 19:22:29 -07001253 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1254 GT_BSD_CS_ERROR_INTERRUPT |
1255 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001256 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1257 i915_handle_error(dev, false);
1258 }
Ben Widawskye3689192012-05-25 16:56:22 -07001259
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001260 if (gt_iir & GT_PARITY_ERROR(dev))
1261 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001262}
1263
Ben Widawskyabd58f02013-11-02 21:07:09 -07001264static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1265 struct drm_i915_private *dev_priv,
1266 u32 master_ctl)
1267{
1268 u32 rcs, bcs, vcs;
1269 uint32_t tmp = 0;
1270 irqreturn_t ret = IRQ_NONE;
1271
1272 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1273 tmp = I915_READ(GEN8_GT_IIR(0));
1274 if (tmp) {
1275 ret = IRQ_HANDLED;
1276 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1277 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1278 if (rcs & GT_RENDER_USER_INTERRUPT)
1279 notify_ring(dev, &dev_priv->ring[RCS]);
1280 if (bcs & GT_RENDER_USER_INTERRUPT)
1281 notify_ring(dev, &dev_priv->ring[BCS]);
1282 I915_WRITE(GEN8_GT_IIR(0), tmp);
1283 } else
1284 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1285 }
1286
1287 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1288 tmp = I915_READ(GEN8_GT_IIR(1));
1289 if (tmp) {
1290 ret = IRQ_HANDLED;
1291 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1292 if (vcs & GT_RENDER_USER_INTERRUPT)
1293 notify_ring(dev, &dev_priv->ring[VCS]);
1294 I915_WRITE(GEN8_GT_IIR(1), tmp);
1295 } else
1296 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1297 }
1298
1299 if (master_ctl & GEN8_GT_VECS_IRQ) {
1300 tmp = I915_READ(GEN8_GT_IIR(3));
1301 if (tmp) {
1302 ret = IRQ_HANDLED;
1303 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1304 if (vcs & GT_RENDER_USER_INTERRUPT)
1305 notify_ring(dev, &dev_priv->ring[VECS]);
1306 I915_WRITE(GEN8_GT_IIR(3), tmp);
1307 } else
1308 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1309 }
1310
1311 return ret;
1312}
1313
Egbert Eichb543fb02013-04-16 13:36:54 +02001314#define HPD_STORM_DETECT_PERIOD 1000
1315#define HPD_STORM_THRESHOLD 5
1316
Daniel Vetter10a504d2013-06-27 17:52:12 +02001317static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001318 u32 hotplug_trigger,
1319 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001320{
1321 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001322 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001323 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001324
Daniel Vetter91d131d2013-06-27 17:52:14 +02001325 if (!hotplug_trigger)
1326 return;
1327
Imre Deakcc9bd492014-01-16 19:56:54 +02001328 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1329 hotplug_trigger);
1330
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001331 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001332 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001333
Chris Wilson34320872014-01-10 18:49:20 +00001334 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001335 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001336 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1337 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001338
Egbert Eichb543fb02013-04-16 13:36:54 +02001339 if (!(hpd[i] & hotplug_trigger) ||
1340 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1341 continue;
1342
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001343 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001344 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1345 dev_priv->hpd_stats[i].hpd_last_jiffies
1346 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1347 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1348 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001349 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001350 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1351 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001352 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001353 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001354 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001355 } else {
1356 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001357 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1358 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001359 }
1360 }
1361
Daniel Vetter10a504d2013-06-27 17:52:12 +02001362 if (storm_detected)
1363 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001364 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001365
Daniel Vetter645416f2013-09-02 16:22:25 +02001366 /*
1367 * Our hotplug handler can grab modeset locks (by calling down into the
1368 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1369 * queue for otherwise the flush_work in the pageflip code will
1370 * deadlock.
1371 */
1372 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001373}
1374
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001375static void gmbus_irq_handler(struct drm_device *dev)
1376{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001377 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1378
Daniel Vetter28c70f12012-12-01 13:53:45 +01001379 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001380}
1381
Daniel Vetterce99c252012-12-01 13:53:47 +01001382static void dp_aux_irq_handler(struct drm_device *dev)
1383{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001384 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1385
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001386 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001387}
1388
Shuang He8bf1e9f2013-10-15 18:55:27 +01001389#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001390static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1391 uint32_t crc0, uint32_t crc1,
1392 uint32_t crc2, uint32_t crc3,
1393 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001394{
1395 struct drm_i915_private *dev_priv = dev->dev_private;
1396 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1397 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001398 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001399
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001400 spin_lock(&pipe_crc->lock);
1401
Damien Lespiau0c912c72013-10-15 18:55:37 +01001402 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001403 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001404 DRM_ERROR("spurious interrupt\n");
1405 return;
1406 }
1407
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001408 head = pipe_crc->head;
1409 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001410
1411 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001412 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001413 DRM_ERROR("CRC buffer overflowing\n");
1414 return;
1415 }
1416
1417 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001418
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001419 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001420 entry->crc[0] = crc0;
1421 entry->crc[1] = crc1;
1422 entry->crc[2] = crc2;
1423 entry->crc[3] = crc3;
1424 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001425
1426 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001427 pipe_crc->head = head;
1428
1429 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001430
1431 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001432}
Daniel Vetter277de952013-10-18 16:37:07 +02001433#else
1434static inline void
1435display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1436 uint32_t crc0, uint32_t crc1,
1437 uint32_t crc2, uint32_t crc3,
1438 uint32_t crc4) {}
1439#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001440
Daniel Vetter277de952013-10-18 16:37:07 +02001441
1442static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001443{
1444 struct drm_i915_private *dev_priv = dev->dev_private;
1445
Daniel Vetter277de952013-10-18 16:37:07 +02001446 display_pipe_crc_irq_handler(dev, pipe,
1447 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1448 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001449}
1450
Daniel Vetter277de952013-10-18 16:37:07 +02001451static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001452{
1453 struct drm_i915_private *dev_priv = dev->dev_private;
1454
Daniel Vetter277de952013-10-18 16:37:07 +02001455 display_pipe_crc_irq_handler(dev, pipe,
1456 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1457 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1458 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1459 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1460 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001461}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001462
Daniel Vetter277de952013-10-18 16:37:07 +02001463static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001464{
1465 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001466 uint32_t res1, res2;
1467
1468 if (INTEL_INFO(dev)->gen >= 3)
1469 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1470 else
1471 res1 = 0;
1472
1473 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1474 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1475 else
1476 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001477
Daniel Vetter277de952013-10-18 16:37:07 +02001478 display_pipe_crc_irq_handler(dev, pipe,
1479 I915_READ(PIPE_CRC_RES_RED(pipe)),
1480 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1481 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1482 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001483}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001484
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001485/* The RPS events need forcewake, so we add them to a work queue and mask their
1486 * IMR bits until the work is done. Other interrupts can be processed without
1487 * the work queue. */
1488static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001489{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001490 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001491 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001492 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001493 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001494 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001495
1496 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001497 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001498
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001499 if (HAS_VEBOX(dev_priv->dev)) {
1500 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1501 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001502
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001503 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1504 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1505 i915_handle_error(dev_priv->dev, false);
1506 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001507 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001508}
1509
Imre Deakc1874ed2014-02-04 21:35:46 +02001510static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1511{
1512 struct drm_i915_private *dev_priv = dev->dev_private;
1513 u32 pipe_stats[I915_MAX_PIPES];
Imre Deakc1874ed2014-02-04 21:35:46 +02001514 int pipe;
1515
Imre Deak58ead0d2014-02-04 21:35:47 +02001516 spin_lock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001517 for_each_pipe(pipe) {
1518 int reg = PIPESTAT(pipe);
1519 pipe_stats[pipe] = I915_READ(reg);
1520
1521 /*
1522 * Clear the PIPE*STAT regs before the IIR
1523 */
1524 if (pipe_stats[pipe] & 0x8000ffff)
1525 I915_WRITE(reg, pipe_stats[pipe]);
1526 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001527 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001528
1529 for_each_pipe(pipe) {
1530 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1531 drm_handle_vblank(dev, pipe);
1532
Imre Deak579a9b02014-02-04 21:35:48 +02001533 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001534 intel_prepare_page_flip(dev, pipe);
1535 intel_finish_page_flip(dev, pipe);
1536 }
1537
1538 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1539 i9xx_pipe_crc_irq_handler(dev, pipe);
1540
1541 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1542 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1543 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1544 }
1545
1546 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1547 gmbus_irq_handler(dev);
1548}
1549
Daniel Vetterff1f5252012-10-02 15:10:55 +02001550static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001551{
1552 struct drm_device *dev = (struct drm_device *) arg;
1553 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1554 u32 iir, gt_iir, pm_iir;
1555 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001556
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001557 while (true) {
1558 iir = I915_READ(VLV_IIR);
1559 gt_iir = I915_READ(GTIIR);
1560 pm_iir = I915_READ(GEN6_PMIIR);
1561
1562 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1563 goto out;
1564
1565 ret = IRQ_HANDLED;
1566
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001567 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001568
Imre Deakc1874ed2014-02-04 21:35:46 +02001569 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001570
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001571 /* Consume port. Then clear IIR or we'll miss events */
1572 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1573 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001574 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001575
Daniel Vetter91d131d2013-06-27 17:52:14 +02001576 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1577
Daniel Vetter4aeebd72013-10-31 09:53:36 +01001578 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1579 dp_aux_irq_handler(dev);
1580
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001581 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1582 I915_READ(PORT_HOTPLUG_STAT);
1583 }
1584
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001585
Paulo Zanoni60611c12013-08-15 11:50:01 -03001586 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001587 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001588
1589 I915_WRITE(GTIIR, gt_iir);
1590 I915_WRITE(GEN6_PMIIR, pm_iir);
1591 I915_WRITE(VLV_IIR, iir);
1592 }
1593
1594out:
1595 return ret;
1596}
1597
Adam Jackson23e81d62012-06-06 15:45:44 -04001598static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001599{
1600 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001601 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001602 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001603
Daniel Vetter91d131d2013-06-27 17:52:14 +02001604 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1605
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001606 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1607 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1608 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001609 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001610 port_name(port));
1611 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001612
Daniel Vetterce99c252012-12-01 13:53:47 +01001613 if (pch_iir & SDE_AUX_MASK)
1614 dp_aux_irq_handler(dev);
1615
Jesse Barnes776ad802011-01-04 15:09:39 -08001616 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001617 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001618
1619 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1620 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1621
1622 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1623 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1624
1625 if (pch_iir & SDE_POISON)
1626 DRM_ERROR("PCH poison interrupt\n");
1627
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001628 if (pch_iir & SDE_FDI_MASK)
1629 for_each_pipe(pipe)
1630 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1631 pipe_name(pipe),
1632 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001633
1634 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1635 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1636
1637 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1638 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1639
Jesse Barnes776ad802011-01-04 15:09:39 -08001640 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001641 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1642 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001643 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001644
1645 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1646 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1647 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001648 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001649}
1650
1651static void ivb_err_int_handler(struct drm_device *dev)
1652{
1653 struct drm_i915_private *dev_priv = dev->dev_private;
1654 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001655 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001656
Paulo Zanonide032bf2013-04-12 17:57:58 -03001657 if (err_int & ERR_INT_POISON)
1658 DRM_ERROR("Poison interrupt\n");
1659
Daniel Vetter5a69b892013-10-16 22:55:52 +02001660 for_each_pipe(pipe) {
1661 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1662 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1663 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001664 DRM_ERROR("Pipe %c FIFO underrun\n",
1665 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001666 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001667
Daniel Vetter5a69b892013-10-16 22:55:52 +02001668 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1669 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001670 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001671 else
Daniel Vetter277de952013-10-18 16:37:07 +02001672 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001673 }
1674 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001675
Paulo Zanoni86642812013-04-12 17:57:57 -03001676 I915_WRITE(GEN7_ERR_INT, err_int);
1677}
1678
1679static void cpt_serr_int_handler(struct drm_device *dev)
1680{
1681 struct drm_i915_private *dev_priv = dev->dev_private;
1682 u32 serr_int = I915_READ(SERR_INT);
1683
Paulo Zanonide032bf2013-04-12 17:57:58 -03001684 if (serr_int & SERR_INT_POISON)
1685 DRM_ERROR("PCH poison interrupt\n");
1686
Paulo Zanoni86642812013-04-12 17:57:57 -03001687 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1688 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1689 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001690 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001691
1692 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1693 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1694 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001695 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001696
1697 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1698 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1699 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001700 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001701
1702 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001703}
1704
Adam Jackson23e81d62012-06-06 15:45:44 -04001705static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1706{
1707 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1708 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001709 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001710
Daniel Vetter91d131d2013-06-27 17:52:14 +02001711 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1712
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001713 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1714 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1715 SDE_AUDIO_POWER_SHIFT_CPT);
1716 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1717 port_name(port));
1718 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001719
1720 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001721 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001722
1723 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001724 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001725
1726 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1727 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1728
1729 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1730 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1731
1732 if (pch_iir & SDE_FDI_MASK_CPT)
1733 for_each_pipe(pipe)
1734 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1735 pipe_name(pipe),
1736 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001737
1738 if (pch_iir & SDE_ERROR_CPT)
1739 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001740}
1741
Paulo Zanonic008bc62013-07-12 16:35:10 -03001742static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1743{
1744 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001745 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001746
1747 if (de_iir & DE_AUX_CHANNEL_A)
1748 dp_aux_irq_handler(dev);
1749
1750 if (de_iir & DE_GSE)
1751 intel_opregion_asle_intr(dev);
1752
Paulo Zanonic008bc62013-07-12 16:35:10 -03001753 if (de_iir & DE_POISON)
1754 DRM_ERROR("Poison interrupt\n");
1755
Daniel Vetter40da17c2013-10-21 18:04:36 +02001756 for_each_pipe(pipe) {
1757 if (de_iir & DE_PIPE_VBLANK(pipe))
1758 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001759
Daniel Vetter40da17c2013-10-21 18:04:36 +02001760 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1761 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001762 DRM_ERROR("Pipe %c FIFO underrun\n",
1763 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001764
Daniel Vetter40da17c2013-10-21 18:04:36 +02001765 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1766 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001767
Daniel Vetter40da17c2013-10-21 18:04:36 +02001768 /* plane/pipes map 1:1 on ilk+ */
1769 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1770 intel_prepare_page_flip(dev, pipe);
1771 intel_finish_page_flip_plane(dev, pipe);
1772 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001773 }
1774
1775 /* check event from PCH */
1776 if (de_iir & DE_PCH_EVENT) {
1777 u32 pch_iir = I915_READ(SDEIIR);
1778
1779 if (HAS_PCH_CPT(dev))
1780 cpt_irq_handler(dev, pch_iir);
1781 else
1782 ibx_irq_handler(dev, pch_iir);
1783
1784 /* should clear PCH hotplug event before clear CPU irq */
1785 I915_WRITE(SDEIIR, pch_iir);
1786 }
1787
1788 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1789 ironlake_rps_change_irq_handler(dev);
1790}
1791
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001792static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1793{
1794 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001795 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001796
1797 if (de_iir & DE_ERR_INT_IVB)
1798 ivb_err_int_handler(dev);
1799
1800 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1801 dp_aux_irq_handler(dev);
1802
1803 if (de_iir & DE_GSE_IVB)
1804 intel_opregion_asle_intr(dev);
1805
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001806 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001807 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001808 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001809
1810 /* plane/pipes map 1:1 on ilk+ */
1811 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001812 intel_prepare_page_flip(dev, i);
1813 intel_finish_page_flip_plane(dev, i);
1814 }
1815 }
1816
1817 /* check event from PCH */
1818 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1819 u32 pch_iir = I915_READ(SDEIIR);
1820
1821 cpt_irq_handler(dev, pch_iir);
1822
1823 /* clear PCH hotplug event before clear CPU irq */
1824 I915_WRITE(SDEIIR, pch_iir);
1825 }
1826}
1827
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001828static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001829{
1830 struct drm_device *dev = (struct drm_device *) arg;
1831 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001832 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001833 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001834
Paulo Zanoni86642812013-04-12 17:57:57 -03001835 /* We get interrupts on unclaimed registers, so check for this before we
1836 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001837 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001838
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001839 /* disable master interrupt before clearing iir */
1840 de_ier = I915_READ(DEIER);
1841 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001842 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001843
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001844 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1845 * interrupts will will be stored on its back queue, and then we'll be
1846 * able to process them after we restore SDEIER (as soon as we restore
1847 * it, we'll get an interrupt if SDEIIR still has something to process
1848 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001849 if (!HAS_PCH_NOP(dev)) {
1850 sde_ier = I915_READ(SDEIER);
1851 I915_WRITE(SDEIER, 0);
1852 POSTING_READ(SDEIER);
1853 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001854
Chris Wilson0e434062012-05-09 21:45:44 +01001855 gt_iir = I915_READ(GTIIR);
1856 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001857 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001858 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001859 else
1860 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001861 I915_WRITE(GTIIR, gt_iir);
1862 ret = IRQ_HANDLED;
1863 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001864
1865 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001866 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001867 if (INTEL_INFO(dev)->gen >= 7)
1868 ivb_display_irq_handler(dev, de_iir);
1869 else
1870 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001871 I915_WRITE(DEIIR, de_iir);
1872 ret = IRQ_HANDLED;
1873 }
1874
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001875 if (INTEL_INFO(dev)->gen >= 6) {
1876 u32 pm_iir = I915_READ(GEN6_PMIIR);
1877 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001878 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001879 I915_WRITE(GEN6_PMIIR, pm_iir);
1880 ret = IRQ_HANDLED;
1881 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001882 }
1883
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001884 I915_WRITE(DEIER, de_ier);
1885 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001886 if (!HAS_PCH_NOP(dev)) {
1887 I915_WRITE(SDEIER, sde_ier);
1888 POSTING_READ(SDEIER);
1889 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001890
1891 return ret;
1892}
1893
Ben Widawskyabd58f02013-11-02 21:07:09 -07001894static irqreturn_t gen8_irq_handler(int irq, void *arg)
1895{
1896 struct drm_device *dev = arg;
1897 struct drm_i915_private *dev_priv = dev->dev_private;
1898 u32 master_ctl;
1899 irqreturn_t ret = IRQ_NONE;
1900 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001901 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001902
Ben Widawskyabd58f02013-11-02 21:07:09 -07001903 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1904 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1905 if (!master_ctl)
1906 return IRQ_NONE;
1907
1908 I915_WRITE(GEN8_MASTER_IRQ, 0);
1909 POSTING_READ(GEN8_MASTER_IRQ);
1910
1911 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1912
1913 if (master_ctl & GEN8_DE_MISC_IRQ) {
1914 tmp = I915_READ(GEN8_DE_MISC_IIR);
1915 if (tmp & GEN8_DE_MISC_GSE)
1916 intel_opregion_asle_intr(dev);
1917 else if (tmp)
1918 DRM_ERROR("Unexpected DE Misc interrupt\n");
1919 else
1920 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1921
1922 if (tmp) {
1923 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1924 ret = IRQ_HANDLED;
1925 }
1926 }
1927
Daniel Vetter6d766f02013-11-07 14:49:55 +01001928 if (master_ctl & GEN8_DE_PORT_IRQ) {
1929 tmp = I915_READ(GEN8_DE_PORT_IIR);
1930 if (tmp & GEN8_AUX_CHANNEL_A)
1931 dp_aux_irq_handler(dev);
1932 else if (tmp)
1933 DRM_ERROR("Unexpected DE Port interrupt\n");
1934 else
1935 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1936
1937 if (tmp) {
1938 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1939 ret = IRQ_HANDLED;
1940 }
1941 }
1942
Daniel Vetterc42664c2013-11-07 11:05:40 +01001943 for_each_pipe(pipe) {
1944 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001945
Daniel Vetterc42664c2013-11-07 11:05:40 +01001946 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1947 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001948
Daniel Vetterc42664c2013-11-07 11:05:40 +01001949 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1950 if (pipe_iir & GEN8_PIPE_VBLANK)
1951 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001952
Daniel Vetterc42664c2013-11-07 11:05:40 +01001953 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1954 intel_prepare_page_flip(dev, pipe);
1955 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001956 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001957
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001958 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1959 hsw_pipe_crc_irq_handler(dev, pipe);
1960
Daniel Vetter38d83c962013-11-07 11:05:46 +01001961 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1962 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1963 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001964 DRM_ERROR("Pipe %c FIFO underrun\n",
1965 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01001966 }
1967
Daniel Vetter30100f22013-11-07 14:49:24 +01001968 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1969 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
1970 pipe_name(pipe),
1971 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
1972 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001973
1974 if (pipe_iir) {
1975 ret = IRQ_HANDLED;
1976 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
1977 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07001978 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
1979 }
1980
Daniel Vetter92d03a82013-11-07 11:05:43 +01001981 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
1982 /*
1983 * FIXME(BDW): Assume for now that the new interrupt handling
1984 * scheme also closed the SDE interrupt handling race we've seen
1985 * on older pch-split platforms. But this needs testing.
1986 */
1987 u32 pch_iir = I915_READ(SDEIIR);
1988
1989 cpt_irq_handler(dev, pch_iir);
1990
1991 if (pch_iir) {
1992 I915_WRITE(SDEIIR, pch_iir);
1993 ret = IRQ_HANDLED;
1994 }
1995 }
1996
Ben Widawskyabd58f02013-11-02 21:07:09 -07001997 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1998 POSTING_READ(GEN8_MASTER_IRQ);
1999
2000 return ret;
2001}
2002
Daniel Vetter17e1df02013-09-08 21:57:13 +02002003static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2004 bool reset_completed)
2005{
2006 struct intel_ring_buffer *ring;
2007 int i;
2008
2009 /*
2010 * Notify all waiters for GPU completion events that reset state has
2011 * been changed, and that they need to restart their wait after
2012 * checking for potential errors (and bail out to drop locks if there is
2013 * a gpu reset pending so that i915_error_work_func can acquire them).
2014 */
2015
2016 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2017 for_each_ring(ring, dev_priv, i)
2018 wake_up_all(&ring->irq_queue);
2019
2020 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2021 wake_up_all(&dev_priv->pending_flip_queue);
2022
2023 /*
2024 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2025 * reset state is cleared.
2026 */
2027 if (reset_completed)
2028 wake_up_all(&dev_priv->gpu_error.reset_queue);
2029}
2030
Jesse Barnes8a905232009-07-11 16:48:03 -04002031/**
2032 * i915_error_work_func - do process context error handling work
2033 * @work: work struct
2034 *
2035 * Fire an error uevent so userspace can see that a hang or error
2036 * was detected.
2037 */
2038static void i915_error_work_func(struct work_struct *work)
2039{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002040 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2041 work);
2042 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
2043 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002044 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002045 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2046 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2047 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002048 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002049
Dave Airlie5bdebb12013-10-11 14:07:25 +10002050 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002051
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002052 /*
2053 * Note that there's only one work item which does gpu resets, so we
2054 * need not worry about concurrent gpu resets potentially incrementing
2055 * error->reset_counter twice. We only need to take care of another
2056 * racing irq/hangcheck declaring the gpu dead for a second time. A
2057 * quick check for that is good enough: schedule_work ensures the
2058 * correct ordering between hang detection and this work item, and since
2059 * the reset in-progress bit is only ever set by code outside of this
2060 * work we don't need to worry about any other races.
2061 */
2062 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002063 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002064 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002065 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002066
Daniel Vetter17e1df02013-09-08 21:57:13 +02002067 /*
2068 * All state reset _must_ be completed before we update the
2069 * reset counter, for otherwise waiters might miss the reset
2070 * pending state and not properly drop locks, resulting in
2071 * deadlocks with the reset work.
2072 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002073 ret = i915_reset(dev);
2074
Daniel Vetter17e1df02013-09-08 21:57:13 +02002075 intel_display_handle_reset(dev);
2076
Daniel Vetterf69061b2012-12-06 09:01:42 +01002077 if (ret == 0) {
2078 /*
2079 * After all the gem state is reset, increment the reset
2080 * counter and wake up everyone waiting for the reset to
2081 * complete.
2082 *
2083 * Since unlock operations are a one-sided barrier only,
2084 * we need to insert a barrier here to order any seqno
2085 * updates before
2086 * the counter increment.
2087 */
2088 smp_mb__before_atomic_inc();
2089 atomic_inc(&dev_priv->gpu_error.reset_counter);
2090
Dave Airlie5bdebb12013-10-11 14:07:25 +10002091 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002092 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002093 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002094 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002095 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002096
Daniel Vetter17e1df02013-09-08 21:57:13 +02002097 /*
2098 * Note: The wake_up also serves as a memory barrier so that
2099 * waiters see the update value of the reset counter atomic_t.
2100 */
2101 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002102 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002103}
2104
Chris Wilson35aed2e2010-05-27 13:18:12 +01002105static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002106{
2107 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002108 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002109 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002110 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002111
Chris Wilson35aed2e2010-05-27 13:18:12 +01002112 if (!eir)
2113 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002114
Joe Perchesa70491c2012-03-18 13:00:11 -07002115 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002116
Ben Widawskybd9854f2012-08-23 15:18:09 -07002117 i915_get_extra_instdone(dev, instdone);
2118
Jesse Barnes8a905232009-07-11 16:48:03 -04002119 if (IS_G4X(dev)) {
2120 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2121 u32 ipeir = I915_READ(IPEIR_I965);
2122
Joe Perchesa70491c2012-03-18 13:00:11 -07002123 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2124 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002125 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2126 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002127 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002128 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002129 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002130 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002131 }
2132 if (eir & GM45_ERROR_PAGE_TABLE) {
2133 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002134 pr_err("page table error\n");
2135 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002136 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002137 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002138 }
2139 }
2140
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002141 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002142 if (eir & I915_ERROR_PAGE_TABLE) {
2143 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002144 pr_err("page table error\n");
2145 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002146 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002147 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002148 }
2149 }
2150
2151 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002152 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002153 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002154 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002155 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002156 /* pipestat has already been acked */
2157 }
2158 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002159 pr_err("instruction error\n");
2160 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002161 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2162 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002163 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002164 u32 ipeir = I915_READ(IPEIR);
2165
Joe Perchesa70491c2012-03-18 13:00:11 -07002166 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2167 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002168 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002169 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002170 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002171 } else {
2172 u32 ipeir = I915_READ(IPEIR_I965);
2173
Joe Perchesa70491c2012-03-18 13:00:11 -07002174 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2175 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002176 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002177 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002178 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002179 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002180 }
2181 }
2182
2183 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002184 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002185 eir = I915_READ(EIR);
2186 if (eir) {
2187 /*
2188 * some errors might have become stuck,
2189 * mask them.
2190 */
2191 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2192 I915_WRITE(EMR, I915_READ(EMR) | eir);
2193 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2194 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002195}
2196
2197/**
2198 * i915_handle_error - handle an error interrupt
2199 * @dev: drm device
2200 *
2201 * Do some basic checking of regsiter state at error interrupt time and
2202 * dump it to the syslog. Also call i915_capture_error_state() to make
2203 * sure we get a record and make it available in debugfs. Fire a uevent
2204 * so userspace knows something bad happened (should trigger collection
2205 * of a ring dump etc.).
2206 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002207void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002208{
2209 struct drm_i915_private *dev_priv = dev->dev_private;
2210
2211 i915_capture_error_state(dev);
2212 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002213
Ben Gamariba1234d2009-09-14 17:48:47 -04002214 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002215 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2216 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002217
Ben Gamari11ed50e2009-09-14 17:48:45 -04002218 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002219 * Wakeup waiting processes so that the reset work function
2220 * i915_error_work_func doesn't deadlock trying to grab various
2221 * locks. By bumping the reset counter first, the woken
2222 * processes will see a reset in progress and back off,
2223 * releasing their locks and then wait for the reset completion.
2224 * We must do this for _all_ gpu waiters that might hold locks
2225 * that the reset work needs to acquire.
2226 *
2227 * Note: The wake_up serves as the required memory barrier to
2228 * ensure that the waiters see the updated value of the reset
2229 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002230 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002231 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002232 }
2233
Daniel Vetter122f46b2013-09-04 17:36:14 +02002234 /*
2235 * Our reset work can grab modeset locks (since it needs to reset the
2236 * state of outstanding pagelips). Hence it must not be run on our own
2237 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2238 * code will deadlock.
2239 */
2240 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002241}
2242
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002243static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002244{
2245 drm_i915_private_t *dev_priv = dev->dev_private;
2246 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2247 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002248 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002249 struct intel_unpin_work *work;
2250 unsigned long flags;
2251 bool stall_detected;
2252
2253 /* Ignore early vblank irqs */
2254 if (intel_crtc == NULL)
2255 return;
2256
2257 spin_lock_irqsave(&dev->event_lock, flags);
2258 work = intel_crtc->unpin_work;
2259
Chris Wilsone7d841c2012-12-03 11:36:30 +00002260 if (work == NULL ||
2261 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2262 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002263 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2264 spin_unlock_irqrestore(&dev->event_lock, flags);
2265 return;
2266 }
2267
2268 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002269 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002270 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002271 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002272 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002273 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002274 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002275 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002276 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002277 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002278 crtc->x * crtc->fb->bits_per_pixel/8);
2279 }
2280
2281 spin_unlock_irqrestore(&dev->event_lock, flags);
2282
2283 if (stall_detected) {
2284 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2285 intel_prepare_page_flip(dev, intel_crtc->plane);
2286 }
2287}
2288
Keith Packard42f52ef2008-10-18 19:39:29 -07002289/* Called from drm generic code, passed 'crtc' which
2290 * we use as a pipe index
2291 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002292static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002293{
2294 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002295 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002296
Chris Wilson5eddb702010-09-11 13:48:45 +01002297 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002298 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002299
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002300 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002301 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002302 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002303 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002304 else
Keith Packard7c463582008-11-04 02:03:27 -08002305 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002306 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002307
2308 /* maintain vblank delivery even in deep C-states */
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002309 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002310 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002311 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002312
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002313 return 0;
2314}
2315
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002316static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002317{
2318 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2319 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002320 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002321 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002322
2323 if (!i915_pipe_enabled(dev, pipe))
2324 return -EINVAL;
2325
2326 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002327 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002328 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2329
2330 return 0;
2331}
2332
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002333static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2334{
2335 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2336 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002337
2338 if (!i915_pipe_enabled(dev, pipe))
2339 return -EINVAL;
2340
2341 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002342 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002343 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002344 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2345
2346 return 0;
2347}
2348
Ben Widawskyabd58f02013-11-02 21:07:09 -07002349static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2350{
2351 struct drm_i915_private *dev_priv = dev->dev_private;
2352 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002353
2354 if (!i915_pipe_enabled(dev, pipe))
2355 return -EINVAL;
2356
2357 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002358 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2359 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2360 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002361 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2362 return 0;
2363}
2364
Keith Packard42f52ef2008-10-18 19:39:29 -07002365/* Called from drm generic code, passed 'crtc' which
2366 * we use as a pipe index
2367 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002368static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002369{
2370 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002371 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002372
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002373 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Damien Lespiau3d13ef22014-02-07 19:12:47 +00002374 if (INTEL_INFO(dev)->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002375 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002376
Jesse Barnesf796cf82011-04-07 13:58:17 -07002377 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002378 PIPE_VBLANK_INTERRUPT_STATUS |
2379 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002380 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2381}
2382
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002383static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002384{
2385 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2386 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002387 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002388 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002389
2390 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002391 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002392 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2393}
2394
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002395static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2396{
2397 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2398 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002399
2400 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002401 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002402 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002403 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2404}
2405
Ben Widawskyabd58f02013-11-02 21:07:09 -07002406static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2407{
2408 struct drm_i915_private *dev_priv = dev->dev_private;
2409 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002410
2411 if (!i915_pipe_enabled(dev, pipe))
2412 return;
2413
2414 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002415 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2416 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2417 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002418 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2419}
2420
Chris Wilson893eead2010-10-27 14:44:35 +01002421static u32
2422ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002423{
Chris Wilson893eead2010-10-27 14:44:35 +01002424 return list_entry(ring->request_list.prev,
2425 struct drm_i915_gem_request, list)->seqno;
2426}
2427
Chris Wilson9107e9d2013-06-10 11:20:20 +01002428static bool
2429ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002430{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002431 return (list_empty(&ring->request_list) ||
2432 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002433}
2434
Chris Wilson6274f212013-06-10 11:20:21 +01002435static struct intel_ring_buffer *
2436semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002437{
2438 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002439 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002440
2441 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2442 if ((ipehr & ~(0x3 << 16)) !=
2443 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002444 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002445
2446 /* ACTHD is likely pointing to the dword after the actual command,
2447 * so scan backwards until we find the MBOX.
2448 */
Chris Wilson6274f212013-06-10 11:20:21 +01002449 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002450 acthd_min = max((int)acthd - 3 * 4, 0);
2451 do {
2452 cmd = ioread32(ring->virtual_start + acthd);
2453 if (cmd == ipehr)
2454 break;
2455
2456 acthd -= 4;
2457 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002458 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002459 } while (1);
2460
Chris Wilson6274f212013-06-10 11:20:21 +01002461 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2462 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002463}
2464
Chris Wilson6274f212013-06-10 11:20:21 +01002465static int semaphore_passed(struct intel_ring_buffer *ring)
2466{
2467 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2468 struct intel_ring_buffer *signaller;
2469 u32 seqno, ctl;
2470
2471 ring->hangcheck.deadlock = true;
2472
2473 signaller = semaphore_waits_for(ring, &seqno);
2474 if (signaller == NULL || signaller->hangcheck.deadlock)
2475 return -1;
2476
2477 /* cursory check for an unkickable deadlock */
2478 ctl = I915_READ_CTL(signaller);
2479 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2480 return -1;
2481
2482 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2483}
2484
2485static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2486{
2487 struct intel_ring_buffer *ring;
2488 int i;
2489
2490 for_each_ring(ring, dev_priv, i)
2491 ring->hangcheck.deadlock = false;
2492}
2493
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002494static enum intel_ring_hangcheck_action
2495ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002496{
2497 struct drm_device *dev = ring->dev;
2498 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002499 u32 tmp;
2500
Chris Wilson6274f212013-06-10 11:20:21 +01002501 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002502 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002503
Chris Wilson9107e9d2013-06-10 11:20:20 +01002504 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002505 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002506
2507 /* Is the chip hanging on a WAIT_FOR_EVENT?
2508 * If so we can simply poke the RB_WAIT bit
2509 * and break the hang. This should work on
2510 * all but the second generation chipsets.
2511 */
2512 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002513 if (tmp & RING_WAIT) {
2514 DRM_ERROR("Kicking stuck wait on %s\n",
2515 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002516 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002517 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002518 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002519 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002520
Chris Wilson6274f212013-06-10 11:20:21 +01002521 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2522 switch (semaphore_passed(ring)) {
2523 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002524 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002525 case 1:
2526 DRM_ERROR("Kicking stuck semaphore on %s\n",
2527 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002528 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002529 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002530 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002531 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002532 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002533 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002534 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002535
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002536 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002537}
2538
Ben Gamarif65d9422009-09-14 17:48:44 -04002539/**
2540 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002541 * batchbuffers in a long time. We keep track per ring seqno progress and
2542 * if there are no progress, hangcheck score for that ring is increased.
2543 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2544 * we kick the ring. If we see no progress on three subsequent calls
2545 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002546 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002547static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002548{
2549 struct drm_device *dev = (struct drm_device *)data;
2550 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002551 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002552 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002553 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002554 bool stuck[I915_NUM_RINGS] = { 0 };
2555#define BUSY 1
2556#define KICK 5
2557#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002558
Jani Nikulad330a952014-01-21 11:24:25 +02002559 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002560 return;
2561
Chris Wilsonb4519512012-05-11 14:29:30 +01002562 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002563 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002564 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002565
Chris Wilson6274f212013-06-10 11:20:21 +01002566 semaphore_clear_deadlocks(dev_priv);
2567
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002568 seqno = ring->get_seqno(ring, false);
2569 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002570
Chris Wilson9107e9d2013-06-10 11:20:20 +01002571 if (ring->hangcheck.seqno == seqno) {
2572 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002573 ring->hangcheck.action = HANGCHECK_IDLE;
2574
Chris Wilson9107e9d2013-06-10 11:20:20 +01002575 if (waitqueue_active(&ring->irq_queue)) {
2576 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002577 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002578 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2579 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2580 ring->name);
2581 else
2582 DRM_INFO("Fake missed irq on %s\n",
2583 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002584 wake_up_all(&ring->irq_queue);
2585 }
2586 /* Safeguard against driver failure */
2587 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002588 } else
2589 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002590 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002591 /* We always increment the hangcheck score
2592 * if the ring is busy and still processing
2593 * the same request, so that no single request
2594 * can run indefinitely (such as a chain of
2595 * batches). The only time we do not increment
2596 * the hangcheck score on this ring, if this
2597 * ring is in a legitimate wait for another
2598 * ring. In that case the waiting ring is a
2599 * victim and we want to be sure we catch the
2600 * right culprit. Then every time we do kick
2601 * the ring, add a small increment to the
2602 * score so that we can catch a batch that is
2603 * being repeatedly kicked and so responsible
2604 * for stalling the machine.
2605 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002606 ring->hangcheck.action = ring_stuck(ring,
2607 acthd);
2608
2609 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002610 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002611 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002612 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002613 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002614 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002615 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002616 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002617 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002618 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002619 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002620 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002621 stuck[i] = true;
2622 break;
2623 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002624 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002625 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002626 ring->hangcheck.action = HANGCHECK_ACTIVE;
2627
Chris Wilson9107e9d2013-06-10 11:20:20 +01002628 /* Gradually reduce the count so that we catch DoS
2629 * attempts across multiple batches.
2630 */
2631 if (ring->hangcheck.score > 0)
2632 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002633 }
2634
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002635 ring->hangcheck.seqno = seqno;
2636 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002637 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002638 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002639
Mika Kuoppala92cab732013-05-24 17:16:07 +03002640 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002641 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002642 DRM_INFO("%s on %s\n",
2643 stuck[i] ? "stuck" : "no progress",
2644 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002645 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002646 }
2647 }
2648
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002649 if (rings_hung)
2650 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002651
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002652 if (busy_count)
2653 /* Reset timer case chip hangs without another request
2654 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002655 i915_queue_hangcheck(dev);
2656}
2657
2658void i915_queue_hangcheck(struct drm_device *dev)
2659{
2660 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02002661 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002662 return;
2663
2664 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2665 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002666}
2667
Paulo Zanoni91738a92013-06-05 14:21:51 -03002668static void ibx_irq_preinstall(struct drm_device *dev)
2669{
2670 struct drm_i915_private *dev_priv = dev->dev_private;
2671
2672 if (HAS_PCH_NOP(dev))
2673 return;
2674
2675 /* south display irq */
2676 I915_WRITE(SDEIMR, 0xffffffff);
2677 /*
2678 * SDEIER is also touched by the interrupt handler to work around missed
2679 * PCH interrupts. Hence we can't update it after the interrupt handler
2680 * is enabled - instead we unconditionally enable all PCH interrupt
2681 * sources here, but then only unmask them as needed with SDEIMR.
2682 */
2683 I915_WRITE(SDEIER, 0xffffffff);
2684 POSTING_READ(SDEIER);
2685}
2686
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002687static void gen5_gt_irq_preinstall(struct drm_device *dev)
2688{
2689 struct drm_i915_private *dev_priv = dev->dev_private;
2690
2691 /* and GT */
2692 I915_WRITE(GTIMR, 0xffffffff);
2693 I915_WRITE(GTIER, 0x0);
2694 POSTING_READ(GTIER);
2695
2696 if (INTEL_INFO(dev)->gen >= 6) {
2697 /* and PM */
2698 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2699 I915_WRITE(GEN6_PMIER, 0x0);
2700 POSTING_READ(GEN6_PMIER);
2701 }
2702}
2703
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704/* drm_dma.h hooks
2705*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002706static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002707{
2708 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2709
2710 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002711
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002712 I915_WRITE(DEIMR, 0xffffffff);
2713 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002714 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002715
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002716 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002717
Paulo Zanoni91738a92013-06-05 14:21:51 -03002718 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002719}
2720
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002721static void valleyview_irq_preinstall(struct drm_device *dev)
2722{
2723 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2724 int pipe;
2725
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002726 /* VLV magic */
2727 I915_WRITE(VLV_IMR, 0);
2728 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2729 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2730 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2731
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002732 /* and GT */
2733 I915_WRITE(GTIIR, I915_READ(GTIIR));
2734 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002735
2736 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002737
2738 I915_WRITE(DPINVGTT, 0xff);
2739
2740 I915_WRITE(PORT_HOTPLUG_EN, 0);
2741 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2742 for_each_pipe(pipe)
2743 I915_WRITE(PIPESTAT(pipe), 0xffff);
2744 I915_WRITE(VLV_IIR, 0xffffffff);
2745 I915_WRITE(VLV_IMR, 0xffffffff);
2746 I915_WRITE(VLV_IER, 0x0);
2747 POSTING_READ(VLV_IER);
2748}
2749
Ben Widawskyabd58f02013-11-02 21:07:09 -07002750static void gen8_irq_preinstall(struct drm_device *dev)
2751{
2752 struct drm_i915_private *dev_priv = dev->dev_private;
2753 int pipe;
2754
Ben Widawskyabd58f02013-11-02 21:07:09 -07002755 I915_WRITE(GEN8_MASTER_IRQ, 0);
2756 POSTING_READ(GEN8_MASTER_IRQ);
2757
2758 /* IIR can theoretically queue up two events. Be paranoid */
2759#define GEN8_IRQ_INIT_NDX(type, which) do { \
2760 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2761 POSTING_READ(GEN8_##type##_IMR(which)); \
2762 I915_WRITE(GEN8_##type##_IER(which), 0); \
2763 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2764 POSTING_READ(GEN8_##type##_IIR(which)); \
2765 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2766 } while (0)
2767
2768#define GEN8_IRQ_INIT(type) do { \
2769 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2770 POSTING_READ(GEN8_##type##_IMR); \
2771 I915_WRITE(GEN8_##type##_IER, 0); \
2772 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2773 POSTING_READ(GEN8_##type##_IIR); \
2774 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2775 } while (0)
2776
2777 GEN8_IRQ_INIT_NDX(GT, 0);
2778 GEN8_IRQ_INIT_NDX(GT, 1);
2779 GEN8_IRQ_INIT_NDX(GT, 2);
2780 GEN8_IRQ_INIT_NDX(GT, 3);
2781
2782 for_each_pipe(pipe) {
2783 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2784 }
2785
2786 GEN8_IRQ_INIT(DE_PORT);
2787 GEN8_IRQ_INIT(DE_MISC);
2788 GEN8_IRQ_INIT(PCU);
2789#undef GEN8_IRQ_INIT
2790#undef GEN8_IRQ_INIT_NDX
2791
2792 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002793
2794 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002795}
2796
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002797static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002798{
2799 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002800 struct drm_mode_config *mode_config = &dev->mode_config;
2801 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002802 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002803
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002804 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002805 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002806 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002807 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002808 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002809 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002810 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002811 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002812 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002813 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002814 }
2815
Daniel Vetterfee884e2013-07-04 23:35:21 +02002816 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002817
2818 /*
2819 * Enable digital hotplug on the PCH, and configure the DP short pulse
2820 * duration to 2ms (which is the minimum in the Display Port spec)
2821 *
2822 * This register is the same on all known PCH chips.
2823 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002824 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2825 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2826 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2827 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2828 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2829 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2830}
2831
Paulo Zanonid46da432013-02-08 17:35:15 -02002832static void ibx_irq_postinstall(struct drm_device *dev)
2833{
2834 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002835 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002836
Daniel Vetter692a04c2013-05-29 21:43:05 +02002837 if (HAS_PCH_NOP(dev))
2838 return;
2839
Paulo Zanoni86642812013-04-12 17:57:57 -03002840 if (HAS_PCH_IBX(dev)) {
2841 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002842 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002843 } else {
2844 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2845
2846 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2847 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002848
Paulo Zanonid46da432013-02-08 17:35:15 -02002849 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2850 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002851}
2852
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002853static void gen5_gt_irq_postinstall(struct drm_device *dev)
2854{
2855 struct drm_i915_private *dev_priv = dev->dev_private;
2856 u32 pm_irqs, gt_irqs;
2857
2858 pm_irqs = gt_irqs = 0;
2859
2860 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002861 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002862 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002863 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2864 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002865 }
2866
2867 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2868 if (IS_GEN5(dev)) {
2869 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2870 ILK_BSD_USER_INTERRUPT;
2871 } else {
2872 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2873 }
2874
2875 I915_WRITE(GTIIR, I915_READ(GTIIR));
2876 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2877 I915_WRITE(GTIER, gt_irqs);
2878 POSTING_READ(GTIER);
2879
2880 if (INTEL_INFO(dev)->gen >= 6) {
2881 pm_irqs |= GEN6_PM_RPS_EVENTS;
2882
2883 if (HAS_VEBOX(dev))
2884 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2885
Paulo Zanoni605cd252013-08-06 18:57:15 -03002886 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002887 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002888 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002889 I915_WRITE(GEN6_PMIER, pm_irqs);
2890 POSTING_READ(GEN6_PMIER);
2891 }
2892}
2893
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002894static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002895{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002896 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002897 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002898 u32 display_mask, extra_mask;
2899
2900 if (INTEL_INFO(dev)->gen >= 7) {
2901 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2902 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2903 DE_PLANEB_FLIP_DONE_IVB |
2904 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2905 DE_ERR_INT_IVB);
2906 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2907 DE_PIPEA_VBLANK_IVB);
2908
2909 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2910 } else {
2911 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2912 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002913 DE_AUX_CHANNEL_A |
2914 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2915 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2916 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002917 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2918 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002919
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002920 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002921
2922 /* should always can generate irq */
2923 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002924 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002925 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002926 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002927
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002928 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002929
Paulo Zanonid46da432013-02-08 17:35:15 -02002930 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002931
Jesse Barnesf97108d2010-01-29 11:27:07 -08002932 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002933 /* Enable PCU event interrupts
2934 *
2935 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002936 * setup is guaranteed to run in single-threaded context. But we
2937 * need it to make the assert_spin_locked happy. */
2938 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002939 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002940 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002941 }
2942
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002943 return 0;
2944}
2945
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002946static int valleyview_irq_postinstall(struct drm_device *dev)
2947{
2948 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002949 u32 enable_mask;
Imre Deak755e9012014-02-10 18:42:47 +02002950 u32 pipestat_enable = PLANE_FLIP_DONE_INT_STATUS_VLV |
2951 PIPE_CRC_DONE_INTERRUPT_STATUS;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002952 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002953
2954 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002955 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2956 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2957 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002958 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2959
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002960 /*
2961 *Leave vblank interrupts masked initially. enable/disable will
2962 * toggle them based on usage.
2963 */
2964 dev_priv->irq_mask = (~enable_mask) |
2965 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2966 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002967
Daniel Vetter20afbda2012-12-11 14:05:07 +01002968 I915_WRITE(PORT_HOTPLUG_EN, 0);
2969 POSTING_READ(PORT_HOTPLUG_EN);
2970
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002971 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2972 I915_WRITE(VLV_IER, enable_mask);
2973 I915_WRITE(VLV_IIR, 0xffffffff);
2974 I915_WRITE(PIPESTAT(0), 0xffff);
2975 I915_WRITE(PIPESTAT(1), 0xffff);
2976 POSTING_READ(VLV_IER);
2977
Daniel Vetterb79480b2013-06-27 17:52:10 +02002978 /* Interrupt setup is already guaranteed to be single-threaded, this is
2979 * just to make the assert_spin_locked check happy. */
2980 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002981 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
Imre Deak755e9012014-02-10 18:42:47 +02002982 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002983 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002984 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002985
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002986 I915_WRITE(VLV_IIR, 0xffffffff);
2987 I915_WRITE(VLV_IIR, 0xffffffff);
2988
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002989 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002990
2991 /* ack & enable invalid PTE error interrupts */
2992#if 0 /* FIXME: add support to irq handler for checking these bits */
2993 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2994 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2995#endif
2996
2997 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002998
2999 return 0;
3000}
3001
Ben Widawskyabd58f02013-11-02 21:07:09 -07003002static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3003{
3004 int i;
3005
3006 /* These are interrupts we'll toggle with the ring mask register */
3007 uint32_t gt_interrupts[] = {
3008 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
3009 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
3010 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
3011 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3012 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
3013 0,
3014 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
3015 };
3016
3017 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
3018 u32 tmp = I915_READ(GEN8_GT_IIR(i));
3019 if (tmp)
3020 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3021 i, tmp);
3022 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
3023 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
3024 }
3025 POSTING_READ(GEN8_GT_IER(0));
3026}
3027
3028static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3029{
3030 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003031 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
3032 GEN8_PIPE_CDCLK_CRC_DONE |
3033 GEN8_PIPE_FIFO_UNDERRUN |
3034 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3035 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003036 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003037 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3038 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3039 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003040
3041 for_each_pipe(pipe) {
3042 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
3043 if (tmp)
3044 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3045 pipe, tmp);
3046 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3047 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
3048 }
3049 POSTING_READ(GEN8_DE_PIPE_ISR(0));
3050
Daniel Vetter6d766f02013-11-07 14:49:55 +01003051 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
3052 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003053 POSTING_READ(GEN8_DE_PORT_IER);
3054}
3055
3056static int gen8_irq_postinstall(struct drm_device *dev)
3057{
3058 struct drm_i915_private *dev_priv = dev->dev_private;
3059
3060 gen8_gt_irq_postinstall(dev_priv);
3061 gen8_de_irq_postinstall(dev_priv);
3062
3063 ibx_irq_postinstall(dev);
3064
3065 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3066 POSTING_READ(GEN8_MASTER_IRQ);
3067
3068 return 0;
3069}
3070
3071static void gen8_irq_uninstall(struct drm_device *dev)
3072{
3073 struct drm_i915_private *dev_priv = dev->dev_private;
3074 int pipe;
3075
3076 if (!dev_priv)
3077 return;
3078
Ben Widawskyabd58f02013-11-02 21:07:09 -07003079 I915_WRITE(GEN8_MASTER_IRQ, 0);
3080
3081#define GEN8_IRQ_FINI_NDX(type, which) do { \
3082 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3083 I915_WRITE(GEN8_##type##_IER(which), 0); \
3084 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3085 } while (0)
3086
3087#define GEN8_IRQ_FINI(type) do { \
3088 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3089 I915_WRITE(GEN8_##type##_IER, 0); \
3090 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3091 } while (0)
3092
3093 GEN8_IRQ_FINI_NDX(GT, 0);
3094 GEN8_IRQ_FINI_NDX(GT, 1);
3095 GEN8_IRQ_FINI_NDX(GT, 2);
3096 GEN8_IRQ_FINI_NDX(GT, 3);
3097
3098 for_each_pipe(pipe) {
3099 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3100 }
3101
3102 GEN8_IRQ_FINI(DE_PORT);
3103 GEN8_IRQ_FINI(DE_MISC);
3104 GEN8_IRQ_FINI(PCU);
3105#undef GEN8_IRQ_FINI
3106#undef GEN8_IRQ_FINI_NDX
3107
3108 POSTING_READ(GEN8_PCU_IIR);
3109}
3110
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003111static void valleyview_irq_uninstall(struct drm_device *dev)
3112{
3113 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3114 int pipe;
3115
3116 if (!dev_priv)
3117 return;
3118
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003119 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003120
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003121 for_each_pipe(pipe)
3122 I915_WRITE(PIPESTAT(pipe), 0xffff);
3123
3124 I915_WRITE(HWSTAM, 0xffffffff);
3125 I915_WRITE(PORT_HOTPLUG_EN, 0);
3126 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3127 for_each_pipe(pipe)
3128 I915_WRITE(PIPESTAT(pipe), 0xffff);
3129 I915_WRITE(VLV_IIR, 0xffffffff);
3130 I915_WRITE(VLV_IMR, 0xffffffff);
3131 I915_WRITE(VLV_IER, 0x0);
3132 POSTING_READ(VLV_IER);
3133}
3134
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003135static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003136{
3137 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003138
3139 if (!dev_priv)
3140 return;
3141
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003142 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003143
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003144 I915_WRITE(HWSTAM, 0xffffffff);
3145
3146 I915_WRITE(DEIMR, 0xffffffff);
3147 I915_WRITE(DEIER, 0x0);
3148 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003149 if (IS_GEN7(dev))
3150 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003151
3152 I915_WRITE(GTIMR, 0xffffffff);
3153 I915_WRITE(GTIER, 0x0);
3154 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003155
Ben Widawskyab5c6082013-04-05 13:12:41 -07003156 if (HAS_PCH_NOP(dev))
3157 return;
3158
Keith Packard192aac1f2011-09-20 10:12:44 -07003159 I915_WRITE(SDEIMR, 0xffffffff);
3160 I915_WRITE(SDEIER, 0x0);
3161 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003162 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3163 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003164}
3165
Chris Wilsonc2798b12012-04-22 21:13:57 +01003166static void i8xx_irq_preinstall(struct drm_device * dev)
3167{
3168 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3169 int pipe;
3170
Chris Wilsonc2798b12012-04-22 21:13:57 +01003171 for_each_pipe(pipe)
3172 I915_WRITE(PIPESTAT(pipe), 0);
3173 I915_WRITE16(IMR, 0xffff);
3174 I915_WRITE16(IER, 0x0);
3175 POSTING_READ16(IER);
3176}
3177
3178static int i8xx_irq_postinstall(struct drm_device *dev)
3179{
3180 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003181 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003182
Chris Wilsonc2798b12012-04-22 21:13:57 +01003183 I915_WRITE16(EMR,
3184 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3185
3186 /* Unmask the interrupts that we always want on. */
3187 dev_priv->irq_mask =
3188 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3189 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3190 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3191 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3192 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3193 I915_WRITE16(IMR, dev_priv->irq_mask);
3194
3195 I915_WRITE16(IER,
3196 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3197 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3198 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3199 I915_USER_INTERRUPT);
3200 POSTING_READ16(IER);
3201
Daniel Vetter379ef822013-10-16 22:55:56 +02003202 /* Interrupt setup is already guaranteed to be single-threaded, this is
3203 * just to make the assert_spin_locked check happy. */
3204 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003205 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3206 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003207 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3208
Chris Wilsonc2798b12012-04-22 21:13:57 +01003209 return 0;
3210}
3211
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003212/*
3213 * Returns true when a page flip has completed.
3214 */
3215static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003216 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003217{
3218 drm_i915_private_t *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003219 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003220
3221 if (!drm_handle_vblank(dev, pipe))
3222 return false;
3223
3224 if ((iir & flip_pending) == 0)
3225 return false;
3226
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003227 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003228
3229 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3230 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3231 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3232 * the flip is completed (no longer pending). Since this doesn't raise
3233 * an interrupt per se, we watch for the change at vblank.
3234 */
3235 if (I915_READ16(ISR) & flip_pending)
3236 return false;
3237
3238 intel_finish_page_flip(dev, pipe);
3239
3240 return true;
3241}
3242
Daniel Vetterff1f5252012-10-02 15:10:55 +02003243static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003244{
3245 struct drm_device *dev = (struct drm_device *) arg;
3246 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003247 u16 iir, new_iir;
3248 u32 pipe_stats[2];
3249 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003250 int pipe;
3251 u16 flip_mask =
3252 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3253 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3254
Chris Wilsonc2798b12012-04-22 21:13:57 +01003255 iir = I915_READ16(IIR);
3256 if (iir == 0)
3257 return IRQ_NONE;
3258
3259 while (iir & ~flip_mask) {
3260 /* Can't rely on pipestat interrupt bit in iir as it might
3261 * have been cleared after the pipestat interrupt was received.
3262 * It doesn't set the bit in iir again, but it still produces
3263 * interrupts (for non-MSI).
3264 */
3265 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3266 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3267 i915_handle_error(dev, false);
3268
3269 for_each_pipe(pipe) {
3270 int reg = PIPESTAT(pipe);
3271 pipe_stats[pipe] = I915_READ(reg);
3272
3273 /*
3274 * Clear the PIPE*STAT regs before the IIR
3275 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003276 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003277 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003278 }
3279 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3280
3281 I915_WRITE16(IIR, iir & ~flip_mask);
3282 new_iir = I915_READ16(IIR); /* Flush posted writes */
3283
Daniel Vetterd05c6172012-04-26 23:28:09 +02003284 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003285
3286 if (iir & I915_USER_INTERRUPT)
3287 notify_ring(dev, &dev_priv->ring[RCS]);
3288
Daniel Vetter4356d582013-10-16 22:55:55 +02003289 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003290 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003291 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003292 plane = !plane;
3293
Daniel Vetter4356d582013-10-16 22:55:55 +02003294 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003295 i8xx_handle_vblank(dev, plane, pipe, iir))
3296 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003297
Daniel Vetter4356d582013-10-16 22:55:55 +02003298 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003299 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003300
3301 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3302 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003303 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003304 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003305
3306 iir = new_iir;
3307 }
3308
3309 return IRQ_HANDLED;
3310}
3311
3312static void i8xx_irq_uninstall(struct drm_device * dev)
3313{
3314 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3315 int pipe;
3316
Chris Wilsonc2798b12012-04-22 21:13:57 +01003317 for_each_pipe(pipe) {
3318 /* Clear enable bits; then clear status bits */
3319 I915_WRITE(PIPESTAT(pipe), 0);
3320 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3321 }
3322 I915_WRITE16(IMR, 0xffff);
3323 I915_WRITE16(IER, 0x0);
3324 I915_WRITE16(IIR, I915_READ16(IIR));
3325}
3326
Chris Wilsona266c7d2012-04-24 22:59:44 +01003327static void i915_irq_preinstall(struct drm_device * dev)
3328{
3329 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3330 int pipe;
3331
Chris Wilsona266c7d2012-04-24 22:59:44 +01003332 if (I915_HAS_HOTPLUG(dev)) {
3333 I915_WRITE(PORT_HOTPLUG_EN, 0);
3334 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3335 }
3336
Chris Wilson00d98eb2012-04-24 22:59:48 +01003337 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003338 for_each_pipe(pipe)
3339 I915_WRITE(PIPESTAT(pipe), 0);
3340 I915_WRITE(IMR, 0xffffffff);
3341 I915_WRITE(IER, 0x0);
3342 POSTING_READ(IER);
3343}
3344
3345static int i915_irq_postinstall(struct drm_device *dev)
3346{
3347 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003348 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003349 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003350
Chris Wilson38bde182012-04-24 22:59:50 +01003351 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3352
3353 /* Unmask the interrupts that we always want on. */
3354 dev_priv->irq_mask =
3355 ~(I915_ASLE_INTERRUPT |
3356 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3357 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3358 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3359 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3360 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3361
3362 enable_mask =
3363 I915_ASLE_INTERRUPT |
3364 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3365 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3366 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3367 I915_USER_INTERRUPT;
3368
Chris Wilsona266c7d2012-04-24 22:59:44 +01003369 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003370 I915_WRITE(PORT_HOTPLUG_EN, 0);
3371 POSTING_READ(PORT_HOTPLUG_EN);
3372
Chris Wilsona266c7d2012-04-24 22:59:44 +01003373 /* Enable in IER... */
3374 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3375 /* and unmask in IMR */
3376 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3377 }
3378
Chris Wilsona266c7d2012-04-24 22:59:44 +01003379 I915_WRITE(IMR, dev_priv->irq_mask);
3380 I915_WRITE(IER, enable_mask);
3381 POSTING_READ(IER);
3382
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003383 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003384
Daniel Vetter379ef822013-10-16 22:55:56 +02003385 /* Interrupt setup is already guaranteed to be single-threaded, this is
3386 * just to make the assert_spin_locked check happy. */
3387 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003388 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3389 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetter379ef822013-10-16 22:55:56 +02003390 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3391
Daniel Vetter20afbda2012-12-11 14:05:07 +01003392 return 0;
3393}
3394
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003395/*
3396 * Returns true when a page flip has completed.
3397 */
3398static bool i915_handle_vblank(struct drm_device *dev,
3399 int plane, int pipe, u32 iir)
3400{
3401 drm_i915_private_t *dev_priv = dev->dev_private;
3402 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3403
3404 if (!drm_handle_vblank(dev, pipe))
3405 return false;
3406
3407 if ((iir & flip_pending) == 0)
3408 return false;
3409
3410 intel_prepare_page_flip(dev, plane);
3411
3412 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3413 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3414 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3415 * the flip is completed (no longer pending). Since this doesn't raise
3416 * an interrupt per se, we watch for the change at vblank.
3417 */
3418 if (I915_READ(ISR) & flip_pending)
3419 return false;
3420
3421 intel_finish_page_flip(dev, pipe);
3422
3423 return true;
3424}
3425
Daniel Vetterff1f5252012-10-02 15:10:55 +02003426static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003427{
3428 struct drm_device *dev = (struct drm_device *) arg;
3429 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003430 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003431 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003432 u32 flip_mask =
3433 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3434 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003435 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003436
Chris Wilsona266c7d2012-04-24 22:59:44 +01003437 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003438 do {
3439 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003440 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003441
3442 /* Can't rely on pipestat interrupt bit in iir as it might
3443 * have been cleared after the pipestat interrupt was received.
3444 * It doesn't set the bit in iir again, but it still produces
3445 * interrupts (for non-MSI).
3446 */
3447 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3448 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3449 i915_handle_error(dev, false);
3450
3451 for_each_pipe(pipe) {
3452 int reg = PIPESTAT(pipe);
3453 pipe_stats[pipe] = I915_READ(reg);
3454
Chris Wilson38bde182012-04-24 22:59:50 +01003455 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003456 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003457 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003458 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003459 }
3460 }
3461 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3462
3463 if (!irq_received)
3464 break;
3465
Chris Wilsona266c7d2012-04-24 22:59:44 +01003466 /* Consume port. Then clear IIR or we'll miss events */
3467 if ((I915_HAS_HOTPLUG(dev)) &&
3468 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3469 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003470 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003471
Daniel Vetter91d131d2013-06-27 17:52:14 +02003472 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3473
Chris Wilsona266c7d2012-04-24 22:59:44 +01003474 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003475 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003476 }
3477
Chris Wilson38bde182012-04-24 22:59:50 +01003478 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003479 new_iir = I915_READ(IIR); /* Flush posted writes */
3480
Chris Wilsona266c7d2012-04-24 22:59:44 +01003481 if (iir & I915_USER_INTERRUPT)
3482 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003483
Chris Wilsona266c7d2012-04-24 22:59:44 +01003484 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003485 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003486 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003487 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003488
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003489 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3490 i915_handle_vblank(dev, plane, pipe, iir))
3491 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003492
3493 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3494 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003495
3496 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003497 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003498
3499 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3500 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003501 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003502 }
3503
Chris Wilsona266c7d2012-04-24 22:59:44 +01003504 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3505 intel_opregion_asle_intr(dev);
3506
3507 /* With MSI, interrupts are only generated when iir
3508 * transitions from zero to nonzero. If another bit got
3509 * set while we were handling the existing iir bits, then
3510 * we would never get another interrupt.
3511 *
3512 * This is fine on non-MSI as well, as if we hit this path
3513 * we avoid exiting the interrupt handler only to generate
3514 * another one.
3515 *
3516 * Note that for MSI this could cause a stray interrupt report
3517 * if an interrupt landed in the time between writing IIR and
3518 * the posting read. This should be rare enough to never
3519 * trigger the 99% of 100,000 interrupts test for disabling
3520 * stray interrupts.
3521 */
Chris Wilson38bde182012-04-24 22:59:50 +01003522 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003523 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003524 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003525
Daniel Vetterd05c6172012-04-26 23:28:09 +02003526 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003527
Chris Wilsona266c7d2012-04-24 22:59:44 +01003528 return ret;
3529}
3530
3531static void i915_irq_uninstall(struct drm_device * dev)
3532{
3533 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3534 int pipe;
3535
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003536 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003537
Chris Wilsona266c7d2012-04-24 22:59:44 +01003538 if (I915_HAS_HOTPLUG(dev)) {
3539 I915_WRITE(PORT_HOTPLUG_EN, 0);
3540 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3541 }
3542
Chris Wilson00d98eb2012-04-24 22:59:48 +01003543 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003544 for_each_pipe(pipe) {
3545 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003546 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003547 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3548 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003549 I915_WRITE(IMR, 0xffffffff);
3550 I915_WRITE(IER, 0x0);
3551
Chris Wilsona266c7d2012-04-24 22:59:44 +01003552 I915_WRITE(IIR, I915_READ(IIR));
3553}
3554
3555static void i965_irq_preinstall(struct drm_device * dev)
3556{
3557 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3558 int pipe;
3559
Chris Wilsonadca4732012-05-11 18:01:31 +01003560 I915_WRITE(PORT_HOTPLUG_EN, 0);
3561 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003562
3563 I915_WRITE(HWSTAM, 0xeffe);
3564 for_each_pipe(pipe)
3565 I915_WRITE(PIPESTAT(pipe), 0);
3566 I915_WRITE(IMR, 0xffffffff);
3567 I915_WRITE(IER, 0x0);
3568 POSTING_READ(IER);
3569}
3570
3571static int i965_irq_postinstall(struct drm_device *dev)
3572{
3573 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003574 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003575 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003576 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003577
Chris Wilsona266c7d2012-04-24 22:59:44 +01003578 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003579 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003580 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003581 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3582 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3583 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3584 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3585 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3586
3587 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003588 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3589 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003590 enable_mask |= I915_USER_INTERRUPT;
3591
3592 if (IS_G4X(dev))
3593 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003594
Daniel Vetterb79480b2013-06-27 17:52:10 +02003595 /* Interrupt setup is already guaranteed to be single-threaded, this is
3596 * just to make the assert_spin_locked check happy. */
3597 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Imre Deak755e9012014-02-10 18:42:47 +02003598 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3599 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3600 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003601 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003602
Chris Wilsona266c7d2012-04-24 22:59:44 +01003603 /*
3604 * Enable some error detection, note the instruction error mask
3605 * bit is reserved, so we leave it masked.
3606 */
3607 if (IS_G4X(dev)) {
3608 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3609 GM45_ERROR_MEM_PRIV |
3610 GM45_ERROR_CP_PRIV |
3611 I915_ERROR_MEMORY_REFRESH);
3612 } else {
3613 error_mask = ~(I915_ERROR_PAGE_TABLE |
3614 I915_ERROR_MEMORY_REFRESH);
3615 }
3616 I915_WRITE(EMR, error_mask);
3617
3618 I915_WRITE(IMR, dev_priv->irq_mask);
3619 I915_WRITE(IER, enable_mask);
3620 POSTING_READ(IER);
3621
Daniel Vetter20afbda2012-12-11 14:05:07 +01003622 I915_WRITE(PORT_HOTPLUG_EN, 0);
3623 POSTING_READ(PORT_HOTPLUG_EN);
3624
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003625 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003626
3627 return 0;
3628}
3629
Egbert Eichbac56d52013-02-25 12:06:51 -05003630static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003631{
3632 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003633 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003634 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003635 u32 hotplug_en;
3636
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003637 assert_spin_locked(&dev_priv->irq_lock);
3638
Egbert Eichbac56d52013-02-25 12:06:51 -05003639 if (I915_HAS_HOTPLUG(dev)) {
3640 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3641 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3642 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003643 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003644 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3645 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3646 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003647 /* Programming the CRT detection parameters tends
3648 to generate a spurious hotplug event about three
3649 seconds later. So just do it once.
3650 */
3651 if (IS_G4X(dev))
3652 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003653 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003654 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003655
Egbert Eichbac56d52013-02-25 12:06:51 -05003656 /* Ignore TV since it's buggy */
3657 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3658 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003659}
3660
Daniel Vetterff1f5252012-10-02 15:10:55 +02003661static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003662{
3663 struct drm_device *dev = (struct drm_device *) arg;
3664 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003665 u32 iir, new_iir;
3666 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003667 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003668 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003669 u32 flip_mask =
3670 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3671 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003672
Chris Wilsona266c7d2012-04-24 22:59:44 +01003673 iir = I915_READ(IIR);
3674
Chris Wilsona266c7d2012-04-24 22:59:44 +01003675 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003676 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003677 bool blc_event = false;
3678
Chris Wilsona266c7d2012-04-24 22:59:44 +01003679 /* Can't rely on pipestat interrupt bit in iir as it might
3680 * have been cleared after the pipestat interrupt was received.
3681 * It doesn't set the bit in iir again, but it still produces
3682 * interrupts (for non-MSI).
3683 */
3684 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3685 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3686 i915_handle_error(dev, false);
3687
3688 for_each_pipe(pipe) {
3689 int reg = PIPESTAT(pipe);
3690 pipe_stats[pipe] = I915_READ(reg);
3691
3692 /*
3693 * Clear the PIPE*STAT regs before the IIR
3694 */
3695 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003696 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003697 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003698 }
3699 }
3700 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3701
3702 if (!irq_received)
3703 break;
3704
3705 ret = IRQ_HANDLED;
3706
3707 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003708 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003709 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003710 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3711 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003712 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003713
Daniel Vetter91d131d2013-06-27 17:52:14 +02003714 intel_hpd_irq_handler(dev, hotplug_trigger,
Daniel Vetter704cfb82013-12-18 09:08:43 +01003715 IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003716
Daniel Vetter4aeebd72013-10-31 09:53:36 +01003717 if (IS_G4X(dev) &&
3718 (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
3719 dp_aux_irq_handler(dev);
3720
Chris Wilsona266c7d2012-04-24 22:59:44 +01003721 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3722 I915_READ(PORT_HOTPLUG_STAT);
3723 }
3724
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003725 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003726 new_iir = I915_READ(IIR); /* Flush posted writes */
3727
Chris Wilsona266c7d2012-04-24 22:59:44 +01003728 if (iir & I915_USER_INTERRUPT)
3729 notify_ring(dev, &dev_priv->ring[RCS]);
3730 if (iir & I915_BSD_USER_INTERRUPT)
3731 notify_ring(dev, &dev_priv->ring[VCS]);
3732
Chris Wilsona266c7d2012-04-24 22:59:44 +01003733 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003734 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003735 i915_handle_vblank(dev, pipe, pipe, iir))
3736 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003737
3738 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3739 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003740
3741 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003742 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003743
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003744 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3745 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003746 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003747 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003748
3749 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3750 intel_opregion_asle_intr(dev);
3751
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003752 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3753 gmbus_irq_handler(dev);
3754
Chris Wilsona266c7d2012-04-24 22:59:44 +01003755 /* With MSI, interrupts are only generated when iir
3756 * transitions from zero to nonzero. If another bit got
3757 * set while we were handling the existing iir bits, then
3758 * we would never get another interrupt.
3759 *
3760 * This is fine on non-MSI as well, as if we hit this path
3761 * we avoid exiting the interrupt handler only to generate
3762 * another one.
3763 *
3764 * Note that for MSI this could cause a stray interrupt report
3765 * if an interrupt landed in the time between writing IIR and
3766 * the posting read. This should be rare enough to never
3767 * trigger the 99% of 100,000 interrupts test for disabling
3768 * stray interrupts.
3769 */
3770 iir = new_iir;
3771 }
3772
Daniel Vetterd05c6172012-04-26 23:28:09 +02003773 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003774
Chris Wilsona266c7d2012-04-24 22:59:44 +01003775 return ret;
3776}
3777
3778static void i965_irq_uninstall(struct drm_device * dev)
3779{
3780 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3781 int pipe;
3782
3783 if (!dev_priv)
3784 return;
3785
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003786 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003787
Chris Wilsonadca4732012-05-11 18:01:31 +01003788 I915_WRITE(PORT_HOTPLUG_EN, 0);
3789 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003790
3791 I915_WRITE(HWSTAM, 0xffffffff);
3792 for_each_pipe(pipe)
3793 I915_WRITE(PIPESTAT(pipe), 0);
3794 I915_WRITE(IMR, 0xffffffff);
3795 I915_WRITE(IER, 0x0);
3796
3797 for_each_pipe(pipe)
3798 I915_WRITE(PIPESTAT(pipe),
3799 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3800 I915_WRITE(IIR, I915_READ(IIR));
3801}
3802
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003803static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02003804{
3805 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3806 struct drm_device *dev = dev_priv->dev;
3807 struct drm_mode_config *mode_config = &dev->mode_config;
3808 unsigned long irqflags;
3809 int i;
3810
3811 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3812 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3813 struct drm_connector *connector;
3814
3815 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3816 continue;
3817
3818 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3819
3820 list_for_each_entry(connector, &mode_config->connector_list, head) {
3821 struct intel_connector *intel_connector = to_intel_connector(connector);
3822
3823 if (intel_connector->encoder->hpd_pin == i) {
3824 if (connector->polled != intel_connector->polled)
3825 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3826 drm_get_connector_name(connector));
3827 connector->polled = intel_connector->polled;
3828 if (!connector->polled)
3829 connector->polled = DRM_CONNECTOR_POLL_HPD;
3830 }
3831 }
3832 }
3833 if (dev_priv->display.hpd_irq_setup)
3834 dev_priv->display.hpd_irq_setup(dev);
3835 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3836}
3837
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003838void intel_irq_init(struct drm_device *dev)
3839{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003840 struct drm_i915_private *dev_priv = dev->dev_private;
3841
3842 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003843 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003844 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003845 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003846
Daniel Vetter99584db2012-11-14 17:14:04 +01003847 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3848 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003849 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003850 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02003851 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003852
Tomas Janousek97a19a22012-12-08 13:48:13 +01003853 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003854
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003855 if (IS_GEN2(dev)) {
3856 dev->max_vblank_count = 0;
3857 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3858 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003859 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3860 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003861 } else {
3862 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3863 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003864 }
3865
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003866 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003867 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003868 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3869 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003870
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003871 if (IS_VALLEYVIEW(dev)) {
3872 dev->driver->irq_handler = valleyview_irq_handler;
3873 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3874 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3875 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3876 dev->driver->enable_vblank = valleyview_enable_vblank;
3877 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003878 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003879 } else if (IS_GEN8(dev)) {
3880 dev->driver->irq_handler = gen8_irq_handler;
3881 dev->driver->irq_preinstall = gen8_irq_preinstall;
3882 dev->driver->irq_postinstall = gen8_irq_postinstall;
3883 dev->driver->irq_uninstall = gen8_irq_uninstall;
3884 dev->driver->enable_vblank = gen8_enable_vblank;
3885 dev->driver->disable_vblank = gen8_disable_vblank;
3886 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003887 } else if (HAS_PCH_SPLIT(dev)) {
3888 dev->driver->irq_handler = ironlake_irq_handler;
3889 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3890 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3891 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3892 dev->driver->enable_vblank = ironlake_enable_vblank;
3893 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003894 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003895 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003896 if (INTEL_INFO(dev)->gen == 2) {
3897 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3898 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3899 dev->driver->irq_handler = i8xx_irq_handler;
3900 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003901 } else if (INTEL_INFO(dev)->gen == 3) {
3902 dev->driver->irq_preinstall = i915_irq_preinstall;
3903 dev->driver->irq_postinstall = i915_irq_postinstall;
3904 dev->driver->irq_uninstall = i915_irq_uninstall;
3905 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003906 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003907 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003908 dev->driver->irq_preinstall = i965_irq_preinstall;
3909 dev->driver->irq_postinstall = i965_irq_postinstall;
3910 dev->driver->irq_uninstall = i965_irq_uninstall;
3911 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003912 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003913 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003914 dev->driver->enable_vblank = i915_enable_vblank;
3915 dev->driver->disable_vblank = i915_disable_vblank;
3916 }
3917}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003918
3919void intel_hpd_init(struct drm_device *dev)
3920{
3921 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003922 struct drm_mode_config *mode_config = &dev->mode_config;
3923 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003924 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003925 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003926
Egbert Eich821450c2013-04-16 13:36:55 +02003927 for (i = 1; i < HPD_NUM_PINS; i++) {
3928 dev_priv->hpd_stats[i].hpd_cnt = 0;
3929 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3930 }
3931 list_for_each_entry(connector, &mode_config->connector_list, head) {
3932 struct intel_connector *intel_connector = to_intel_connector(connector);
3933 connector->polled = intel_connector->polled;
3934 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3935 connector->polled = DRM_CONNECTOR_POLL_HPD;
3936 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003937
3938 /* Interrupt setup is already guaranteed to be single-threaded, this is
3939 * just to make the assert_spin_locked checks happy. */
3940 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003941 if (dev_priv->display.hpd_irq_setup)
3942 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003943 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003944}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003945
3946/* Disable interrupts so we can allow Package C8+. */
3947void hsw_pc8_disable_interrupts(struct drm_device *dev)
3948{
3949 struct drm_i915_private *dev_priv = dev->dev_private;
3950 unsigned long irqflags;
3951
3952 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3953
3954 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3955 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3956 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3957 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3958 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3959
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003960 ironlake_disable_display_irq(dev_priv, 0xffffffff);
3961 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003962 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3963 snb_disable_pm_irq(dev_priv, 0xffffffff);
3964
3965 dev_priv->pc8.irqs_disabled = true;
3966
3967 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3968}
3969
3970/* Restore interrupts so we can recover from Package C8+. */
3971void hsw_pc8_restore_interrupts(struct drm_device *dev)
3972{
3973 struct drm_i915_private *dev_priv = dev->dev_private;
3974 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003975 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03003976
3977 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3978
3979 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003980 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003981
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003982 val = I915_READ(SDEIMR);
3983 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003984
3985 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003986 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003987
3988 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003989 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003990
3991 dev_priv->pc8.irqs_disabled = false;
3992
3993 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003994 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003995 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3996 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3997 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3998
3999 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
4000}