blob: a34714de7968e229a655e3d2b3c3454e7847ddf6 [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Egbert Eiche5868a32013-02-28 04:17:12 -050040static const u32 hpd_ibx[] = {
41 [HPD_CRT] = SDE_CRT_HOTPLUG,
42 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
43 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
44 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
45 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
46};
47
48static const u32 hpd_cpt[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010050 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050051 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
54};
55
56static const u32 hpd_mask_i915[] = {
57 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
58 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
59 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
60 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
61 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
62 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
63};
64
Daniel Vetter704cfb82013-12-18 09:08:43 +010065static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050066 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
67 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
68 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
69 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
70 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
71 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
72};
73
Egbert Eiche5868a32013-02-28 04:17:12 -050074static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
75 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
76 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
77 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
78 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
79 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
80 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
81};
82
Zhenyu Wang036a4a72009-06-08 14:40:19 +080083/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010084static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050085ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080086{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020087 assert_spin_locked(&dev_priv->irq_lock);
88
Paulo Zanonic67a4702013-08-19 13:18:09 -030089 if (dev_priv->pc8.irqs_disabled) {
90 WARN(1, "IRQs disabled\n");
91 dev_priv->pc8.regsave.deimr &= ~mask;
92 return;
93 }
94
Chris Wilson1ec14ad2010-12-04 11:30:53 +000095 if ((dev_priv->irq_mask & mask) != 0) {
96 dev_priv->irq_mask &= ~mask;
97 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000098 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080099 }
100}
101
Paulo Zanoni0ff98002013-02-22 17:05:31 -0300102static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -0500103ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200105 assert_spin_locked(&dev_priv->irq_lock);
106
Paulo Zanonic67a4702013-08-19 13:18:09 -0300107 if (dev_priv->pc8.irqs_disabled) {
108 WARN(1, "IRQs disabled\n");
109 dev_priv->pc8.regsave.deimr |= mask;
110 return;
111 }
112
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000113 if ((dev_priv->irq_mask & mask) != mask) {
114 dev_priv->irq_mask |= mask;
115 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000116 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800117 }
118}
119
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300120/**
121 * ilk_update_gt_irq - update GTIMR
122 * @dev_priv: driver private
123 * @interrupt_mask: mask of interrupt bits to update
124 * @enabled_irq_mask: mask of interrupt bits to enable
125 */
126static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
127 uint32_t interrupt_mask,
128 uint32_t enabled_irq_mask)
129{
130 assert_spin_locked(&dev_priv->irq_lock);
131
Paulo Zanonic67a4702013-08-19 13:18:09 -0300132 if (dev_priv->pc8.irqs_disabled) {
133 WARN(1, "IRQs disabled\n");
134 dev_priv->pc8.regsave.gtimr &= ~interrupt_mask;
135 dev_priv->pc8.regsave.gtimr |= (~enabled_irq_mask &
136 interrupt_mask);
137 return;
138 }
139
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300140 dev_priv->gt_irq_mask &= ~interrupt_mask;
141 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
142 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
143 POSTING_READ(GTIMR);
144}
145
146void ilk_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
147{
148 ilk_update_gt_irq(dev_priv, mask, mask);
149}
150
151void ilk_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
152{
153 ilk_update_gt_irq(dev_priv, mask, 0);
154}
155
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300156/**
157 * snb_update_pm_irq - update GEN6_PMIMR
158 * @dev_priv: driver private
159 * @interrupt_mask: mask of interrupt bits to update
160 * @enabled_irq_mask: mask of interrupt bits to enable
161 */
162static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
163 uint32_t interrupt_mask,
164 uint32_t enabled_irq_mask)
165{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300166 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300167
168 assert_spin_locked(&dev_priv->irq_lock);
169
Paulo Zanonic67a4702013-08-19 13:18:09 -0300170 if (dev_priv->pc8.irqs_disabled) {
171 WARN(1, "IRQs disabled\n");
172 dev_priv->pc8.regsave.gen6_pmimr &= ~interrupt_mask;
173 dev_priv->pc8.regsave.gen6_pmimr |= (~enabled_irq_mask &
174 interrupt_mask);
175 return;
176 }
177
Paulo Zanoni605cd252013-08-06 18:57:15 -0300178 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300179 new_val &= ~interrupt_mask;
180 new_val |= (~enabled_irq_mask & interrupt_mask);
181
Paulo Zanoni605cd252013-08-06 18:57:15 -0300182 if (new_val != dev_priv->pm_irq_mask) {
183 dev_priv->pm_irq_mask = new_val;
184 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300185 POSTING_READ(GEN6_PMIMR);
186 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300187}
188
189void snb_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
190{
191 snb_update_pm_irq(dev_priv, mask, mask);
192}
193
194void snb_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
195{
196 snb_update_pm_irq(dev_priv, mask, 0);
197}
198
Paulo Zanoni86642812013-04-12 17:57:57 -0300199static bool ivb_can_enable_err_int(struct drm_device *dev)
200{
201 struct drm_i915_private *dev_priv = dev->dev_private;
202 struct intel_crtc *crtc;
203 enum pipe pipe;
204
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200205 assert_spin_locked(&dev_priv->irq_lock);
206
Paulo Zanoni86642812013-04-12 17:57:57 -0300207 for_each_pipe(pipe) {
208 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
209
210 if (crtc->cpu_fifo_underrun_disabled)
211 return false;
212 }
213
214 return true;
215}
216
217static bool cpt_can_enable_serr_int(struct drm_device *dev)
218{
219 struct drm_i915_private *dev_priv = dev->dev_private;
220 enum pipe pipe;
221 struct intel_crtc *crtc;
222
Daniel Vetterfee884e2013-07-04 23:35:21 +0200223 assert_spin_locked(&dev_priv->irq_lock);
224
Paulo Zanoni86642812013-04-12 17:57:57 -0300225 for_each_pipe(pipe) {
226 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
227
228 if (crtc->pch_fifo_underrun_disabled)
229 return false;
230 }
231
232 return true;
233}
234
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200235static void i9xx_clear_fifo_underrun(struct drm_device *dev, enum pipe pipe)
236{
237 struct drm_i915_private *dev_priv = dev->dev_private;
238 u32 reg = PIPESTAT(pipe);
239 u32 pipestat = I915_READ(reg) & 0x7fff0000;
240
241 assert_spin_locked(&dev_priv->irq_lock);
242
243 I915_WRITE(reg, pipestat | PIPE_FIFO_UNDERRUN_STATUS);
244 POSTING_READ(reg);
245}
246
Paulo Zanoni86642812013-04-12 17:57:57 -0300247static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
248 enum pipe pipe, bool enable)
249{
250 struct drm_i915_private *dev_priv = dev->dev_private;
251 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
252 DE_PIPEB_FIFO_UNDERRUN;
253
254 if (enable)
255 ironlake_enable_display_irq(dev_priv, bit);
256 else
257 ironlake_disable_display_irq(dev_priv, bit);
258}
259
260static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200261 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300262{
263 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300264 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200265 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
266
Paulo Zanoni86642812013-04-12 17:57:57 -0300267 if (!ivb_can_enable_err_int(dev))
268 return;
269
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
271 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200272 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
273
274 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300275 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200276
277 if (!was_enabled &&
278 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
279 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
280 pipe_name(pipe));
281 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300282 }
283}
284
Daniel Vetter38d83c962013-11-07 11:05:46 +0100285static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
286 enum pipe pipe, bool enable)
287{
288 struct drm_i915_private *dev_priv = dev->dev_private;
289
290 assert_spin_locked(&dev_priv->irq_lock);
291
292 if (enable)
293 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
294 else
295 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
296 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
297 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
298}
299
Daniel Vetterfee884e2013-07-04 23:35:21 +0200300/**
301 * ibx_display_interrupt_update - update SDEIMR
302 * @dev_priv: driver private
303 * @interrupt_mask: mask of interrupt bits to update
304 * @enabled_irq_mask: mask of interrupt bits to enable
305 */
306static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
307 uint32_t interrupt_mask,
308 uint32_t enabled_irq_mask)
309{
310 uint32_t sdeimr = I915_READ(SDEIMR);
311 sdeimr &= ~interrupt_mask;
312 sdeimr |= (~enabled_irq_mask & interrupt_mask);
313
314 assert_spin_locked(&dev_priv->irq_lock);
315
Paulo Zanonic67a4702013-08-19 13:18:09 -0300316 if (dev_priv->pc8.irqs_disabled &&
317 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
318 WARN(1, "IRQs disabled\n");
319 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
320 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
321 interrupt_mask);
322 return;
323 }
324
Daniel Vetterfee884e2013-07-04 23:35:21 +0200325 I915_WRITE(SDEIMR, sdeimr);
326 POSTING_READ(SDEIMR);
327}
328#define ibx_enable_display_interrupt(dev_priv, bits) \
329 ibx_display_interrupt_update((dev_priv), (bits), (bits))
330#define ibx_disable_display_interrupt(dev_priv, bits) \
331 ibx_display_interrupt_update((dev_priv), (bits), 0)
332
Daniel Vetterde280752013-07-04 23:35:24 +0200333static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
334 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300335 bool enable)
336{
Paulo Zanoni86642812013-04-12 17:57:57 -0300337 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200338 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
339 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300340
341 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200342 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300343 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200344 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300345}
346
347static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
348 enum transcoder pch_transcoder,
349 bool enable)
350{
351 struct drm_i915_private *dev_priv = dev->dev_private;
352
353 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200354 I915_WRITE(SERR_INT,
355 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
356
Paulo Zanoni86642812013-04-12 17:57:57 -0300357 if (!cpt_can_enable_serr_int(dev))
358 return;
359
Daniel Vetterfee884e2013-07-04 23:35:21 +0200360 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300361 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200362 uint32_t tmp = I915_READ(SERR_INT);
363 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
364
365 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200366 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200367
368 if (!was_enabled &&
369 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
370 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
371 transcoder_name(pch_transcoder));
372 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300373 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300374}
375
376/**
377 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
378 * @dev: drm device
379 * @pipe: pipe
380 * @enable: true if we want to report FIFO underrun errors, false otherwise
381 *
382 * This function makes us disable or enable CPU fifo underruns for a specific
383 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
384 * reporting for one pipe may also disable all the other CPU error interruts for
385 * the other pipes, due to the fact that there's just one interrupt mask/enable
386 * bit for all the pipes.
387 *
388 * Returns the previous state of underrun reporting.
389 */
390bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
391 enum pipe pipe, bool enable)
392{
393 struct drm_i915_private *dev_priv = dev->dev_private;
394 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
395 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
396 unsigned long flags;
397 bool ret;
398
399 spin_lock_irqsave(&dev_priv->irq_lock, flags);
400
401 ret = !intel_crtc->cpu_fifo_underrun_disabled;
402
403 if (enable == ret)
404 goto done;
405
406 intel_crtc->cpu_fifo_underrun_disabled = !enable;
407
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +0200408 if (enable && (INTEL_INFO(dev)->gen < 5 || IS_VALLEYVIEW(dev)))
409 i9xx_clear_fifo_underrun(dev, pipe);
410 else if (IS_GEN5(dev) || IS_GEN6(dev))
Paulo Zanoni86642812013-04-12 17:57:57 -0300411 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
412 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200413 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100414 else if (IS_GEN8(dev))
415 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300416
417done:
418 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
419 return ret;
420}
421
422/**
423 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
424 * @dev: drm device
425 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
426 * @enable: true if we want to report FIFO underrun errors, false otherwise
427 *
428 * This function makes us disable or enable PCH fifo underruns for a specific
429 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
430 * underrun reporting for one transcoder may also disable all the other PCH
431 * error interruts for the other transcoders, due to the fact that there's just
432 * one interrupt mask/enable bit for all the transcoders.
433 *
434 * Returns the previous state of underrun reporting.
435 */
436bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
437 enum transcoder pch_transcoder,
438 bool enable)
439{
440 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200441 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
442 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300443 unsigned long flags;
444 bool ret;
445
Daniel Vetterde280752013-07-04 23:35:24 +0200446 /*
447 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
448 * has only one pch transcoder A that all pipes can use. To avoid racy
449 * pch transcoder -> pipe lookups from interrupt code simply store the
450 * underrun statistics in crtc A. Since we never expose this anywhere
451 * nor use it outside of the fifo underrun code here using the "wrong"
452 * crtc on LPT won't cause issues.
453 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300454
455 spin_lock_irqsave(&dev_priv->irq_lock, flags);
456
457 ret = !intel_crtc->pch_fifo_underrun_disabled;
458
459 if (enable == ret)
460 goto done;
461
462 intel_crtc->pch_fifo_underrun_disabled = !enable;
463
464 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200465 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300466 else
467 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
468
469done:
470 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
471 return ret;
472}
473
474
Keith Packard7c463582008-11-04 02:03:27 -0800475void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200476i915_enable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800477{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200478 u32 reg = PIPESTAT(pipe);
479 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800480
Daniel Vetterb79480b2013-06-27 17:52:10 +0200481 assert_spin_locked(&dev_priv->irq_lock);
482
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200483 if ((pipestat & mask) == mask)
484 return;
485
486 /* Enable the interrupt, clear any pending status */
487 pipestat |= mask | (mask >> 16);
488 I915_WRITE(reg, pipestat);
489 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800490}
491
492void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200493i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800494{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200495 u32 reg = PIPESTAT(pipe);
496 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800497
Daniel Vetterb79480b2013-06-27 17:52:10 +0200498 assert_spin_locked(&dev_priv->irq_lock);
499
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200500 if ((pipestat & mask) == 0)
501 return;
502
503 pipestat &= ~mask;
504 I915_WRITE(reg, pipestat);
505 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800506}
507
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000508/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300509 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000510 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300511static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000512{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000513 drm_i915_private_t *dev_priv = dev->dev_private;
514 unsigned long irqflags;
515
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300516 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
517 return;
518
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000519 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000520
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200521 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE);
Jani Nikulaf8987802013-04-29 13:02:53 +0300522 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200523 i915_enable_pipestat(dev_priv, PIPE_A,
524 PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000525
526 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000527}
528
529/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700530 * i915_pipe_enabled - check if a pipe is enabled
531 * @dev: DRM device
532 * @pipe: pipe to check
533 *
534 * Reading certain registers when the pipe is disabled can hang the chip.
535 * Use this routine to make sure the PLL is running and the pipe is active
536 * before reading such registers if unsure.
537 */
538static int
539i915_pipe_enabled(struct drm_device *dev, int pipe)
540{
541 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200542
Daniel Vettera01025a2013-05-22 00:50:23 +0200543 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
544 /* Locking is horribly broken here, but whatever. */
545 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
546 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300547
Daniel Vettera01025a2013-05-22 00:50:23 +0200548 return intel_crtc->active;
549 } else {
550 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
551 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700552}
553
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300554static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
555{
556 /* Gen2 doesn't have a hardware frame counter */
557 return 0;
558}
559
Keith Packard42f52ef2008-10-18 19:39:29 -0700560/* Called from drm generic code, passed a 'crtc', which
561 * we use as a pipe index
562 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700563static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700564{
565 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
566 unsigned long high_frame;
567 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300568 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700569
570 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800571 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800572 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700573 return 0;
574 }
575
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300576 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
577 struct intel_crtc *intel_crtc =
578 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
579 const struct drm_display_mode *mode =
580 &intel_crtc->config.adjusted_mode;
581
582 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
583 } else {
584 enum transcoder cpu_transcoder =
585 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
586 u32 htotal;
587
588 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
589 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
590
591 vbl_start *= htotal;
592 }
593
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800594 high_frame = PIPEFRAME(pipe);
595 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100596
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700597 /*
598 * High & low register fields aren't synchronized, so make sure
599 * we get a low value that's stable across two reads of the high
600 * register.
601 */
602 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100603 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300604 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100605 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700606 } while (high1 != high2);
607
Chris Wilson5eddb702010-09-11 13:48:45 +0100608 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300609 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100610 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300611
612 /*
613 * The frame counter increments at beginning of active.
614 * Cook up a vblank counter by also checking the pixel
615 * counter against vblank start.
616 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200617 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700618}
619
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700620static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800621{
622 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800623 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800624
625 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800626 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800627 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800628 return 0;
629 }
630
631 return I915_READ(reg);
632}
633
Mario Kleinerad3543e2013-10-30 05:13:08 +0100634/* raw reads, only for fast reads of display block, no need for forcewake etc. */
635#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
636#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
637
Ville Syrjälä095163b2013-10-29 00:04:43 +0200638static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300639{
640 struct drm_i915_private *dev_priv = dev->dev_private;
641 uint32_t status;
642
Ville Syrjälä095163b2013-10-29 00:04:43 +0200643 if (INTEL_INFO(dev)->gen < 7) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300644 status = pipe == PIPE_A ?
645 DE_PIPEA_VBLANK :
646 DE_PIPEB_VBLANK;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300647 } else {
648 switch (pipe) {
649 default:
650 case PIPE_A:
651 status = DE_PIPEA_VBLANK_IVB;
652 break;
653 case PIPE_B:
654 status = DE_PIPEB_VBLANK_IVB;
655 break;
656 case PIPE_C:
657 status = DE_PIPEC_VBLANK_IVB;
658 break;
659 }
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300660 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100661
Ville Syrjälä095163b2013-10-29 00:04:43 +0200662 return __raw_i915_read32(dev_priv, DEISR) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300663}
664
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700665static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200666 unsigned int flags, int *vpos, int *hpos,
667 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100668{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300669 struct drm_i915_private *dev_priv = dev->dev_private;
670 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
671 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
672 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300673 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100674 int vbl_start, vbl_end, htotal, vtotal;
675 bool in_vbl = true;
676 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100677 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100678
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300679 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100680 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800681 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100682 return 0;
683 }
684
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300685 htotal = mode->crtc_htotal;
686 vtotal = mode->crtc_vtotal;
687 vbl_start = mode->crtc_vblank_start;
688 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100689
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200690 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
691 vbl_start = DIV_ROUND_UP(vbl_start, 2);
692 vbl_end /= 2;
693 vtotal /= 2;
694 }
695
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300696 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
697
Mario Kleinerad3543e2013-10-30 05:13:08 +0100698 /*
699 * Lock uncore.lock, as we will do multiple timing critical raw
700 * register reads, potentially with preemption disabled, so the
701 * following code must not block on uncore.lock.
702 */
703 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
704
705 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
706
707 /* Get optional system timestamp before query. */
708 if (stime)
709 *stime = ktime_get();
710
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300711 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100712 /* No obvious pixelcount register. Only query vertical
713 * scanout position from Display scan line register.
714 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300715 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100716 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300717 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100718 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300719
Ville Syrjälä095163b2013-10-29 00:04:43 +0200720 if (HAS_PCH_SPLIT(dev)) {
721 /*
722 * The scanline counter increments at the leading edge
723 * of hsync, ie. it completely misses the active portion
724 * of the line. Fix up the counter at both edges of vblank
725 * to get a more accurate picture whether we're in vblank
726 * or not.
727 */
728 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
729 if ((in_vbl && position == vbl_start - 1) ||
730 (!in_vbl && position == vbl_end - 1))
731 position = (position + 1) % vtotal;
732 } else {
733 /*
734 * ISR vblank status bits don't work the way we'd want
735 * them to work on non-PCH platforms (for
736 * ilk_pipe_in_vblank_locked()), and there doesn't
737 * appear any other way to determine if we're currently
738 * in vblank.
739 *
740 * Instead let's assume that we're already in vblank if
741 * we got called from the vblank interrupt and the
742 * scanline counter value indicates that we're on the
743 * line just prior to vblank start. This should result
744 * in the correct answer, unless the vblank interrupt
745 * delivery really got delayed for almost exactly one
746 * full frame/field.
747 */
748 if (flags & DRM_CALLED_FROM_VBLIRQ &&
749 position == vbl_start - 1) {
750 position = (position + 1) % vtotal;
751
752 /* Signal this correction as "applied". */
753 ret |= 0x8;
754 }
755 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100756 } else {
757 /* Have access to pixelcount since start of frame.
758 * We can split this into vertical and horizontal
759 * scanout position.
760 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100761 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100762
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300763 /* convert to pixel counts */
764 vbl_start *= htotal;
765 vbl_end *= htotal;
766 vtotal *= htotal;
767 }
768
Mario Kleinerad3543e2013-10-30 05:13:08 +0100769 /* Get optional system timestamp after query. */
770 if (etime)
771 *etime = ktime_get();
772
773 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
774
775 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
776
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300777 in_vbl = position >= vbl_start && position < vbl_end;
778
779 /*
780 * While in vblank, position will be negative
781 * counting up towards 0 at vbl_end. And outside
782 * vblank, position will be positive counting
783 * up since vbl_end.
784 */
785 if (position >= vbl_start)
786 position -= vbl_end;
787 else
788 position += vtotal - vbl_end;
789
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300790 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300791 *vpos = position;
792 *hpos = 0;
793 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100794 *vpos = position / htotal;
795 *hpos = position - (*vpos * htotal);
796 }
797
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100798 /* In vblank? */
799 if (in_vbl)
800 ret |= DRM_SCANOUTPOS_INVBL;
801
802 return ret;
803}
804
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700805static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100806 int *max_error,
807 struct timeval *vblank_time,
808 unsigned flags)
809{
Chris Wilson4041b852011-01-22 10:07:56 +0000810 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100811
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700812 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000813 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100814 return -EINVAL;
815 }
816
817 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000818 crtc = intel_get_crtc_for_pipe(dev, pipe);
819 if (crtc == NULL) {
820 DRM_ERROR("Invalid crtc %d\n", pipe);
821 return -EINVAL;
822 }
823
824 if (!crtc->enabled) {
825 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
826 return -EBUSY;
827 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100828
829 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000830 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
831 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300832 crtc,
833 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100834}
835
Jani Nikula67c347f2013-09-17 14:26:34 +0300836static bool intel_hpd_irq_event(struct drm_device *dev,
837 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200838{
839 enum drm_connector_status old_status;
840
841 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
842 old_status = connector->status;
843
844 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300845 if (old_status == connector->status)
846 return false;
847
848 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200849 connector->base.id,
850 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300851 drm_get_connector_status_name(old_status),
852 drm_get_connector_status_name(connector->status));
853
854 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200855}
856
Jesse Barnes5ca58282009-03-31 14:11:15 -0700857/*
858 * Handle hotplug events outside the interrupt handler proper.
859 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200860#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
861
Jesse Barnes5ca58282009-03-31 14:11:15 -0700862static void i915_hotplug_work_func(struct work_struct *work)
863{
864 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
865 hotplug_work);
866 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700867 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200868 struct intel_connector *intel_connector;
869 struct intel_encoder *intel_encoder;
870 struct drm_connector *connector;
871 unsigned long irqflags;
872 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200873 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200874 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700875
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100876 /* HPD irq before everything is fully set up. */
877 if (!dev_priv->enable_hotplug_processing)
878 return;
879
Keith Packarda65e34c2011-07-25 10:04:56 -0700880 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800881 DRM_DEBUG_KMS("running encoder hotplug functions\n");
882
Egbert Eichcd569ae2013-04-16 13:36:57 +0200883 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200884
885 hpd_event_bits = dev_priv->hpd_event_bits;
886 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200887 list_for_each_entry(connector, &mode_config->connector_list, head) {
888 intel_connector = to_intel_connector(connector);
889 intel_encoder = intel_connector->encoder;
890 if (intel_encoder->hpd_pin > HPD_NONE &&
891 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
892 connector->polled == DRM_CONNECTOR_POLL_HPD) {
893 DRM_INFO("HPD interrupt storm detected on connector %s: "
894 "switching from hotplug detection to polling\n",
895 drm_get_connector_name(connector));
896 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
897 connector->polled = DRM_CONNECTOR_POLL_CONNECT
898 | DRM_CONNECTOR_POLL_DISCONNECT;
899 hpd_disabled = true;
900 }
Egbert Eich142e2392013-04-11 15:57:57 +0200901 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
902 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
903 drm_get_connector_name(connector), intel_encoder->hpd_pin);
904 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200905 }
906 /* if there were no outputs to poll, poll was disabled,
907 * therefore make sure it's enabled when disabling HPD on
908 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200909 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200910 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200911 mod_timer(&dev_priv->hotplug_reenable_timer,
912 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
913 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200914
915 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
916
Egbert Eich321a1b32013-04-11 16:00:26 +0200917 list_for_each_entry(connector, &mode_config->connector_list, head) {
918 intel_connector = to_intel_connector(connector);
919 intel_encoder = intel_connector->encoder;
920 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
921 if (intel_encoder->hot_plug)
922 intel_encoder->hot_plug(intel_encoder);
923 if (intel_hpd_irq_event(dev, connector))
924 changed = true;
925 }
926 }
Keith Packard40ee3382011-07-28 15:31:19 -0700927 mutex_unlock(&mode_config->mutex);
928
Egbert Eich321a1b32013-04-11 16:00:26 +0200929 if (changed)
930 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700931}
932
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +0200933static void intel_hpd_irq_uninstall(struct drm_i915_private *dev_priv)
934{
935 del_timer_sync(&dev_priv->hotplug_reenable_timer);
936}
937
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200938static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800939{
940 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000941 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200942 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200943
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200944 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800945
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200946 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
947
Daniel Vetter20e4d402012-08-08 23:35:39 +0200948 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200949
Jesse Barnes7648fa92010-05-20 14:28:11 -0700950 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000951 busy_up = I915_READ(RCPREVBSYTUPAVG);
952 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800953 max_avg = I915_READ(RCBMAXAVG);
954 min_avg = I915_READ(RCBMINAVG);
955
956 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000957 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200958 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
959 new_delay = dev_priv->ips.cur_delay - 1;
960 if (new_delay < dev_priv->ips.max_delay)
961 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000962 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200963 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
964 new_delay = dev_priv->ips.cur_delay + 1;
965 if (new_delay > dev_priv->ips.min_delay)
966 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800967 }
968
Jesse Barnes7648fa92010-05-20 14:28:11 -0700969 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200970 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800971
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200972 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200973
Jesse Barnesf97108d2010-01-29 11:27:07 -0800974 return;
975}
976
Chris Wilson549f7362010-10-19 11:19:32 +0100977static void notify_ring(struct drm_device *dev,
978 struct intel_ring_buffer *ring)
979{
Chris Wilson475553d2011-01-20 09:52:56 +0000980 if (ring->obj == NULL)
981 return;
982
Chris Wilson814e9b52013-09-23 17:33:19 -0300983 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000984
Chris Wilson549f7362010-10-19 11:19:32 +0100985 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300986 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100987}
988
Deepak S76c3552f2014-01-30 23:08:16 +0530989void gen6_set_pm_mask(struct drm_i915_private *dev_priv,
Deepak S27544362014-01-27 21:35:05 +0530990 u32 pm_iir, int new_delay)
991{
992 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
993 if (new_delay >= dev_priv->rps.max_delay) {
994 /* Mask UP THRESHOLD Interrupts */
995 I915_WRITE(GEN6_PMINTRMSK,
996 I915_READ(GEN6_PMINTRMSK) |
997 GEN6_PM_RP_UP_THRESHOLD);
998 dev_priv->rps.rp_up_masked = true;
999 }
1000 if (dev_priv->rps.rp_down_masked) {
1001 /* UnMask DOWN THRESHOLD Interrupts */
1002 I915_WRITE(GEN6_PMINTRMSK,
1003 I915_READ(GEN6_PMINTRMSK) &
1004 ~GEN6_PM_RP_DOWN_THRESHOLD);
1005 dev_priv->rps.rp_down_masked = false;
1006 }
1007 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1008 if (new_delay <= dev_priv->rps.min_delay) {
1009 /* Mask DOWN THRESHOLD Interrupts */
1010 I915_WRITE(GEN6_PMINTRMSK,
1011 I915_READ(GEN6_PMINTRMSK) |
1012 GEN6_PM_RP_DOWN_THRESHOLD);
1013 dev_priv->rps.rp_down_masked = true;
1014 }
1015
1016 if (dev_priv->rps.rp_up_masked) {
1017 /* UnMask UP THRESHOLD Interrupts */
1018 I915_WRITE(GEN6_PMINTRMSK,
1019 I915_READ(GEN6_PMINTRMSK) &
1020 ~GEN6_PM_RP_UP_THRESHOLD);
1021 dev_priv->rps.rp_up_masked = false;
1022 }
1023 }
1024}
1025
Ben Widawsky4912d042011-04-25 11:25:20 -07001026static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001027{
Ben Widawsky4912d042011-04-25 11:25:20 -07001028 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001029 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001030 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001031 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001032
Daniel Vetter59cdb632013-07-04 23:35:28 +02001033 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001034 pm_iir = dev_priv->rps.pm_iir;
1035 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -07001036 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001037 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001038 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001039
Paulo Zanoni60611c12013-08-15 11:50:01 -03001040 /* Make sure we didn't queue anything we're not going to process. */
1041 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
1042
Ben Widawsky48484052013-05-28 19:22:27 -07001043 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001044 return;
1045
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001046 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001047
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001048 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001049 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001050 if (adj > 0)
1051 adj *= 2;
1052 else
1053 adj = 1;
1054 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001055
1056 /*
1057 * For better performance, jump directly
1058 * to RPe if we're below it.
1059 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001060 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +03001061 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001062 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1063 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
1064 new_delay = dev_priv->rps.rpe_delay;
1065 else
1066 new_delay = dev_priv->rps.min_delay;
1067 adj = 0;
1068 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1069 if (adj < 0)
1070 adj *= 2;
1071 else
1072 adj = -1;
1073 new_delay = dev_priv->rps.cur_delay + adj;
1074 } else { /* unknown event */
1075 new_delay = dev_priv->rps.cur_delay;
1076 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001077
Ben Widawsky79249632012-09-07 19:43:42 -07001078 /* sysfs frequency interfaces may have snuck in while servicing the
1079 * interrupt
1080 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001081 new_delay = clamp_t(int, new_delay,
1082 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Deepak S27544362014-01-27 21:35:05 +05301083
1084 gen6_set_pm_mask(dev_priv, pm_iir, new_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001085 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
1086
1087 if (IS_VALLEYVIEW(dev_priv->dev))
1088 valleyview_set_rps(dev_priv->dev, new_delay);
1089 else
1090 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001091
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001092 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001093}
1094
Ben Widawskye3689192012-05-25 16:56:22 -07001095
1096/**
1097 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1098 * occurred.
1099 * @work: workqueue struct
1100 *
1101 * Doesn't actually do anything except notify userspace. As a consequence of
1102 * this event, userspace should try to remap the bad rows since statistically
1103 * it is likely the same row is more likely to go bad again.
1104 */
1105static void ivybridge_parity_work(struct work_struct *work)
1106{
1107 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001108 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001109 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001110 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001111 uint32_t misccpctl;
1112 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001113 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001114
1115 /* We must turn off DOP level clock gating to access the L3 registers.
1116 * In order to prevent a get/put style interface, acquire struct mutex
1117 * any time we access those registers.
1118 */
1119 mutex_lock(&dev_priv->dev->struct_mutex);
1120
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001121 /* If we've screwed up tracking, just let the interrupt fire again */
1122 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1123 goto out;
1124
Ben Widawskye3689192012-05-25 16:56:22 -07001125 misccpctl = I915_READ(GEN7_MISCCPCTL);
1126 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1127 POSTING_READ(GEN7_MISCCPCTL);
1128
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001129 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1130 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001131
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001132 slice--;
1133 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1134 break;
1135
1136 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1137
1138 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1139
1140 error_status = I915_READ(reg);
1141 row = GEN7_PARITY_ERROR_ROW(error_status);
1142 bank = GEN7_PARITY_ERROR_BANK(error_status);
1143 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1144
1145 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1146 POSTING_READ(reg);
1147
1148 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1149 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1150 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1151 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1152 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1153 parity_event[5] = NULL;
1154
Dave Airlie5bdebb12013-10-11 14:07:25 +10001155 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001156 KOBJ_CHANGE, parity_event);
1157
1158 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1159 slice, row, bank, subbank);
1160
1161 kfree(parity_event[4]);
1162 kfree(parity_event[3]);
1163 kfree(parity_event[2]);
1164 kfree(parity_event[1]);
1165 }
Ben Widawskye3689192012-05-25 16:56:22 -07001166
1167 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1168
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001169out:
1170 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001171 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001172 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001173 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1174
1175 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001176}
1177
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001178static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001179{
1180 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001181
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001182 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001183 return;
1184
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001185 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001186 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001187 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001188
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001189 iir &= GT_PARITY_ERROR(dev);
1190 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1191 dev_priv->l3_parity.which_slice |= 1 << 1;
1192
1193 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1194 dev_priv->l3_parity.which_slice |= 1 << 0;
1195
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001196 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001197}
1198
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001199static void ilk_gt_irq_handler(struct drm_device *dev,
1200 struct drm_i915_private *dev_priv,
1201 u32 gt_iir)
1202{
1203 if (gt_iir &
1204 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1205 notify_ring(dev, &dev_priv->ring[RCS]);
1206 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1207 notify_ring(dev, &dev_priv->ring[VCS]);
1208}
1209
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001210static void snb_gt_irq_handler(struct drm_device *dev,
1211 struct drm_i915_private *dev_priv,
1212 u32 gt_iir)
1213{
1214
Ben Widawskycc609d52013-05-28 19:22:29 -07001215 if (gt_iir &
1216 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001217 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001218 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001219 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001220 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001221 notify_ring(dev, &dev_priv->ring[BCS]);
1222
Ben Widawskycc609d52013-05-28 19:22:29 -07001223 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1224 GT_BSD_CS_ERROR_INTERRUPT |
1225 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001226 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1227 i915_handle_error(dev, false);
1228 }
Ben Widawskye3689192012-05-25 16:56:22 -07001229
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001230 if (gt_iir & GT_PARITY_ERROR(dev))
1231 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001232}
1233
Ben Widawskyabd58f02013-11-02 21:07:09 -07001234static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1235 struct drm_i915_private *dev_priv,
1236 u32 master_ctl)
1237{
1238 u32 rcs, bcs, vcs;
1239 uint32_t tmp = 0;
1240 irqreturn_t ret = IRQ_NONE;
1241
1242 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1243 tmp = I915_READ(GEN8_GT_IIR(0));
1244 if (tmp) {
1245 ret = IRQ_HANDLED;
1246 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1247 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1248 if (rcs & GT_RENDER_USER_INTERRUPT)
1249 notify_ring(dev, &dev_priv->ring[RCS]);
1250 if (bcs & GT_RENDER_USER_INTERRUPT)
1251 notify_ring(dev, &dev_priv->ring[BCS]);
1252 I915_WRITE(GEN8_GT_IIR(0), tmp);
1253 } else
1254 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1255 }
1256
1257 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1258 tmp = I915_READ(GEN8_GT_IIR(1));
1259 if (tmp) {
1260 ret = IRQ_HANDLED;
1261 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1262 if (vcs & GT_RENDER_USER_INTERRUPT)
1263 notify_ring(dev, &dev_priv->ring[VCS]);
1264 I915_WRITE(GEN8_GT_IIR(1), tmp);
1265 } else
1266 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1267 }
1268
1269 if (master_ctl & GEN8_GT_VECS_IRQ) {
1270 tmp = I915_READ(GEN8_GT_IIR(3));
1271 if (tmp) {
1272 ret = IRQ_HANDLED;
1273 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1274 if (vcs & GT_RENDER_USER_INTERRUPT)
1275 notify_ring(dev, &dev_priv->ring[VECS]);
1276 I915_WRITE(GEN8_GT_IIR(3), tmp);
1277 } else
1278 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1279 }
1280
1281 return ret;
1282}
1283
Egbert Eichb543fb02013-04-16 13:36:54 +02001284#define HPD_STORM_DETECT_PERIOD 1000
1285#define HPD_STORM_THRESHOLD 5
1286
Daniel Vetter10a504d2013-06-27 17:52:12 +02001287static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001288 u32 hotplug_trigger,
1289 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001290{
1291 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001292 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001293 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001294
Daniel Vetter91d131d2013-06-27 17:52:14 +02001295 if (!hotplug_trigger)
1296 return;
1297
Imre Deakcc9bd492014-01-16 19:56:54 +02001298 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1299 hotplug_trigger);
1300
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001301 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001302 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001303
Chris Wilson34320872014-01-10 18:49:20 +00001304 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001305 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001306 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1307 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001308
Egbert Eichb543fb02013-04-16 13:36:54 +02001309 if (!(hpd[i] & hotplug_trigger) ||
1310 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1311 continue;
1312
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001313 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001314 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1315 dev_priv->hpd_stats[i].hpd_last_jiffies
1316 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1317 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1318 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001319 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001320 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1321 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001322 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001323 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001324 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001325 } else {
1326 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001327 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1328 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001329 }
1330 }
1331
Daniel Vetter10a504d2013-06-27 17:52:12 +02001332 if (storm_detected)
1333 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001334 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001335
Daniel Vetter645416f2013-09-02 16:22:25 +02001336 /*
1337 * Our hotplug handler can grab modeset locks (by calling down into the
1338 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1339 * queue for otherwise the flush_work in the pageflip code will
1340 * deadlock.
1341 */
1342 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001343}
1344
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001345static void gmbus_irq_handler(struct drm_device *dev)
1346{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001347 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1348
Daniel Vetter28c70f12012-12-01 13:53:45 +01001349 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001350}
1351
Daniel Vetterce99c252012-12-01 13:53:47 +01001352static void dp_aux_irq_handler(struct drm_device *dev)
1353{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001354 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1355
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001356 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001357}
1358
Shuang He8bf1e9f2013-10-15 18:55:27 +01001359#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001360static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1361 uint32_t crc0, uint32_t crc1,
1362 uint32_t crc2, uint32_t crc3,
1363 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001364{
1365 struct drm_i915_private *dev_priv = dev->dev_private;
1366 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1367 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001368 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001369
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001370 spin_lock(&pipe_crc->lock);
1371
Damien Lespiau0c912c72013-10-15 18:55:37 +01001372 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001373 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001374 DRM_ERROR("spurious interrupt\n");
1375 return;
1376 }
1377
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001378 head = pipe_crc->head;
1379 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001380
1381 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001382 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001383 DRM_ERROR("CRC buffer overflowing\n");
1384 return;
1385 }
1386
1387 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001388
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001389 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001390 entry->crc[0] = crc0;
1391 entry->crc[1] = crc1;
1392 entry->crc[2] = crc2;
1393 entry->crc[3] = crc3;
1394 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001395
1396 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001397 pipe_crc->head = head;
1398
1399 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001400
1401 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001402}
Daniel Vetter277de952013-10-18 16:37:07 +02001403#else
1404static inline void
1405display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1406 uint32_t crc0, uint32_t crc1,
1407 uint32_t crc2, uint32_t crc3,
1408 uint32_t crc4) {}
1409#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001410
Daniel Vetter277de952013-10-18 16:37:07 +02001411
1412static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001413{
1414 struct drm_i915_private *dev_priv = dev->dev_private;
1415
Daniel Vetter277de952013-10-18 16:37:07 +02001416 display_pipe_crc_irq_handler(dev, pipe,
1417 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1418 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001419}
1420
Daniel Vetter277de952013-10-18 16:37:07 +02001421static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001422{
1423 struct drm_i915_private *dev_priv = dev->dev_private;
1424
Daniel Vetter277de952013-10-18 16:37:07 +02001425 display_pipe_crc_irq_handler(dev, pipe,
1426 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1427 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1428 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1429 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1430 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001431}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001432
Daniel Vetter277de952013-10-18 16:37:07 +02001433static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001434{
1435 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001436 uint32_t res1, res2;
1437
1438 if (INTEL_INFO(dev)->gen >= 3)
1439 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1440 else
1441 res1 = 0;
1442
1443 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1444 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1445 else
1446 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001447
Daniel Vetter277de952013-10-18 16:37:07 +02001448 display_pipe_crc_irq_handler(dev, pipe,
1449 I915_READ(PIPE_CRC_RES_RED(pipe)),
1450 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1451 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1452 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001453}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001454
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001455/* The RPS events need forcewake, so we add them to a work queue and mask their
1456 * IMR bits until the work is done. Other interrupts can be processed without
1457 * the work queue. */
1458static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001459{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001460 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001461 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001462 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001463 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001464 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001465
1466 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001467 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001468
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001469 if (HAS_VEBOX(dev_priv->dev)) {
1470 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1471 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001472
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001473 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1474 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1475 i915_handle_error(dev_priv->dev, false);
1476 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001477 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001478}
1479
Imre Deakc1874ed2014-02-04 21:35:46 +02001480static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1481{
1482 struct drm_i915_private *dev_priv = dev->dev_private;
1483 u32 pipe_stats[I915_MAX_PIPES];
1484 unsigned long irqflags;
1485 int pipe;
1486
1487 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1488 for_each_pipe(pipe) {
1489 int reg = PIPESTAT(pipe);
1490 pipe_stats[pipe] = I915_READ(reg);
1491
1492 /*
1493 * Clear the PIPE*STAT regs before the IIR
1494 */
1495 if (pipe_stats[pipe] & 0x8000ffff)
1496 I915_WRITE(reg, pipe_stats[pipe]);
1497 }
1498 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1499
1500 for_each_pipe(pipe) {
1501 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1502 drm_handle_vblank(dev, pipe);
1503
1504 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1505 intel_prepare_page_flip(dev, pipe);
1506 intel_finish_page_flip(dev, pipe);
1507 }
1508
1509 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1510 i9xx_pipe_crc_irq_handler(dev, pipe);
1511
1512 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
1513 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1514 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
1515 }
1516
1517 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1518 gmbus_irq_handler(dev);
1519}
1520
Daniel Vetterff1f5252012-10-02 15:10:55 +02001521static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001522{
1523 struct drm_device *dev = (struct drm_device *) arg;
1524 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1525 u32 iir, gt_iir, pm_iir;
1526 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001527
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001528 while (true) {
1529 iir = I915_READ(VLV_IIR);
1530 gt_iir = I915_READ(GTIIR);
1531 pm_iir = I915_READ(GEN6_PMIIR);
1532
1533 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1534 goto out;
1535
1536 ret = IRQ_HANDLED;
1537
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001538 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001539
Imre Deakc1874ed2014-02-04 21:35:46 +02001540 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001541
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001542 /* Consume port. Then clear IIR or we'll miss events */
1543 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1544 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001545 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001546
Daniel Vetter91d131d2013-06-27 17:52:14 +02001547 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1548
Daniel Vetter4aeebd72013-10-31 09:53:36 +01001549 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1550 dp_aux_irq_handler(dev);
1551
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001552 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1553 I915_READ(PORT_HOTPLUG_STAT);
1554 }
1555
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001556
Paulo Zanoni60611c12013-08-15 11:50:01 -03001557 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001558 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001559
1560 I915_WRITE(GTIIR, gt_iir);
1561 I915_WRITE(GEN6_PMIIR, pm_iir);
1562 I915_WRITE(VLV_IIR, iir);
1563 }
1564
1565out:
1566 return ret;
1567}
1568
Adam Jackson23e81d62012-06-06 15:45:44 -04001569static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001570{
1571 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001572 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001573 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001574
Daniel Vetter91d131d2013-06-27 17:52:14 +02001575 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1576
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001577 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1578 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1579 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001580 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001581 port_name(port));
1582 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001583
Daniel Vetterce99c252012-12-01 13:53:47 +01001584 if (pch_iir & SDE_AUX_MASK)
1585 dp_aux_irq_handler(dev);
1586
Jesse Barnes776ad802011-01-04 15:09:39 -08001587 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001588 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001589
1590 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1591 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1592
1593 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1594 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1595
1596 if (pch_iir & SDE_POISON)
1597 DRM_ERROR("PCH poison interrupt\n");
1598
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001599 if (pch_iir & SDE_FDI_MASK)
1600 for_each_pipe(pipe)
1601 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1602 pipe_name(pipe),
1603 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001604
1605 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1606 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1607
1608 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1609 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1610
Jesse Barnes776ad802011-01-04 15:09:39 -08001611 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001612 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1613 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001614 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001615
1616 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1617 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1618 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001619 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001620}
1621
1622static void ivb_err_int_handler(struct drm_device *dev)
1623{
1624 struct drm_i915_private *dev_priv = dev->dev_private;
1625 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001626 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001627
Paulo Zanonide032bf2013-04-12 17:57:58 -03001628 if (err_int & ERR_INT_POISON)
1629 DRM_ERROR("Poison interrupt\n");
1630
Daniel Vetter5a69b892013-10-16 22:55:52 +02001631 for_each_pipe(pipe) {
1632 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1633 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1634 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001635 DRM_ERROR("Pipe %c FIFO underrun\n",
1636 pipe_name(pipe));
Daniel Vetter5a69b892013-10-16 22:55:52 +02001637 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001638
Daniel Vetter5a69b892013-10-16 22:55:52 +02001639 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1640 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001641 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001642 else
Daniel Vetter277de952013-10-18 16:37:07 +02001643 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001644 }
1645 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001646
Paulo Zanoni86642812013-04-12 17:57:57 -03001647 I915_WRITE(GEN7_ERR_INT, err_int);
1648}
1649
1650static void cpt_serr_int_handler(struct drm_device *dev)
1651{
1652 struct drm_i915_private *dev_priv = dev->dev_private;
1653 u32 serr_int = I915_READ(SERR_INT);
1654
Paulo Zanonide032bf2013-04-12 17:57:58 -03001655 if (serr_int & SERR_INT_POISON)
1656 DRM_ERROR("PCH poison interrupt\n");
1657
Paulo Zanoni86642812013-04-12 17:57:57 -03001658 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1659 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1660 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001661 DRM_ERROR("PCH transcoder A FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001662
1663 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1664 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1665 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001666 DRM_ERROR("PCH transcoder B FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001667
1668 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1669 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1670 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001671 DRM_ERROR("PCH transcoder C FIFO underrun\n");
Paulo Zanoni86642812013-04-12 17:57:57 -03001672
1673 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001674}
1675
Adam Jackson23e81d62012-06-06 15:45:44 -04001676static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1677{
1678 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1679 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001680 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001681
Daniel Vetter91d131d2013-06-27 17:52:14 +02001682 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1683
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001684 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1685 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1686 SDE_AUDIO_POWER_SHIFT_CPT);
1687 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1688 port_name(port));
1689 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001690
1691 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001692 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001693
1694 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001695 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001696
1697 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1698 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1699
1700 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1701 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1702
1703 if (pch_iir & SDE_FDI_MASK_CPT)
1704 for_each_pipe(pipe)
1705 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1706 pipe_name(pipe),
1707 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001708
1709 if (pch_iir & SDE_ERROR_CPT)
1710 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001711}
1712
Paulo Zanonic008bc62013-07-12 16:35:10 -03001713static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1714{
1715 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001716 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001717
1718 if (de_iir & DE_AUX_CHANNEL_A)
1719 dp_aux_irq_handler(dev);
1720
1721 if (de_iir & DE_GSE)
1722 intel_opregion_asle_intr(dev);
1723
Paulo Zanonic008bc62013-07-12 16:35:10 -03001724 if (de_iir & DE_POISON)
1725 DRM_ERROR("Poison interrupt\n");
1726
Daniel Vetter40da17c2013-10-21 18:04:36 +02001727 for_each_pipe(pipe) {
1728 if (de_iir & DE_PIPE_VBLANK(pipe))
1729 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001730
Daniel Vetter40da17c2013-10-21 18:04:36 +02001731 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1732 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001733 DRM_ERROR("Pipe %c FIFO underrun\n",
1734 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001735
Daniel Vetter40da17c2013-10-21 18:04:36 +02001736 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1737 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001738
Daniel Vetter40da17c2013-10-21 18:04:36 +02001739 /* plane/pipes map 1:1 on ilk+ */
1740 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1741 intel_prepare_page_flip(dev, pipe);
1742 intel_finish_page_flip_plane(dev, pipe);
1743 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001744 }
1745
1746 /* check event from PCH */
1747 if (de_iir & DE_PCH_EVENT) {
1748 u32 pch_iir = I915_READ(SDEIIR);
1749
1750 if (HAS_PCH_CPT(dev))
1751 cpt_irq_handler(dev, pch_iir);
1752 else
1753 ibx_irq_handler(dev, pch_iir);
1754
1755 /* should clear PCH hotplug event before clear CPU irq */
1756 I915_WRITE(SDEIIR, pch_iir);
1757 }
1758
1759 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1760 ironlake_rps_change_irq_handler(dev);
1761}
1762
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001763static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1764{
1765 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001766 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001767
1768 if (de_iir & DE_ERR_INT_IVB)
1769 ivb_err_int_handler(dev);
1770
1771 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1772 dp_aux_irq_handler(dev);
1773
1774 if (de_iir & DE_GSE_IVB)
1775 intel_opregion_asle_intr(dev);
1776
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001777 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001778 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001779 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001780
1781 /* plane/pipes map 1:1 on ilk+ */
1782 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001783 intel_prepare_page_flip(dev, i);
1784 intel_finish_page_flip_plane(dev, i);
1785 }
1786 }
1787
1788 /* check event from PCH */
1789 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1790 u32 pch_iir = I915_READ(SDEIIR);
1791
1792 cpt_irq_handler(dev, pch_iir);
1793
1794 /* clear PCH hotplug event before clear CPU irq */
1795 I915_WRITE(SDEIIR, pch_iir);
1796 }
1797}
1798
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001799static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001800{
1801 struct drm_device *dev = (struct drm_device *) arg;
1802 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001803 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001804 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001805
Paulo Zanoni86642812013-04-12 17:57:57 -03001806 /* We get interrupts on unclaimed registers, so check for this before we
1807 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001808 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001809
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001810 /* disable master interrupt before clearing iir */
1811 de_ier = I915_READ(DEIER);
1812 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001813 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001814
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001815 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1816 * interrupts will will be stored on its back queue, and then we'll be
1817 * able to process them after we restore SDEIER (as soon as we restore
1818 * it, we'll get an interrupt if SDEIIR still has something to process
1819 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001820 if (!HAS_PCH_NOP(dev)) {
1821 sde_ier = I915_READ(SDEIER);
1822 I915_WRITE(SDEIER, 0);
1823 POSTING_READ(SDEIER);
1824 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001825
Chris Wilson0e434062012-05-09 21:45:44 +01001826 gt_iir = I915_READ(GTIIR);
1827 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001828 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001829 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001830 else
1831 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001832 I915_WRITE(GTIIR, gt_iir);
1833 ret = IRQ_HANDLED;
1834 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001835
1836 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001837 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001838 if (INTEL_INFO(dev)->gen >= 7)
1839 ivb_display_irq_handler(dev, de_iir);
1840 else
1841 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001842 I915_WRITE(DEIIR, de_iir);
1843 ret = IRQ_HANDLED;
1844 }
1845
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001846 if (INTEL_INFO(dev)->gen >= 6) {
1847 u32 pm_iir = I915_READ(GEN6_PMIIR);
1848 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001849 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001850 I915_WRITE(GEN6_PMIIR, pm_iir);
1851 ret = IRQ_HANDLED;
1852 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001853 }
1854
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001855 I915_WRITE(DEIER, de_ier);
1856 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001857 if (!HAS_PCH_NOP(dev)) {
1858 I915_WRITE(SDEIER, sde_ier);
1859 POSTING_READ(SDEIER);
1860 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001861
1862 return ret;
1863}
1864
Ben Widawskyabd58f02013-11-02 21:07:09 -07001865static irqreturn_t gen8_irq_handler(int irq, void *arg)
1866{
1867 struct drm_device *dev = arg;
1868 struct drm_i915_private *dev_priv = dev->dev_private;
1869 u32 master_ctl;
1870 irqreturn_t ret = IRQ_NONE;
1871 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001872 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001873
Ben Widawskyabd58f02013-11-02 21:07:09 -07001874 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1875 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1876 if (!master_ctl)
1877 return IRQ_NONE;
1878
1879 I915_WRITE(GEN8_MASTER_IRQ, 0);
1880 POSTING_READ(GEN8_MASTER_IRQ);
1881
1882 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1883
1884 if (master_ctl & GEN8_DE_MISC_IRQ) {
1885 tmp = I915_READ(GEN8_DE_MISC_IIR);
1886 if (tmp & GEN8_DE_MISC_GSE)
1887 intel_opregion_asle_intr(dev);
1888 else if (tmp)
1889 DRM_ERROR("Unexpected DE Misc interrupt\n");
1890 else
1891 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1892
1893 if (tmp) {
1894 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1895 ret = IRQ_HANDLED;
1896 }
1897 }
1898
Daniel Vetter6d766f02013-11-07 14:49:55 +01001899 if (master_ctl & GEN8_DE_PORT_IRQ) {
1900 tmp = I915_READ(GEN8_DE_PORT_IIR);
1901 if (tmp & GEN8_AUX_CHANNEL_A)
1902 dp_aux_irq_handler(dev);
1903 else if (tmp)
1904 DRM_ERROR("Unexpected DE Port interrupt\n");
1905 else
1906 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1907
1908 if (tmp) {
1909 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1910 ret = IRQ_HANDLED;
1911 }
1912 }
1913
Daniel Vetterc42664c2013-11-07 11:05:40 +01001914 for_each_pipe(pipe) {
1915 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001916
Daniel Vetterc42664c2013-11-07 11:05:40 +01001917 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1918 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001919
Daniel Vetterc42664c2013-11-07 11:05:40 +01001920 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1921 if (pipe_iir & GEN8_PIPE_VBLANK)
1922 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001923
Daniel Vetterc42664c2013-11-07 11:05:40 +01001924 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1925 intel_prepare_page_flip(dev, pipe);
1926 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001927 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001928
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001929 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1930 hsw_pipe_crc_irq_handler(dev, pipe);
1931
Daniel Vetter38d83c962013-11-07 11:05:46 +01001932 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1933 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1934 false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02001935 DRM_ERROR("Pipe %c FIFO underrun\n",
1936 pipe_name(pipe));
Daniel Vetter38d83c962013-11-07 11:05:46 +01001937 }
1938
Daniel Vetter30100f22013-11-07 14:49:24 +01001939 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1940 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
1941 pipe_name(pipe),
1942 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
1943 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001944
1945 if (pipe_iir) {
1946 ret = IRQ_HANDLED;
1947 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
1948 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07001949 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
1950 }
1951
Daniel Vetter92d03a82013-11-07 11:05:43 +01001952 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
1953 /*
1954 * FIXME(BDW): Assume for now that the new interrupt handling
1955 * scheme also closed the SDE interrupt handling race we've seen
1956 * on older pch-split platforms. But this needs testing.
1957 */
1958 u32 pch_iir = I915_READ(SDEIIR);
1959
1960 cpt_irq_handler(dev, pch_iir);
1961
1962 if (pch_iir) {
1963 I915_WRITE(SDEIIR, pch_iir);
1964 ret = IRQ_HANDLED;
1965 }
1966 }
1967
Ben Widawskyabd58f02013-11-02 21:07:09 -07001968 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1969 POSTING_READ(GEN8_MASTER_IRQ);
1970
1971 return ret;
1972}
1973
Daniel Vetter17e1df02013-09-08 21:57:13 +02001974static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1975 bool reset_completed)
1976{
1977 struct intel_ring_buffer *ring;
1978 int i;
1979
1980 /*
1981 * Notify all waiters for GPU completion events that reset state has
1982 * been changed, and that they need to restart their wait after
1983 * checking for potential errors (and bail out to drop locks if there is
1984 * a gpu reset pending so that i915_error_work_func can acquire them).
1985 */
1986
1987 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1988 for_each_ring(ring, dev_priv, i)
1989 wake_up_all(&ring->irq_queue);
1990
1991 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1992 wake_up_all(&dev_priv->pending_flip_queue);
1993
1994 /*
1995 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1996 * reset state is cleared.
1997 */
1998 if (reset_completed)
1999 wake_up_all(&dev_priv->gpu_error.reset_queue);
2000}
2001
Jesse Barnes8a905232009-07-11 16:48:03 -04002002/**
2003 * i915_error_work_func - do process context error handling work
2004 * @work: work struct
2005 *
2006 * Fire an error uevent so userspace can see that a hang or error
2007 * was detected.
2008 */
2009static void i915_error_work_func(struct work_struct *work)
2010{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002011 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2012 work);
2013 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
2014 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002015 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002016 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2017 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2018 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002019 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002020
Dave Airlie5bdebb12013-10-11 14:07:25 +10002021 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002022
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002023 /*
2024 * Note that there's only one work item which does gpu resets, so we
2025 * need not worry about concurrent gpu resets potentially incrementing
2026 * error->reset_counter twice. We only need to take care of another
2027 * racing irq/hangcheck declaring the gpu dead for a second time. A
2028 * quick check for that is good enough: schedule_work ensures the
2029 * correct ordering between hang detection and this work item, and since
2030 * the reset in-progress bit is only ever set by code outside of this
2031 * work we don't need to worry about any other races.
2032 */
2033 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002034 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002035 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002036 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002037
Daniel Vetter17e1df02013-09-08 21:57:13 +02002038 /*
2039 * All state reset _must_ be completed before we update the
2040 * reset counter, for otherwise waiters might miss the reset
2041 * pending state and not properly drop locks, resulting in
2042 * deadlocks with the reset work.
2043 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002044 ret = i915_reset(dev);
2045
Daniel Vetter17e1df02013-09-08 21:57:13 +02002046 intel_display_handle_reset(dev);
2047
Daniel Vetterf69061b2012-12-06 09:01:42 +01002048 if (ret == 0) {
2049 /*
2050 * After all the gem state is reset, increment the reset
2051 * counter and wake up everyone waiting for the reset to
2052 * complete.
2053 *
2054 * Since unlock operations are a one-sided barrier only,
2055 * we need to insert a barrier here to order any seqno
2056 * updates before
2057 * the counter increment.
2058 */
2059 smp_mb__before_atomic_inc();
2060 atomic_inc(&dev_priv->gpu_error.reset_counter);
2061
Dave Airlie5bdebb12013-10-11 14:07:25 +10002062 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002063 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002064 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002065 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002066 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002067
Daniel Vetter17e1df02013-09-08 21:57:13 +02002068 /*
2069 * Note: The wake_up also serves as a memory barrier so that
2070 * waiters see the update value of the reset counter atomic_t.
2071 */
2072 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002073 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002074}
2075
Chris Wilson35aed2e2010-05-27 13:18:12 +01002076static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002077{
2078 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002079 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002080 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002081 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002082
Chris Wilson35aed2e2010-05-27 13:18:12 +01002083 if (!eir)
2084 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002085
Joe Perchesa70491c2012-03-18 13:00:11 -07002086 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002087
Ben Widawskybd9854f2012-08-23 15:18:09 -07002088 i915_get_extra_instdone(dev, instdone);
2089
Jesse Barnes8a905232009-07-11 16:48:03 -04002090 if (IS_G4X(dev)) {
2091 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2092 u32 ipeir = I915_READ(IPEIR_I965);
2093
Joe Perchesa70491c2012-03-18 13:00:11 -07002094 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2095 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002096 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2097 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002098 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002099 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002100 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002101 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002102 }
2103 if (eir & GM45_ERROR_PAGE_TABLE) {
2104 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002105 pr_err("page table error\n");
2106 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002107 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002108 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002109 }
2110 }
2111
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002112 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002113 if (eir & I915_ERROR_PAGE_TABLE) {
2114 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002115 pr_err("page table error\n");
2116 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002117 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002118 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002119 }
2120 }
2121
2122 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002123 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002124 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002125 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002126 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002127 /* pipestat has already been acked */
2128 }
2129 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002130 pr_err("instruction error\n");
2131 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002132 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2133 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002134 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002135 u32 ipeir = I915_READ(IPEIR);
2136
Joe Perchesa70491c2012-03-18 13:00:11 -07002137 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2138 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002139 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002140 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002141 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002142 } else {
2143 u32 ipeir = I915_READ(IPEIR_I965);
2144
Joe Perchesa70491c2012-03-18 13:00:11 -07002145 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2146 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002147 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002148 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002149 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002150 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002151 }
2152 }
2153
2154 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002155 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002156 eir = I915_READ(EIR);
2157 if (eir) {
2158 /*
2159 * some errors might have become stuck,
2160 * mask them.
2161 */
2162 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2163 I915_WRITE(EMR, I915_READ(EMR) | eir);
2164 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2165 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002166}
2167
2168/**
2169 * i915_handle_error - handle an error interrupt
2170 * @dev: drm device
2171 *
2172 * Do some basic checking of regsiter state at error interrupt time and
2173 * dump it to the syslog. Also call i915_capture_error_state() to make
2174 * sure we get a record and make it available in debugfs. Fire a uevent
2175 * so userspace knows something bad happened (should trigger collection
2176 * of a ring dump etc.).
2177 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002178void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002179{
2180 struct drm_i915_private *dev_priv = dev->dev_private;
2181
2182 i915_capture_error_state(dev);
2183 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002184
Ben Gamariba1234d2009-09-14 17:48:47 -04002185 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002186 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2187 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002188
Ben Gamari11ed50e2009-09-14 17:48:45 -04002189 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002190 * Wakeup waiting processes so that the reset work function
2191 * i915_error_work_func doesn't deadlock trying to grab various
2192 * locks. By bumping the reset counter first, the woken
2193 * processes will see a reset in progress and back off,
2194 * releasing their locks and then wait for the reset completion.
2195 * We must do this for _all_ gpu waiters that might hold locks
2196 * that the reset work needs to acquire.
2197 *
2198 * Note: The wake_up serves as the required memory barrier to
2199 * ensure that the waiters see the updated value of the reset
2200 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002201 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002202 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002203 }
2204
Daniel Vetter122f46b2013-09-04 17:36:14 +02002205 /*
2206 * Our reset work can grab modeset locks (since it needs to reset the
2207 * state of outstanding pagelips). Hence it must not be run on our own
2208 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2209 * code will deadlock.
2210 */
2211 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002212}
2213
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002214static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002215{
2216 drm_i915_private_t *dev_priv = dev->dev_private;
2217 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2218 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002219 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002220 struct intel_unpin_work *work;
2221 unsigned long flags;
2222 bool stall_detected;
2223
2224 /* Ignore early vblank irqs */
2225 if (intel_crtc == NULL)
2226 return;
2227
2228 spin_lock_irqsave(&dev->event_lock, flags);
2229 work = intel_crtc->unpin_work;
2230
Chris Wilsone7d841c2012-12-03 11:36:30 +00002231 if (work == NULL ||
2232 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2233 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002234 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2235 spin_unlock_irqrestore(&dev->event_lock, flags);
2236 return;
2237 }
2238
2239 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002240 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002241 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002242 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002243 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002244 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002245 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002246 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002247 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002248 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002249 crtc->x * crtc->fb->bits_per_pixel/8);
2250 }
2251
2252 spin_unlock_irqrestore(&dev->event_lock, flags);
2253
2254 if (stall_detected) {
2255 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2256 intel_prepare_page_flip(dev, intel_crtc->plane);
2257 }
2258}
2259
Keith Packard42f52ef2008-10-18 19:39:29 -07002260/* Called from drm generic code, passed 'crtc' which
2261 * we use as a pipe index
2262 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002263static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002264{
2265 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002266 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002267
Chris Wilson5eddb702010-09-11 13:48:45 +01002268 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002269 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002270
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002271 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002272 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002273 i915_enable_pipestat(dev_priv, pipe,
2274 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07002275 else
Keith Packard7c463582008-11-04 02:03:27 -08002276 i915_enable_pipestat(dev_priv, pipe,
2277 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002278
2279 /* maintain vblank delivery even in deep C-states */
2280 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002281 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002282 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002283
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002284 return 0;
2285}
2286
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002287static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002288{
2289 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2290 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002291 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002292 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002293
2294 if (!i915_pipe_enabled(dev, pipe))
2295 return -EINVAL;
2296
2297 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002298 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002299 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2300
2301 return 0;
2302}
2303
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002304static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2305{
2306 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2307 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002308
2309 if (!i915_pipe_enabled(dev, pipe))
2310 return -EINVAL;
2311
2312 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002313 i915_enable_pipestat(dev_priv, pipe,
2314 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002315 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2316
2317 return 0;
2318}
2319
Ben Widawskyabd58f02013-11-02 21:07:09 -07002320static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2321{
2322 struct drm_i915_private *dev_priv = dev->dev_private;
2323 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002324
2325 if (!i915_pipe_enabled(dev, pipe))
2326 return -EINVAL;
2327
2328 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002329 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2330 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2331 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002332 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2333 return 0;
2334}
2335
Keith Packard42f52ef2008-10-18 19:39:29 -07002336/* Called from drm generic code, passed 'crtc' which
2337 * we use as a pipe index
2338 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002339static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002340{
2341 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002342 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002343
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002344 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002345 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002346 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002347
Jesse Barnesf796cf82011-04-07 13:58:17 -07002348 i915_disable_pipestat(dev_priv, pipe,
2349 PIPE_VBLANK_INTERRUPT_ENABLE |
2350 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2351 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2352}
2353
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002354static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002355{
2356 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2357 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002358 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002359 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002360
2361 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002362 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002363 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2364}
2365
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002366static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2367{
2368 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2369 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002370
2371 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002372 i915_disable_pipestat(dev_priv, pipe,
2373 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002374 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2375}
2376
Ben Widawskyabd58f02013-11-02 21:07:09 -07002377static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2378{
2379 struct drm_i915_private *dev_priv = dev->dev_private;
2380 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002381
2382 if (!i915_pipe_enabled(dev, pipe))
2383 return;
2384
2385 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002386 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2387 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2388 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002389 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2390}
2391
Chris Wilson893eead2010-10-27 14:44:35 +01002392static u32
2393ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002394{
Chris Wilson893eead2010-10-27 14:44:35 +01002395 return list_entry(ring->request_list.prev,
2396 struct drm_i915_gem_request, list)->seqno;
2397}
2398
Chris Wilson9107e9d2013-06-10 11:20:20 +01002399static bool
2400ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002401{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002402 return (list_empty(&ring->request_list) ||
2403 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002404}
2405
Chris Wilson6274f212013-06-10 11:20:21 +01002406static struct intel_ring_buffer *
2407semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002408{
2409 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002410 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002411
2412 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2413 if ((ipehr & ~(0x3 << 16)) !=
2414 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002415 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002416
2417 /* ACTHD is likely pointing to the dword after the actual command,
2418 * so scan backwards until we find the MBOX.
2419 */
Chris Wilson6274f212013-06-10 11:20:21 +01002420 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002421 acthd_min = max((int)acthd - 3 * 4, 0);
2422 do {
2423 cmd = ioread32(ring->virtual_start + acthd);
2424 if (cmd == ipehr)
2425 break;
2426
2427 acthd -= 4;
2428 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002429 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002430 } while (1);
2431
Chris Wilson6274f212013-06-10 11:20:21 +01002432 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2433 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002434}
2435
Chris Wilson6274f212013-06-10 11:20:21 +01002436static int semaphore_passed(struct intel_ring_buffer *ring)
2437{
2438 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2439 struct intel_ring_buffer *signaller;
2440 u32 seqno, ctl;
2441
2442 ring->hangcheck.deadlock = true;
2443
2444 signaller = semaphore_waits_for(ring, &seqno);
2445 if (signaller == NULL || signaller->hangcheck.deadlock)
2446 return -1;
2447
2448 /* cursory check for an unkickable deadlock */
2449 ctl = I915_READ_CTL(signaller);
2450 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2451 return -1;
2452
2453 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2454}
2455
2456static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2457{
2458 struct intel_ring_buffer *ring;
2459 int i;
2460
2461 for_each_ring(ring, dev_priv, i)
2462 ring->hangcheck.deadlock = false;
2463}
2464
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002465static enum intel_ring_hangcheck_action
2466ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002467{
2468 struct drm_device *dev = ring->dev;
2469 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002470 u32 tmp;
2471
Chris Wilson6274f212013-06-10 11:20:21 +01002472 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002473 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002474
Chris Wilson9107e9d2013-06-10 11:20:20 +01002475 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002476 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002477
2478 /* Is the chip hanging on a WAIT_FOR_EVENT?
2479 * If so we can simply poke the RB_WAIT bit
2480 * and break the hang. This should work on
2481 * all but the second generation chipsets.
2482 */
2483 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002484 if (tmp & RING_WAIT) {
2485 DRM_ERROR("Kicking stuck wait on %s\n",
2486 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002487 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002488 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002489 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002490 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002491
Chris Wilson6274f212013-06-10 11:20:21 +01002492 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2493 switch (semaphore_passed(ring)) {
2494 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002495 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002496 case 1:
2497 DRM_ERROR("Kicking stuck semaphore on %s\n",
2498 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002499 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002500 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002501 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002502 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002503 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002504 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002505 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002506
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002507 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002508}
2509
Ben Gamarif65d9422009-09-14 17:48:44 -04002510/**
2511 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002512 * batchbuffers in a long time. We keep track per ring seqno progress and
2513 * if there are no progress, hangcheck score for that ring is increased.
2514 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2515 * we kick the ring. If we see no progress on three subsequent calls
2516 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002517 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002518static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002519{
2520 struct drm_device *dev = (struct drm_device *)data;
2521 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002522 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002523 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002524 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002525 bool stuck[I915_NUM_RINGS] = { 0 };
2526#define BUSY 1
2527#define KICK 5
2528#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002529
Jani Nikulad330a952014-01-21 11:24:25 +02002530 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002531 return;
2532
Chris Wilsonb4519512012-05-11 14:29:30 +01002533 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002534 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002535 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002536
Chris Wilson6274f212013-06-10 11:20:21 +01002537 semaphore_clear_deadlocks(dev_priv);
2538
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002539 seqno = ring->get_seqno(ring, false);
2540 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002541
Chris Wilson9107e9d2013-06-10 11:20:20 +01002542 if (ring->hangcheck.seqno == seqno) {
2543 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002544 ring->hangcheck.action = HANGCHECK_IDLE;
2545
Chris Wilson9107e9d2013-06-10 11:20:20 +01002546 if (waitqueue_active(&ring->irq_queue)) {
2547 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002548 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002549 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2550 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2551 ring->name);
2552 else
2553 DRM_INFO("Fake missed irq on %s\n",
2554 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002555 wake_up_all(&ring->irq_queue);
2556 }
2557 /* Safeguard against driver failure */
2558 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002559 } else
2560 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002561 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002562 /* We always increment the hangcheck score
2563 * if the ring is busy and still processing
2564 * the same request, so that no single request
2565 * can run indefinitely (such as a chain of
2566 * batches). The only time we do not increment
2567 * the hangcheck score on this ring, if this
2568 * ring is in a legitimate wait for another
2569 * ring. In that case the waiting ring is a
2570 * victim and we want to be sure we catch the
2571 * right culprit. Then every time we do kick
2572 * the ring, add a small increment to the
2573 * score so that we can catch a batch that is
2574 * being repeatedly kicked and so responsible
2575 * for stalling the machine.
2576 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002577 ring->hangcheck.action = ring_stuck(ring,
2578 acthd);
2579
2580 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002581 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002582 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002583 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002584 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002585 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002586 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002587 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002588 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002589 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002590 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002591 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002592 stuck[i] = true;
2593 break;
2594 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002595 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002596 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002597 ring->hangcheck.action = HANGCHECK_ACTIVE;
2598
Chris Wilson9107e9d2013-06-10 11:20:20 +01002599 /* Gradually reduce the count so that we catch DoS
2600 * attempts across multiple batches.
2601 */
2602 if (ring->hangcheck.score > 0)
2603 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002604 }
2605
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002606 ring->hangcheck.seqno = seqno;
2607 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002608 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002609 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002610
Mika Kuoppala92cab732013-05-24 17:16:07 +03002611 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002612 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002613 DRM_INFO("%s on %s\n",
2614 stuck[i] ? "stuck" : "no progress",
2615 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002616 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002617 }
2618 }
2619
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002620 if (rings_hung)
2621 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002622
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002623 if (busy_count)
2624 /* Reset timer case chip hangs without another request
2625 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002626 i915_queue_hangcheck(dev);
2627}
2628
2629void i915_queue_hangcheck(struct drm_device *dev)
2630{
2631 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikulad330a952014-01-21 11:24:25 +02002632 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002633 return;
2634
2635 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2636 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002637}
2638
Paulo Zanoni91738a92013-06-05 14:21:51 -03002639static void ibx_irq_preinstall(struct drm_device *dev)
2640{
2641 struct drm_i915_private *dev_priv = dev->dev_private;
2642
2643 if (HAS_PCH_NOP(dev))
2644 return;
2645
2646 /* south display irq */
2647 I915_WRITE(SDEIMR, 0xffffffff);
2648 /*
2649 * SDEIER is also touched by the interrupt handler to work around missed
2650 * PCH interrupts. Hence we can't update it after the interrupt handler
2651 * is enabled - instead we unconditionally enable all PCH interrupt
2652 * sources here, but then only unmask them as needed with SDEIMR.
2653 */
2654 I915_WRITE(SDEIER, 0xffffffff);
2655 POSTING_READ(SDEIER);
2656}
2657
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002658static void gen5_gt_irq_preinstall(struct drm_device *dev)
2659{
2660 struct drm_i915_private *dev_priv = dev->dev_private;
2661
2662 /* and GT */
2663 I915_WRITE(GTIMR, 0xffffffff);
2664 I915_WRITE(GTIER, 0x0);
2665 POSTING_READ(GTIER);
2666
2667 if (INTEL_INFO(dev)->gen >= 6) {
2668 /* and PM */
2669 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2670 I915_WRITE(GEN6_PMIER, 0x0);
2671 POSTING_READ(GEN6_PMIER);
2672 }
2673}
2674
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675/* drm_dma.h hooks
2676*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002677static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002678{
2679 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2680
2681 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002682
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002683 I915_WRITE(DEIMR, 0xffffffff);
2684 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002685 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002686
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002687 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002688
Paulo Zanoni91738a92013-06-05 14:21:51 -03002689 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002690}
2691
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002692static void valleyview_irq_preinstall(struct drm_device *dev)
2693{
2694 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2695 int pipe;
2696
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002697 /* VLV magic */
2698 I915_WRITE(VLV_IMR, 0);
2699 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2700 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2701 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2702
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002703 /* and GT */
2704 I915_WRITE(GTIIR, I915_READ(GTIIR));
2705 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002706
2707 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002708
2709 I915_WRITE(DPINVGTT, 0xff);
2710
2711 I915_WRITE(PORT_HOTPLUG_EN, 0);
2712 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2713 for_each_pipe(pipe)
2714 I915_WRITE(PIPESTAT(pipe), 0xffff);
2715 I915_WRITE(VLV_IIR, 0xffffffff);
2716 I915_WRITE(VLV_IMR, 0xffffffff);
2717 I915_WRITE(VLV_IER, 0x0);
2718 POSTING_READ(VLV_IER);
2719}
2720
Ben Widawskyabd58f02013-11-02 21:07:09 -07002721static void gen8_irq_preinstall(struct drm_device *dev)
2722{
2723 struct drm_i915_private *dev_priv = dev->dev_private;
2724 int pipe;
2725
Ben Widawskyabd58f02013-11-02 21:07:09 -07002726 I915_WRITE(GEN8_MASTER_IRQ, 0);
2727 POSTING_READ(GEN8_MASTER_IRQ);
2728
2729 /* IIR can theoretically queue up two events. Be paranoid */
2730#define GEN8_IRQ_INIT_NDX(type, which) do { \
2731 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2732 POSTING_READ(GEN8_##type##_IMR(which)); \
2733 I915_WRITE(GEN8_##type##_IER(which), 0); \
2734 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2735 POSTING_READ(GEN8_##type##_IIR(which)); \
2736 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2737 } while (0)
2738
2739#define GEN8_IRQ_INIT(type) do { \
2740 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2741 POSTING_READ(GEN8_##type##_IMR); \
2742 I915_WRITE(GEN8_##type##_IER, 0); \
2743 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2744 POSTING_READ(GEN8_##type##_IIR); \
2745 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2746 } while (0)
2747
2748 GEN8_IRQ_INIT_NDX(GT, 0);
2749 GEN8_IRQ_INIT_NDX(GT, 1);
2750 GEN8_IRQ_INIT_NDX(GT, 2);
2751 GEN8_IRQ_INIT_NDX(GT, 3);
2752
2753 for_each_pipe(pipe) {
2754 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2755 }
2756
2757 GEN8_IRQ_INIT(DE_PORT);
2758 GEN8_IRQ_INIT(DE_MISC);
2759 GEN8_IRQ_INIT(PCU);
2760#undef GEN8_IRQ_INIT
2761#undef GEN8_IRQ_INIT_NDX
2762
2763 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002764
2765 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002766}
2767
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002768static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002769{
2770 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002771 struct drm_mode_config *mode_config = &dev->mode_config;
2772 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002773 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002774
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002775 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002776 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002777 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002778 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002779 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002780 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002781 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002782 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002783 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002784 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002785 }
2786
Daniel Vetterfee884e2013-07-04 23:35:21 +02002787 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002788
2789 /*
2790 * Enable digital hotplug on the PCH, and configure the DP short pulse
2791 * duration to 2ms (which is the minimum in the Display Port spec)
2792 *
2793 * This register is the same on all known PCH chips.
2794 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002795 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2796 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2797 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2798 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2799 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2800 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2801}
2802
Paulo Zanonid46da432013-02-08 17:35:15 -02002803static void ibx_irq_postinstall(struct drm_device *dev)
2804{
2805 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002806 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002807
Daniel Vetter692a04c2013-05-29 21:43:05 +02002808 if (HAS_PCH_NOP(dev))
2809 return;
2810
Paulo Zanoni86642812013-04-12 17:57:57 -03002811 if (HAS_PCH_IBX(dev)) {
2812 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002813 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002814 } else {
2815 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2816
2817 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2818 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002819
Paulo Zanonid46da432013-02-08 17:35:15 -02002820 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2821 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002822}
2823
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002824static void gen5_gt_irq_postinstall(struct drm_device *dev)
2825{
2826 struct drm_i915_private *dev_priv = dev->dev_private;
2827 u32 pm_irqs, gt_irqs;
2828
2829 pm_irqs = gt_irqs = 0;
2830
2831 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002832 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002833 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002834 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2835 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002836 }
2837
2838 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2839 if (IS_GEN5(dev)) {
2840 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2841 ILK_BSD_USER_INTERRUPT;
2842 } else {
2843 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2844 }
2845
2846 I915_WRITE(GTIIR, I915_READ(GTIIR));
2847 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2848 I915_WRITE(GTIER, gt_irqs);
2849 POSTING_READ(GTIER);
2850
2851 if (INTEL_INFO(dev)->gen >= 6) {
2852 pm_irqs |= GEN6_PM_RPS_EVENTS;
2853
2854 if (HAS_VEBOX(dev))
2855 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2856
Paulo Zanoni605cd252013-08-06 18:57:15 -03002857 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002858 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002859 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002860 I915_WRITE(GEN6_PMIER, pm_irqs);
2861 POSTING_READ(GEN6_PMIER);
2862 }
2863}
2864
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002865static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002866{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002867 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002868 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002869 u32 display_mask, extra_mask;
2870
2871 if (INTEL_INFO(dev)->gen >= 7) {
2872 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2873 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2874 DE_PLANEB_FLIP_DONE_IVB |
2875 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2876 DE_ERR_INT_IVB);
2877 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2878 DE_PIPEA_VBLANK_IVB);
2879
2880 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2881 } else {
2882 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2883 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002884 DE_AUX_CHANNEL_A |
2885 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2886 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2887 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002888 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2889 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002890
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002891 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002892
2893 /* should always can generate irq */
2894 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002895 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002896 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002897 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002898
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002899 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002900
Paulo Zanonid46da432013-02-08 17:35:15 -02002901 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002902
Jesse Barnesf97108d2010-01-29 11:27:07 -08002903 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002904 /* Enable PCU event interrupts
2905 *
2906 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002907 * setup is guaranteed to run in single-threaded context. But we
2908 * need it to make the assert_spin_locked happy. */
2909 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002910 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002911 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002912 }
2913
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002914 return 0;
2915}
2916
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002917static int valleyview_irq_postinstall(struct drm_device *dev)
2918{
2919 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002920 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002921 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2922 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002923 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002924
2925 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002926 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2927 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2928 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002929 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2930
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002931 /*
2932 *Leave vblank interrupts masked initially. enable/disable will
2933 * toggle them based on usage.
2934 */
2935 dev_priv->irq_mask = (~enable_mask) |
2936 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2937 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002938
Daniel Vetter20afbda2012-12-11 14:05:07 +01002939 I915_WRITE(PORT_HOTPLUG_EN, 0);
2940 POSTING_READ(PORT_HOTPLUG_EN);
2941
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002942 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2943 I915_WRITE(VLV_IER, enable_mask);
2944 I915_WRITE(VLV_IIR, 0xffffffff);
2945 I915_WRITE(PIPESTAT(0), 0xffff);
2946 I915_WRITE(PIPESTAT(1), 0xffff);
2947 POSTING_READ(VLV_IER);
2948
Daniel Vetterb79480b2013-06-27 17:52:10 +02002949 /* Interrupt setup is already guaranteed to be single-threaded, this is
2950 * just to make the assert_spin_locked check happy. */
2951 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002952 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
2953 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
2954 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002955 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002956
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002957 I915_WRITE(VLV_IIR, 0xffffffff);
2958 I915_WRITE(VLV_IIR, 0xffffffff);
2959
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002960 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002961
2962 /* ack & enable invalid PTE error interrupts */
2963#if 0 /* FIXME: add support to irq handler for checking these bits */
2964 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2965 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2966#endif
2967
2968 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002969
2970 return 0;
2971}
2972
Ben Widawskyabd58f02013-11-02 21:07:09 -07002973static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
2974{
2975 int i;
2976
2977 /* These are interrupts we'll toggle with the ring mask register */
2978 uint32_t gt_interrupts[] = {
2979 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
2980 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
2981 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
2982 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
2983 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
2984 0,
2985 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
2986 };
2987
2988 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
2989 u32 tmp = I915_READ(GEN8_GT_IIR(i));
2990 if (tmp)
2991 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2992 i, tmp);
2993 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
2994 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
2995 }
2996 POSTING_READ(GEN8_GT_IER(0));
2997}
2998
2999static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3000{
3001 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003002 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
3003 GEN8_PIPE_CDCLK_CRC_DONE |
3004 GEN8_PIPE_FIFO_UNDERRUN |
3005 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3006 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003007 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003008 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3009 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3010 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003011
3012 for_each_pipe(pipe) {
3013 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
3014 if (tmp)
3015 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
3016 pipe, tmp);
3017 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
3018 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
3019 }
3020 POSTING_READ(GEN8_DE_PIPE_ISR(0));
3021
Daniel Vetter6d766f02013-11-07 14:49:55 +01003022 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
3023 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003024 POSTING_READ(GEN8_DE_PORT_IER);
3025}
3026
3027static int gen8_irq_postinstall(struct drm_device *dev)
3028{
3029 struct drm_i915_private *dev_priv = dev->dev_private;
3030
3031 gen8_gt_irq_postinstall(dev_priv);
3032 gen8_de_irq_postinstall(dev_priv);
3033
3034 ibx_irq_postinstall(dev);
3035
3036 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3037 POSTING_READ(GEN8_MASTER_IRQ);
3038
3039 return 0;
3040}
3041
3042static void gen8_irq_uninstall(struct drm_device *dev)
3043{
3044 struct drm_i915_private *dev_priv = dev->dev_private;
3045 int pipe;
3046
3047 if (!dev_priv)
3048 return;
3049
Ben Widawskyabd58f02013-11-02 21:07:09 -07003050 I915_WRITE(GEN8_MASTER_IRQ, 0);
3051
3052#define GEN8_IRQ_FINI_NDX(type, which) do { \
3053 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3054 I915_WRITE(GEN8_##type##_IER(which), 0); \
3055 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3056 } while (0)
3057
3058#define GEN8_IRQ_FINI(type) do { \
3059 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3060 I915_WRITE(GEN8_##type##_IER, 0); \
3061 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3062 } while (0)
3063
3064 GEN8_IRQ_FINI_NDX(GT, 0);
3065 GEN8_IRQ_FINI_NDX(GT, 1);
3066 GEN8_IRQ_FINI_NDX(GT, 2);
3067 GEN8_IRQ_FINI_NDX(GT, 3);
3068
3069 for_each_pipe(pipe) {
3070 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3071 }
3072
3073 GEN8_IRQ_FINI(DE_PORT);
3074 GEN8_IRQ_FINI(DE_MISC);
3075 GEN8_IRQ_FINI(PCU);
3076#undef GEN8_IRQ_FINI
3077#undef GEN8_IRQ_FINI_NDX
3078
3079 POSTING_READ(GEN8_PCU_IIR);
3080}
3081
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003082static void valleyview_irq_uninstall(struct drm_device *dev)
3083{
3084 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3085 int pipe;
3086
3087 if (!dev_priv)
3088 return;
3089
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003090 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003091
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003092 for_each_pipe(pipe)
3093 I915_WRITE(PIPESTAT(pipe), 0xffff);
3094
3095 I915_WRITE(HWSTAM, 0xffffffff);
3096 I915_WRITE(PORT_HOTPLUG_EN, 0);
3097 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3098 for_each_pipe(pipe)
3099 I915_WRITE(PIPESTAT(pipe), 0xffff);
3100 I915_WRITE(VLV_IIR, 0xffffffff);
3101 I915_WRITE(VLV_IMR, 0xffffffff);
3102 I915_WRITE(VLV_IER, 0x0);
3103 POSTING_READ(VLV_IER);
3104}
3105
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003106static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003107{
3108 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003109
3110 if (!dev_priv)
3111 return;
3112
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003113 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003114
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003115 I915_WRITE(HWSTAM, 0xffffffff);
3116
3117 I915_WRITE(DEIMR, 0xffffffff);
3118 I915_WRITE(DEIER, 0x0);
3119 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003120 if (IS_GEN7(dev))
3121 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003122
3123 I915_WRITE(GTIMR, 0xffffffff);
3124 I915_WRITE(GTIER, 0x0);
3125 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003126
Ben Widawskyab5c6082013-04-05 13:12:41 -07003127 if (HAS_PCH_NOP(dev))
3128 return;
3129
Keith Packard192aac1f2011-09-20 10:12:44 -07003130 I915_WRITE(SDEIMR, 0xffffffff);
3131 I915_WRITE(SDEIER, 0x0);
3132 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003133 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3134 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003135}
3136
Chris Wilsonc2798b12012-04-22 21:13:57 +01003137static void i8xx_irq_preinstall(struct drm_device * dev)
3138{
3139 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3140 int pipe;
3141
Chris Wilsonc2798b12012-04-22 21:13:57 +01003142 for_each_pipe(pipe)
3143 I915_WRITE(PIPESTAT(pipe), 0);
3144 I915_WRITE16(IMR, 0xffff);
3145 I915_WRITE16(IER, 0x0);
3146 POSTING_READ16(IER);
3147}
3148
3149static int i8xx_irq_postinstall(struct drm_device *dev)
3150{
3151 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003152 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003153
Chris Wilsonc2798b12012-04-22 21:13:57 +01003154 I915_WRITE16(EMR,
3155 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3156
3157 /* Unmask the interrupts that we always want on. */
3158 dev_priv->irq_mask =
3159 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3160 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3161 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3162 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3163 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3164 I915_WRITE16(IMR, dev_priv->irq_mask);
3165
3166 I915_WRITE16(IER,
3167 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3168 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3169 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3170 I915_USER_INTERRUPT);
3171 POSTING_READ16(IER);
3172
Daniel Vetter379ef822013-10-16 22:55:56 +02003173 /* Interrupt setup is already guaranteed to be single-threaded, this is
3174 * just to make the assert_spin_locked check happy. */
3175 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003176 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3177 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003178 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3179
Chris Wilsonc2798b12012-04-22 21:13:57 +01003180 return 0;
3181}
3182
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003183/*
3184 * Returns true when a page flip has completed.
3185 */
3186static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003187 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003188{
3189 drm_i915_private_t *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003190 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003191
3192 if (!drm_handle_vblank(dev, pipe))
3193 return false;
3194
3195 if ((iir & flip_pending) == 0)
3196 return false;
3197
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003198 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003199
3200 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3201 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3202 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3203 * the flip is completed (no longer pending). Since this doesn't raise
3204 * an interrupt per se, we watch for the change at vblank.
3205 */
3206 if (I915_READ16(ISR) & flip_pending)
3207 return false;
3208
3209 intel_finish_page_flip(dev, pipe);
3210
3211 return true;
3212}
3213
Daniel Vetterff1f5252012-10-02 15:10:55 +02003214static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003215{
3216 struct drm_device *dev = (struct drm_device *) arg;
3217 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003218 u16 iir, new_iir;
3219 u32 pipe_stats[2];
3220 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003221 int pipe;
3222 u16 flip_mask =
3223 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3224 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3225
Chris Wilsonc2798b12012-04-22 21:13:57 +01003226 iir = I915_READ16(IIR);
3227 if (iir == 0)
3228 return IRQ_NONE;
3229
3230 while (iir & ~flip_mask) {
3231 /* Can't rely on pipestat interrupt bit in iir as it might
3232 * have been cleared after the pipestat interrupt was received.
3233 * It doesn't set the bit in iir again, but it still produces
3234 * interrupts (for non-MSI).
3235 */
3236 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3237 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3238 i915_handle_error(dev, false);
3239
3240 for_each_pipe(pipe) {
3241 int reg = PIPESTAT(pipe);
3242 pipe_stats[pipe] = I915_READ(reg);
3243
3244 /*
3245 * Clear the PIPE*STAT regs before the IIR
3246 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003247 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003248 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003249 }
3250 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3251
3252 I915_WRITE16(IIR, iir & ~flip_mask);
3253 new_iir = I915_READ16(IIR); /* Flush posted writes */
3254
Daniel Vetterd05c6172012-04-26 23:28:09 +02003255 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003256
3257 if (iir & I915_USER_INTERRUPT)
3258 notify_ring(dev, &dev_priv->ring[RCS]);
3259
Daniel Vetter4356d582013-10-16 22:55:55 +02003260 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003261 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003262 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003263 plane = !plane;
3264
Daniel Vetter4356d582013-10-16 22:55:55 +02003265 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003266 i8xx_handle_vblank(dev, plane, pipe, iir))
3267 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003268
Daniel Vetter4356d582013-10-16 22:55:55 +02003269 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003270 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003271
3272 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3273 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003274 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Daniel Vetter4356d582013-10-16 22:55:55 +02003275 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003276
3277 iir = new_iir;
3278 }
3279
3280 return IRQ_HANDLED;
3281}
3282
3283static void i8xx_irq_uninstall(struct drm_device * dev)
3284{
3285 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3286 int pipe;
3287
Chris Wilsonc2798b12012-04-22 21:13:57 +01003288 for_each_pipe(pipe) {
3289 /* Clear enable bits; then clear status bits */
3290 I915_WRITE(PIPESTAT(pipe), 0);
3291 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3292 }
3293 I915_WRITE16(IMR, 0xffff);
3294 I915_WRITE16(IER, 0x0);
3295 I915_WRITE16(IIR, I915_READ16(IIR));
3296}
3297
Chris Wilsona266c7d2012-04-24 22:59:44 +01003298static void i915_irq_preinstall(struct drm_device * dev)
3299{
3300 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3301 int pipe;
3302
Chris Wilsona266c7d2012-04-24 22:59:44 +01003303 if (I915_HAS_HOTPLUG(dev)) {
3304 I915_WRITE(PORT_HOTPLUG_EN, 0);
3305 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3306 }
3307
Chris Wilson00d98eb2012-04-24 22:59:48 +01003308 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003309 for_each_pipe(pipe)
3310 I915_WRITE(PIPESTAT(pipe), 0);
3311 I915_WRITE(IMR, 0xffffffff);
3312 I915_WRITE(IER, 0x0);
3313 POSTING_READ(IER);
3314}
3315
3316static int i915_irq_postinstall(struct drm_device *dev)
3317{
3318 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003319 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003320 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003321
Chris Wilson38bde182012-04-24 22:59:50 +01003322 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3323
3324 /* Unmask the interrupts that we always want on. */
3325 dev_priv->irq_mask =
3326 ~(I915_ASLE_INTERRUPT |
3327 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3328 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3329 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3330 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3331 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3332
3333 enable_mask =
3334 I915_ASLE_INTERRUPT |
3335 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3336 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3337 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3338 I915_USER_INTERRUPT;
3339
Chris Wilsona266c7d2012-04-24 22:59:44 +01003340 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003341 I915_WRITE(PORT_HOTPLUG_EN, 0);
3342 POSTING_READ(PORT_HOTPLUG_EN);
3343
Chris Wilsona266c7d2012-04-24 22:59:44 +01003344 /* Enable in IER... */
3345 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3346 /* and unmask in IMR */
3347 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3348 }
3349
Chris Wilsona266c7d2012-04-24 22:59:44 +01003350 I915_WRITE(IMR, dev_priv->irq_mask);
3351 I915_WRITE(IER, enable_mask);
3352 POSTING_READ(IER);
3353
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003354 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003355
Daniel Vetter379ef822013-10-16 22:55:56 +02003356 /* Interrupt setup is already guaranteed to be single-threaded, this is
3357 * just to make the assert_spin_locked check happy. */
3358 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003359 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3360 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003361 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3362
Daniel Vetter20afbda2012-12-11 14:05:07 +01003363 return 0;
3364}
3365
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003366/*
3367 * Returns true when a page flip has completed.
3368 */
3369static bool i915_handle_vblank(struct drm_device *dev,
3370 int plane, int pipe, u32 iir)
3371{
3372 drm_i915_private_t *dev_priv = dev->dev_private;
3373 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3374
3375 if (!drm_handle_vblank(dev, pipe))
3376 return false;
3377
3378 if ((iir & flip_pending) == 0)
3379 return false;
3380
3381 intel_prepare_page_flip(dev, plane);
3382
3383 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3384 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3385 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3386 * the flip is completed (no longer pending). Since this doesn't raise
3387 * an interrupt per se, we watch for the change at vblank.
3388 */
3389 if (I915_READ(ISR) & flip_pending)
3390 return false;
3391
3392 intel_finish_page_flip(dev, pipe);
3393
3394 return true;
3395}
3396
Daniel Vetterff1f5252012-10-02 15:10:55 +02003397static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003398{
3399 struct drm_device *dev = (struct drm_device *) arg;
3400 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003401 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003402 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003403 u32 flip_mask =
3404 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3405 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003406 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003407
Chris Wilsona266c7d2012-04-24 22:59:44 +01003408 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003409 do {
3410 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003411 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003412
3413 /* Can't rely on pipestat interrupt bit in iir as it might
3414 * have been cleared after the pipestat interrupt was received.
3415 * It doesn't set the bit in iir again, but it still produces
3416 * interrupts (for non-MSI).
3417 */
3418 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3419 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3420 i915_handle_error(dev, false);
3421
3422 for_each_pipe(pipe) {
3423 int reg = PIPESTAT(pipe);
3424 pipe_stats[pipe] = I915_READ(reg);
3425
Chris Wilson38bde182012-04-24 22:59:50 +01003426 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003427 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003428 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003429 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003430 }
3431 }
3432 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3433
3434 if (!irq_received)
3435 break;
3436
Chris Wilsona266c7d2012-04-24 22:59:44 +01003437 /* Consume port. Then clear IIR or we'll miss events */
3438 if ((I915_HAS_HOTPLUG(dev)) &&
3439 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3440 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003441 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003442
Daniel Vetter91d131d2013-06-27 17:52:14 +02003443 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3444
Chris Wilsona266c7d2012-04-24 22:59:44 +01003445 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003446 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003447 }
3448
Chris Wilson38bde182012-04-24 22:59:50 +01003449 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003450 new_iir = I915_READ(IIR); /* Flush posted writes */
3451
Chris Wilsona266c7d2012-04-24 22:59:44 +01003452 if (iir & I915_USER_INTERRUPT)
3453 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003454
Chris Wilsona266c7d2012-04-24 22:59:44 +01003455 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003456 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003457 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003458 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003459
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003460 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3461 i915_handle_vblank(dev, plane, pipe, iir))
3462 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003463
3464 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3465 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003466
3467 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003468 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003469
3470 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3471 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003472 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003473 }
3474
Chris Wilsona266c7d2012-04-24 22:59:44 +01003475 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3476 intel_opregion_asle_intr(dev);
3477
3478 /* With MSI, interrupts are only generated when iir
3479 * transitions from zero to nonzero. If another bit got
3480 * set while we were handling the existing iir bits, then
3481 * we would never get another interrupt.
3482 *
3483 * This is fine on non-MSI as well, as if we hit this path
3484 * we avoid exiting the interrupt handler only to generate
3485 * another one.
3486 *
3487 * Note that for MSI this could cause a stray interrupt report
3488 * if an interrupt landed in the time between writing IIR and
3489 * the posting read. This should be rare enough to never
3490 * trigger the 99% of 100,000 interrupts test for disabling
3491 * stray interrupts.
3492 */
Chris Wilson38bde182012-04-24 22:59:50 +01003493 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003494 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003495 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003496
Daniel Vetterd05c6172012-04-26 23:28:09 +02003497 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003498
Chris Wilsona266c7d2012-04-24 22:59:44 +01003499 return ret;
3500}
3501
3502static void i915_irq_uninstall(struct drm_device * dev)
3503{
3504 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3505 int pipe;
3506
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003507 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003508
Chris Wilsona266c7d2012-04-24 22:59:44 +01003509 if (I915_HAS_HOTPLUG(dev)) {
3510 I915_WRITE(PORT_HOTPLUG_EN, 0);
3511 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3512 }
3513
Chris Wilson00d98eb2012-04-24 22:59:48 +01003514 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003515 for_each_pipe(pipe) {
3516 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003517 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003518 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3519 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003520 I915_WRITE(IMR, 0xffffffff);
3521 I915_WRITE(IER, 0x0);
3522
Chris Wilsona266c7d2012-04-24 22:59:44 +01003523 I915_WRITE(IIR, I915_READ(IIR));
3524}
3525
3526static void i965_irq_preinstall(struct drm_device * dev)
3527{
3528 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3529 int pipe;
3530
Chris Wilsonadca4732012-05-11 18:01:31 +01003531 I915_WRITE(PORT_HOTPLUG_EN, 0);
3532 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003533
3534 I915_WRITE(HWSTAM, 0xeffe);
3535 for_each_pipe(pipe)
3536 I915_WRITE(PIPESTAT(pipe), 0);
3537 I915_WRITE(IMR, 0xffffffff);
3538 I915_WRITE(IER, 0x0);
3539 POSTING_READ(IER);
3540}
3541
3542static int i965_irq_postinstall(struct drm_device *dev)
3543{
3544 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003545 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003546 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003547 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003548
Chris Wilsona266c7d2012-04-24 22:59:44 +01003549 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003550 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003551 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003552 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3553 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3554 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3555 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3556 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3557
3558 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003559 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3560 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003561 enable_mask |= I915_USER_INTERRUPT;
3562
3563 if (IS_G4X(dev))
3564 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003565
Daniel Vetterb79480b2013-06-27 17:52:10 +02003566 /* Interrupt setup is already guaranteed to be single-threaded, this is
3567 * just to make the assert_spin_locked check happy. */
3568 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003569 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
3570 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3571 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003572 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003573
Chris Wilsona266c7d2012-04-24 22:59:44 +01003574 /*
3575 * Enable some error detection, note the instruction error mask
3576 * bit is reserved, so we leave it masked.
3577 */
3578 if (IS_G4X(dev)) {
3579 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3580 GM45_ERROR_MEM_PRIV |
3581 GM45_ERROR_CP_PRIV |
3582 I915_ERROR_MEMORY_REFRESH);
3583 } else {
3584 error_mask = ~(I915_ERROR_PAGE_TABLE |
3585 I915_ERROR_MEMORY_REFRESH);
3586 }
3587 I915_WRITE(EMR, error_mask);
3588
3589 I915_WRITE(IMR, dev_priv->irq_mask);
3590 I915_WRITE(IER, enable_mask);
3591 POSTING_READ(IER);
3592
Daniel Vetter20afbda2012-12-11 14:05:07 +01003593 I915_WRITE(PORT_HOTPLUG_EN, 0);
3594 POSTING_READ(PORT_HOTPLUG_EN);
3595
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003596 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003597
3598 return 0;
3599}
3600
Egbert Eichbac56d52013-02-25 12:06:51 -05003601static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003602{
3603 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003604 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003605 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003606 u32 hotplug_en;
3607
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003608 assert_spin_locked(&dev_priv->irq_lock);
3609
Egbert Eichbac56d52013-02-25 12:06:51 -05003610 if (I915_HAS_HOTPLUG(dev)) {
3611 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3612 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3613 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003614 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003615 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3616 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3617 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003618 /* Programming the CRT detection parameters tends
3619 to generate a spurious hotplug event about three
3620 seconds later. So just do it once.
3621 */
3622 if (IS_G4X(dev))
3623 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003624 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003625 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003626
Egbert Eichbac56d52013-02-25 12:06:51 -05003627 /* Ignore TV since it's buggy */
3628 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3629 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003630}
3631
Daniel Vetterff1f5252012-10-02 15:10:55 +02003632static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003633{
3634 struct drm_device *dev = (struct drm_device *) arg;
3635 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003636 u32 iir, new_iir;
3637 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003638 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003639 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003640 u32 flip_mask =
3641 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3642 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003643
Chris Wilsona266c7d2012-04-24 22:59:44 +01003644 iir = I915_READ(IIR);
3645
Chris Wilsona266c7d2012-04-24 22:59:44 +01003646 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003647 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003648 bool blc_event = false;
3649
Chris Wilsona266c7d2012-04-24 22:59:44 +01003650 /* Can't rely on pipestat interrupt bit in iir as it might
3651 * have been cleared after the pipestat interrupt was received.
3652 * It doesn't set the bit in iir again, but it still produces
3653 * interrupts (for non-MSI).
3654 */
3655 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3656 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3657 i915_handle_error(dev, false);
3658
3659 for_each_pipe(pipe) {
3660 int reg = PIPESTAT(pipe);
3661 pipe_stats[pipe] = I915_READ(reg);
3662
3663 /*
3664 * Clear the PIPE*STAT regs before the IIR
3665 */
3666 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003667 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02003668 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003669 }
3670 }
3671 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3672
3673 if (!irq_received)
3674 break;
3675
3676 ret = IRQ_HANDLED;
3677
3678 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003679 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003680 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003681 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3682 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003683 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003684
Daniel Vetter91d131d2013-06-27 17:52:14 +02003685 intel_hpd_irq_handler(dev, hotplug_trigger,
Daniel Vetter704cfb82013-12-18 09:08:43 +01003686 IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003687
Daniel Vetter4aeebd72013-10-31 09:53:36 +01003688 if (IS_G4X(dev) &&
3689 (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
3690 dp_aux_irq_handler(dev);
3691
Chris Wilsona266c7d2012-04-24 22:59:44 +01003692 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3693 I915_READ(PORT_HOTPLUG_STAT);
3694 }
3695
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003696 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003697 new_iir = I915_READ(IIR); /* Flush posted writes */
3698
Chris Wilsona266c7d2012-04-24 22:59:44 +01003699 if (iir & I915_USER_INTERRUPT)
3700 notify_ring(dev, &dev_priv->ring[RCS]);
3701 if (iir & I915_BSD_USER_INTERRUPT)
3702 notify_ring(dev, &dev_priv->ring[VCS]);
3703
Chris Wilsona266c7d2012-04-24 22:59:44 +01003704 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003705 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003706 i915_handle_vblank(dev, pipe, pipe, iir))
3707 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003708
3709 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3710 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003711
3712 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003713 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003714
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003715 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS &&
3716 intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
Ville Syrjäläfc2c8072014-01-17 11:44:32 +02003717 DRM_ERROR("pipe %c underrun\n", pipe_name(pipe));
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003718 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003719
3720 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3721 intel_opregion_asle_intr(dev);
3722
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003723 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3724 gmbus_irq_handler(dev);
3725
Chris Wilsona266c7d2012-04-24 22:59:44 +01003726 /* With MSI, interrupts are only generated when iir
3727 * transitions from zero to nonzero. If another bit got
3728 * set while we were handling the existing iir bits, then
3729 * we would never get another interrupt.
3730 *
3731 * This is fine on non-MSI as well, as if we hit this path
3732 * we avoid exiting the interrupt handler only to generate
3733 * another one.
3734 *
3735 * Note that for MSI this could cause a stray interrupt report
3736 * if an interrupt landed in the time between writing IIR and
3737 * the posting read. This should be rare enough to never
3738 * trigger the 99% of 100,000 interrupts test for disabling
3739 * stray interrupts.
3740 */
3741 iir = new_iir;
3742 }
3743
Daniel Vetterd05c6172012-04-26 23:28:09 +02003744 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003745
Chris Wilsona266c7d2012-04-24 22:59:44 +01003746 return ret;
3747}
3748
3749static void i965_irq_uninstall(struct drm_device * dev)
3750{
3751 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3752 int pipe;
3753
3754 if (!dev_priv)
3755 return;
3756
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003757 intel_hpd_irq_uninstall(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003758
Chris Wilsonadca4732012-05-11 18:01:31 +01003759 I915_WRITE(PORT_HOTPLUG_EN, 0);
3760 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003761
3762 I915_WRITE(HWSTAM, 0xffffffff);
3763 for_each_pipe(pipe)
3764 I915_WRITE(PIPESTAT(pipe), 0);
3765 I915_WRITE(IMR, 0xffffffff);
3766 I915_WRITE(IER, 0x0);
3767
3768 for_each_pipe(pipe)
3769 I915_WRITE(PIPESTAT(pipe),
3770 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3771 I915_WRITE(IIR, I915_READ(IIR));
3772}
3773
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003774static void intel_hpd_irq_reenable(unsigned long data)
Egbert Eichac4c16c2013-04-16 13:36:58 +02003775{
3776 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3777 struct drm_device *dev = dev_priv->dev;
3778 struct drm_mode_config *mode_config = &dev->mode_config;
3779 unsigned long irqflags;
3780 int i;
3781
3782 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3783 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3784 struct drm_connector *connector;
3785
3786 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3787 continue;
3788
3789 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3790
3791 list_for_each_entry(connector, &mode_config->connector_list, head) {
3792 struct intel_connector *intel_connector = to_intel_connector(connector);
3793
3794 if (intel_connector->encoder->hpd_pin == i) {
3795 if (connector->polled != intel_connector->polled)
3796 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3797 drm_get_connector_name(connector));
3798 connector->polled = intel_connector->polled;
3799 if (!connector->polled)
3800 connector->polled = DRM_CONNECTOR_POLL_HPD;
3801 }
3802 }
3803 }
3804 if (dev_priv->display.hpd_irq_setup)
3805 dev_priv->display.hpd_irq_setup(dev);
3806 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3807}
3808
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003809void intel_irq_init(struct drm_device *dev)
3810{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003811 struct drm_i915_private *dev_priv = dev->dev_private;
3812
3813 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003814 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003815 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003816 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003817
Daniel Vetter99584db2012-11-14 17:14:04 +01003818 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3819 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003820 (unsigned long) dev);
Ville Syrjälä3ca1cce2014-01-17 13:43:51 +02003821 setup_timer(&dev_priv->hotplug_reenable_timer, intel_hpd_irq_reenable,
Egbert Eichac4c16c2013-04-16 13:36:58 +02003822 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003823
Tomas Janousek97a19a22012-12-08 13:48:13 +01003824 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003825
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003826 if (IS_GEN2(dev)) {
3827 dev->max_vblank_count = 0;
3828 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3829 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003830 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3831 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003832 } else {
3833 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3834 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003835 }
3836
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003837 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003838 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003839 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3840 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003841
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003842 if (IS_VALLEYVIEW(dev)) {
3843 dev->driver->irq_handler = valleyview_irq_handler;
3844 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3845 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3846 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3847 dev->driver->enable_vblank = valleyview_enable_vblank;
3848 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003849 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003850 } else if (IS_GEN8(dev)) {
3851 dev->driver->irq_handler = gen8_irq_handler;
3852 dev->driver->irq_preinstall = gen8_irq_preinstall;
3853 dev->driver->irq_postinstall = gen8_irq_postinstall;
3854 dev->driver->irq_uninstall = gen8_irq_uninstall;
3855 dev->driver->enable_vblank = gen8_enable_vblank;
3856 dev->driver->disable_vblank = gen8_disable_vblank;
3857 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003858 } else if (HAS_PCH_SPLIT(dev)) {
3859 dev->driver->irq_handler = ironlake_irq_handler;
3860 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3861 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3862 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3863 dev->driver->enable_vblank = ironlake_enable_vblank;
3864 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003865 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003866 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003867 if (INTEL_INFO(dev)->gen == 2) {
3868 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3869 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3870 dev->driver->irq_handler = i8xx_irq_handler;
3871 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003872 } else if (INTEL_INFO(dev)->gen == 3) {
3873 dev->driver->irq_preinstall = i915_irq_preinstall;
3874 dev->driver->irq_postinstall = i915_irq_postinstall;
3875 dev->driver->irq_uninstall = i915_irq_uninstall;
3876 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003877 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003878 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003879 dev->driver->irq_preinstall = i965_irq_preinstall;
3880 dev->driver->irq_postinstall = i965_irq_postinstall;
3881 dev->driver->irq_uninstall = i965_irq_uninstall;
3882 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003883 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003884 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003885 dev->driver->enable_vblank = i915_enable_vblank;
3886 dev->driver->disable_vblank = i915_disable_vblank;
3887 }
3888}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003889
3890void intel_hpd_init(struct drm_device *dev)
3891{
3892 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003893 struct drm_mode_config *mode_config = &dev->mode_config;
3894 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003895 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003896 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003897
Egbert Eich821450c2013-04-16 13:36:55 +02003898 for (i = 1; i < HPD_NUM_PINS; i++) {
3899 dev_priv->hpd_stats[i].hpd_cnt = 0;
3900 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3901 }
3902 list_for_each_entry(connector, &mode_config->connector_list, head) {
3903 struct intel_connector *intel_connector = to_intel_connector(connector);
3904 connector->polled = intel_connector->polled;
3905 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3906 connector->polled = DRM_CONNECTOR_POLL_HPD;
3907 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003908
3909 /* Interrupt setup is already guaranteed to be single-threaded, this is
3910 * just to make the assert_spin_locked checks happy. */
3911 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003912 if (dev_priv->display.hpd_irq_setup)
3913 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003914 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003915}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003916
3917/* Disable interrupts so we can allow Package C8+. */
3918void hsw_pc8_disable_interrupts(struct drm_device *dev)
3919{
3920 struct drm_i915_private *dev_priv = dev->dev_private;
3921 unsigned long irqflags;
3922
3923 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3924
3925 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3926 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3927 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3928 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3929 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3930
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003931 ironlake_disable_display_irq(dev_priv, 0xffffffff);
3932 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003933 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3934 snb_disable_pm_irq(dev_priv, 0xffffffff);
3935
3936 dev_priv->pc8.irqs_disabled = true;
3937
3938 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3939}
3940
3941/* Restore interrupts so we can recover from Package C8+. */
3942void hsw_pc8_restore_interrupts(struct drm_device *dev)
3943{
3944 struct drm_i915_private *dev_priv = dev->dev_private;
3945 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003946 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03003947
3948 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3949
3950 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003951 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003952
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003953 val = I915_READ(SDEIMR);
3954 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003955
3956 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003957 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003958
3959 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003960 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003961
3962 dev_priv->pc8.irqs_disabled = false;
3963
3964 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003965 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003966 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3967 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3968 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3969
3970 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3971}