blob: 9fec71175571e068cce957973431fe21eca962d2 [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
235static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
236 enum pipe pipe, bool enable)
237{
238 struct drm_i915_private *dev_priv = dev->dev_private;
239 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
240 DE_PIPEB_FIFO_UNDERRUN;
241
242 if (enable)
243 ironlake_enable_display_irq(dev_priv, bit);
244 else
245 ironlake_disable_display_irq(dev_priv, bit);
246}
247
248static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200249 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300250{
251 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300252 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200253 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
254
Paulo Zanoni86642812013-04-12 17:57:57 -0300255 if (!ivb_can_enable_err_int(dev))
256 return;
257
Paulo Zanoni86642812013-04-12 17:57:57 -0300258 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
259 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200260 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
261
262 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300263 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200264
265 if (!was_enabled &&
266 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
267 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
268 pipe_name(pipe));
269 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300270 }
271}
272
Daniel Vetter38d83c962013-11-07 11:05:46 +0100273static void broadwell_set_fifo_underrun_reporting(struct drm_device *dev,
274 enum pipe pipe, bool enable)
275{
276 struct drm_i915_private *dev_priv = dev->dev_private;
277
278 assert_spin_locked(&dev_priv->irq_lock);
279
280 if (enable)
281 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_FIFO_UNDERRUN;
282 else
283 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_FIFO_UNDERRUN;
284 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
285 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
286}
287
Daniel Vetterfee884e2013-07-04 23:35:21 +0200288/**
289 * ibx_display_interrupt_update - update SDEIMR
290 * @dev_priv: driver private
291 * @interrupt_mask: mask of interrupt bits to update
292 * @enabled_irq_mask: mask of interrupt bits to enable
293 */
294static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
295 uint32_t interrupt_mask,
296 uint32_t enabled_irq_mask)
297{
298 uint32_t sdeimr = I915_READ(SDEIMR);
299 sdeimr &= ~interrupt_mask;
300 sdeimr |= (~enabled_irq_mask & interrupt_mask);
301
302 assert_spin_locked(&dev_priv->irq_lock);
303
Paulo Zanonic67a4702013-08-19 13:18:09 -0300304 if (dev_priv->pc8.irqs_disabled &&
305 (interrupt_mask & SDE_HOTPLUG_MASK_CPT)) {
306 WARN(1, "IRQs disabled\n");
307 dev_priv->pc8.regsave.sdeimr &= ~interrupt_mask;
308 dev_priv->pc8.regsave.sdeimr |= (~enabled_irq_mask &
309 interrupt_mask);
310 return;
311 }
312
Daniel Vetterfee884e2013-07-04 23:35:21 +0200313 I915_WRITE(SDEIMR, sdeimr);
314 POSTING_READ(SDEIMR);
315}
316#define ibx_enable_display_interrupt(dev_priv, bits) \
317 ibx_display_interrupt_update((dev_priv), (bits), (bits))
318#define ibx_disable_display_interrupt(dev_priv, bits) \
319 ibx_display_interrupt_update((dev_priv), (bits), 0)
320
Daniel Vetterde280752013-07-04 23:35:24 +0200321static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
322 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300323 bool enable)
324{
Paulo Zanoni86642812013-04-12 17:57:57 -0300325 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200326 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
327 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300328
329 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200330 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300331 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200332 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300333}
334
335static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
336 enum transcoder pch_transcoder,
337 bool enable)
338{
339 struct drm_i915_private *dev_priv = dev->dev_private;
340
341 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200342 I915_WRITE(SERR_INT,
343 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
344
Paulo Zanoni86642812013-04-12 17:57:57 -0300345 if (!cpt_can_enable_serr_int(dev))
346 return;
347
Daniel Vetterfee884e2013-07-04 23:35:21 +0200348 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300349 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200350 uint32_t tmp = I915_READ(SERR_INT);
351 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
352
353 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200354 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200355
356 if (!was_enabled &&
357 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
358 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
359 transcoder_name(pch_transcoder));
360 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300361 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300362}
363
364/**
365 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
366 * @dev: drm device
367 * @pipe: pipe
368 * @enable: true if we want to report FIFO underrun errors, false otherwise
369 *
370 * This function makes us disable or enable CPU fifo underruns for a specific
371 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
372 * reporting for one pipe may also disable all the other CPU error interruts for
373 * the other pipes, due to the fact that there's just one interrupt mask/enable
374 * bit for all the pipes.
375 *
376 * Returns the previous state of underrun reporting.
377 */
378bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
379 enum pipe pipe, bool enable)
380{
381 struct drm_i915_private *dev_priv = dev->dev_private;
382 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
383 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
384 unsigned long flags;
385 bool ret;
386
387 spin_lock_irqsave(&dev_priv->irq_lock, flags);
388
389 ret = !intel_crtc->cpu_fifo_underrun_disabled;
390
391 if (enable == ret)
392 goto done;
393
394 intel_crtc->cpu_fifo_underrun_disabled = !enable;
395
396 if (IS_GEN5(dev) || IS_GEN6(dev))
397 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
398 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200399 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Daniel Vetter38d83c962013-11-07 11:05:46 +0100400 else if (IS_GEN8(dev))
401 broadwell_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300402
403done:
404 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
405 return ret;
406}
407
408/**
409 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
410 * @dev: drm device
411 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
412 * @enable: true if we want to report FIFO underrun errors, false otherwise
413 *
414 * This function makes us disable or enable PCH fifo underruns for a specific
415 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
416 * underrun reporting for one transcoder may also disable all the other PCH
417 * error interruts for the other transcoders, due to the fact that there's just
418 * one interrupt mask/enable bit for all the transcoders.
419 *
420 * Returns the previous state of underrun reporting.
421 */
422bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
423 enum transcoder pch_transcoder,
424 bool enable)
425{
426 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200427 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
428 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300429 unsigned long flags;
430 bool ret;
431
Daniel Vetterde280752013-07-04 23:35:24 +0200432 /*
433 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
434 * has only one pch transcoder A that all pipes can use. To avoid racy
435 * pch transcoder -> pipe lookups from interrupt code simply store the
436 * underrun statistics in crtc A. Since we never expose this anywhere
437 * nor use it outside of the fifo underrun code here using the "wrong"
438 * crtc on LPT won't cause issues.
439 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300440
441 spin_lock_irqsave(&dev_priv->irq_lock, flags);
442
443 ret = !intel_crtc->pch_fifo_underrun_disabled;
444
445 if (enable == ret)
446 goto done;
447
448 intel_crtc->pch_fifo_underrun_disabled = !enable;
449
450 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200451 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300452 else
453 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
454
455done:
456 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
457 return ret;
458}
459
460
Keith Packard7c463582008-11-04 02:03:27 -0800461void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200462i915_enable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800463{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200464 u32 reg = PIPESTAT(pipe);
465 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800466
Daniel Vetterb79480b2013-06-27 17:52:10 +0200467 assert_spin_locked(&dev_priv->irq_lock);
468
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200469 if ((pipestat & mask) == mask)
470 return;
471
472 /* Enable the interrupt, clear any pending status */
473 pipestat |= mask | (mask >> 16);
474 I915_WRITE(reg, pipestat);
475 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800476}
477
478void
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200479i915_disable_pipestat(drm_i915_private_t *dev_priv, enum pipe pipe, u32 mask)
Keith Packard7c463582008-11-04 02:03:27 -0800480{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200481 u32 reg = PIPESTAT(pipe);
482 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800483
Daniel Vetterb79480b2013-06-27 17:52:10 +0200484 assert_spin_locked(&dev_priv->irq_lock);
485
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200486 if ((pipestat & mask) == 0)
487 return;
488
489 pipestat &= ~mask;
490 I915_WRITE(reg, pipestat);
491 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800492}
493
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000494/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300495 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000496 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300497static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000498{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000499 drm_i915_private_t *dev_priv = dev->dev_private;
500 unsigned long irqflags;
501
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300502 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
503 return;
504
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000505 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000506
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200507 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_ENABLE);
Jani Nikulaf8987802013-04-29 13:02:53 +0300508 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200509 i915_enable_pipestat(dev_priv, PIPE_A,
510 PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000511
512 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000513}
514
515/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700516 * i915_pipe_enabled - check if a pipe is enabled
517 * @dev: DRM device
518 * @pipe: pipe to check
519 *
520 * Reading certain registers when the pipe is disabled can hang the chip.
521 * Use this routine to make sure the PLL is running and the pipe is active
522 * before reading such registers if unsure.
523 */
524static int
525i915_pipe_enabled(struct drm_device *dev, int pipe)
526{
527 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200528
Daniel Vettera01025a2013-05-22 00:50:23 +0200529 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
530 /* Locking is horribly broken here, but whatever. */
531 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
532 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300533
Daniel Vettera01025a2013-05-22 00:50:23 +0200534 return intel_crtc->active;
535 } else {
536 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
537 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700538}
539
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300540static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
541{
542 /* Gen2 doesn't have a hardware frame counter */
543 return 0;
544}
545
Keith Packard42f52ef2008-10-18 19:39:29 -0700546/* Called from drm generic code, passed a 'crtc', which
547 * we use as a pipe index
548 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700549static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700550{
551 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
552 unsigned long high_frame;
553 unsigned long low_frame;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300554 u32 high1, high2, low, pixel, vbl_start;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700555
556 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800557 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800558 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700559 return 0;
560 }
561
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300562 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
563 struct intel_crtc *intel_crtc =
564 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
565 const struct drm_display_mode *mode =
566 &intel_crtc->config.adjusted_mode;
567
568 vbl_start = mode->crtc_vblank_start * mode->crtc_htotal;
569 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100570 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300571 u32 htotal;
572
573 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
574 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
575
576 vbl_start *= htotal;
577 }
578
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800579 high_frame = PIPEFRAME(pipe);
580 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100581
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700582 /*
583 * High & low register fields aren't synchronized, so make sure
584 * we get a low value that's stable across two reads of the high
585 * register.
586 */
587 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100588 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300589 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100590 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700591 } while (high1 != high2);
592
Chris Wilson5eddb702010-09-11 13:48:45 +0100593 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300594 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100595 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300596
597 /*
598 * The frame counter increments at beginning of active.
599 * Cook up a vblank counter by also checking the pixel
600 * counter against vblank start.
601 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200602 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700603}
604
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700605static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800606{
607 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800608 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800609
610 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800611 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800612 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800613 return 0;
614 }
615
616 return I915_READ(reg);
617}
618
Mario Kleinerad3543e2013-10-30 05:13:08 +0100619/* raw reads, only for fast reads of display block, no need for forcewake etc. */
620#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
621#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
622
Ville Syrjälä095163b2013-10-29 00:04:43 +0200623static bool ilk_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300624{
625 struct drm_i915_private *dev_priv = dev->dev_private;
626 uint32_t status;
627
Ville Syrjälä095163b2013-10-29 00:04:43 +0200628 if (INTEL_INFO(dev)->gen < 7) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300629 status = pipe == PIPE_A ?
630 DE_PIPEA_VBLANK :
631 DE_PIPEB_VBLANK;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300632 } else {
633 switch (pipe) {
634 default:
635 case PIPE_A:
636 status = DE_PIPEA_VBLANK_IVB;
637 break;
638 case PIPE_B:
639 status = DE_PIPEB_VBLANK_IVB;
640 break;
641 case PIPE_C:
642 status = DE_PIPEC_VBLANK_IVB;
643 break;
644 }
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300645 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100646
Ville Syrjälä095163b2013-10-29 00:04:43 +0200647 return __raw_i915_read32(dev_priv, DEISR) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300648}
649
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700650static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200651 unsigned int flags, int *vpos, int *hpos,
652 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100653{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300654 struct drm_i915_private *dev_priv = dev->dev_private;
655 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
656 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
657 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300658 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100659 int vbl_start, vbl_end, htotal, vtotal;
660 bool in_vbl = true;
661 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100662 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100663
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300664 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100665 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800666 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100667 return 0;
668 }
669
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300670 htotal = mode->crtc_htotal;
671 vtotal = mode->crtc_vtotal;
672 vbl_start = mode->crtc_vblank_start;
673 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100674
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200675 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
676 vbl_start = DIV_ROUND_UP(vbl_start, 2);
677 vbl_end /= 2;
678 vtotal /= 2;
679 }
680
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300681 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
682
Mario Kleinerad3543e2013-10-30 05:13:08 +0100683 /*
684 * Lock uncore.lock, as we will do multiple timing critical raw
685 * register reads, potentially with preemption disabled, so the
686 * following code must not block on uncore.lock.
687 */
688 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
689
690 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
691
692 /* Get optional system timestamp before query. */
693 if (stime)
694 *stime = ktime_get();
695
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300696 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100697 /* No obvious pixelcount register. Only query vertical
698 * scanout position from Display scan line register.
699 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300700 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100701 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300702 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100703 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300704
Ville Syrjälä095163b2013-10-29 00:04:43 +0200705 if (HAS_PCH_SPLIT(dev)) {
706 /*
707 * The scanline counter increments at the leading edge
708 * of hsync, ie. it completely misses the active portion
709 * of the line. Fix up the counter at both edges of vblank
710 * to get a more accurate picture whether we're in vblank
711 * or not.
712 */
713 in_vbl = ilk_pipe_in_vblank_locked(dev, pipe);
714 if ((in_vbl && position == vbl_start - 1) ||
715 (!in_vbl && position == vbl_end - 1))
716 position = (position + 1) % vtotal;
717 } else {
718 /*
719 * ISR vblank status bits don't work the way we'd want
720 * them to work on non-PCH platforms (for
721 * ilk_pipe_in_vblank_locked()), and there doesn't
722 * appear any other way to determine if we're currently
723 * in vblank.
724 *
725 * Instead let's assume that we're already in vblank if
726 * we got called from the vblank interrupt and the
727 * scanline counter value indicates that we're on the
728 * line just prior to vblank start. This should result
729 * in the correct answer, unless the vblank interrupt
730 * delivery really got delayed for almost exactly one
731 * full frame/field.
732 */
733 if (flags & DRM_CALLED_FROM_VBLIRQ &&
734 position == vbl_start - 1) {
735 position = (position + 1) % vtotal;
736
737 /* Signal this correction as "applied". */
738 ret |= 0x8;
739 }
740 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100741 } else {
742 /* Have access to pixelcount since start of frame.
743 * We can split this into vertical and horizontal
744 * scanout position.
745 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100746 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100747
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300748 /* convert to pixel counts */
749 vbl_start *= htotal;
750 vbl_end *= htotal;
751 vtotal *= htotal;
752 }
753
Mario Kleinerad3543e2013-10-30 05:13:08 +0100754 /* Get optional system timestamp after query. */
755 if (etime)
756 *etime = ktime_get();
757
758 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
759
760 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
761
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300762 in_vbl = position >= vbl_start && position < vbl_end;
763
764 /*
765 * While in vblank, position will be negative
766 * counting up towards 0 at vbl_end. And outside
767 * vblank, position will be positive counting
768 * up since vbl_end.
769 */
770 if (position >= vbl_start)
771 position -= vbl_end;
772 else
773 position += vtotal - vbl_end;
774
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300775 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300776 *vpos = position;
777 *hpos = 0;
778 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100779 *vpos = position / htotal;
780 *hpos = position - (*vpos * htotal);
781 }
782
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100783 /* In vblank? */
784 if (in_vbl)
785 ret |= DRM_SCANOUTPOS_INVBL;
786
787 return ret;
788}
789
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700790static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100791 int *max_error,
792 struct timeval *vblank_time,
793 unsigned flags)
794{
Chris Wilson4041b852011-01-22 10:07:56 +0000795 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100796
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700797 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000798 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100799 return -EINVAL;
800 }
801
802 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000803 crtc = intel_get_crtc_for_pipe(dev, pipe);
804 if (crtc == NULL) {
805 DRM_ERROR("Invalid crtc %d\n", pipe);
806 return -EINVAL;
807 }
808
809 if (!crtc->enabled) {
810 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
811 return -EBUSY;
812 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100813
814 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000815 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
816 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300817 crtc,
818 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100819}
820
Jani Nikula67c347f2013-09-17 14:26:34 +0300821static bool intel_hpd_irq_event(struct drm_device *dev,
822 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200823{
824 enum drm_connector_status old_status;
825
826 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
827 old_status = connector->status;
828
829 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300830 if (old_status == connector->status)
831 return false;
832
833 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200834 connector->base.id,
835 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300836 drm_get_connector_status_name(old_status),
837 drm_get_connector_status_name(connector->status));
838
839 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200840}
841
Jesse Barnes5ca58282009-03-31 14:11:15 -0700842/*
843 * Handle hotplug events outside the interrupt handler proper.
844 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200845#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
846
Jesse Barnes5ca58282009-03-31 14:11:15 -0700847static void i915_hotplug_work_func(struct work_struct *work)
848{
849 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
850 hotplug_work);
851 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700852 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200853 struct intel_connector *intel_connector;
854 struct intel_encoder *intel_encoder;
855 struct drm_connector *connector;
856 unsigned long irqflags;
857 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200858 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200859 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700860
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100861 /* HPD irq before everything is fully set up. */
862 if (!dev_priv->enable_hotplug_processing)
863 return;
864
Keith Packarda65e34c2011-07-25 10:04:56 -0700865 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800866 DRM_DEBUG_KMS("running encoder hotplug functions\n");
867
Egbert Eichcd569ae2013-04-16 13:36:57 +0200868 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200869
870 hpd_event_bits = dev_priv->hpd_event_bits;
871 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200872 list_for_each_entry(connector, &mode_config->connector_list, head) {
873 intel_connector = to_intel_connector(connector);
874 intel_encoder = intel_connector->encoder;
875 if (intel_encoder->hpd_pin > HPD_NONE &&
876 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
877 connector->polled == DRM_CONNECTOR_POLL_HPD) {
878 DRM_INFO("HPD interrupt storm detected on connector %s: "
879 "switching from hotplug detection to polling\n",
880 drm_get_connector_name(connector));
881 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
882 connector->polled = DRM_CONNECTOR_POLL_CONNECT
883 | DRM_CONNECTOR_POLL_DISCONNECT;
884 hpd_disabled = true;
885 }
Egbert Eich142e2392013-04-11 15:57:57 +0200886 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
887 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
888 drm_get_connector_name(connector), intel_encoder->hpd_pin);
889 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200890 }
891 /* if there were no outputs to poll, poll was disabled,
892 * therefore make sure it's enabled when disabling HPD on
893 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200894 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200895 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200896 mod_timer(&dev_priv->hotplug_reenable_timer,
897 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
898 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200899
900 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
901
Egbert Eich321a1b32013-04-11 16:00:26 +0200902 list_for_each_entry(connector, &mode_config->connector_list, head) {
903 intel_connector = to_intel_connector(connector);
904 intel_encoder = intel_connector->encoder;
905 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
906 if (intel_encoder->hot_plug)
907 intel_encoder->hot_plug(intel_encoder);
908 if (intel_hpd_irq_event(dev, connector))
909 changed = true;
910 }
911 }
Keith Packard40ee3382011-07-28 15:31:19 -0700912 mutex_unlock(&mode_config->mutex);
913
Egbert Eich321a1b32013-04-11 16:00:26 +0200914 if (changed)
915 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700916}
917
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200918static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800919{
920 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000921 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200922 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200923
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200924 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800925
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200926 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
927
Daniel Vetter20e4d402012-08-08 23:35:39 +0200928 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200929
Jesse Barnes7648fa92010-05-20 14:28:11 -0700930 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000931 busy_up = I915_READ(RCPREVBSYTUPAVG);
932 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800933 max_avg = I915_READ(RCBMAXAVG);
934 min_avg = I915_READ(RCBMINAVG);
935
936 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000937 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200938 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
939 new_delay = dev_priv->ips.cur_delay - 1;
940 if (new_delay < dev_priv->ips.max_delay)
941 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000942 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200943 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
944 new_delay = dev_priv->ips.cur_delay + 1;
945 if (new_delay > dev_priv->ips.min_delay)
946 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800947 }
948
Jesse Barnes7648fa92010-05-20 14:28:11 -0700949 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200950 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800951
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200952 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200953
Jesse Barnesf97108d2010-01-29 11:27:07 -0800954 return;
955}
956
Chris Wilson549f7362010-10-19 11:19:32 +0100957static void notify_ring(struct drm_device *dev,
958 struct intel_ring_buffer *ring)
959{
Chris Wilson475553d2011-01-20 09:52:56 +0000960 if (ring->obj == NULL)
961 return;
962
Chris Wilson814e9b52013-09-23 17:33:19 -0300963 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000964
Chris Wilson549f7362010-10-19 11:19:32 +0100965 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300966 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100967}
968
Ben Widawsky4912d042011-04-25 11:25:20 -0700969static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800970{
Ben Widawsky4912d042011-04-25 11:25:20 -0700971 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200972 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300973 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100974 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800975
Daniel Vetter59cdb632013-07-04 23:35:28 +0200976 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200977 pm_iir = dev_priv->rps.pm_iir;
978 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -0700979 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300980 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200981 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700982
Paulo Zanoni60611c12013-08-15 11:50:01 -0300983 /* Make sure we didn't queue anything we're not going to process. */
984 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
985
Ben Widawsky48484052013-05-28 19:22:27 -0700986 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800987 return;
988
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700989 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100990
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100991 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300992 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100993 if (adj > 0)
994 adj *= 2;
995 else
996 adj = 1;
997 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300998
999 /*
1000 * For better performance, jump directly
1001 * to RPe if we're below it.
1002 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001003 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +03001004 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001005 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1006 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
1007 new_delay = dev_priv->rps.rpe_delay;
1008 else
1009 new_delay = dev_priv->rps.min_delay;
1010 adj = 0;
1011 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1012 if (adj < 0)
1013 adj *= 2;
1014 else
1015 adj = -1;
1016 new_delay = dev_priv->rps.cur_delay + adj;
1017 } else { /* unknown event */
1018 new_delay = dev_priv->rps.cur_delay;
1019 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001020
Ben Widawsky79249632012-09-07 19:43:42 -07001021 /* sysfs frequency interfaces may have snuck in while servicing the
1022 * interrupt
1023 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001024 new_delay = clamp_t(int, new_delay,
1025 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001026 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
1027
1028 if (IS_VALLEYVIEW(dev_priv->dev))
1029 valleyview_set_rps(dev_priv->dev, new_delay);
1030 else
1031 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001032
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001033 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001034}
1035
Ben Widawskye3689192012-05-25 16:56:22 -07001036
1037/**
1038 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1039 * occurred.
1040 * @work: workqueue struct
1041 *
1042 * Doesn't actually do anything except notify userspace. As a consequence of
1043 * this event, userspace should try to remap the bad rows since statistically
1044 * it is likely the same row is more likely to go bad again.
1045 */
1046static void ivybridge_parity_work(struct work_struct *work)
1047{
1048 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001049 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001050 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001051 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001052 uint32_t misccpctl;
1053 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001054 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001055
1056 /* We must turn off DOP level clock gating to access the L3 registers.
1057 * In order to prevent a get/put style interface, acquire struct mutex
1058 * any time we access those registers.
1059 */
1060 mutex_lock(&dev_priv->dev->struct_mutex);
1061
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001062 /* If we've screwed up tracking, just let the interrupt fire again */
1063 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1064 goto out;
1065
Ben Widawskye3689192012-05-25 16:56:22 -07001066 misccpctl = I915_READ(GEN7_MISCCPCTL);
1067 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1068 POSTING_READ(GEN7_MISCCPCTL);
1069
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001070 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1071 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001072
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001073 slice--;
1074 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1075 break;
1076
1077 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1078
1079 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1080
1081 error_status = I915_READ(reg);
1082 row = GEN7_PARITY_ERROR_ROW(error_status);
1083 bank = GEN7_PARITY_ERROR_BANK(error_status);
1084 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1085
1086 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1087 POSTING_READ(reg);
1088
1089 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1090 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1091 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1092 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1093 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1094 parity_event[5] = NULL;
1095
Dave Airlie5bdebb12013-10-11 14:07:25 +10001096 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001097 KOBJ_CHANGE, parity_event);
1098
1099 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1100 slice, row, bank, subbank);
1101
1102 kfree(parity_event[4]);
1103 kfree(parity_event[3]);
1104 kfree(parity_event[2]);
1105 kfree(parity_event[1]);
1106 }
Ben Widawskye3689192012-05-25 16:56:22 -07001107
1108 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1109
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001110out:
1111 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001112 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001113 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001114 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1115
1116 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001117}
1118
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001119static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001120{
1121 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001122
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001123 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001124 return;
1125
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001126 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001127 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001128 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001129
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001130 iir &= GT_PARITY_ERROR(dev);
1131 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1132 dev_priv->l3_parity.which_slice |= 1 << 1;
1133
1134 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1135 dev_priv->l3_parity.which_slice |= 1 << 0;
1136
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001137 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001138}
1139
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001140static void ilk_gt_irq_handler(struct drm_device *dev,
1141 struct drm_i915_private *dev_priv,
1142 u32 gt_iir)
1143{
1144 if (gt_iir &
1145 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1146 notify_ring(dev, &dev_priv->ring[RCS]);
1147 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1148 notify_ring(dev, &dev_priv->ring[VCS]);
1149}
1150
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001151static void snb_gt_irq_handler(struct drm_device *dev,
1152 struct drm_i915_private *dev_priv,
1153 u32 gt_iir)
1154{
1155
Ben Widawskycc609d52013-05-28 19:22:29 -07001156 if (gt_iir &
1157 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001158 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001159 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001160 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001161 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001162 notify_ring(dev, &dev_priv->ring[BCS]);
1163
Ben Widawskycc609d52013-05-28 19:22:29 -07001164 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1165 GT_BSD_CS_ERROR_INTERRUPT |
1166 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001167 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1168 i915_handle_error(dev, false);
1169 }
Ben Widawskye3689192012-05-25 16:56:22 -07001170
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001171 if (gt_iir & GT_PARITY_ERROR(dev))
1172 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001173}
1174
Ben Widawskyabd58f02013-11-02 21:07:09 -07001175static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1176 struct drm_i915_private *dev_priv,
1177 u32 master_ctl)
1178{
1179 u32 rcs, bcs, vcs;
1180 uint32_t tmp = 0;
1181 irqreturn_t ret = IRQ_NONE;
1182
1183 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1184 tmp = I915_READ(GEN8_GT_IIR(0));
1185 if (tmp) {
1186 ret = IRQ_HANDLED;
1187 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1188 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1189 if (rcs & GT_RENDER_USER_INTERRUPT)
1190 notify_ring(dev, &dev_priv->ring[RCS]);
1191 if (bcs & GT_RENDER_USER_INTERRUPT)
1192 notify_ring(dev, &dev_priv->ring[BCS]);
1193 I915_WRITE(GEN8_GT_IIR(0), tmp);
1194 } else
1195 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1196 }
1197
1198 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1199 tmp = I915_READ(GEN8_GT_IIR(1));
1200 if (tmp) {
1201 ret = IRQ_HANDLED;
1202 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1203 if (vcs & GT_RENDER_USER_INTERRUPT)
1204 notify_ring(dev, &dev_priv->ring[VCS]);
1205 I915_WRITE(GEN8_GT_IIR(1), tmp);
1206 } else
1207 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1208 }
1209
1210 if (master_ctl & GEN8_GT_VECS_IRQ) {
1211 tmp = I915_READ(GEN8_GT_IIR(3));
1212 if (tmp) {
1213 ret = IRQ_HANDLED;
1214 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1215 if (vcs & GT_RENDER_USER_INTERRUPT)
1216 notify_ring(dev, &dev_priv->ring[VECS]);
1217 I915_WRITE(GEN8_GT_IIR(3), tmp);
1218 } else
1219 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1220 }
1221
1222 return ret;
1223}
1224
Egbert Eichb543fb02013-04-16 13:36:54 +02001225#define HPD_STORM_DETECT_PERIOD 1000
1226#define HPD_STORM_THRESHOLD 5
1227
Daniel Vetter10a504d2013-06-27 17:52:12 +02001228static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001229 u32 hotplug_trigger,
1230 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001231{
1232 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001233 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001234 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001235
Daniel Vetter91d131d2013-06-27 17:52:14 +02001236 if (!hotplug_trigger)
1237 return;
1238
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001239 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001240 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001241
Chris Wilson34320872014-01-10 18:49:20 +00001242 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001243 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001244 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1245 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001246
Egbert Eichb543fb02013-04-16 13:36:54 +02001247 if (!(hpd[i] & hotplug_trigger) ||
1248 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1249 continue;
1250
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001251 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001252 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1253 dev_priv->hpd_stats[i].hpd_last_jiffies
1254 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1255 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1256 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001257 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001258 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1259 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001260 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001261 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001262 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001263 } else {
1264 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001265 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1266 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001267 }
1268 }
1269
Daniel Vetter10a504d2013-06-27 17:52:12 +02001270 if (storm_detected)
1271 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001272 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001273
Daniel Vetter645416f2013-09-02 16:22:25 +02001274 /*
1275 * Our hotplug handler can grab modeset locks (by calling down into the
1276 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1277 * queue for otherwise the flush_work in the pageflip code will
1278 * deadlock.
1279 */
1280 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001281}
1282
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001283static void gmbus_irq_handler(struct drm_device *dev)
1284{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001285 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1286
Daniel Vetter28c70f12012-12-01 13:53:45 +01001287 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001288}
1289
Daniel Vetterce99c252012-12-01 13:53:47 +01001290static void dp_aux_irq_handler(struct drm_device *dev)
1291{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001292 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1293
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001294 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001295}
1296
Shuang He8bf1e9f2013-10-15 18:55:27 +01001297#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001298static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1299 uint32_t crc0, uint32_t crc1,
1300 uint32_t crc2, uint32_t crc3,
1301 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001302{
1303 struct drm_i915_private *dev_priv = dev->dev_private;
1304 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1305 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001306 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001307
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001308 spin_lock(&pipe_crc->lock);
1309
Damien Lespiau0c912c72013-10-15 18:55:37 +01001310 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001311 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001312 DRM_ERROR("spurious interrupt\n");
1313 return;
1314 }
1315
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001316 head = pipe_crc->head;
1317 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001318
1319 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001320 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001321 DRM_ERROR("CRC buffer overflowing\n");
1322 return;
1323 }
1324
1325 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001326
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001327 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001328 entry->crc[0] = crc0;
1329 entry->crc[1] = crc1;
1330 entry->crc[2] = crc2;
1331 entry->crc[3] = crc3;
1332 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001333
1334 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001335 pipe_crc->head = head;
1336
1337 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001338
1339 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001340}
Daniel Vetter277de952013-10-18 16:37:07 +02001341#else
1342static inline void
1343display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1344 uint32_t crc0, uint32_t crc1,
1345 uint32_t crc2, uint32_t crc3,
1346 uint32_t crc4) {}
1347#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001348
Daniel Vetter277de952013-10-18 16:37:07 +02001349
1350static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001351{
1352 struct drm_i915_private *dev_priv = dev->dev_private;
1353
Daniel Vetter277de952013-10-18 16:37:07 +02001354 display_pipe_crc_irq_handler(dev, pipe,
1355 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1356 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001357}
1358
Daniel Vetter277de952013-10-18 16:37:07 +02001359static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001360{
1361 struct drm_i915_private *dev_priv = dev->dev_private;
1362
Daniel Vetter277de952013-10-18 16:37:07 +02001363 display_pipe_crc_irq_handler(dev, pipe,
1364 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1365 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1366 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1367 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1368 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001369}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001370
Daniel Vetter277de952013-10-18 16:37:07 +02001371static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001372{
1373 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001374 uint32_t res1, res2;
1375
1376 if (INTEL_INFO(dev)->gen >= 3)
1377 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1378 else
1379 res1 = 0;
1380
1381 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1382 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1383 else
1384 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001385
Daniel Vetter277de952013-10-18 16:37:07 +02001386 display_pipe_crc_irq_handler(dev, pipe,
1387 I915_READ(PIPE_CRC_RES_RED(pipe)),
1388 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1389 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1390 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001391}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001392
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001393/* The RPS events need forcewake, so we add them to a work queue and mask their
1394 * IMR bits until the work is done. Other interrupts can be processed without
1395 * the work queue. */
1396static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001397{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001398 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001399 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001400 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001401 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001402 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001403
1404 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001405 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001406
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001407 if (HAS_VEBOX(dev_priv->dev)) {
1408 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1409 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001410
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001411 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1412 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1413 i915_handle_error(dev_priv->dev, false);
1414 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001415 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001416}
1417
Daniel Vetterff1f5252012-10-02 15:10:55 +02001418static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001419{
1420 struct drm_device *dev = (struct drm_device *) arg;
1421 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1422 u32 iir, gt_iir, pm_iir;
1423 irqreturn_t ret = IRQ_NONE;
1424 unsigned long irqflags;
1425 int pipe;
1426 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001427
1428 atomic_inc(&dev_priv->irq_received);
1429
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001430 while (true) {
1431 iir = I915_READ(VLV_IIR);
1432 gt_iir = I915_READ(GTIIR);
1433 pm_iir = I915_READ(GEN6_PMIIR);
1434
1435 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1436 goto out;
1437
1438 ret = IRQ_HANDLED;
1439
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001440 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001441
1442 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1443 for_each_pipe(pipe) {
1444 int reg = PIPESTAT(pipe);
1445 pipe_stats[pipe] = I915_READ(reg);
1446
1447 /*
1448 * Clear the PIPE*STAT regs before the IIR
1449 */
1450 if (pipe_stats[pipe] & 0x8000ffff) {
1451 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1452 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1453 pipe_name(pipe));
1454 I915_WRITE(reg, pipe_stats[pipe]);
1455 }
1456 }
1457 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1458
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001459 for_each_pipe(pipe) {
Jesse Barnes7b5562d2013-11-05 15:48:01 -08001460 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001461 drm_handle_vblank(dev, pipe);
1462
1463 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1464 intel_prepare_page_flip(dev, pipe);
1465 intel_finish_page_flip(dev, pipe);
1466 }
Daniel Vetter4356d582013-10-16 22:55:55 +02001467
1468 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02001469 i9xx_pipe_crc_irq_handler(dev, pipe);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001470 }
1471
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001472 /* Consume port. Then clear IIR or we'll miss events */
1473 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1474 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001475 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001476
1477 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1478 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001479
1480 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1481
Daniel Vetter4aeebd72013-10-31 09:53:36 +01001482 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1483 dp_aux_irq_handler(dev);
1484
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001485 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1486 I915_READ(PORT_HOTPLUG_STAT);
1487 }
1488
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001489 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1490 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001491
Paulo Zanoni60611c12013-08-15 11:50:01 -03001492 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001493 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001494
1495 I915_WRITE(GTIIR, gt_iir);
1496 I915_WRITE(GEN6_PMIIR, pm_iir);
1497 I915_WRITE(VLV_IIR, iir);
1498 }
1499
1500out:
1501 return ret;
1502}
1503
Adam Jackson23e81d62012-06-06 15:45:44 -04001504static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001505{
1506 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001507 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001508 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001509
Daniel Vetter91d131d2013-06-27 17:52:14 +02001510 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1511
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001512 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1513 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1514 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001515 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001516 port_name(port));
1517 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001518
Daniel Vetterce99c252012-12-01 13:53:47 +01001519 if (pch_iir & SDE_AUX_MASK)
1520 dp_aux_irq_handler(dev);
1521
Jesse Barnes776ad802011-01-04 15:09:39 -08001522 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001523 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001524
1525 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1526 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1527
1528 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1529 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1530
1531 if (pch_iir & SDE_POISON)
1532 DRM_ERROR("PCH poison interrupt\n");
1533
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001534 if (pch_iir & SDE_FDI_MASK)
1535 for_each_pipe(pipe)
1536 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1537 pipe_name(pipe),
1538 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001539
1540 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1541 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1542
1543 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1544 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1545
Jesse Barnes776ad802011-01-04 15:09:39 -08001546 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001547 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1548 false))
1549 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1550
1551 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1552 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1553 false))
1554 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1555}
1556
1557static void ivb_err_int_handler(struct drm_device *dev)
1558{
1559 struct drm_i915_private *dev_priv = dev->dev_private;
1560 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001561 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001562
Paulo Zanonide032bf2013-04-12 17:57:58 -03001563 if (err_int & ERR_INT_POISON)
1564 DRM_ERROR("Poison interrupt\n");
1565
Daniel Vetter5a69b892013-10-16 22:55:52 +02001566 for_each_pipe(pipe) {
1567 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1568 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1569 false))
1570 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1571 pipe_name(pipe));
1572 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001573
Daniel Vetter5a69b892013-10-16 22:55:52 +02001574 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1575 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001576 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001577 else
Daniel Vetter277de952013-10-18 16:37:07 +02001578 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001579 }
1580 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001581
Paulo Zanoni86642812013-04-12 17:57:57 -03001582 I915_WRITE(GEN7_ERR_INT, err_int);
1583}
1584
1585static void cpt_serr_int_handler(struct drm_device *dev)
1586{
1587 struct drm_i915_private *dev_priv = dev->dev_private;
1588 u32 serr_int = I915_READ(SERR_INT);
1589
Paulo Zanonide032bf2013-04-12 17:57:58 -03001590 if (serr_int & SERR_INT_POISON)
1591 DRM_ERROR("PCH poison interrupt\n");
1592
Paulo Zanoni86642812013-04-12 17:57:57 -03001593 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1594 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1595 false))
1596 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1597
1598 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1599 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1600 false))
1601 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1602
1603 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1604 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1605 false))
1606 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1607
1608 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001609}
1610
Adam Jackson23e81d62012-06-06 15:45:44 -04001611static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1612{
1613 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1614 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001615 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001616
Daniel Vetter91d131d2013-06-27 17:52:14 +02001617 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1618
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001619 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1620 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1621 SDE_AUDIO_POWER_SHIFT_CPT);
1622 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1623 port_name(port));
1624 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001625
1626 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001627 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001628
1629 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001630 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001631
1632 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1633 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1634
1635 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1636 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1637
1638 if (pch_iir & SDE_FDI_MASK_CPT)
1639 for_each_pipe(pipe)
1640 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1641 pipe_name(pipe),
1642 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001643
1644 if (pch_iir & SDE_ERROR_CPT)
1645 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001646}
1647
Paulo Zanonic008bc62013-07-12 16:35:10 -03001648static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1649{
1650 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001651 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001652
1653 if (de_iir & DE_AUX_CHANNEL_A)
1654 dp_aux_irq_handler(dev);
1655
1656 if (de_iir & DE_GSE)
1657 intel_opregion_asle_intr(dev);
1658
Paulo Zanonic008bc62013-07-12 16:35:10 -03001659 if (de_iir & DE_POISON)
1660 DRM_ERROR("Poison interrupt\n");
1661
Daniel Vetter40da17c2013-10-21 18:04:36 +02001662 for_each_pipe(pipe) {
1663 if (de_iir & DE_PIPE_VBLANK(pipe))
1664 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001665
Daniel Vetter40da17c2013-10-21 18:04:36 +02001666 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1667 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1668 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1669 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001670
Daniel Vetter40da17c2013-10-21 18:04:36 +02001671 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1672 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001673
Daniel Vetter40da17c2013-10-21 18:04:36 +02001674 /* plane/pipes map 1:1 on ilk+ */
1675 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1676 intel_prepare_page_flip(dev, pipe);
1677 intel_finish_page_flip_plane(dev, pipe);
1678 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001679 }
1680
1681 /* check event from PCH */
1682 if (de_iir & DE_PCH_EVENT) {
1683 u32 pch_iir = I915_READ(SDEIIR);
1684
1685 if (HAS_PCH_CPT(dev))
1686 cpt_irq_handler(dev, pch_iir);
1687 else
1688 ibx_irq_handler(dev, pch_iir);
1689
1690 /* should clear PCH hotplug event before clear CPU irq */
1691 I915_WRITE(SDEIIR, pch_iir);
1692 }
1693
1694 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1695 ironlake_rps_change_irq_handler(dev);
1696}
1697
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001698static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1699{
1700 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001701 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001702
1703 if (de_iir & DE_ERR_INT_IVB)
1704 ivb_err_int_handler(dev);
1705
1706 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1707 dp_aux_irq_handler(dev);
1708
1709 if (de_iir & DE_GSE_IVB)
1710 intel_opregion_asle_intr(dev);
1711
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001712 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001713 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001714 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001715
1716 /* plane/pipes map 1:1 on ilk+ */
1717 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001718 intel_prepare_page_flip(dev, i);
1719 intel_finish_page_flip_plane(dev, i);
1720 }
1721 }
1722
1723 /* check event from PCH */
1724 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1725 u32 pch_iir = I915_READ(SDEIIR);
1726
1727 cpt_irq_handler(dev, pch_iir);
1728
1729 /* clear PCH hotplug event before clear CPU irq */
1730 I915_WRITE(SDEIIR, pch_iir);
1731 }
1732}
1733
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001734static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001735{
1736 struct drm_device *dev = (struct drm_device *) arg;
1737 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001738 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001739 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001740
1741 atomic_inc(&dev_priv->irq_received);
1742
Paulo Zanoni86642812013-04-12 17:57:57 -03001743 /* We get interrupts on unclaimed registers, so check for this before we
1744 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001745 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001746
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001747 /* disable master interrupt before clearing iir */
1748 de_ier = I915_READ(DEIER);
1749 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001750 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001751
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001752 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1753 * interrupts will will be stored on its back queue, and then we'll be
1754 * able to process them after we restore SDEIER (as soon as we restore
1755 * it, we'll get an interrupt if SDEIIR still has something to process
1756 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001757 if (!HAS_PCH_NOP(dev)) {
1758 sde_ier = I915_READ(SDEIER);
1759 I915_WRITE(SDEIER, 0);
1760 POSTING_READ(SDEIER);
1761 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001762
Chris Wilson0e434062012-05-09 21:45:44 +01001763 gt_iir = I915_READ(GTIIR);
1764 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001765 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001766 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001767 else
1768 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001769 I915_WRITE(GTIIR, gt_iir);
1770 ret = IRQ_HANDLED;
1771 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001772
1773 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001774 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001775 if (INTEL_INFO(dev)->gen >= 7)
1776 ivb_display_irq_handler(dev, de_iir);
1777 else
1778 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001779 I915_WRITE(DEIIR, de_iir);
1780 ret = IRQ_HANDLED;
1781 }
1782
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001783 if (INTEL_INFO(dev)->gen >= 6) {
1784 u32 pm_iir = I915_READ(GEN6_PMIIR);
1785 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001786 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001787 I915_WRITE(GEN6_PMIIR, pm_iir);
1788 ret = IRQ_HANDLED;
1789 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001790 }
1791
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001792 I915_WRITE(DEIER, de_ier);
1793 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001794 if (!HAS_PCH_NOP(dev)) {
1795 I915_WRITE(SDEIER, sde_ier);
1796 POSTING_READ(SDEIER);
1797 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001798
1799 return ret;
1800}
1801
Ben Widawskyabd58f02013-11-02 21:07:09 -07001802static irqreturn_t gen8_irq_handler(int irq, void *arg)
1803{
1804 struct drm_device *dev = arg;
1805 struct drm_i915_private *dev_priv = dev->dev_private;
1806 u32 master_ctl;
1807 irqreturn_t ret = IRQ_NONE;
1808 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001809 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001810
1811 atomic_inc(&dev_priv->irq_received);
1812
1813 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1814 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1815 if (!master_ctl)
1816 return IRQ_NONE;
1817
1818 I915_WRITE(GEN8_MASTER_IRQ, 0);
1819 POSTING_READ(GEN8_MASTER_IRQ);
1820
1821 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1822
1823 if (master_ctl & GEN8_DE_MISC_IRQ) {
1824 tmp = I915_READ(GEN8_DE_MISC_IIR);
1825 if (tmp & GEN8_DE_MISC_GSE)
1826 intel_opregion_asle_intr(dev);
1827 else if (tmp)
1828 DRM_ERROR("Unexpected DE Misc interrupt\n");
1829 else
1830 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1831
1832 if (tmp) {
1833 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1834 ret = IRQ_HANDLED;
1835 }
1836 }
1837
Daniel Vetter6d766f02013-11-07 14:49:55 +01001838 if (master_ctl & GEN8_DE_PORT_IRQ) {
1839 tmp = I915_READ(GEN8_DE_PORT_IIR);
1840 if (tmp & GEN8_AUX_CHANNEL_A)
1841 dp_aux_irq_handler(dev);
1842 else if (tmp)
1843 DRM_ERROR("Unexpected DE Port interrupt\n");
1844 else
1845 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1846
1847 if (tmp) {
1848 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1849 ret = IRQ_HANDLED;
1850 }
1851 }
1852
Daniel Vetterc42664c2013-11-07 11:05:40 +01001853 for_each_pipe(pipe) {
1854 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001855
Daniel Vetterc42664c2013-11-07 11:05:40 +01001856 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1857 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001858
Daniel Vetterc42664c2013-11-07 11:05:40 +01001859 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1860 if (pipe_iir & GEN8_PIPE_VBLANK)
1861 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001862
Daniel Vetterc42664c2013-11-07 11:05:40 +01001863 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1864 intel_prepare_page_flip(dev, pipe);
1865 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001866 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001867
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001868 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1869 hsw_pipe_crc_irq_handler(dev, pipe);
1870
Daniel Vetter38d83c962013-11-07 11:05:46 +01001871 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1872 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1873 false))
1874 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1875 pipe_name(pipe));
1876 }
1877
Daniel Vetter30100f22013-11-07 14:49:24 +01001878 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1879 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
1880 pipe_name(pipe),
1881 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
1882 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001883
1884 if (pipe_iir) {
1885 ret = IRQ_HANDLED;
1886 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
1887 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07001888 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
1889 }
1890
Daniel Vetter92d03a82013-11-07 11:05:43 +01001891 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
1892 /*
1893 * FIXME(BDW): Assume for now that the new interrupt handling
1894 * scheme also closed the SDE interrupt handling race we've seen
1895 * on older pch-split platforms. But this needs testing.
1896 */
1897 u32 pch_iir = I915_READ(SDEIIR);
1898
1899 cpt_irq_handler(dev, pch_iir);
1900
1901 if (pch_iir) {
1902 I915_WRITE(SDEIIR, pch_iir);
1903 ret = IRQ_HANDLED;
1904 }
1905 }
1906
Ben Widawskyabd58f02013-11-02 21:07:09 -07001907 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1908 POSTING_READ(GEN8_MASTER_IRQ);
1909
1910 return ret;
1911}
1912
Daniel Vetter17e1df02013-09-08 21:57:13 +02001913static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1914 bool reset_completed)
1915{
1916 struct intel_ring_buffer *ring;
1917 int i;
1918
1919 /*
1920 * Notify all waiters for GPU completion events that reset state has
1921 * been changed, and that they need to restart their wait after
1922 * checking for potential errors (and bail out to drop locks if there is
1923 * a gpu reset pending so that i915_error_work_func can acquire them).
1924 */
1925
1926 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1927 for_each_ring(ring, dev_priv, i)
1928 wake_up_all(&ring->irq_queue);
1929
1930 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1931 wake_up_all(&dev_priv->pending_flip_queue);
1932
1933 /*
1934 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1935 * reset state is cleared.
1936 */
1937 if (reset_completed)
1938 wake_up_all(&dev_priv->gpu_error.reset_queue);
1939}
1940
Jesse Barnes8a905232009-07-11 16:48:03 -04001941/**
1942 * i915_error_work_func - do process context error handling work
1943 * @work: work struct
1944 *
1945 * Fire an error uevent so userspace can see that a hang or error
1946 * was detected.
1947 */
1948static void i915_error_work_func(struct work_struct *work)
1949{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001950 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1951 work);
1952 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1953 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001954 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07001955 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1956 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1957 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02001958 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001959
Dave Airlie5bdebb12013-10-11 14:07:25 +10001960 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001961
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001962 /*
1963 * Note that there's only one work item which does gpu resets, so we
1964 * need not worry about concurrent gpu resets potentially incrementing
1965 * error->reset_counter twice. We only need to take care of another
1966 * racing irq/hangcheck declaring the gpu dead for a second time. A
1967 * quick check for that is good enough: schedule_work ensures the
1968 * correct ordering between hang detection and this work item, and since
1969 * the reset in-progress bit is only ever set by code outside of this
1970 * work we don't need to worry about any other races.
1971 */
1972 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001973 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10001974 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001975 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001976
Daniel Vetter17e1df02013-09-08 21:57:13 +02001977 /*
1978 * All state reset _must_ be completed before we update the
1979 * reset counter, for otherwise waiters might miss the reset
1980 * pending state and not properly drop locks, resulting in
1981 * deadlocks with the reset work.
1982 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01001983 ret = i915_reset(dev);
1984
Daniel Vetter17e1df02013-09-08 21:57:13 +02001985 intel_display_handle_reset(dev);
1986
Daniel Vetterf69061b2012-12-06 09:01:42 +01001987 if (ret == 0) {
1988 /*
1989 * After all the gem state is reset, increment the reset
1990 * counter and wake up everyone waiting for the reset to
1991 * complete.
1992 *
1993 * Since unlock operations are a one-sided barrier only,
1994 * we need to insert a barrier here to order any seqno
1995 * updates before
1996 * the counter increment.
1997 */
1998 smp_mb__before_atomic_inc();
1999 atomic_inc(&dev_priv->gpu_error.reset_counter);
2000
Dave Airlie5bdebb12013-10-11 14:07:25 +10002001 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002002 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002003 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002004 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002005 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002006
Daniel Vetter17e1df02013-09-08 21:57:13 +02002007 /*
2008 * Note: The wake_up also serves as a memory barrier so that
2009 * waiters see the update value of the reset counter atomic_t.
2010 */
2011 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002012 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002013}
2014
Chris Wilson35aed2e2010-05-27 13:18:12 +01002015static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002016{
2017 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002018 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002019 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002020 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002021
Chris Wilson35aed2e2010-05-27 13:18:12 +01002022 if (!eir)
2023 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002024
Joe Perchesa70491c2012-03-18 13:00:11 -07002025 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002026
Ben Widawskybd9854f2012-08-23 15:18:09 -07002027 i915_get_extra_instdone(dev, instdone);
2028
Jesse Barnes8a905232009-07-11 16:48:03 -04002029 if (IS_G4X(dev)) {
2030 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2031 u32 ipeir = I915_READ(IPEIR_I965);
2032
Joe Perchesa70491c2012-03-18 13:00:11 -07002033 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2034 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002035 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2036 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002037 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002038 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002039 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002040 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002041 }
2042 if (eir & GM45_ERROR_PAGE_TABLE) {
2043 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002044 pr_err("page table error\n");
2045 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002046 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002047 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002048 }
2049 }
2050
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002051 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002052 if (eir & I915_ERROR_PAGE_TABLE) {
2053 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002054 pr_err("page table error\n");
2055 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002056 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002057 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002058 }
2059 }
2060
2061 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002062 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002063 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002064 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002065 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002066 /* pipestat has already been acked */
2067 }
2068 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002069 pr_err("instruction error\n");
2070 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002071 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2072 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002073 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002074 u32 ipeir = I915_READ(IPEIR);
2075
Joe Perchesa70491c2012-03-18 13:00:11 -07002076 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2077 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002078 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002079 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002080 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002081 } else {
2082 u32 ipeir = I915_READ(IPEIR_I965);
2083
Joe Perchesa70491c2012-03-18 13:00:11 -07002084 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2085 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002086 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002087 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002088 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002089 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002090 }
2091 }
2092
2093 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002094 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002095 eir = I915_READ(EIR);
2096 if (eir) {
2097 /*
2098 * some errors might have become stuck,
2099 * mask them.
2100 */
2101 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2102 I915_WRITE(EMR, I915_READ(EMR) | eir);
2103 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2104 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002105}
2106
2107/**
2108 * i915_handle_error - handle an error interrupt
2109 * @dev: drm device
2110 *
2111 * Do some basic checking of regsiter state at error interrupt time and
2112 * dump it to the syslog. Also call i915_capture_error_state() to make
2113 * sure we get a record and make it available in debugfs. Fire a uevent
2114 * so userspace knows something bad happened (should trigger collection
2115 * of a ring dump etc.).
2116 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002117void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002118{
2119 struct drm_i915_private *dev_priv = dev->dev_private;
2120
2121 i915_capture_error_state(dev);
2122 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002123
Ben Gamariba1234d2009-09-14 17:48:47 -04002124 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002125 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2126 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002127
Ben Gamari11ed50e2009-09-14 17:48:45 -04002128 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002129 * Wakeup waiting processes so that the reset work function
2130 * i915_error_work_func doesn't deadlock trying to grab various
2131 * locks. By bumping the reset counter first, the woken
2132 * processes will see a reset in progress and back off,
2133 * releasing their locks and then wait for the reset completion.
2134 * We must do this for _all_ gpu waiters that might hold locks
2135 * that the reset work needs to acquire.
2136 *
2137 * Note: The wake_up serves as the required memory barrier to
2138 * ensure that the waiters see the updated value of the reset
2139 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002140 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002141 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002142 }
2143
Daniel Vetter122f46b2013-09-04 17:36:14 +02002144 /*
2145 * Our reset work can grab modeset locks (since it needs to reset the
2146 * state of outstanding pagelips). Hence it must not be run on our own
2147 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2148 * code will deadlock.
2149 */
2150 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002151}
2152
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002153static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002154{
2155 drm_i915_private_t *dev_priv = dev->dev_private;
2156 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2157 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002158 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002159 struct intel_unpin_work *work;
2160 unsigned long flags;
2161 bool stall_detected;
2162
2163 /* Ignore early vblank irqs */
2164 if (intel_crtc == NULL)
2165 return;
2166
2167 spin_lock_irqsave(&dev->event_lock, flags);
2168 work = intel_crtc->unpin_work;
2169
Chris Wilsone7d841c2012-12-03 11:36:30 +00002170 if (work == NULL ||
2171 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2172 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002173 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2174 spin_unlock_irqrestore(&dev->event_lock, flags);
2175 return;
2176 }
2177
2178 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002179 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002180 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002181 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002182 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002183 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002184 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002185 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002186 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002187 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002188 crtc->x * crtc->fb->bits_per_pixel/8);
2189 }
2190
2191 spin_unlock_irqrestore(&dev->event_lock, flags);
2192
2193 if (stall_detected) {
2194 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2195 intel_prepare_page_flip(dev, intel_crtc->plane);
2196 }
2197}
2198
Keith Packard42f52ef2008-10-18 19:39:29 -07002199/* Called from drm generic code, passed 'crtc' which
2200 * we use as a pipe index
2201 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002202static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002203{
2204 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002205 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002206
Chris Wilson5eddb702010-09-11 13:48:45 +01002207 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002208 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002209
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002210 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002211 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002212 i915_enable_pipestat(dev_priv, pipe,
2213 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07002214 else
Keith Packard7c463582008-11-04 02:03:27 -08002215 i915_enable_pipestat(dev_priv, pipe,
2216 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002217
2218 /* maintain vblank delivery even in deep C-states */
2219 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002220 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002221 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002222
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002223 return 0;
2224}
2225
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002226static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002227{
2228 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2229 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002230 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002231 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002232
2233 if (!i915_pipe_enabled(dev, pipe))
2234 return -EINVAL;
2235
2236 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002237 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002238 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2239
2240 return 0;
2241}
2242
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002243static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2244{
2245 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2246 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002247 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002248
2249 if (!i915_pipe_enabled(dev, pipe))
2250 return -EINVAL;
2251
2252 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002253 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002254 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002255 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002256 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002257 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002258 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002259 i915_enable_pipestat(dev_priv, pipe,
2260 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002261 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2262
2263 return 0;
2264}
2265
Ben Widawskyabd58f02013-11-02 21:07:09 -07002266static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2267{
2268 struct drm_i915_private *dev_priv = dev->dev_private;
2269 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002270
2271 if (!i915_pipe_enabled(dev, pipe))
2272 return -EINVAL;
2273
2274 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002275 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2276 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2277 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002278 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2279 return 0;
2280}
2281
Keith Packard42f52ef2008-10-18 19:39:29 -07002282/* Called from drm generic code, passed 'crtc' which
2283 * we use as a pipe index
2284 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002285static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002286{
2287 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002288 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002289
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002290 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002291 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002292 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002293
Jesse Barnesf796cf82011-04-07 13:58:17 -07002294 i915_disable_pipestat(dev_priv, pipe,
2295 PIPE_VBLANK_INTERRUPT_ENABLE |
2296 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2297 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2298}
2299
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002300static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002301{
2302 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2303 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002304 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002305 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002306
2307 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002308 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002309 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2310}
2311
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002312static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2313{
2314 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2315 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002316 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002317
2318 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002319 i915_disable_pipestat(dev_priv, pipe,
2320 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002321 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002322 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002323 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002324 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002325 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002326 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002327 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2328}
2329
Ben Widawskyabd58f02013-11-02 21:07:09 -07002330static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2331{
2332 struct drm_i915_private *dev_priv = dev->dev_private;
2333 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002334
2335 if (!i915_pipe_enabled(dev, pipe))
2336 return;
2337
2338 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002339 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2340 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2341 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002342 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2343}
2344
Chris Wilson893eead2010-10-27 14:44:35 +01002345static u32
2346ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002347{
Chris Wilson893eead2010-10-27 14:44:35 +01002348 return list_entry(ring->request_list.prev,
2349 struct drm_i915_gem_request, list)->seqno;
2350}
2351
Chris Wilson9107e9d2013-06-10 11:20:20 +01002352static bool
2353ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002354{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002355 return (list_empty(&ring->request_list) ||
2356 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002357}
2358
Chris Wilson6274f212013-06-10 11:20:21 +01002359static struct intel_ring_buffer *
2360semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002361{
2362 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002363 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002364
2365 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2366 if ((ipehr & ~(0x3 << 16)) !=
2367 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002368 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002369
2370 /* ACTHD is likely pointing to the dword after the actual command,
2371 * so scan backwards until we find the MBOX.
2372 */
Chris Wilson6274f212013-06-10 11:20:21 +01002373 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002374 acthd_min = max((int)acthd - 3 * 4, 0);
2375 do {
2376 cmd = ioread32(ring->virtual_start + acthd);
2377 if (cmd == ipehr)
2378 break;
2379
2380 acthd -= 4;
2381 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002382 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002383 } while (1);
2384
Chris Wilson6274f212013-06-10 11:20:21 +01002385 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2386 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002387}
2388
Chris Wilson6274f212013-06-10 11:20:21 +01002389static int semaphore_passed(struct intel_ring_buffer *ring)
2390{
2391 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2392 struct intel_ring_buffer *signaller;
2393 u32 seqno, ctl;
2394
2395 ring->hangcheck.deadlock = true;
2396
2397 signaller = semaphore_waits_for(ring, &seqno);
2398 if (signaller == NULL || signaller->hangcheck.deadlock)
2399 return -1;
2400
2401 /* cursory check for an unkickable deadlock */
2402 ctl = I915_READ_CTL(signaller);
2403 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2404 return -1;
2405
2406 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2407}
2408
2409static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2410{
2411 struct intel_ring_buffer *ring;
2412 int i;
2413
2414 for_each_ring(ring, dev_priv, i)
2415 ring->hangcheck.deadlock = false;
2416}
2417
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002418static enum intel_ring_hangcheck_action
2419ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002420{
2421 struct drm_device *dev = ring->dev;
2422 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002423 u32 tmp;
2424
Chris Wilson6274f212013-06-10 11:20:21 +01002425 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002426 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002427
Chris Wilson9107e9d2013-06-10 11:20:20 +01002428 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002429 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002430
2431 /* Is the chip hanging on a WAIT_FOR_EVENT?
2432 * If so we can simply poke the RB_WAIT bit
2433 * and break the hang. This should work on
2434 * all but the second generation chipsets.
2435 */
2436 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002437 if (tmp & RING_WAIT) {
2438 DRM_ERROR("Kicking stuck wait on %s\n",
2439 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002440 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002441 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002442 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002443 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002444
Chris Wilson6274f212013-06-10 11:20:21 +01002445 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2446 switch (semaphore_passed(ring)) {
2447 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002448 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002449 case 1:
2450 DRM_ERROR("Kicking stuck semaphore on %s\n",
2451 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002452 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002453 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002454 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002455 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002456 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002457 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002458 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002459
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002460 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002461}
2462
Ben Gamarif65d9422009-09-14 17:48:44 -04002463/**
2464 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002465 * batchbuffers in a long time. We keep track per ring seqno progress and
2466 * if there are no progress, hangcheck score for that ring is increased.
2467 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2468 * we kick the ring. If we see no progress on three subsequent calls
2469 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002470 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002471static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002472{
2473 struct drm_device *dev = (struct drm_device *)data;
2474 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002475 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002476 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002477 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002478 bool stuck[I915_NUM_RINGS] = { 0 };
2479#define BUSY 1
2480#define KICK 5
2481#define HUNG 20
2482#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01002483
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002484 if (!i915_enable_hangcheck)
2485 return;
2486
Chris Wilsonb4519512012-05-11 14:29:30 +01002487 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002488 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002489 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002490
Chris Wilson6274f212013-06-10 11:20:21 +01002491 semaphore_clear_deadlocks(dev_priv);
2492
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002493 seqno = ring->get_seqno(ring, false);
2494 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002495
Chris Wilson9107e9d2013-06-10 11:20:20 +01002496 if (ring->hangcheck.seqno == seqno) {
2497 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002498 ring->hangcheck.action = HANGCHECK_IDLE;
2499
Chris Wilson9107e9d2013-06-10 11:20:20 +01002500 if (waitqueue_active(&ring->irq_queue)) {
2501 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002502 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002503 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2504 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2505 ring->name);
2506 else
2507 DRM_INFO("Fake missed irq on %s\n",
2508 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002509 wake_up_all(&ring->irq_queue);
2510 }
2511 /* Safeguard against driver failure */
2512 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002513 } else
2514 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002515 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002516 /* We always increment the hangcheck score
2517 * if the ring is busy and still processing
2518 * the same request, so that no single request
2519 * can run indefinitely (such as a chain of
2520 * batches). The only time we do not increment
2521 * the hangcheck score on this ring, if this
2522 * ring is in a legitimate wait for another
2523 * ring. In that case the waiting ring is a
2524 * victim and we want to be sure we catch the
2525 * right culprit. Then every time we do kick
2526 * the ring, add a small increment to the
2527 * score so that we can catch a batch that is
2528 * being repeatedly kicked and so responsible
2529 * for stalling the machine.
2530 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002531 ring->hangcheck.action = ring_stuck(ring,
2532 acthd);
2533
2534 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002535 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002536 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002537 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002538 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002539 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002540 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002541 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002542 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002543 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002544 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002545 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002546 stuck[i] = true;
2547 break;
2548 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002549 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002550 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002551 ring->hangcheck.action = HANGCHECK_ACTIVE;
2552
Chris Wilson9107e9d2013-06-10 11:20:20 +01002553 /* Gradually reduce the count so that we catch DoS
2554 * attempts across multiple batches.
2555 */
2556 if (ring->hangcheck.score > 0)
2557 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002558 }
2559
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002560 ring->hangcheck.seqno = seqno;
2561 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002562 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002563 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002564
Mika Kuoppala92cab732013-05-24 17:16:07 +03002565 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002566 if (ring->hangcheck.score > FIRE) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002567 DRM_INFO("%s on %s\n",
2568 stuck[i] ? "stuck" : "no progress",
2569 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002570 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002571 }
2572 }
2573
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002574 if (rings_hung)
2575 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002576
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002577 if (busy_count)
2578 /* Reset timer case chip hangs without another request
2579 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002580 i915_queue_hangcheck(dev);
2581}
2582
2583void i915_queue_hangcheck(struct drm_device *dev)
2584{
2585 struct drm_i915_private *dev_priv = dev->dev_private;
2586 if (!i915_enable_hangcheck)
2587 return;
2588
2589 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2590 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002591}
2592
Paulo Zanoni91738a92013-06-05 14:21:51 -03002593static void ibx_irq_preinstall(struct drm_device *dev)
2594{
2595 struct drm_i915_private *dev_priv = dev->dev_private;
2596
2597 if (HAS_PCH_NOP(dev))
2598 return;
2599
2600 /* south display irq */
2601 I915_WRITE(SDEIMR, 0xffffffff);
2602 /*
2603 * SDEIER is also touched by the interrupt handler to work around missed
2604 * PCH interrupts. Hence we can't update it after the interrupt handler
2605 * is enabled - instead we unconditionally enable all PCH interrupt
2606 * sources here, but then only unmask them as needed with SDEIMR.
2607 */
2608 I915_WRITE(SDEIER, 0xffffffff);
2609 POSTING_READ(SDEIER);
2610}
2611
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002612static void gen5_gt_irq_preinstall(struct drm_device *dev)
2613{
2614 struct drm_i915_private *dev_priv = dev->dev_private;
2615
2616 /* and GT */
2617 I915_WRITE(GTIMR, 0xffffffff);
2618 I915_WRITE(GTIER, 0x0);
2619 POSTING_READ(GTIER);
2620
2621 if (INTEL_INFO(dev)->gen >= 6) {
2622 /* and PM */
2623 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2624 I915_WRITE(GEN6_PMIER, 0x0);
2625 POSTING_READ(GEN6_PMIER);
2626 }
2627}
2628
Linus Torvalds1da177e2005-04-16 15:20:36 -07002629/* drm_dma.h hooks
2630*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002631static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002632{
2633 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2634
Jesse Barnes46979952011-04-07 13:53:55 -07002635 atomic_set(&dev_priv->irq_received, 0);
2636
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002637 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002638
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002639 I915_WRITE(DEIMR, 0xffffffff);
2640 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002641 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002642
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002643 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002644
Paulo Zanoni91738a92013-06-05 14:21:51 -03002645 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002646}
2647
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002648static void valleyview_irq_preinstall(struct drm_device *dev)
2649{
2650 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2651 int pipe;
2652
2653 atomic_set(&dev_priv->irq_received, 0);
2654
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002655 /* VLV magic */
2656 I915_WRITE(VLV_IMR, 0);
2657 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2658 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2659 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2660
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002661 /* and GT */
2662 I915_WRITE(GTIIR, I915_READ(GTIIR));
2663 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002664
2665 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002666
2667 I915_WRITE(DPINVGTT, 0xff);
2668
2669 I915_WRITE(PORT_HOTPLUG_EN, 0);
2670 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2671 for_each_pipe(pipe)
2672 I915_WRITE(PIPESTAT(pipe), 0xffff);
2673 I915_WRITE(VLV_IIR, 0xffffffff);
2674 I915_WRITE(VLV_IMR, 0xffffffff);
2675 I915_WRITE(VLV_IER, 0x0);
2676 POSTING_READ(VLV_IER);
2677}
2678
Ben Widawskyabd58f02013-11-02 21:07:09 -07002679static void gen8_irq_preinstall(struct drm_device *dev)
2680{
2681 struct drm_i915_private *dev_priv = dev->dev_private;
2682 int pipe;
2683
2684 atomic_set(&dev_priv->irq_received, 0);
2685
2686 I915_WRITE(GEN8_MASTER_IRQ, 0);
2687 POSTING_READ(GEN8_MASTER_IRQ);
2688
2689 /* IIR can theoretically queue up two events. Be paranoid */
2690#define GEN8_IRQ_INIT_NDX(type, which) do { \
2691 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2692 POSTING_READ(GEN8_##type##_IMR(which)); \
2693 I915_WRITE(GEN8_##type##_IER(which), 0); \
2694 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2695 POSTING_READ(GEN8_##type##_IIR(which)); \
2696 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2697 } while (0)
2698
2699#define GEN8_IRQ_INIT(type) do { \
2700 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2701 POSTING_READ(GEN8_##type##_IMR); \
2702 I915_WRITE(GEN8_##type##_IER, 0); \
2703 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2704 POSTING_READ(GEN8_##type##_IIR); \
2705 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2706 } while (0)
2707
2708 GEN8_IRQ_INIT_NDX(GT, 0);
2709 GEN8_IRQ_INIT_NDX(GT, 1);
2710 GEN8_IRQ_INIT_NDX(GT, 2);
2711 GEN8_IRQ_INIT_NDX(GT, 3);
2712
2713 for_each_pipe(pipe) {
2714 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2715 }
2716
2717 GEN8_IRQ_INIT(DE_PORT);
2718 GEN8_IRQ_INIT(DE_MISC);
2719 GEN8_IRQ_INIT(PCU);
2720#undef GEN8_IRQ_INIT
2721#undef GEN8_IRQ_INIT_NDX
2722
2723 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002724
2725 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002726}
2727
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002728static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002729{
2730 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002731 struct drm_mode_config *mode_config = &dev->mode_config;
2732 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002733 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002734
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002735 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002736 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002737 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002738 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002739 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002740 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002741 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002742 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002743 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002744 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002745 }
2746
Daniel Vetterfee884e2013-07-04 23:35:21 +02002747 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002748
2749 /*
2750 * Enable digital hotplug on the PCH, and configure the DP short pulse
2751 * duration to 2ms (which is the minimum in the Display Port spec)
2752 *
2753 * This register is the same on all known PCH chips.
2754 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002755 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2756 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2757 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2758 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2759 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2760 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2761}
2762
Paulo Zanonid46da432013-02-08 17:35:15 -02002763static void ibx_irq_postinstall(struct drm_device *dev)
2764{
2765 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002766 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002767
Daniel Vetter692a04c2013-05-29 21:43:05 +02002768 if (HAS_PCH_NOP(dev))
2769 return;
2770
Paulo Zanoni86642812013-04-12 17:57:57 -03002771 if (HAS_PCH_IBX(dev)) {
2772 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002773 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002774 } else {
2775 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2776
2777 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2778 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002779
Paulo Zanonid46da432013-02-08 17:35:15 -02002780 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2781 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002782}
2783
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002784static void gen5_gt_irq_postinstall(struct drm_device *dev)
2785{
2786 struct drm_i915_private *dev_priv = dev->dev_private;
2787 u32 pm_irqs, gt_irqs;
2788
2789 pm_irqs = gt_irqs = 0;
2790
2791 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002792 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002793 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002794 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2795 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002796 }
2797
2798 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2799 if (IS_GEN5(dev)) {
2800 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2801 ILK_BSD_USER_INTERRUPT;
2802 } else {
2803 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2804 }
2805
2806 I915_WRITE(GTIIR, I915_READ(GTIIR));
2807 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2808 I915_WRITE(GTIER, gt_irqs);
2809 POSTING_READ(GTIER);
2810
2811 if (INTEL_INFO(dev)->gen >= 6) {
2812 pm_irqs |= GEN6_PM_RPS_EVENTS;
2813
2814 if (HAS_VEBOX(dev))
2815 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2816
Paulo Zanoni605cd252013-08-06 18:57:15 -03002817 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002818 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002819 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002820 I915_WRITE(GEN6_PMIER, pm_irqs);
2821 POSTING_READ(GEN6_PMIER);
2822 }
2823}
2824
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002825static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002826{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002827 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002828 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002829 u32 display_mask, extra_mask;
2830
2831 if (INTEL_INFO(dev)->gen >= 7) {
2832 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2833 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2834 DE_PLANEB_FLIP_DONE_IVB |
2835 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2836 DE_ERR_INT_IVB);
2837 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2838 DE_PIPEA_VBLANK_IVB);
2839
2840 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2841 } else {
2842 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2843 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002844 DE_AUX_CHANNEL_A |
2845 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2846 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2847 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002848 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2849 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002850
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002851 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002852
2853 /* should always can generate irq */
2854 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002855 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002856 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002857 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002858
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002859 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002860
Paulo Zanonid46da432013-02-08 17:35:15 -02002861 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002862
Jesse Barnesf97108d2010-01-29 11:27:07 -08002863 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002864 /* Enable PCU event interrupts
2865 *
2866 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002867 * setup is guaranteed to run in single-threaded context. But we
2868 * need it to make the assert_spin_locked happy. */
2869 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002870 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002871 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002872 }
2873
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002874 return 0;
2875}
2876
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002877static int valleyview_irq_postinstall(struct drm_device *dev)
2878{
2879 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002880 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002881 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2882 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002883 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002884
2885 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002886 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2887 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2888 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002889 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2890
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002891 /*
2892 *Leave vblank interrupts masked initially. enable/disable will
2893 * toggle them based on usage.
2894 */
2895 dev_priv->irq_mask = (~enable_mask) |
2896 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2897 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002898
Daniel Vetter20afbda2012-12-11 14:05:07 +01002899 I915_WRITE(PORT_HOTPLUG_EN, 0);
2900 POSTING_READ(PORT_HOTPLUG_EN);
2901
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002902 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2903 I915_WRITE(VLV_IER, enable_mask);
2904 I915_WRITE(VLV_IIR, 0xffffffff);
2905 I915_WRITE(PIPESTAT(0), 0xffff);
2906 I915_WRITE(PIPESTAT(1), 0xffff);
2907 POSTING_READ(VLV_IER);
2908
Daniel Vetterb79480b2013-06-27 17:52:10 +02002909 /* Interrupt setup is already guaranteed to be single-threaded, this is
2910 * just to make the assert_spin_locked check happy. */
2911 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002912 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
2913 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
2914 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002915 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002916
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002917 I915_WRITE(VLV_IIR, 0xffffffff);
2918 I915_WRITE(VLV_IIR, 0xffffffff);
2919
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002920 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002921
2922 /* ack & enable invalid PTE error interrupts */
2923#if 0 /* FIXME: add support to irq handler for checking these bits */
2924 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2925 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2926#endif
2927
2928 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002929
2930 return 0;
2931}
2932
Ben Widawskyabd58f02013-11-02 21:07:09 -07002933static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
2934{
2935 int i;
2936
2937 /* These are interrupts we'll toggle with the ring mask register */
2938 uint32_t gt_interrupts[] = {
2939 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
2940 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
2941 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
2942 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
2943 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
2944 0,
2945 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
2946 };
2947
2948 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
2949 u32 tmp = I915_READ(GEN8_GT_IIR(i));
2950 if (tmp)
2951 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2952 i, tmp);
2953 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
2954 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
2955 }
2956 POSTING_READ(GEN8_GT_IER(0));
2957}
2958
2959static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
2960{
2961 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002962 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
2963 GEN8_PIPE_CDCLK_CRC_DONE |
2964 GEN8_PIPE_FIFO_UNDERRUN |
2965 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2966 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002967 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002968 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
2969 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
2970 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002971
2972 for_each_pipe(pipe) {
2973 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2974 if (tmp)
2975 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2976 pipe, tmp);
2977 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2978 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
2979 }
2980 POSTING_READ(GEN8_DE_PIPE_ISR(0));
2981
Daniel Vetter6d766f02013-11-07 14:49:55 +01002982 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
2983 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002984 POSTING_READ(GEN8_DE_PORT_IER);
2985}
2986
2987static int gen8_irq_postinstall(struct drm_device *dev)
2988{
2989 struct drm_i915_private *dev_priv = dev->dev_private;
2990
2991 gen8_gt_irq_postinstall(dev_priv);
2992 gen8_de_irq_postinstall(dev_priv);
2993
2994 ibx_irq_postinstall(dev);
2995
2996 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
2997 POSTING_READ(GEN8_MASTER_IRQ);
2998
2999 return 0;
3000}
3001
3002static void gen8_irq_uninstall(struct drm_device *dev)
3003{
3004 struct drm_i915_private *dev_priv = dev->dev_private;
3005 int pipe;
3006
3007 if (!dev_priv)
3008 return;
3009
3010 atomic_set(&dev_priv->irq_received, 0);
3011
3012 I915_WRITE(GEN8_MASTER_IRQ, 0);
3013
3014#define GEN8_IRQ_FINI_NDX(type, which) do { \
3015 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3016 I915_WRITE(GEN8_##type##_IER(which), 0); \
3017 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3018 } while (0)
3019
3020#define GEN8_IRQ_FINI(type) do { \
3021 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3022 I915_WRITE(GEN8_##type##_IER, 0); \
3023 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3024 } while (0)
3025
3026 GEN8_IRQ_FINI_NDX(GT, 0);
3027 GEN8_IRQ_FINI_NDX(GT, 1);
3028 GEN8_IRQ_FINI_NDX(GT, 2);
3029 GEN8_IRQ_FINI_NDX(GT, 3);
3030
3031 for_each_pipe(pipe) {
3032 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3033 }
3034
3035 GEN8_IRQ_FINI(DE_PORT);
3036 GEN8_IRQ_FINI(DE_MISC);
3037 GEN8_IRQ_FINI(PCU);
3038#undef GEN8_IRQ_FINI
3039#undef GEN8_IRQ_FINI_NDX
3040
3041 POSTING_READ(GEN8_PCU_IIR);
3042}
3043
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003044static void valleyview_irq_uninstall(struct drm_device *dev)
3045{
3046 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3047 int pipe;
3048
3049 if (!dev_priv)
3050 return;
3051
Egbert Eichac4c16c2013-04-16 13:36:58 +02003052 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3053
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003054 for_each_pipe(pipe)
3055 I915_WRITE(PIPESTAT(pipe), 0xffff);
3056
3057 I915_WRITE(HWSTAM, 0xffffffff);
3058 I915_WRITE(PORT_HOTPLUG_EN, 0);
3059 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3060 for_each_pipe(pipe)
3061 I915_WRITE(PIPESTAT(pipe), 0xffff);
3062 I915_WRITE(VLV_IIR, 0xffffffff);
3063 I915_WRITE(VLV_IMR, 0xffffffff);
3064 I915_WRITE(VLV_IER, 0x0);
3065 POSTING_READ(VLV_IER);
3066}
3067
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003068static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003069{
3070 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003071
3072 if (!dev_priv)
3073 return;
3074
Egbert Eichac4c16c2013-04-16 13:36:58 +02003075 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3076
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003077 I915_WRITE(HWSTAM, 0xffffffff);
3078
3079 I915_WRITE(DEIMR, 0xffffffff);
3080 I915_WRITE(DEIER, 0x0);
3081 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003082 if (IS_GEN7(dev))
3083 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003084
3085 I915_WRITE(GTIMR, 0xffffffff);
3086 I915_WRITE(GTIER, 0x0);
3087 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003088
Ben Widawskyab5c6082013-04-05 13:12:41 -07003089 if (HAS_PCH_NOP(dev))
3090 return;
3091
Keith Packard192aac1f2011-09-20 10:12:44 -07003092 I915_WRITE(SDEIMR, 0xffffffff);
3093 I915_WRITE(SDEIER, 0x0);
3094 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003095 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3096 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003097}
3098
Chris Wilsonc2798b12012-04-22 21:13:57 +01003099static void i8xx_irq_preinstall(struct drm_device * dev)
3100{
3101 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3102 int pipe;
3103
3104 atomic_set(&dev_priv->irq_received, 0);
3105
3106 for_each_pipe(pipe)
3107 I915_WRITE(PIPESTAT(pipe), 0);
3108 I915_WRITE16(IMR, 0xffff);
3109 I915_WRITE16(IER, 0x0);
3110 POSTING_READ16(IER);
3111}
3112
3113static int i8xx_irq_postinstall(struct drm_device *dev)
3114{
3115 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003116 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003117
Chris Wilsonc2798b12012-04-22 21:13:57 +01003118 I915_WRITE16(EMR,
3119 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3120
3121 /* Unmask the interrupts that we always want on. */
3122 dev_priv->irq_mask =
3123 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3124 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3125 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3126 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3127 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3128 I915_WRITE16(IMR, dev_priv->irq_mask);
3129
3130 I915_WRITE16(IER,
3131 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3132 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3133 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3134 I915_USER_INTERRUPT);
3135 POSTING_READ16(IER);
3136
Daniel Vetter379ef822013-10-16 22:55:56 +02003137 /* Interrupt setup is already guaranteed to be single-threaded, this is
3138 * just to make the assert_spin_locked check happy. */
3139 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003140 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3141 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003142 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3143
Chris Wilsonc2798b12012-04-22 21:13:57 +01003144 return 0;
3145}
3146
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003147/*
3148 * Returns true when a page flip has completed.
3149 */
3150static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003151 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003152{
3153 drm_i915_private_t *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003154 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003155
3156 if (!drm_handle_vblank(dev, pipe))
3157 return false;
3158
3159 if ((iir & flip_pending) == 0)
3160 return false;
3161
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003162 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003163
3164 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3165 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3166 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3167 * the flip is completed (no longer pending). Since this doesn't raise
3168 * an interrupt per se, we watch for the change at vblank.
3169 */
3170 if (I915_READ16(ISR) & flip_pending)
3171 return false;
3172
3173 intel_finish_page_flip(dev, pipe);
3174
3175 return true;
3176}
3177
Daniel Vetterff1f5252012-10-02 15:10:55 +02003178static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003179{
3180 struct drm_device *dev = (struct drm_device *) arg;
3181 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003182 u16 iir, new_iir;
3183 u32 pipe_stats[2];
3184 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003185 int pipe;
3186 u16 flip_mask =
3187 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3188 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3189
3190 atomic_inc(&dev_priv->irq_received);
3191
3192 iir = I915_READ16(IIR);
3193 if (iir == 0)
3194 return IRQ_NONE;
3195
3196 while (iir & ~flip_mask) {
3197 /* Can't rely on pipestat interrupt bit in iir as it might
3198 * have been cleared after the pipestat interrupt was received.
3199 * It doesn't set the bit in iir again, but it still produces
3200 * interrupts (for non-MSI).
3201 */
3202 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3203 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3204 i915_handle_error(dev, false);
3205
3206 for_each_pipe(pipe) {
3207 int reg = PIPESTAT(pipe);
3208 pipe_stats[pipe] = I915_READ(reg);
3209
3210 /*
3211 * Clear the PIPE*STAT regs before the IIR
3212 */
3213 if (pipe_stats[pipe] & 0x8000ffff) {
3214 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3215 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3216 pipe_name(pipe));
3217 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003218 }
3219 }
3220 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3221
3222 I915_WRITE16(IIR, iir & ~flip_mask);
3223 new_iir = I915_READ16(IIR); /* Flush posted writes */
3224
Daniel Vetterd05c6172012-04-26 23:28:09 +02003225 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003226
3227 if (iir & I915_USER_INTERRUPT)
3228 notify_ring(dev, &dev_priv->ring[RCS]);
3229
Daniel Vetter4356d582013-10-16 22:55:55 +02003230 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003231 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003232 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003233 plane = !plane;
3234
Daniel Vetter4356d582013-10-16 22:55:55 +02003235 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003236 i8xx_handle_vblank(dev, plane, pipe, iir))
3237 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003238
Daniel Vetter4356d582013-10-16 22:55:55 +02003239 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003240 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003241 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003242
3243 iir = new_iir;
3244 }
3245
3246 return IRQ_HANDLED;
3247}
3248
3249static void i8xx_irq_uninstall(struct drm_device * dev)
3250{
3251 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3252 int pipe;
3253
Chris Wilsonc2798b12012-04-22 21:13:57 +01003254 for_each_pipe(pipe) {
3255 /* Clear enable bits; then clear status bits */
3256 I915_WRITE(PIPESTAT(pipe), 0);
3257 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3258 }
3259 I915_WRITE16(IMR, 0xffff);
3260 I915_WRITE16(IER, 0x0);
3261 I915_WRITE16(IIR, I915_READ16(IIR));
3262}
3263
Chris Wilsona266c7d2012-04-24 22:59:44 +01003264static void i915_irq_preinstall(struct drm_device * dev)
3265{
3266 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3267 int pipe;
3268
3269 atomic_set(&dev_priv->irq_received, 0);
3270
3271 if (I915_HAS_HOTPLUG(dev)) {
3272 I915_WRITE(PORT_HOTPLUG_EN, 0);
3273 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3274 }
3275
Chris Wilson00d98eb2012-04-24 22:59:48 +01003276 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003277 for_each_pipe(pipe)
3278 I915_WRITE(PIPESTAT(pipe), 0);
3279 I915_WRITE(IMR, 0xffffffff);
3280 I915_WRITE(IER, 0x0);
3281 POSTING_READ(IER);
3282}
3283
3284static int i915_irq_postinstall(struct drm_device *dev)
3285{
3286 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003287 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003288 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003289
Chris Wilson38bde182012-04-24 22:59:50 +01003290 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3291
3292 /* Unmask the interrupts that we always want on. */
3293 dev_priv->irq_mask =
3294 ~(I915_ASLE_INTERRUPT |
3295 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3296 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3297 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3298 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3299 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3300
3301 enable_mask =
3302 I915_ASLE_INTERRUPT |
3303 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3304 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3305 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3306 I915_USER_INTERRUPT;
3307
Chris Wilsona266c7d2012-04-24 22:59:44 +01003308 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003309 I915_WRITE(PORT_HOTPLUG_EN, 0);
3310 POSTING_READ(PORT_HOTPLUG_EN);
3311
Chris Wilsona266c7d2012-04-24 22:59:44 +01003312 /* Enable in IER... */
3313 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3314 /* and unmask in IMR */
3315 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3316 }
3317
Chris Wilsona266c7d2012-04-24 22:59:44 +01003318 I915_WRITE(IMR, dev_priv->irq_mask);
3319 I915_WRITE(IER, enable_mask);
3320 POSTING_READ(IER);
3321
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003322 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003323
Daniel Vetter379ef822013-10-16 22:55:56 +02003324 /* Interrupt setup is already guaranteed to be single-threaded, this is
3325 * just to make the assert_spin_locked check happy. */
3326 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003327 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3328 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003329 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3330
Daniel Vetter20afbda2012-12-11 14:05:07 +01003331 return 0;
3332}
3333
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003334/*
3335 * Returns true when a page flip has completed.
3336 */
3337static bool i915_handle_vblank(struct drm_device *dev,
3338 int plane, int pipe, u32 iir)
3339{
3340 drm_i915_private_t *dev_priv = dev->dev_private;
3341 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3342
3343 if (!drm_handle_vblank(dev, pipe))
3344 return false;
3345
3346 if ((iir & flip_pending) == 0)
3347 return false;
3348
3349 intel_prepare_page_flip(dev, plane);
3350
3351 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3352 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3353 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3354 * the flip is completed (no longer pending). Since this doesn't raise
3355 * an interrupt per se, we watch for the change at vblank.
3356 */
3357 if (I915_READ(ISR) & flip_pending)
3358 return false;
3359
3360 intel_finish_page_flip(dev, pipe);
3361
3362 return true;
3363}
3364
Daniel Vetterff1f5252012-10-02 15:10:55 +02003365static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003366{
3367 struct drm_device *dev = (struct drm_device *) arg;
3368 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003369 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003370 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003371 u32 flip_mask =
3372 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3373 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003374 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003375
3376 atomic_inc(&dev_priv->irq_received);
3377
3378 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003379 do {
3380 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003381 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003382
3383 /* Can't rely on pipestat interrupt bit in iir as it might
3384 * have been cleared after the pipestat interrupt was received.
3385 * It doesn't set the bit in iir again, but it still produces
3386 * interrupts (for non-MSI).
3387 */
3388 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3389 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3390 i915_handle_error(dev, false);
3391
3392 for_each_pipe(pipe) {
3393 int reg = PIPESTAT(pipe);
3394 pipe_stats[pipe] = I915_READ(reg);
3395
Chris Wilson38bde182012-04-24 22:59:50 +01003396 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003397 if (pipe_stats[pipe] & 0x8000ffff) {
3398 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3399 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3400 pipe_name(pipe));
3401 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003402 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003403 }
3404 }
3405 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3406
3407 if (!irq_received)
3408 break;
3409
Chris Wilsona266c7d2012-04-24 22:59:44 +01003410 /* Consume port. Then clear IIR or we'll miss events */
3411 if ((I915_HAS_HOTPLUG(dev)) &&
3412 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3413 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003414 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003415
3416 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3417 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003418
3419 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3420
Chris Wilsona266c7d2012-04-24 22:59:44 +01003421 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003422 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003423 }
3424
Chris Wilson38bde182012-04-24 22:59:50 +01003425 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003426 new_iir = I915_READ(IIR); /* Flush posted writes */
3427
Chris Wilsona266c7d2012-04-24 22:59:44 +01003428 if (iir & I915_USER_INTERRUPT)
3429 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003430
Chris Wilsona266c7d2012-04-24 22:59:44 +01003431 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003432 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003433 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003434 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003435
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003436 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3437 i915_handle_vblank(dev, plane, pipe, iir))
3438 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003439
3440 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3441 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003442
3443 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003444 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003445 }
3446
Chris Wilsona266c7d2012-04-24 22:59:44 +01003447 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3448 intel_opregion_asle_intr(dev);
3449
3450 /* With MSI, interrupts are only generated when iir
3451 * transitions from zero to nonzero. If another bit got
3452 * set while we were handling the existing iir bits, then
3453 * we would never get another interrupt.
3454 *
3455 * This is fine on non-MSI as well, as if we hit this path
3456 * we avoid exiting the interrupt handler only to generate
3457 * another one.
3458 *
3459 * Note that for MSI this could cause a stray interrupt report
3460 * if an interrupt landed in the time between writing IIR and
3461 * the posting read. This should be rare enough to never
3462 * trigger the 99% of 100,000 interrupts test for disabling
3463 * stray interrupts.
3464 */
Chris Wilson38bde182012-04-24 22:59:50 +01003465 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003466 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003467 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003468
Daniel Vetterd05c6172012-04-26 23:28:09 +02003469 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003470
Chris Wilsona266c7d2012-04-24 22:59:44 +01003471 return ret;
3472}
3473
3474static void i915_irq_uninstall(struct drm_device * dev)
3475{
3476 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3477 int pipe;
3478
Egbert Eichac4c16c2013-04-16 13:36:58 +02003479 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3480
Chris Wilsona266c7d2012-04-24 22:59:44 +01003481 if (I915_HAS_HOTPLUG(dev)) {
3482 I915_WRITE(PORT_HOTPLUG_EN, 0);
3483 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3484 }
3485
Chris Wilson00d98eb2012-04-24 22:59:48 +01003486 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003487 for_each_pipe(pipe) {
3488 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003489 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003490 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3491 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003492 I915_WRITE(IMR, 0xffffffff);
3493 I915_WRITE(IER, 0x0);
3494
Chris Wilsona266c7d2012-04-24 22:59:44 +01003495 I915_WRITE(IIR, I915_READ(IIR));
3496}
3497
3498static void i965_irq_preinstall(struct drm_device * dev)
3499{
3500 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3501 int pipe;
3502
3503 atomic_set(&dev_priv->irq_received, 0);
3504
Chris Wilsonadca4732012-05-11 18:01:31 +01003505 I915_WRITE(PORT_HOTPLUG_EN, 0);
3506 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003507
3508 I915_WRITE(HWSTAM, 0xeffe);
3509 for_each_pipe(pipe)
3510 I915_WRITE(PIPESTAT(pipe), 0);
3511 I915_WRITE(IMR, 0xffffffff);
3512 I915_WRITE(IER, 0x0);
3513 POSTING_READ(IER);
3514}
3515
3516static int i965_irq_postinstall(struct drm_device *dev)
3517{
3518 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003519 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003520 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003521 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003522
Chris Wilsona266c7d2012-04-24 22:59:44 +01003523 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003524 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003525 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003526 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3527 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3528 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3529 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3530 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3531
3532 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003533 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3534 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003535 enable_mask |= I915_USER_INTERRUPT;
3536
3537 if (IS_G4X(dev))
3538 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003539
Daniel Vetterb79480b2013-06-27 17:52:10 +02003540 /* Interrupt setup is already guaranteed to be single-threaded, this is
3541 * just to make the assert_spin_locked check happy. */
3542 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003543 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
3544 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3545 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003546 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003547
Chris Wilsona266c7d2012-04-24 22:59:44 +01003548 /*
3549 * Enable some error detection, note the instruction error mask
3550 * bit is reserved, so we leave it masked.
3551 */
3552 if (IS_G4X(dev)) {
3553 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3554 GM45_ERROR_MEM_PRIV |
3555 GM45_ERROR_CP_PRIV |
3556 I915_ERROR_MEMORY_REFRESH);
3557 } else {
3558 error_mask = ~(I915_ERROR_PAGE_TABLE |
3559 I915_ERROR_MEMORY_REFRESH);
3560 }
3561 I915_WRITE(EMR, error_mask);
3562
3563 I915_WRITE(IMR, dev_priv->irq_mask);
3564 I915_WRITE(IER, enable_mask);
3565 POSTING_READ(IER);
3566
Daniel Vetter20afbda2012-12-11 14:05:07 +01003567 I915_WRITE(PORT_HOTPLUG_EN, 0);
3568 POSTING_READ(PORT_HOTPLUG_EN);
3569
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003570 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003571
3572 return 0;
3573}
3574
Egbert Eichbac56d52013-02-25 12:06:51 -05003575static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003576{
3577 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003578 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003579 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003580 u32 hotplug_en;
3581
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003582 assert_spin_locked(&dev_priv->irq_lock);
3583
Egbert Eichbac56d52013-02-25 12:06:51 -05003584 if (I915_HAS_HOTPLUG(dev)) {
3585 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3586 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3587 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003588 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003589 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3590 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3591 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003592 /* Programming the CRT detection parameters tends
3593 to generate a spurious hotplug event about three
3594 seconds later. So just do it once.
3595 */
3596 if (IS_G4X(dev))
3597 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003598 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003599 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003600
Egbert Eichbac56d52013-02-25 12:06:51 -05003601 /* Ignore TV since it's buggy */
3602 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3603 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003604}
3605
Daniel Vetterff1f5252012-10-02 15:10:55 +02003606static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003607{
3608 struct drm_device *dev = (struct drm_device *) arg;
3609 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003610 u32 iir, new_iir;
3611 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003612 unsigned long irqflags;
3613 int irq_received;
3614 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003615 u32 flip_mask =
3616 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3617 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003618
3619 atomic_inc(&dev_priv->irq_received);
3620
3621 iir = I915_READ(IIR);
3622
Chris Wilsona266c7d2012-04-24 22:59:44 +01003623 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003624 bool blc_event = false;
3625
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003626 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003627
3628 /* Can't rely on pipestat interrupt bit in iir as it might
3629 * have been cleared after the pipestat interrupt was received.
3630 * It doesn't set the bit in iir again, but it still produces
3631 * interrupts (for non-MSI).
3632 */
3633 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3634 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3635 i915_handle_error(dev, false);
3636
3637 for_each_pipe(pipe) {
3638 int reg = PIPESTAT(pipe);
3639 pipe_stats[pipe] = I915_READ(reg);
3640
3641 /*
3642 * Clear the PIPE*STAT regs before the IIR
3643 */
3644 if (pipe_stats[pipe] & 0x8000ffff) {
3645 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3646 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3647 pipe_name(pipe));
3648 I915_WRITE(reg, pipe_stats[pipe]);
3649 irq_received = 1;
3650 }
3651 }
3652 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3653
3654 if (!irq_received)
3655 break;
3656
3657 ret = IRQ_HANDLED;
3658
3659 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003660 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003661 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003662 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3663 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003664 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003665
3666 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3667 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003668
3669 intel_hpd_irq_handler(dev, hotplug_trigger,
Daniel Vetter704cfb82013-12-18 09:08:43 +01003670 IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003671
Daniel Vetter4aeebd72013-10-31 09:53:36 +01003672 if (IS_G4X(dev) &&
3673 (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
3674 dp_aux_irq_handler(dev);
3675
Chris Wilsona266c7d2012-04-24 22:59:44 +01003676 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3677 I915_READ(PORT_HOTPLUG_STAT);
3678 }
3679
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003680 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003681 new_iir = I915_READ(IIR); /* Flush posted writes */
3682
Chris Wilsona266c7d2012-04-24 22:59:44 +01003683 if (iir & I915_USER_INTERRUPT)
3684 notify_ring(dev, &dev_priv->ring[RCS]);
3685 if (iir & I915_BSD_USER_INTERRUPT)
3686 notify_ring(dev, &dev_priv->ring[VCS]);
3687
Chris Wilsona266c7d2012-04-24 22:59:44 +01003688 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003689 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003690 i915_handle_vblank(dev, pipe, pipe, iir))
3691 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003692
3693 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3694 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003695
3696 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003697 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003698 }
3699
3700
3701 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3702 intel_opregion_asle_intr(dev);
3703
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003704 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3705 gmbus_irq_handler(dev);
3706
Chris Wilsona266c7d2012-04-24 22:59:44 +01003707 /* With MSI, interrupts are only generated when iir
3708 * transitions from zero to nonzero. If another bit got
3709 * set while we were handling the existing iir bits, then
3710 * we would never get another interrupt.
3711 *
3712 * This is fine on non-MSI as well, as if we hit this path
3713 * we avoid exiting the interrupt handler only to generate
3714 * another one.
3715 *
3716 * Note that for MSI this could cause a stray interrupt report
3717 * if an interrupt landed in the time between writing IIR and
3718 * the posting read. This should be rare enough to never
3719 * trigger the 99% of 100,000 interrupts test for disabling
3720 * stray interrupts.
3721 */
3722 iir = new_iir;
3723 }
3724
Daniel Vetterd05c6172012-04-26 23:28:09 +02003725 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003726
Chris Wilsona266c7d2012-04-24 22:59:44 +01003727 return ret;
3728}
3729
3730static void i965_irq_uninstall(struct drm_device * dev)
3731{
3732 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3733 int pipe;
3734
3735 if (!dev_priv)
3736 return;
3737
Egbert Eichac4c16c2013-04-16 13:36:58 +02003738 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3739
Chris Wilsonadca4732012-05-11 18:01:31 +01003740 I915_WRITE(PORT_HOTPLUG_EN, 0);
3741 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003742
3743 I915_WRITE(HWSTAM, 0xffffffff);
3744 for_each_pipe(pipe)
3745 I915_WRITE(PIPESTAT(pipe), 0);
3746 I915_WRITE(IMR, 0xffffffff);
3747 I915_WRITE(IER, 0x0);
3748
3749 for_each_pipe(pipe)
3750 I915_WRITE(PIPESTAT(pipe),
3751 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3752 I915_WRITE(IIR, I915_READ(IIR));
3753}
3754
Egbert Eichac4c16c2013-04-16 13:36:58 +02003755static void i915_reenable_hotplug_timer_func(unsigned long data)
3756{
3757 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3758 struct drm_device *dev = dev_priv->dev;
3759 struct drm_mode_config *mode_config = &dev->mode_config;
3760 unsigned long irqflags;
3761 int i;
3762
3763 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3764 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3765 struct drm_connector *connector;
3766
3767 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3768 continue;
3769
3770 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3771
3772 list_for_each_entry(connector, &mode_config->connector_list, head) {
3773 struct intel_connector *intel_connector = to_intel_connector(connector);
3774
3775 if (intel_connector->encoder->hpd_pin == i) {
3776 if (connector->polled != intel_connector->polled)
3777 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3778 drm_get_connector_name(connector));
3779 connector->polled = intel_connector->polled;
3780 if (!connector->polled)
3781 connector->polled = DRM_CONNECTOR_POLL_HPD;
3782 }
3783 }
3784 }
3785 if (dev_priv->display.hpd_irq_setup)
3786 dev_priv->display.hpd_irq_setup(dev);
3787 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3788}
3789
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003790void intel_irq_init(struct drm_device *dev)
3791{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003792 struct drm_i915_private *dev_priv = dev->dev_private;
3793
3794 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003795 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003796 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003797 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003798
Daniel Vetter99584db2012-11-14 17:14:04 +01003799 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3800 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003801 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003802 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3803 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003804
Tomas Janousek97a19a22012-12-08 13:48:13 +01003805 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003806
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003807 if (IS_GEN2(dev)) {
3808 dev->max_vblank_count = 0;
3809 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3810 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003811 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3812 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003813 } else {
3814 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3815 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003816 }
3817
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003818 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003819 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003820 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3821 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003822
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003823 if (IS_VALLEYVIEW(dev)) {
3824 dev->driver->irq_handler = valleyview_irq_handler;
3825 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3826 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3827 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3828 dev->driver->enable_vblank = valleyview_enable_vblank;
3829 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003830 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003831 } else if (IS_GEN8(dev)) {
3832 dev->driver->irq_handler = gen8_irq_handler;
3833 dev->driver->irq_preinstall = gen8_irq_preinstall;
3834 dev->driver->irq_postinstall = gen8_irq_postinstall;
3835 dev->driver->irq_uninstall = gen8_irq_uninstall;
3836 dev->driver->enable_vblank = gen8_enable_vblank;
3837 dev->driver->disable_vblank = gen8_disable_vblank;
3838 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003839 } else if (HAS_PCH_SPLIT(dev)) {
3840 dev->driver->irq_handler = ironlake_irq_handler;
3841 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3842 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3843 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3844 dev->driver->enable_vblank = ironlake_enable_vblank;
3845 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003846 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003847 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003848 if (INTEL_INFO(dev)->gen == 2) {
3849 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3850 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3851 dev->driver->irq_handler = i8xx_irq_handler;
3852 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003853 } else if (INTEL_INFO(dev)->gen == 3) {
3854 dev->driver->irq_preinstall = i915_irq_preinstall;
3855 dev->driver->irq_postinstall = i915_irq_postinstall;
3856 dev->driver->irq_uninstall = i915_irq_uninstall;
3857 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003858 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003859 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003860 dev->driver->irq_preinstall = i965_irq_preinstall;
3861 dev->driver->irq_postinstall = i965_irq_postinstall;
3862 dev->driver->irq_uninstall = i965_irq_uninstall;
3863 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003864 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003865 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003866 dev->driver->enable_vblank = i915_enable_vblank;
3867 dev->driver->disable_vblank = i915_disable_vblank;
3868 }
3869}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003870
3871void intel_hpd_init(struct drm_device *dev)
3872{
3873 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003874 struct drm_mode_config *mode_config = &dev->mode_config;
3875 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003876 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003877 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003878
Egbert Eich821450c2013-04-16 13:36:55 +02003879 for (i = 1; i < HPD_NUM_PINS; i++) {
3880 dev_priv->hpd_stats[i].hpd_cnt = 0;
3881 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3882 }
3883 list_for_each_entry(connector, &mode_config->connector_list, head) {
3884 struct intel_connector *intel_connector = to_intel_connector(connector);
3885 connector->polled = intel_connector->polled;
3886 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3887 connector->polled = DRM_CONNECTOR_POLL_HPD;
3888 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003889
3890 /* Interrupt setup is already guaranteed to be single-threaded, this is
3891 * just to make the assert_spin_locked checks happy. */
3892 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003893 if (dev_priv->display.hpd_irq_setup)
3894 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003895 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003896}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003897
3898/* Disable interrupts so we can allow Package C8+. */
3899void hsw_pc8_disable_interrupts(struct drm_device *dev)
3900{
3901 struct drm_i915_private *dev_priv = dev->dev_private;
3902 unsigned long irqflags;
3903
3904 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3905
3906 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3907 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3908 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3909 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3910 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3911
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003912 ironlake_disable_display_irq(dev_priv, 0xffffffff);
3913 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003914 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3915 snb_disable_pm_irq(dev_priv, 0xffffffff);
3916
3917 dev_priv->pc8.irqs_disabled = true;
3918
3919 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3920}
3921
3922/* Restore interrupts so we can recover from Package C8+. */
3923void hsw_pc8_restore_interrupts(struct drm_device *dev)
3924{
3925 struct drm_i915_private *dev_priv = dev->dev_private;
3926 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003927 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03003928
3929 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3930
3931 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003932 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003933
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003934 val = I915_READ(SDEIMR);
3935 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003936
3937 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003938 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003939
3940 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003941 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003942
3943 dev_priv->pc8.irqs_disabled = false;
3944
3945 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003946 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003947 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3948 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3949 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3950
3951 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3952}