blob: fb4801c7d9e4959bd927dd8763eb37b4c456c84c [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 {
570 enum transcoder cpu_transcoder =
571 intel_pipe_to_cpu_transcoder(dev_priv, pipe);
572 u32 htotal;
573
574 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
575 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
576
577 vbl_start *= htotal;
578 }
579
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800580 high_frame = PIPEFRAME(pipe);
581 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100582
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700583 /*
584 * High & low register fields aren't synchronized, so make sure
585 * we get a low value that's stable across two reads of the high
586 * register.
587 */
588 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100589 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300590 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100591 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700592 } while (high1 != high2);
593
Chris Wilson5eddb702010-09-11 13:48:45 +0100594 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300595 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100596 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300597
598 /*
599 * The frame counter increments at beginning of active.
600 * Cook up a vblank counter by also checking the pixel
601 * counter against vblank start.
602 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200603 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700604}
605
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700606static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800607{
608 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800609 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800610
611 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800612 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800613 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800614 return 0;
615 }
616
617 return I915_READ(reg);
618}
619
Mario Kleinerad3543e2013-10-30 05:13:08 +0100620/* raw reads, only for fast reads of display block, no need for forcewake etc. */
621#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
622#define __raw_i915_read16(dev_priv__, reg__) readw((dev_priv__)->regs + (reg__))
623
624static bool intel_pipe_in_vblank_locked(struct drm_device *dev, enum pipe pipe)
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300625{
626 struct drm_i915_private *dev_priv = dev->dev_private;
627 uint32_t status;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100628 int reg;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300629
630 if (IS_VALLEYVIEW(dev)) {
631 status = pipe == PIPE_A ?
632 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
633 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
634
Mario Kleinerad3543e2013-10-30 05:13:08 +0100635 reg = VLV_ISR;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300636 } else if (IS_GEN2(dev)) {
637 status = pipe == PIPE_A ?
638 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
639 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
640
Mario Kleinerad3543e2013-10-30 05:13:08 +0100641 reg = ISR;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300642 } else if (INTEL_INFO(dev)->gen < 5) {
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300643 status = pipe == PIPE_A ?
644 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT :
645 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
646
Mario Kleinerad3543e2013-10-30 05:13:08 +0100647 reg = ISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300648 } else if (INTEL_INFO(dev)->gen < 7) {
649 status = pipe == PIPE_A ?
650 DE_PIPEA_VBLANK :
651 DE_PIPEB_VBLANK;
652
Mario Kleinerad3543e2013-10-30 05:13:08 +0100653 reg = DEISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300654 } else {
655 switch (pipe) {
656 default:
657 case PIPE_A:
658 status = DE_PIPEA_VBLANK_IVB;
659 break;
660 case PIPE_B:
661 status = DE_PIPEB_VBLANK_IVB;
662 break;
663 case PIPE_C:
664 status = DE_PIPEC_VBLANK_IVB;
665 break;
666 }
667
Mario Kleinerad3543e2013-10-30 05:13:08 +0100668 reg = DEISR;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300669 }
Mario Kleinerad3543e2013-10-30 05:13:08 +0100670
671 if (IS_GEN2(dev))
672 return __raw_i915_read16(dev_priv, reg) & status;
673 else
674 return __raw_i915_read32(dev_priv, reg) & status;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300675}
676
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700677static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200678 unsigned int flags, int *vpos, int *hpos,
679 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100680{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300681 struct drm_i915_private *dev_priv = dev->dev_private;
682 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
683 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
684 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300685 int position;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100686 int vbl_start, vbl_end, htotal, vtotal;
687 bool in_vbl = true;
688 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100689 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100690
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300691 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100692 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800693 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100694 return 0;
695 }
696
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300697 htotal = mode->crtc_htotal;
698 vtotal = mode->crtc_vtotal;
699 vbl_start = mode->crtc_vblank_start;
700 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100701
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200702 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
703 vbl_start = DIV_ROUND_UP(vbl_start, 2);
704 vbl_end /= 2;
705 vtotal /= 2;
706 }
707
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300708 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
709
Mario Kleinerad3543e2013-10-30 05:13:08 +0100710 /*
711 * Lock uncore.lock, as we will do multiple timing critical raw
712 * register reads, potentially with preemption disabled, so the
713 * following code must not block on uncore.lock.
714 */
715 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
716
717 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
718
719 /* Get optional system timestamp before query. */
720 if (stime)
721 *stime = ktime_get();
722
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300723 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100724 /* No obvious pixelcount register. Only query vertical
725 * scanout position from Display scan line register.
726 */
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300727 if (IS_GEN2(dev))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100728 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300729 else
Mario Kleinerad3543e2013-10-30 05:13:08 +0100730 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300731
732 /*
733 * The scanline counter increments at the leading edge
734 * of hsync, ie. it completely misses the active portion
735 * of the line. Fix up the counter at both edges of vblank
736 * to get a more accurate picture whether we're in vblank
737 * or not.
738 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100739 in_vbl = intel_pipe_in_vblank_locked(dev, pipe);
Ville Syrjälä54ddcbd2013-09-23 13:02:07 +0300740 if ((in_vbl && position == vbl_start - 1) ||
741 (!in_vbl && position == vbl_end - 1))
742 position = (position + 1) % vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100743 } else {
744 /* Have access to pixelcount since start of frame.
745 * We can split this into vertical and horizontal
746 * scanout position.
747 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100748 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100749
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300750 /* convert to pixel counts */
751 vbl_start *= htotal;
752 vbl_end *= htotal;
753 vtotal *= htotal;
754 }
755
Mario Kleinerad3543e2013-10-30 05:13:08 +0100756 /* Get optional system timestamp after query. */
757 if (etime)
758 *etime = ktime_get();
759
760 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
761
762 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
763
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300764 in_vbl = position >= vbl_start && position < vbl_end;
765
766 /*
767 * While in vblank, position will be negative
768 * counting up towards 0 at vbl_end. And outside
769 * vblank, position will be positive counting
770 * up since vbl_end.
771 */
772 if (position >= vbl_start)
773 position -= vbl_end;
774 else
775 position += vtotal - vbl_end;
776
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300777 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300778 *vpos = position;
779 *hpos = 0;
780 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100781 *vpos = position / htotal;
782 *hpos = position - (*vpos * htotal);
783 }
784
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100785 /* In vblank? */
786 if (in_vbl)
787 ret |= DRM_SCANOUTPOS_INVBL;
788
789 return ret;
790}
791
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700792static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100793 int *max_error,
794 struct timeval *vblank_time,
795 unsigned flags)
796{
Chris Wilson4041b852011-01-22 10:07:56 +0000797 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100798
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700799 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000800 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100801 return -EINVAL;
802 }
803
804 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000805 crtc = intel_get_crtc_for_pipe(dev, pipe);
806 if (crtc == NULL) {
807 DRM_ERROR("Invalid crtc %d\n", pipe);
808 return -EINVAL;
809 }
810
811 if (!crtc->enabled) {
812 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
813 return -EBUSY;
814 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100815
816 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000817 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
818 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300819 crtc,
820 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100821}
822
Jani Nikula67c347f2013-09-17 14:26:34 +0300823static bool intel_hpd_irq_event(struct drm_device *dev,
824 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200825{
826 enum drm_connector_status old_status;
827
828 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
829 old_status = connector->status;
830
831 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300832 if (old_status == connector->status)
833 return false;
834
835 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200836 connector->base.id,
837 drm_get_connector_name(connector),
Jani Nikula67c347f2013-09-17 14:26:34 +0300838 drm_get_connector_status_name(old_status),
839 drm_get_connector_status_name(connector->status));
840
841 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200842}
843
Jesse Barnes5ca58282009-03-31 14:11:15 -0700844/*
845 * Handle hotplug events outside the interrupt handler proper.
846 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200847#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
848
Jesse Barnes5ca58282009-03-31 14:11:15 -0700849static void i915_hotplug_work_func(struct work_struct *work)
850{
851 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
852 hotplug_work);
853 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700854 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200855 struct intel_connector *intel_connector;
856 struct intel_encoder *intel_encoder;
857 struct drm_connector *connector;
858 unsigned long irqflags;
859 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200860 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200861 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700862
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100863 /* HPD irq before everything is fully set up. */
864 if (!dev_priv->enable_hotplug_processing)
865 return;
866
Keith Packarda65e34c2011-07-25 10:04:56 -0700867 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800868 DRM_DEBUG_KMS("running encoder hotplug functions\n");
869
Egbert Eichcd569ae2013-04-16 13:36:57 +0200870 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200871
872 hpd_event_bits = dev_priv->hpd_event_bits;
873 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200874 list_for_each_entry(connector, &mode_config->connector_list, head) {
875 intel_connector = to_intel_connector(connector);
876 intel_encoder = intel_connector->encoder;
877 if (intel_encoder->hpd_pin > HPD_NONE &&
878 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
879 connector->polled == DRM_CONNECTOR_POLL_HPD) {
880 DRM_INFO("HPD interrupt storm detected on connector %s: "
881 "switching from hotplug detection to polling\n",
882 drm_get_connector_name(connector));
883 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
884 connector->polled = DRM_CONNECTOR_POLL_CONNECT
885 | DRM_CONNECTOR_POLL_DISCONNECT;
886 hpd_disabled = true;
887 }
Egbert Eich142e2392013-04-11 15:57:57 +0200888 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
889 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
890 drm_get_connector_name(connector), intel_encoder->hpd_pin);
891 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200892 }
893 /* if there were no outputs to poll, poll was disabled,
894 * therefore make sure it's enabled when disabling HPD on
895 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200896 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200897 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200898 mod_timer(&dev_priv->hotplug_reenable_timer,
899 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
900 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200901
902 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
903
Egbert Eich321a1b32013-04-11 16:00:26 +0200904 list_for_each_entry(connector, &mode_config->connector_list, head) {
905 intel_connector = to_intel_connector(connector);
906 intel_encoder = intel_connector->encoder;
907 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
908 if (intel_encoder->hot_plug)
909 intel_encoder->hot_plug(intel_encoder);
910 if (intel_hpd_irq_event(dev, connector))
911 changed = true;
912 }
913 }
Keith Packard40ee3382011-07-28 15:31:19 -0700914 mutex_unlock(&mode_config->mutex);
915
Egbert Eich321a1b32013-04-11 16:00:26 +0200916 if (changed)
917 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700918}
919
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200920static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800921{
922 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000923 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200924 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200925
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200926 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800927
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200928 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
929
Daniel Vetter20e4d402012-08-08 23:35:39 +0200930 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200931
Jesse Barnes7648fa92010-05-20 14:28:11 -0700932 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000933 busy_up = I915_READ(RCPREVBSYTUPAVG);
934 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800935 max_avg = I915_READ(RCBMAXAVG);
936 min_avg = I915_READ(RCBMINAVG);
937
938 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000939 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200940 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
941 new_delay = dev_priv->ips.cur_delay - 1;
942 if (new_delay < dev_priv->ips.max_delay)
943 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000944 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200945 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
946 new_delay = dev_priv->ips.cur_delay + 1;
947 if (new_delay > dev_priv->ips.min_delay)
948 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800949 }
950
Jesse Barnes7648fa92010-05-20 14:28:11 -0700951 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200952 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800953
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200954 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200955
Jesse Barnesf97108d2010-01-29 11:27:07 -0800956 return;
957}
958
Chris Wilson549f7362010-10-19 11:19:32 +0100959static void notify_ring(struct drm_device *dev,
960 struct intel_ring_buffer *ring)
961{
Chris Wilson475553d2011-01-20 09:52:56 +0000962 if (ring->obj == NULL)
963 return;
964
Chris Wilson814e9b52013-09-23 17:33:19 -0300965 trace_i915_gem_request_complete(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000966
Chris Wilson549f7362010-10-19 11:19:32 +0100967 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300968 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100969}
970
Ben Widawsky4912d042011-04-25 11:25:20 -0700971static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800972{
Ben Widawsky4912d042011-04-25 11:25:20 -0700973 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200974 rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300975 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100976 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800977
Daniel Vetter59cdb632013-07-04 23:35:28 +0200978 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200979 pm_iir = dev_priv->rps.pm_iir;
980 dev_priv->rps.pm_iir = 0;
Ben Widawsky48484052013-05-28 19:22:27 -0700981 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300982 snb_enable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200983 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700984
Paulo Zanoni60611c12013-08-15 11:50:01 -0300985 /* Make sure we didn't queue anything we're not going to process. */
986 WARN_ON(pm_iir & ~GEN6_PM_RPS_EVENTS);
987
Ben Widawsky48484052013-05-28 19:22:27 -0700988 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800989 return;
990
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700991 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100992
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100993 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +0300994 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100995 if (adj > 0)
996 adj *= 2;
997 else
998 adj = 1;
999 new_delay = dev_priv->rps.cur_delay + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001000
1001 /*
1002 * For better performance, jump directly
1003 * to RPe if we're below it.
1004 */
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001005 if (new_delay < dev_priv->rps.rpe_delay)
Ville Syrjälä74250342013-06-25 21:38:11 +03001006 new_delay = dev_priv->rps.rpe_delay;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001007 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
1008 if (dev_priv->rps.cur_delay > dev_priv->rps.rpe_delay)
1009 new_delay = dev_priv->rps.rpe_delay;
1010 else
1011 new_delay = dev_priv->rps.min_delay;
1012 adj = 0;
1013 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1014 if (adj < 0)
1015 adj *= 2;
1016 else
1017 adj = -1;
1018 new_delay = dev_priv->rps.cur_delay + adj;
1019 } else { /* unknown event */
1020 new_delay = dev_priv->rps.cur_delay;
1021 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001022
Ben Widawsky79249632012-09-07 19:43:42 -07001023 /* sysfs frequency interfaces may have snuck in while servicing the
1024 * interrupt
1025 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001026 new_delay = clamp_t(int, new_delay,
1027 dev_priv->rps.min_delay, dev_priv->rps.max_delay);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001028 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_delay;
1029
1030 if (IS_VALLEYVIEW(dev_priv->dev))
1031 valleyview_set_rps(dev_priv->dev, new_delay);
1032 else
1033 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001034
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001035 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001036}
1037
Ben Widawskye3689192012-05-25 16:56:22 -07001038
1039/**
1040 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1041 * occurred.
1042 * @work: workqueue struct
1043 *
1044 * Doesn't actually do anything except notify userspace. As a consequence of
1045 * this event, userspace should try to remap the bad rows since statistically
1046 * it is likely the same row is more likely to go bad again.
1047 */
1048static void ivybridge_parity_work(struct work_struct *work)
1049{
1050 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001051 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001052 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001053 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001054 uint32_t misccpctl;
1055 unsigned long flags;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001056 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001057
1058 /* We must turn off DOP level clock gating to access the L3 registers.
1059 * In order to prevent a get/put style interface, acquire struct mutex
1060 * any time we access those registers.
1061 */
1062 mutex_lock(&dev_priv->dev->struct_mutex);
1063
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001064 /* If we've screwed up tracking, just let the interrupt fire again */
1065 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1066 goto out;
1067
Ben Widawskye3689192012-05-25 16:56:22 -07001068 misccpctl = I915_READ(GEN7_MISCCPCTL);
1069 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1070 POSTING_READ(GEN7_MISCCPCTL);
1071
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001072 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1073 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001074
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001075 slice--;
1076 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1077 break;
1078
1079 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1080
1081 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1082
1083 error_status = I915_READ(reg);
1084 row = GEN7_PARITY_ERROR_ROW(error_status);
1085 bank = GEN7_PARITY_ERROR_BANK(error_status);
1086 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1087
1088 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1089 POSTING_READ(reg);
1090
1091 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1092 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1093 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1094 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1095 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1096 parity_event[5] = NULL;
1097
Dave Airlie5bdebb12013-10-11 14:07:25 +10001098 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001099 KOBJ_CHANGE, parity_event);
1100
1101 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1102 slice, row, bank, subbank);
1103
1104 kfree(parity_event[4]);
1105 kfree(parity_event[3]);
1106 kfree(parity_event[2]);
1107 kfree(parity_event[1]);
1108 }
Ben Widawskye3689192012-05-25 16:56:22 -07001109
1110 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1111
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001112out:
1113 WARN_ON(dev_priv->l3_parity.which_slice);
Ben Widawskye3689192012-05-25 16:56:22 -07001114 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001115 ilk_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Ben Widawskye3689192012-05-25 16:56:22 -07001116 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
1117
1118 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001119}
1120
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001121static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001122{
1123 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001124
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001125 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001126 return;
1127
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001128 spin_lock(&dev_priv->irq_lock);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001129 ilk_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001130 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001131
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001132 iir &= GT_PARITY_ERROR(dev);
1133 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1134 dev_priv->l3_parity.which_slice |= 1 << 1;
1135
1136 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1137 dev_priv->l3_parity.which_slice |= 1 << 0;
1138
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001139 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001140}
1141
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001142static void ilk_gt_irq_handler(struct drm_device *dev,
1143 struct drm_i915_private *dev_priv,
1144 u32 gt_iir)
1145{
1146 if (gt_iir &
1147 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1148 notify_ring(dev, &dev_priv->ring[RCS]);
1149 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1150 notify_ring(dev, &dev_priv->ring[VCS]);
1151}
1152
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001153static void snb_gt_irq_handler(struct drm_device *dev,
1154 struct drm_i915_private *dev_priv,
1155 u32 gt_iir)
1156{
1157
Ben Widawskycc609d52013-05-28 19:22:29 -07001158 if (gt_iir &
1159 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001160 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001161 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001162 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001163 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001164 notify_ring(dev, &dev_priv->ring[BCS]);
1165
Ben Widawskycc609d52013-05-28 19:22:29 -07001166 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1167 GT_BSD_CS_ERROR_INTERRUPT |
1168 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001169 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
1170 i915_handle_error(dev, false);
1171 }
Ben Widawskye3689192012-05-25 16:56:22 -07001172
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001173 if (gt_iir & GT_PARITY_ERROR(dev))
1174 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001175}
1176
Ben Widawskyabd58f02013-11-02 21:07:09 -07001177static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1178 struct drm_i915_private *dev_priv,
1179 u32 master_ctl)
1180{
1181 u32 rcs, bcs, vcs;
1182 uint32_t tmp = 0;
1183 irqreturn_t ret = IRQ_NONE;
1184
1185 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1186 tmp = I915_READ(GEN8_GT_IIR(0));
1187 if (tmp) {
1188 ret = IRQ_HANDLED;
1189 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
1190 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1191 if (rcs & GT_RENDER_USER_INTERRUPT)
1192 notify_ring(dev, &dev_priv->ring[RCS]);
1193 if (bcs & GT_RENDER_USER_INTERRUPT)
1194 notify_ring(dev, &dev_priv->ring[BCS]);
1195 I915_WRITE(GEN8_GT_IIR(0), tmp);
1196 } else
1197 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1198 }
1199
1200 if (master_ctl & GEN8_GT_VCS1_IRQ) {
1201 tmp = I915_READ(GEN8_GT_IIR(1));
1202 if (tmp) {
1203 ret = IRQ_HANDLED;
1204 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
1205 if (vcs & GT_RENDER_USER_INTERRUPT)
1206 notify_ring(dev, &dev_priv->ring[VCS]);
1207 I915_WRITE(GEN8_GT_IIR(1), tmp);
1208 } else
1209 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1210 }
1211
1212 if (master_ctl & GEN8_GT_VECS_IRQ) {
1213 tmp = I915_READ(GEN8_GT_IIR(3));
1214 if (tmp) {
1215 ret = IRQ_HANDLED;
1216 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
1217 if (vcs & GT_RENDER_USER_INTERRUPT)
1218 notify_ring(dev, &dev_priv->ring[VECS]);
1219 I915_WRITE(GEN8_GT_IIR(3), tmp);
1220 } else
1221 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1222 }
1223
1224 return ret;
1225}
1226
Egbert Eichb543fb02013-04-16 13:36:54 +02001227#define HPD_STORM_DETECT_PERIOD 1000
1228#define HPD_STORM_THRESHOLD 5
1229
Daniel Vetter10a504d2013-06-27 17:52:12 +02001230static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001231 u32 hotplug_trigger,
1232 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001233{
1234 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001235 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001236 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +02001237
Daniel Vetter91d131d2013-06-27 17:52:14 +02001238 if (!hotplug_trigger)
1239 return;
1240
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001241 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001242 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +02001243
Chris Wilson34320872014-01-10 18:49:20 +00001244 WARN_ONCE(hpd[i] & hotplug_trigger &&
Chris Wilson8b5565b2014-01-10 18:49:21 +00001245 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED,
Chris Wilsoncba1c072014-01-10 20:17:07 +00001246 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1247 hotplug_trigger, i, hpd[i]);
Egbert Eichb8f102e2013-07-26 14:14:24 +02001248
Egbert Eichb543fb02013-04-16 13:36:54 +02001249 if (!(hpd[i] & hotplug_trigger) ||
1250 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1251 continue;
1252
Jani Nikulabc5ead8c2013-05-07 15:10:29 +03001253 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001254 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1255 dev_priv->hpd_stats[i].hpd_last_jiffies
1256 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1257 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1258 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001259 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001260 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1261 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001262 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001263 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001264 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001265 } else {
1266 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001267 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1268 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001269 }
1270 }
1271
Daniel Vetter10a504d2013-06-27 17:52:12 +02001272 if (storm_detected)
1273 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001274 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001275
Daniel Vetter645416f2013-09-02 16:22:25 +02001276 /*
1277 * Our hotplug handler can grab modeset locks (by calling down into the
1278 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1279 * queue for otherwise the flush_work in the pageflip code will
1280 * deadlock.
1281 */
1282 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001283}
1284
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001285static void gmbus_irq_handler(struct drm_device *dev)
1286{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001287 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1288
Daniel Vetter28c70f12012-12-01 13:53:45 +01001289 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001290}
1291
Daniel Vetterce99c252012-12-01 13:53:47 +01001292static void dp_aux_irq_handler(struct drm_device *dev)
1293{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001294 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
1295
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001296 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001297}
1298
Shuang He8bf1e9f2013-10-15 18:55:27 +01001299#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001300static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1301 uint32_t crc0, uint32_t crc1,
1302 uint32_t crc2, uint32_t crc3,
1303 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001304{
1305 struct drm_i915_private *dev_priv = dev->dev_private;
1306 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1307 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001308 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001309
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001310 spin_lock(&pipe_crc->lock);
1311
Damien Lespiau0c912c72013-10-15 18:55:37 +01001312 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001313 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001314 DRM_ERROR("spurious interrupt\n");
1315 return;
1316 }
1317
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001318 head = pipe_crc->head;
1319 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001320
1321 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001322 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001323 DRM_ERROR("CRC buffer overflowing\n");
1324 return;
1325 }
1326
1327 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001328
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001329 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001330 entry->crc[0] = crc0;
1331 entry->crc[1] = crc1;
1332 entry->crc[2] = crc2;
1333 entry->crc[3] = crc3;
1334 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001335
1336 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001337 pipe_crc->head = head;
1338
1339 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001340
1341 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001342}
Daniel Vetter277de952013-10-18 16:37:07 +02001343#else
1344static inline void
1345display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1346 uint32_t crc0, uint32_t crc1,
1347 uint32_t crc2, uint32_t crc3,
1348 uint32_t crc4) {}
1349#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001350
Daniel Vetter277de952013-10-18 16:37:07 +02001351
1352static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001353{
1354 struct drm_i915_private *dev_priv = dev->dev_private;
1355
Daniel Vetter277de952013-10-18 16:37:07 +02001356 display_pipe_crc_irq_handler(dev, pipe,
1357 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1358 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001359}
1360
Daniel Vetter277de952013-10-18 16:37:07 +02001361static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001362{
1363 struct drm_i915_private *dev_priv = dev->dev_private;
1364
Daniel Vetter277de952013-10-18 16:37:07 +02001365 display_pipe_crc_irq_handler(dev, pipe,
1366 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1367 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1368 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1369 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1370 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001371}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001372
Daniel Vetter277de952013-10-18 16:37:07 +02001373static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001374{
1375 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001376 uint32_t res1, res2;
1377
1378 if (INTEL_INFO(dev)->gen >= 3)
1379 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1380 else
1381 res1 = 0;
1382
1383 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1384 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1385 else
1386 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001387
Daniel Vetter277de952013-10-18 16:37:07 +02001388 display_pipe_crc_irq_handler(dev, pipe,
1389 I915_READ(PIPE_CRC_RES_RED(pipe)),
1390 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1391 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1392 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001393}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001394
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001395/* The RPS events need forcewake, so we add them to a work queue and mask their
1396 * IMR bits until the work is done. Other interrupts can be processed without
1397 * the work queue. */
1398static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001399{
Daniel Vetter41a05a32013-07-04 23:35:26 +02001400 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001401 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +02001402 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Paulo Zanoni4d3b3d52013-08-09 17:04:36 -03001403 snb_disable_pm_irq(dev_priv, pm_iir & GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001404 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +02001405
1406 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001407 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001408
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001409 if (HAS_VEBOX(dev_priv->dev)) {
1410 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1411 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001412
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001413 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
1414 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
1415 i915_handle_error(dev_priv->dev, false);
1416 }
Ben Widawsky12638c52013-05-28 19:22:31 -07001417 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001418}
1419
Daniel Vetterff1f5252012-10-02 15:10:55 +02001420static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001421{
1422 struct drm_device *dev = (struct drm_device *) arg;
1423 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1424 u32 iir, gt_iir, pm_iir;
1425 irqreturn_t ret = IRQ_NONE;
1426 unsigned long irqflags;
1427 int pipe;
1428 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001429
1430 atomic_inc(&dev_priv->irq_received);
1431
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001432 while (true) {
1433 iir = I915_READ(VLV_IIR);
1434 gt_iir = I915_READ(GTIIR);
1435 pm_iir = I915_READ(GEN6_PMIIR);
1436
1437 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1438 goto out;
1439
1440 ret = IRQ_HANDLED;
1441
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001442 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001443
1444 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1445 for_each_pipe(pipe) {
1446 int reg = PIPESTAT(pipe);
1447 pipe_stats[pipe] = I915_READ(reg);
1448
1449 /*
1450 * Clear the PIPE*STAT regs before the IIR
1451 */
1452 if (pipe_stats[pipe] & 0x8000ffff) {
1453 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1454 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1455 pipe_name(pipe));
1456 I915_WRITE(reg, pipe_stats[pipe]);
1457 }
1458 }
1459 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1460
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001461 for_each_pipe(pipe) {
Jesse Barnes7b5562d2013-11-05 15:48:01 -08001462 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001463 drm_handle_vblank(dev, pipe);
1464
1465 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1466 intel_prepare_page_flip(dev, pipe);
1467 intel_finish_page_flip(dev, pipe);
1468 }
Daniel Vetter4356d582013-10-16 22:55:55 +02001469
1470 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02001471 i9xx_pipe_crc_irq_handler(dev, pipe);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001472 }
1473
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001474 /* Consume port. Then clear IIR or we'll miss events */
1475 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1476 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001477 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001478
1479 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1480 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001481
1482 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1483
Daniel Vetter4aeebd72013-10-31 09:53:36 +01001484 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1485 dp_aux_irq_handler(dev);
1486
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001487 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1488 I915_READ(PORT_HOTPLUG_STAT);
1489 }
1490
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001491 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1492 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001493
Paulo Zanoni60611c12013-08-15 11:50:01 -03001494 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001495 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001496
1497 I915_WRITE(GTIIR, gt_iir);
1498 I915_WRITE(GEN6_PMIIR, pm_iir);
1499 I915_WRITE(VLV_IIR, iir);
1500 }
1501
1502out:
1503 return ret;
1504}
1505
Adam Jackson23e81d62012-06-06 15:45:44 -04001506static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001507{
1508 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001509 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001510 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001511
Daniel Vetter91d131d2013-06-27 17:52:14 +02001512 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1513
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001514 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1515 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1516 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001517 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001518 port_name(port));
1519 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001520
Daniel Vetterce99c252012-12-01 13:53:47 +01001521 if (pch_iir & SDE_AUX_MASK)
1522 dp_aux_irq_handler(dev);
1523
Jesse Barnes776ad802011-01-04 15:09:39 -08001524 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001525 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001526
1527 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1528 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1529
1530 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1531 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1532
1533 if (pch_iir & SDE_POISON)
1534 DRM_ERROR("PCH poison interrupt\n");
1535
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001536 if (pch_iir & SDE_FDI_MASK)
1537 for_each_pipe(pipe)
1538 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1539 pipe_name(pipe),
1540 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001541
1542 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1543 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1544
1545 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1546 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1547
Jesse Barnes776ad802011-01-04 15:09:39 -08001548 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001549 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1550 false))
1551 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1552
1553 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1554 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1555 false))
1556 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1557}
1558
1559static void ivb_err_int_handler(struct drm_device *dev)
1560{
1561 struct drm_i915_private *dev_priv = dev->dev_private;
1562 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001563 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001564
Paulo Zanonide032bf2013-04-12 17:57:58 -03001565 if (err_int & ERR_INT_POISON)
1566 DRM_ERROR("Poison interrupt\n");
1567
Daniel Vetter5a69b892013-10-16 22:55:52 +02001568 for_each_pipe(pipe) {
1569 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) {
1570 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1571 false))
1572 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1573 pipe_name(pipe));
1574 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001575
Daniel Vetter5a69b892013-10-16 22:55:52 +02001576 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1577 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001578 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001579 else
Daniel Vetter277de952013-10-18 16:37:07 +02001580 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001581 }
1582 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001583
Paulo Zanoni86642812013-04-12 17:57:57 -03001584 I915_WRITE(GEN7_ERR_INT, err_int);
1585}
1586
1587static void cpt_serr_int_handler(struct drm_device *dev)
1588{
1589 struct drm_i915_private *dev_priv = dev->dev_private;
1590 u32 serr_int = I915_READ(SERR_INT);
1591
Paulo Zanonide032bf2013-04-12 17:57:58 -03001592 if (serr_int & SERR_INT_POISON)
1593 DRM_ERROR("PCH poison interrupt\n");
1594
Paulo Zanoni86642812013-04-12 17:57:57 -03001595 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1596 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1597 false))
1598 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1599
1600 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1601 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1602 false))
1603 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1604
1605 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1606 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1607 false))
1608 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1609
1610 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001611}
1612
Adam Jackson23e81d62012-06-06 15:45:44 -04001613static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1614{
1615 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1616 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001617 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001618
Daniel Vetter91d131d2013-06-27 17:52:14 +02001619 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1620
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001621 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1622 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1623 SDE_AUDIO_POWER_SHIFT_CPT);
1624 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1625 port_name(port));
1626 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001627
1628 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001629 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001630
1631 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001632 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001633
1634 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1635 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1636
1637 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1638 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1639
1640 if (pch_iir & SDE_FDI_MASK_CPT)
1641 for_each_pipe(pipe)
1642 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1643 pipe_name(pipe),
1644 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001645
1646 if (pch_iir & SDE_ERROR_CPT)
1647 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001648}
1649
Paulo Zanonic008bc62013-07-12 16:35:10 -03001650static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1651{
1652 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001653 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001654
1655 if (de_iir & DE_AUX_CHANNEL_A)
1656 dp_aux_irq_handler(dev);
1657
1658 if (de_iir & DE_GSE)
1659 intel_opregion_asle_intr(dev);
1660
Paulo Zanonic008bc62013-07-12 16:35:10 -03001661 if (de_iir & DE_POISON)
1662 DRM_ERROR("Poison interrupt\n");
1663
Daniel Vetter40da17c2013-10-21 18:04:36 +02001664 for_each_pipe(pipe) {
1665 if (de_iir & DE_PIPE_VBLANK(pipe))
1666 drm_handle_vblank(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001667
Daniel Vetter40da17c2013-10-21 18:04:36 +02001668 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
1669 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe, false))
1670 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1671 pipe_name(pipe));
Paulo Zanonic008bc62013-07-12 16:35:10 -03001672
Daniel Vetter40da17c2013-10-21 18:04:36 +02001673 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1674 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001675
Daniel Vetter40da17c2013-10-21 18:04:36 +02001676 /* plane/pipes map 1:1 on ilk+ */
1677 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1678 intel_prepare_page_flip(dev, pipe);
1679 intel_finish_page_flip_plane(dev, pipe);
1680 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001681 }
1682
1683 /* check event from PCH */
1684 if (de_iir & DE_PCH_EVENT) {
1685 u32 pch_iir = I915_READ(SDEIIR);
1686
1687 if (HAS_PCH_CPT(dev))
1688 cpt_irq_handler(dev, pch_iir);
1689 else
1690 ibx_irq_handler(dev, pch_iir);
1691
1692 /* should clear PCH hotplug event before clear CPU irq */
1693 I915_WRITE(SDEIIR, pch_iir);
1694 }
1695
1696 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1697 ironlake_rps_change_irq_handler(dev);
1698}
1699
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001700static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1701{
1702 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001703 enum pipe i;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001704
1705 if (de_iir & DE_ERR_INT_IVB)
1706 ivb_err_int_handler(dev);
1707
1708 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1709 dp_aux_irq_handler(dev);
1710
1711 if (de_iir & DE_GSE_IVB)
1712 intel_opregion_asle_intr(dev);
1713
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02001714 for_each_pipe(i) {
Daniel Vetter40da17c2013-10-21 18:04:36 +02001715 if (de_iir & (DE_PIPE_VBLANK_IVB(i)))
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001716 drm_handle_vblank(dev, i);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001717
1718 /* plane/pipes map 1:1 on ilk+ */
1719 if (de_iir & DE_PLANE_FLIP_DONE_IVB(i)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001720 intel_prepare_page_flip(dev, i);
1721 intel_finish_page_flip_plane(dev, i);
1722 }
1723 }
1724
1725 /* check event from PCH */
1726 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1727 u32 pch_iir = I915_READ(SDEIIR);
1728
1729 cpt_irq_handler(dev, pch_iir);
1730
1731 /* clear PCH hotplug event before clear CPU irq */
1732 I915_WRITE(SDEIIR, pch_iir);
1733 }
1734}
1735
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001736static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001737{
1738 struct drm_device *dev = (struct drm_device *) arg;
1739 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001740 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001741 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001742
1743 atomic_inc(&dev_priv->irq_received);
1744
Paulo Zanoni86642812013-04-12 17:57:57 -03001745 /* We get interrupts on unclaimed registers, so check for this before we
1746 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001747 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001748
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001749 /* disable master interrupt before clearing iir */
1750 de_ier = I915_READ(DEIER);
1751 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001752 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001753
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001754 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1755 * interrupts will will be stored on its back queue, and then we'll be
1756 * able to process them after we restore SDEIER (as soon as we restore
1757 * it, we'll get an interrupt if SDEIIR still has something to process
1758 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001759 if (!HAS_PCH_NOP(dev)) {
1760 sde_ier = I915_READ(SDEIER);
1761 I915_WRITE(SDEIER, 0);
1762 POSTING_READ(SDEIER);
1763 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001764
Chris Wilson0e434062012-05-09 21:45:44 +01001765 gt_iir = I915_READ(GTIIR);
1766 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001767 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001768 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001769 else
1770 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001771 I915_WRITE(GTIIR, gt_iir);
1772 ret = IRQ_HANDLED;
1773 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001774
1775 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001776 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001777 if (INTEL_INFO(dev)->gen >= 7)
1778 ivb_display_irq_handler(dev, de_iir);
1779 else
1780 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001781 I915_WRITE(DEIIR, de_iir);
1782 ret = IRQ_HANDLED;
1783 }
1784
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001785 if (INTEL_INFO(dev)->gen >= 6) {
1786 u32 pm_iir = I915_READ(GEN6_PMIIR);
1787 if (pm_iir) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001788 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001789 I915_WRITE(GEN6_PMIIR, pm_iir);
1790 ret = IRQ_HANDLED;
1791 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001792 }
1793
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001794 I915_WRITE(DEIER, de_ier);
1795 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001796 if (!HAS_PCH_NOP(dev)) {
1797 I915_WRITE(SDEIER, sde_ier);
1798 POSTING_READ(SDEIER);
1799 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001800
1801 return ret;
1802}
1803
Ben Widawskyabd58f02013-11-02 21:07:09 -07001804static irqreturn_t gen8_irq_handler(int irq, void *arg)
1805{
1806 struct drm_device *dev = arg;
1807 struct drm_i915_private *dev_priv = dev->dev_private;
1808 u32 master_ctl;
1809 irqreturn_t ret = IRQ_NONE;
1810 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01001811 enum pipe pipe;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001812
1813 atomic_inc(&dev_priv->irq_received);
1814
1815 master_ctl = I915_READ(GEN8_MASTER_IRQ);
1816 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
1817 if (!master_ctl)
1818 return IRQ_NONE;
1819
1820 I915_WRITE(GEN8_MASTER_IRQ, 0);
1821 POSTING_READ(GEN8_MASTER_IRQ);
1822
1823 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
1824
1825 if (master_ctl & GEN8_DE_MISC_IRQ) {
1826 tmp = I915_READ(GEN8_DE_MISC_IIR);
1827 if (tmp & GEN8_DE_MISC_GSE)
1828 intel_opregion_asle_intr(dev);
1829 else if (tmp)
1830 DRM_ERROR("Unexpected DE Misc interrupt\n");
1831 else
1832 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
1833
1834 if (tmp) {
1835 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
1836 ret = IRQ_HANDLED;
1837 }
1838 }
1839
Daniel Vetter6d766f02013-11-07 14:49:55 +01001840 if (master_ctl & GEN8_DE_PORT_IRQ) {
1841 tmp = I915_READ(GEN8_DE_PORT_IIR);
1842 if (tmp & GEN8_AUX_CHANNEL_A)
1843 dp_aux_irq_handler(dev);
1844 else if (tmp)
1845 DRM_ERROR("Unexpected DE Port interrupt\n");
1846 else
1847 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
1848
1849 if (tmp) {
1850 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
1851 ret = IRQ_HANDLED;
1852 }
1853 }
1854
Daniel Vetterc42664c2013-11-07 11:05:40 +01001855 for_each_pipe(pipe) {
1856 uint32_t pipe_iir;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001857
Daniel Vetterc42664c2013-11-07 11:05:40 +01001858 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
1859 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001860
Daniel Vetterc42664c2013-11-07 11:05:40 +01001861 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
1862 if (pipe_iir & GEN8_PIPE_VBLANK)
1863 drm_handle_vblank(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001864
Daniel Vetterc42664c2013-11-07 11:05:40 +01001865 if (pipe_iir & GEN8_PIPE_FLIP_DONE) {
1866 intel_prepare_page_flip(dev, pipe);
1867 intel_finish_page_flip_plane(dev, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001868 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001869
Daniel Vetter0fbe7872013-11-07 11:05:44 +01001870 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
1871 hsw_pipe_crc_irq_handler(dev, pipe);
1872
Daniel Vetter38d83c962013-11-07 11:05:46 +01001873 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN) {
1874 if (intel_set_cpu_fifo_underrun_reporting(dev, pipe,
1875 false))
1876 DRM_DEBUG_DRIVER("Pipe %c FIFO underrun\n",
1877 pipe_name(pipe));
1878 }
1879
Daniel Vetter30100f22013-11-07 14:49:24 +01001880 if (pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS) {
1881 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
1882 pipe_name(pipe),
1883 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
1884 }
Daniel Vetterc42664c2013-11-07 11:05:40 +01001885
1886 if (pipe_iir) {
1887 ret = IRQ_HANDLED;
1888 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
1889 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07001890 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
1891 }
1892
Daniel Vetter92d03a82013-11-07 11:05:43 +01001893 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
1894 /*
1895 * FIXME(BDW): Assume for now that the new interrupt handling
1896 * scheme also closed the SDE interrupt handling race we've seen
1897 * on older pch-split platforms. But this needs testing.
1898 */
1899 u32 pch_iir = I915_READ(SDEIIR);
1900
1901 cpt_irq_handler(dev, pch_iir);
1902
1903 if (pch_iir) {
1904 I915_WRITE(SDEIIR, pch_iir);
1905 ret = IRQ_HANDLED;
1906 }
1907 }
1908
Ben Widawskyabd58f02013-11-02 21:07:09 -07001909 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
1910 POSTING_READ(GEN8_MASTER_IRQ);
1911
1912 return ret;
1913}
1914
Daniel Vetter17e1df02013-09-08 21:57:13 +02001915static void i915_error_wake_up(struct drm_i915_private *dev_priv,
1916 bool reset_completed)
1917{
1918 struct intel_ring_buffer *ring;
1919 int i;
1920
1921 /*
1922 * Notify all waiters for GPU completion events that reset state has
1923 * been changed, and that they need to restart their wait after
1924 * checking for potential errors (and bail out to drop locks if there is
1925 * a gpu reset pending so that i915_error_work_func can acquire them).
1926 */
1927
1928 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
1929 for_each_ring(ring, dev_priv, i)
1930 wake_up_all(&ring->irq_queue);
1931
1932 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
1933 wake_up_all(&dev_priv->pending_flip_queue);
1934
1935 /*
1936 * Signal tasks blocked in i915_gem_wait_for_error that the pending
1937 * reset state is cleared.
1938 */
1939 if (reset_completed)
1940 wake_up_all(&dev_priv->gpu_error.reset_queue);
1941}
1942
Jesse Barnes8a905232009-07-11 16:48:03 -04001943/**
1944 * i915_error_work_func - do process context error handling work
1945 * @work: work struct
1946 *
1947 * Fire an error uevent so userspace can see that a hang or error
1948 * was detected.
1949 */
1950static void i915_error_work_func(struct work_struct *work)
1951{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001952 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1953 work);
1954 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1955 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001956 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07001957 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1958 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1959 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02001960 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001961
Dave Airlie5bdebb12013-10-11 14:07:25 +10001962 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001963
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001964 /*
1965 * Note that there's only one work item which does gpu resets, so we
1966 * need not worry about concurrent gpu resets potentially incrementing
1967 * error->reset_counter twice. We only need to take care of another
1968 * racing irq/hangcheck declaring the gpu dead for a second time. A
1969 * quick check for that is good enough: schedule_work ensures the
1970 * correct ordering between hang detection and this work item, and since
1971 * the reset in-progress bit is only ever set by code outside of this
1972 * work we don't need to worry about any other races.
1973 */
1974 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001975 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10001976 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001977 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001978
Daniel Vetter17e1df02013-09-08 21:57:13 +02001979 /*
1980 * All state reset _must_ be completed before we update the
1981 * reset counter, for otherwise waiters might miss the reset
1982 * pending state and not properly drop locks, resulting in
1983 * deadlocks with the reset work.
1984 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01001985 ret = i915_reset(dev);
1986
Daniel Vetter17e1df02013-09-08 21:57:13 +02001987 intel_display_handle_reset(dev);
1988
Daniel Vetterf69061b2012-12-06 09:01:42 +01001989 if (ret == 0) {
1990 /*
1991 * After all the gem state is reset, increment the reset
1992 * counter and wake up everyone waiting for the reset to
1993 * complete.
1994 *
1995 * Since unlock operations are a one-sided barrier only,
1996 * we need to insert a barrier here to order any seqno
1997 * updates before
1998 * the counter increment.
1999 */
2000 smp_mb__before_atomic_inc();
2001 atomic_inc(&dev_priv->gpu_error.reset_counter);
2002
Dave Airlie5bdebb12013-10-11 14:07:25 +10002003 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002004 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002005 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002006 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002007 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002008
Daniel Vetter17e1df02013-09-08 21:57:13 +02002009 /*
2010 * Note: The wake_up also serves as a memory barrier so that
2011 * waiters see the update value of the reset counter atomic_t.
2012 */
2013 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002014 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002015}
2016
Chris Wilson35aed2e2010-05-27 13:18:12 +01002017static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002018{
2019 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002020 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002021 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002022 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002023
Chris Wilson35aed2e2010-05-27 13:18:12 +01002024 if (!eir)
2025 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002026
Joe Perchesa70491c2012-03-18 13:00:11 -07002027 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002028
Ben Widawskybd9854f2012-08-23 15:18:09 -07002029 i915_get_extra_instdone(dev, instdone);
2030
Jesse Barnes8a905232009-07-11 16:48:03 -04002031 if (IS_G4X(dev)) {
2032 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2033 u32 ipeir = I915_READ(IPEIR_I965);
2034
Joe Perchesa70491c2012-03-18 13:00:11 -07002035 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2036 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002037 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2038 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002039 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002040 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002041 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002042 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002043 }
2044 if (eir & GM45_ERROR_PAGE_TABLE) {
2045 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002046 pr_err("page table error\n");
2047 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002048 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002049 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002050 }
2051 }
2052
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002053 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002054 if (eir & I915_ERROR_PAGE_TABLE) {
2055 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002056 pr_err("page table error\n");
2057 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002058 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002059 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002060 }
2061 }
2062
2063 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002064 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002065 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002066 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002067 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002068 /* pipestat has already been acked */
2069 }
2070 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002071 pr_err("instruction error\n");
2072 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002073 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2074 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002075 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002076 u32 ipeir = I915_READ(IPEIR);
2077
Joe Perchesa70491c2012-03-18 13:00:11 -07002078 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2079 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002080 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002081 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002082 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002083 } else {
2084 u32 ipeir = I915_READ(IPEIR_I965);
2085
Joe Perchesa70491c2012-03-18 13:00:11 -07002086 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2087 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002088 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002089 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002090 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002091 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002092 }
2093 }
2094
2095 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002096 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002097 eir = I915_READ(EIR);
2098 if (eir) {
2099 /*
2100 * some errors might have become stuck,
2101 * mask them.
2102 */
2103 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2104 I915_WRITE(EMR, I915_READ(EMR) | eir);
2105 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2106 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002107}
2108
2109/**
2110 * i915_handle_error - handle an error interrupt
2111 * @dev: drm device
2112 *
2113 * Do some basic checking of regsiter state at error interrupt time and
2114 * dump it to the syslog. Also call i915_capture_error_state() to make
2115 * sure we get a record and make it available in debugfs. Fire a uevent
2116 * so userspace knows something bad happened (should trigger collection
2117 * of a ring dump etc.).
2118 */
Chris Wilson527f9e92010-11-11 01:16:58 +00002119void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002120{
2121 struct drm_i915_private *dev_priv = dev->dev_private;
2122
2123 i915_capture_error_state(dev);
2124 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002125
Ben Gamariba1234d2009-09-14 17:48:47 -04002126 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002127 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2128 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002129
Ben Gamari11ed50e2009-09-14 17:48:45 -04002130 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002131 * Wakeup waiting processes so that the reset work function
2132 * i915_error_work_func doesn't deadlock trying to grab various
2133 * locks. By bumping the reset counter first, the woken
2134 * processes will see a reset in progress and back off,
2135 * releasing their locks and then wait for the reset completion.
2136 * We must do this for _all_ gpu waiters that might hold locks
2137 * that the reset work needs to acquire.
2138 *
2139 * Note: The wake_up serves as the required memory barrier to
2140 * ensure that the waiters see the updated value of the reset
2141 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002142 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002143 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002144 }
2145
Daniel Vetter122f46b2013-09-04 17:36:14 +02002146 /*
2147 * Our reset work can grab modeset locks (since it needs to reset the
2148 * state of outstanding pagelips). Hence it must not be run on our own
2149 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2150 * code will deadlock.
2151 */
2152 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002153}
2154
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002155static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002156{
2157 drm_i915_private_t *dev_priv = dev->dev_private;
2158 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
2159 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00002160 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002161 struct intel_unpin_work *work;
2162 unsigned long flags;
2163 bool stall_detected;
2164
2165 /* Ignore early vblank irqs */
2166 if (intel_crtc == NULL)
2167 return;
2168
2169 spin_lock_irqsave(&dev->event_lock, flags);
2170 work = intel_crtc->unpin_work;
2171
Chris Wilsone7d841c2012-12-03 11:36:30 +00002172 if (work == NULL ||
2173 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
2174 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002175 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
2176 spin_unlock_irqrestore(&dev->event_lock, flags);
2177 return;
2178 }
2179
2180 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00002181 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002182 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002183 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07002184 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002185 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002186 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002187 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07002188 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02002189 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01002190 crtc->x * crtc->fb->bits_per_pixel/8);
2191 }
2192
2193 spin_unlock_irqrestore(&dev->event_lock, flags);
2194
2195 if (stall_detected) {
2196 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
2197 intel_prepare_page_flip(dev, intel_crtc->plane);
2198 }
2199}
2200
Keith Packard42f52ef2008-10-18 19:39:29 -07002201/* Called from drm generic code, passed 'crtc' which
2202 * we use as a pipe index
2203 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002204static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002205{
2206 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002207 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002208
Chris Wilson5eddb702010-09-11 13:48:45 +01002209 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002210 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002211
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002212 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002213 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002214 i915_enable_pipestat(dev_priv, pipe,
2215 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07002216 else
Keith Packard7c463582008-11-04 02:03:27 -08002217 i915_enable_pipestat(dev_priv, pipe,
2218 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002219
2220 /* maintain vblank delivery even in deep C-states */
2221 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002222 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002223 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002224
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002225 return 0;
2226}
2227
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002228static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002229{
2230 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2231 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002232 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002233 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002234
2235 if (!i915_pipe_enabled(dev, pipe))
2236 return -EINVAL;
2237
2238 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002239 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002240 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2241
2242 return 0;
2243}
2244
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002245static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2246{
2247 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2248 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002249 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002250
2251 if (!i915_pipe_enabled(dev, pipe))
2252 return -EINVAL;
2253
2254 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002255 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002256 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002257 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002258 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002259 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002260 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002261 i915_enable_pipestat(dev_priv, pipe,
2262 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002263 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2264
2265 return 0;
2266}
2267
Ben Widawskyabd58f02013-11-02 21:07:09 -07002268static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2269{
2270 struct drm_i915_private *dev_priv = dev->dev_private;
2271 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002272
2273 if (!i915_pipe_enabled(dev, pipe))
2274 return -EINVAL;
2275
2276 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002277 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2278 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2279 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002280 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2281 return 0;
2282}
2283
Keith Packard42f52ef2008-10-18 19:39:29 -07002284/* Called from drm generic code, passed 'crtc' which
2285 * we use as a pipe index
2286 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002287static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002288{
2289 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002290 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002291
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002292 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002293 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02002294 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00002295
Jesse Barnesf796cf82011-04-07 13:58:17 -07002296 i915_disable_pipestat(dev_priv, pipe,
2297 PIPE_VBLANK_INTERRUPT_ENABLE |
2298 PIPE_START_VBLANK_INTERRUPT_ENABLE);
2299 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2300}
2301
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002302static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002303{
2304 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2305 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002306 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002307 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002308
2309 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002310 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002311 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2312}
2313
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002314static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2315{
2316 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2317 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002318 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002319
2320 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002321 i915_disable_pipestat(dev_priv, pipe,
2322 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002323 imr = I915_READ(VLV_IMR);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002324 if (pipe == PIPE_A)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002325 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002326 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002327 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002328 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002329 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2330}
2331
Ben Widawskyabd58f02013-11-02 21:07:09 -07002332static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2333{
2334 struct drm_i915_private *dev_priv = dev->dev_private;
2335 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002336
2337 if (!i915_pipe_enabled(dev, pipe))
2338 return;
2339
2340 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002341 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2342 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2343 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002344 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2345}
2346
Chris Wilson893eead2010-10-27 14:44:35 +01002347static u32
2348ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002349{
Chris Wilson893eead2010-10-27 14:44:35 +01002350 return list_entry(ring->request_list.prev,
2351 struct drm_i915_gem_request, list)->seqno;
2352}
2353
Chris Wilson9107e9d2013-06-10 11:20:20 +01002354static bool
2355ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002356{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002357 return (list_empty(&ring->request_list) ||
2358 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04002359}
2360
Chris Wilson6274f212013-06-10 11:20:21 +01002361static struct intel_ring_buffer *
2362semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002363{
2364 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01002365 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002366
2367 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
2368 if ((ipehr & ~(0x3 << 16)) !=
2369 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01002370 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002371
2372 /* ACTHD is likely pointing to the dword after the actual command,
2373 * so scan backwards until we find the MBOX.
2374 */
Chris Wilson6274f212013-06-10 11:20:21 +01002375 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002376 acthd_min = max((int)acthd - 3 * 4, 0);
2377 do {
2378 cmd = ioread32(ring->virtual_start + acthd);
2379 if (cmd == ipehr)
2380 break;
2381
2382 acthd -= 4;
2383 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01002384 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002385 } while (1);
2386
Chris Wilson6274f212013-06-10 11:20:21 +01002387 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
2388 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02002389}
2390
Chris Wilson6274f212013-06-10 11:20:21 +01002391static int semaphore_passed(struct intel_ring_buffer *ring)
2392{
2393 struct drm_i915_private *dev_priv = ring->dev->dev_private;
2394 struct intel_ring_buffer *signaller;
2395 u32 seqno, ctl;
2396
2397 ring->hangcheck.deadlock = true;
2398
2399 signaller = semaphore_waits_for(ring, &seqno);
2400 if (signaller == NULL || signaller->hangcheck.deadlock)
2401 return -1;
2402
2403 /* cursory check for an unkickable deadlock */
2404 ctl = I915_READ_CTL(signaller);
2405 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
2406 return -1;
2407
2408 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
2409}
2410
2411static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2412{
2413 struct intel_ring_buffer *ring;
2414 int i;
2415
2416 for_each_ring(ring, dev_priv, i)
2417 ring->hangcheck.deadlock = false;
2418}
2419
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002420static enum intel_ring_hangcheck_action
2421ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002422{
2423 struct drm_device *dev = ring->dev;
2424 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002425 u32 tmp;
2426
Chris Wilson6274f212013-06-10 11:20:21 +01002427 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002428 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01002429
Chris Wilson9107e9d2013-06-10 11:20:20 +01002430 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002431 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002432
2433 /* Is the chip hanging on a WAIT_FOR_EVENT?
2434 * If so we can simply poke the RB_WAIT bit
2435 * and break the hang. This should work on
2436 * all but the second generation chipsets.
2437 */
2438 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002439 if (tmp & RING_WAIT) {
2440 DRM_ERROR("Kicking stuck wait on %s\n",
2441 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002442 i915_handle_error(dev, false);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002443 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002444 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002445 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002446
Chris Wilson6274f212013-06-10 11:20:21 +01002447 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2448 switch (semaphore_passed(ring)) {
2449 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002450 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002451 case 1:
2452 DRM_ERROR("Kicking stuck semaphore on %s\n",
2453 ring->name);
Chris Wilson09e14bf2013-10-10 09:37:19 +01002454 i915_handle_error(dev, false);
Chris Wilson6274f212013-06-10 11:20:21 +01002455 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002456 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002457 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002458 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002459 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002460 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002461
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002462 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002463}
2464
Ben Gamarif65d9422009-09-14 17:48:44 -04002465/**
2466 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002467 * batchbuffers in a long time. We keep track per ring seqno progress and
2468 * if there are no progress, hangcheck score for that ring is increased.
2469 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2470 * we kick the ring. If we see no progress on three subsequent calls
2471 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002472 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002473static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002474{
2475 struct drm_device *dev = (struct drm_device *)data;
2476 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01002477 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002478 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002479 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002480 bool stuck[I915_NUM_RINGS] = { 0 };
2481#define BUSY 1
2482#define KICK 5
2483#define HUNG 20
2484#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01002485
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002486 if (!i915_enable_hangcheck)
2487 return;
2488
Chris Wilsonb4519512012-05-11 14:29:30 +01002489 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002490 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002491 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002492
Chris Wilson6274f212013-06-10 11:20:21 +01002493 semaphore_clear_deadlocks(dev_priv);
2494
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002495 seqno = ring->get_seqno(ring, false);
2496 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002497
Chris Wilson9107e9d2013-06-10 11:20:20 +01002498 if (ring->hangcheck.seqno == seqno) {
2499 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002500 ring->hangcheck.action = HANGCHECK_IDLE;
2501
Chris Wilson9107e9d2013-06-10 11:20:20 +01002502 if (waitqueue_active(&ring->irq_queue)) {
2503 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002504 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002505 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2506 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2507 ring->name);
2508 else
2509 DRM_INFO("Fake missed irq on %s\n",
2510 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002511 wake_up_all(&ring->irq_queue);
2512 }
2513 /* Safeguard against driver failure */
2514 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002515 } else
2516 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002517 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002518 /* We always increment the hangcheck score
2519 * if the ring is busy and still processing
2520 * the same request, so that no single request
2521 * can run indefinitely (such as a chain of
2522 * batches). The only time we do not increment
2523 * the hangcheck score on this ring, if this
2524 * ring is in a legitimate wait for another
2525 * ring. In that case the waiting ring is a
2526 * victim and we want to be sure we catch the
2527 * right culprit. Then every time we do kick
2528 * the ring, add a small increment to the
2529 * score so that we can catch a batch that is
2530 * being repeatedly kicked and so responsible
2531 * for stalling the machine.
2532 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002533 ring->hangcheck.action = ring_stuck(ring,
2534 acthd);
2535
2536 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002537 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002538 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01002539 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002540 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002541 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002542 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002543 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002544 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002545 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002546 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002547 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002548 stuck[i] = true;
2549 break;
2550 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002551 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002552 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002553 ring->hangcheck.action = HANGCHECK_ACTIVE;
2554
Chris Wilson9107e9d2013-06-10 11:20:20 +01002555 /* Gradually reduce the count so that we catch DoS
2556 * attempts across multiple batches.
2557 */
2558 if (ring->hangcheck.score > 0)
2559 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002560 }
2561
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002562 ring->hangcheck.seqno = seqno;
2563 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002564 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002565 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002566
Mika Kuoppala92cab732013-05-24 17:16:07 +03002567 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002568 if (ring->hangcheck.score > FIRE) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002569 DRM_INFO("%s on %s\n",
2570 stuck[i] ? "stuck" : "no progress",
2571 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002572 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002573 }
2574 }
2575
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002576 if (rings_hung)
2577 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002578
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002579 if (busy_count)
2580 /* Reset timer case chip hangs without another request
2581 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002582 i915_queue_hangcheck(dev);
2583}
2584
2585void i915_queue_hangcheck(struct drm_device *dev)
2586{
2587 struct drm_i915_private *dev_priv = dev->dev_private;
2588 if (!i915_enable_hangcheck)
2589 return;
2590
2591 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2592 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002593}
2594
Paulo Zanoni91738a92013-06-05 14:21:51 -03002595static void ibx_irq_preinstall(struct drm_device *dev)
2596{
2597 struct drm_i915_private *dev_priv = dev->dev_private;
2598
2599 if (HAS_PCH_NOP(dev))
2600 return;
2601
2602 /* south display irq */
2603 I915_WRITE(SDEIMR, 0xffffffff);
2604 /*
2605 * SDEIER is also touched by the interrupt handler to work around missed
2606 * PCH interrupts. Hence we can't update it after the interrupt handler
2607 * is enabled - instead we unconditionally enable all PCH interrupt
2608 * sources here, but then only unmask them as needed with SDEIMR.
2609 */
2610 I915_WRITE(SDEIER, 0xffffffff);
2611 POSTING_READ(SDEIER);
2612}
2613
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002614static void gen5_gt_irq_preinstall(struct drm_device *dev)
2615{
2616 struct drm_i915_private *dev_priv = dev->dev_private;
2617
2618 /* and GT */
2619 I915_WRITE(GTIMR, 0xffffffff);
2620 I915_WRITE(GTIER, 0x0);
2621 POSTING_READ(GTIER);
2622
2623 if (INTEL_INFO(dev)->gen >= 6) {
2624 /* and PM */
2625 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2626 I915_WRITE(GEN6_PMIER, 0x0);
2627 POSTING_READ(GEN6_PMIER);
2628 }
2629}
2630
Linus Torvalds1da177e2005-04-16 15:20:36 -07002631/* drm_dma.h hooks
2632*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002633static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002634{
2635 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2636
Jesse Barnes46979952011-04-07 13:53:55 -07002637 atomic_set(&dev_priv->irq_received, 0);
2638
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002639 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002640
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002641 I915_WRITE(DEIMR, 0xffffffff);
2642 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002643 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002644
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002645 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002646
Paulo Zanoni91738a92013-06-05 14:21:51 -03002647 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002648}
2649
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002650static void valleyview_irq_preinstall(struct drm_device *dev)
2651{
2652 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2653 int pipe;
2654
2655 atomic_set(&dev_priv->irq_received, 0);
2656
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002657 /* VLV magic */
2658 I915_WRITE(VLV_IMR, 0);
2659 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2660 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2661 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2662
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002663 /* and GT */
2664 I915_WRITE(GTIIR, I915_READ(GTIIR));
2665 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002666
2667 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002668
2669 I915_WRITE(DPINVGTT, 0xff);
2670
2671 I915_WRITE(PORT_HOTPLUG_EN, 0);
2672 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2673 for_each_pipe(pipe)
2674 I915_WRITE(PIPESTAT(pipe), 0xffff);
2675 I915_WRITE(VLV_IIR, 0xffffffff);
2676 I915_WRITE(VLV_IMR, 0xffffffff);
2677 I915_WRITE(VLV_IER, 0x0);
2678 POSTING_READ(VLV_IER);
2679}
2680
Ben Widawskyabd58f02013-11-02 21:07:09 -07002681static void gen8_irq_preinstall(struct drm_device *dev)
2682{
2683 struct drm_i915_private *dev_priv = dev->dev_private;
2684 int pipe;
2685
2686 atomic_set(&dev_priv->irq_received, 0);
2687
2688 I915_WRITE(GEN8_MASTER_IRQ, 0);
2689 POSTING_READ(GEN8_MASTER_IRQ);
2690
2691 /* IIR can theoretically queue up two events. Be paranoid */
2692#define GEN8_IRQ_INIT_NDX(type, which) do { \
2693 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
2694 POSTING_READ(GEN8_##type##_IMR(which)); \
2695 I915_WRITE(GEN8_##type##_IER(which), 0); \
2696 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2697 POSTING_READ(GEN8_##type##_IIR(which)); \
2698 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
2699 } while (0)
2700
2701#define GEN8_IRQ_INIT(type) do { \
2702 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
2703 POSTING_READ(GEN8_##type##_IMR); \
2704 I915_WRITE(GEN8_##type##_IER, 0); \
2705 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2706 POSTING_READ(GEN8_##type##_IIR); \
2707 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
2708 } while (0)
2709
2710 GEN8_IRQ_INIT_NDX(GT, 0);
2711 GEN8_IRQ_INIT_NDX(GT, 1);
2712 GEN8_IRQ_INIT_NDX(GT, 2);
2713 GEN8_IRQ_INIT_NDX(GT, 3);
2714
2715 for_each_pipe(pipe) {
2716 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe);
2717 }
2718
2719 GEN8_IRQ_INIT(DE_PORT);
2720 GEN8_IRQ_INIT(DE_MISC);
2721 GEN8_IRQ_INIT(PCU);
2722#undef GEN8_IRQ_INIT
2723#undef GEN8_IRQ_INIT_NDX
2724
2725 POSTING_READ(GEN8_PCU_IIR);
Jesse Barnes09f23442014-01-10 13:13:09 -08002726
2727 ibx_irq_preinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002728}
2729
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002730static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002731{
2732 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002733 struct drm_mode_config *mode_config = &dev->mode_config;
2734 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002735 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002736
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002737 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002738 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002739 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002740 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002741 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002742 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002743 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002744 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002745 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002746 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002747 }
2748
Daniel Vetterfee884e2013-07-04 23:35:21 +02002749 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002750
2751 /*
2752 * Enable digital hotplug on the PCH, and configure the DP short pulse
2753 * duration to 2ms (which is the minimum in the Display Port spec)
2754 *
2755 * This register is the same on all known PCH chips.
2756 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002757 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2758 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2759 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2760 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2761 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2762 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2763}
2764
Paulo Zanonid46da432013-02-08 17:35:15 -02002765static void ibx_irq_postinstall(struct drm_device *dev)
2766{
2767 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002768 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002769
Daniel Vetter692a04c2013-05-29 21:43:05 +02002770 if (HAS_PCH_NOP(dev))
2771 return;
2772
Paulo Zanoni86642812013-04-12 17:57:57 -03002773 if (HAS_PCH_IBX(dev)) {
2774 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002775 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002776 } else {
2777 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2778
2779 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2780 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002781
Paulo Zanonid46da432013-02-08 17:35:15 -02002782 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2783 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002784}
2785
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002786static void gen5_gt_irq_postinstall(struct drm_device *dev)
2787{
2788 struct drm_i915_private *dev_priv = dev->dev_private;
2789 u32 pm_irqs, gt_irqs;
2790
2791 pm_irqs = gt_irqs = 0;
2792
2793 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07002794 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002795 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07002796 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
2797 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002798 }
2799
2800 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2801 if (IS_GEN5(dev)) {
2802 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2803 ILK_BSD_USER_INTERRUPT;
2804 } else {
2805 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2806 }
2807
2808 I915_WRITE(GTIIR, I915_READ(GTIIR));
2809 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2810 I915_WRITE(GTIER, gt_irqs);
2811 POSTING_READ(GTIER);
2812
2813 if (INTEL_INFO(dev)->gen >= 6) {
2814 pm_irqs |= GEN6_PM_RPS_EVENTS;
2815
2816 if (HAS_VEBOX(dev))
2817 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2818
Paulo Zanoni605cd252013-08-06 18:57:15 -03002819 dev_priv->pm_irq_mask = 0xffffffff;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002820 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
Paulo Zanoni605cd252013-08-06 18:57:15 -03002821 I915_WRITE(GEN6_PMIMR, dev_priv->pm_irq_mask);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002822 I915_WRITE(GEN6_PMIER, pm_irqs);
2823 POSTING_READ(GEN6_PMIER);
2824 }
2825}
2826
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002827static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002828{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002829 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002830 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002831 u32 display_mask, extra_mask;
2832
2833 if (INTEL_INFO(dev)->gen >= 7) {
2834 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2835 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2836 DE_PLANEB_FLIP_DONE_IVB |
2837 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2838 DE_ERR_INT_IVB);
2839 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2840 DE_PIPEA_VBLANK_IVB);
2841
2842 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2843 } else {
2844 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2845 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002846 DE_AUX_CHANNEL_A |
2847 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
2848 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
2849 DE_POISON);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002850 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2851 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002852
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002853 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002854
2855 /* should always can generate irq */
2856 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002857 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002858 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002859 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002860
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002861 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002862
Paulo Zanonid46da432013-02-08 17:35:15 -02002863 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002864
Jesse Barnesf97108d2010-01-29 11:27:07 -08002865 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002866 /* Enable PCU event interrupts
2867 *
2868 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002869 * setup is guaranteed to run in single-threaded context. But we
2870 * need it to make the assert_spin_locked happy. */
2871 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002872 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002873 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002874 }
2875
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002876 return 0;
2877}
2878
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002879static int valleyview_irq_postinstall(struct drm_device *dev)
2880{
2881 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002882 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02002883 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV |
2884 PIPE_CRC_DONE_ENABLE;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002885 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002886
2887 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002888 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2889 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2890 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002891 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2892
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002893 /*
2894 *Leave vblank interrupts masked initially. enable/disable will
2895 * toggle them based on usage.
2896 */
2897 dev_priv->irq_mask = (~enable_mask) |
2898 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2899 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002900
Daniel Vetter20afbda2012-12-11 14:05:07 +01002901 I915_WRITE(PORT_HOTPLUG_EN, 0);
2902 POSTING_READ(PORT_HOTPLUG_EN);
2903
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002904 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2905 I915_WRITE(VLV_IER, enable_mask);
2906 I915_WRITE(VLV_IIR, 0xffffffff);
2907 I915_WRITE(PIPESTAT(0), 0xffff);
2908 I915_WRITE(PIPESTAT(1), 0xffff);
2909 POSTING_READ(VLV_IER);
2910
Daniel Vetterb79480b2013-06-27 17:52:10 +02002911 /* Interrupt setup is already guaranteed to be single-threaded, this is
2912 * just to make the assert_spin_locked check happy. */
2913 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02002914 i915_enable_pipestat(dev_priv, PIPE_A, pipestat_enable);
2915 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
2916 i915_enable_pipestat(dev_priv, PIPE_B, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002917 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002918
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002919 I915_WRITE(VLV_IIR, 0xffffffff);
2920 I915_WRITE(VLV_IIR, 0xffffffff);
2921
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002922 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002923
2924 /* ack & enable invalid PTE error interrupts */
2925#if 0 /* FIXME: add support to irq handler for checking these bits */
2926 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2927 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2928#endif
2929
2930 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002931
2932 return 0;
2933}
2934
Ben Widawskyabd58f02013-11-02 21:07:09 -07002935static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
2936{
2937 int i;
2938
2939 /* These are interrupts we'll toggle with the ring mask register */
2940 uint32_t gt_interrupts[] = {
2941 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
2942 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
2943 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
2944 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
2945 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
2946 0,
2947 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT
2948 };
2949
2950 for (i = 0; i < ARRAY_SIZE(gt_interrupts); i++) {
2951 u32 tmp = I915_READ(GEN8_GT_IIR(i));
2952 if (tmp)
2953 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2954 i, tmp);
2955 I915_WRITE(GEN8_GT_IMR(i), ~gt_interrupts[i]);
2956 I915_WRITE(GEN8_GT_IER(i), gt_interrupts[i]);
2957 }
2958 POSTING_READ(GEN8_GT_IER(0));
2959}
2960
2961static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
2962{
2963 struct drm_device *dev = dev_priv->dev;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002964 uint32_t de_pipe_masked = GEN8_PIPE_FLIP_DONE |
2965 GEN8_PIPE_CDCLK_CRC_DONE |
2966 GEN8_PIPE_FIFO_UNDERRUN |
2967 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2968 uint32_t de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002969 int pipe;
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01002970 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
2971 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
2972 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002973
2974 for_each_pipe(pipe) {
2975 u32 tmp = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2976 if (tmp)
2977 DRM_ERROR("Interrupt (%d) should have been masked in pre-install 0x%08x\n",
2978 pipe, tmp);
2979 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2980 I915_WRITE(GEN8_DE_PIPE_IER(pipe), de_pipe_enables);
2981 }
2982 POSTING_READ(GEN8_DE_PIPE_ISR(0));
2983
Daniel Vetter6d766f02013-11-07 14:49:55 +01002984 I915_WRITE(GEN8_DE_PORT_IMR, ~GEN8_AUX_CHANNEL_A);
2985 I915_WRITE(GEN8_DE_PORT_IER, GEN8_AUX_CHANNEL_A);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002986 POSTING_READ(GEN8_DE_PORT_IER);
2987}
2988
2989static int gen8_irq_postinstall(struct drm_device *dev)
2990{
2991 struct drm_i915_private *dev_priv = dev->dev_private;
2992
2993 gen8_gt_irq_postinstall(dev_priv);
2994 gen8_de_irq_postinstall(dev_priv);
2995
2996 ibx_irq_postinstall(dev);
2997
2998 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
2999 POSTING_READ(GEN8_MASTER_IRQ);
3000
3001 return 0;
3002}
3003
3004static void gen8_irq_uninstall(struct drm_device *dev)
3005{
3006 struct drm_i915_private *dev_priv = dev->dev_private;
3007 int pipe;
3008
3009 if (!dev_priv)
3010 return;
3011
3012 atomic_set(&dev_priv->irq_received, 0);
3013
3014 I915_WRITE(GEN8_MASTER_IRQ, 0);
3015
3016#define GEN8_IRQ_FINI_NDX(type, which) do { \
3017 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
3018 I915_WRITE(GEN8_##type##_IER(which), 0); \
3019 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
3020 } while (0)
3021
3022#define GEN8_IRQ_FINI(type) do { \
3023 I915_WRITE(GEN8_##type##_IMR, 0xffffffff); \
3024 I915_WRITE(GEN8_##type##_IER, 0); \
3025 I915_WRITE(GEN8_##type##_IIR, 0xffffffff); \
3026 } while (0)
3027
3028 GEN8_IRQ_FINI_NDX(GT, 0);
3029 GEN8_IRQ_FINI_NDX(GT, 1);
3030 GEN8_IRQ_FINI_NDX(GT, 2);
3031 GEN8_IRQ_FINI_NDX(GT, 3);
3032
3033 for_each_pipe(pipe) {
3034 GEN8_IRQ_FINI_NDX(DE_PIPE, pipe);
3035 }
3036
3037 GEN8_IRQ_FINI(DE_PORT);
3038 GEN8_IRQ_FINI(DE_MISC);
3039 GEN8_IRQ_FINI(PCU);
3040#undef GEN8_IRQ_FINI
3041#undef GEN8_IRQ_FINI_NDX
3042
3043 POSTING_READ(GEN8_PCU_IIR);
3044}
3045
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003046static void valleyview_irq_uninstall(struct drm_device *dev)
3047{
3048 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3049 int pipe;
3050
3051 if (!dev_priv)
3052 return;
3053
Egbert Eichac4c16c2013-04-16 13:36:58 +02003054 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3055
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003056 for_each_pipe(pipe)
3057 I915_WRITE(PIPESTAT(pipe), 0xffff);
3058
3059 I915_WRITE(HWSTAM, 0xffffffff);
3060 I915_WRITE(PORT_HOTPLUG_EN, 0);
3061 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3062 for_each_pipe(pipe)
3063 I915_WRITE(PIPESTAT(pipe), 0xffff);
3064 I915_WRITE(VLV_IIR, 0xffffffff);
3065 I915_WRITE(VLV_IMR, 0xffffffff);
3066 I915_WRITE(VLV_IER, 0x0);
3067 POSTING_READ(VLV_IER);
3068}
3069
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003070static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003071{
3072 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003073
3074 if (!dev_priv)
3075 return;
3076
Egbert Eichac4c16c2013-04-16 13:36:58 +02003077 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3078
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003079 I915_WRITE(HWSTAM, 0xffffffff);
3080
3081 I915_WRITE(DEIMR, 0xffffffff);
3082 I915_WRITE(DEIER, 0x0);
3083 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003084 if (IS_GEN7(dev))
3085 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003086
3087 I915_WRITE(GTIMR, 0xffffffff);
3088 I915_WRITE(GTIER, 0x0);
3089 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07003090
Ben Widawskyab5c6082013-04-05 13:12:41 -07003091 if (HAS_PCH_NOP(dev))
3092 return;
3093
Keith Packard192aac1f2011-09-20 10:12:44 -07003094 I915_WRITE(SDEIMR, 0xffffffff);
3095 I915_WRITE(SDEIER, 0x0);
3096 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03003097 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3098 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003099}
3100
Chris Wilsonc2798b12012-04-22 21:13:57 +01003101static void i8xx_irq_preinstall(struct drm_device * dev)
3102{
3103 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3104 int pipe;
3105
3106 atomic_set(&dev_priv->irq_received, 0);
3107
3108 for_each_pipe(pipe)
3109 I915_WRITE(PIPESTAT(pipe), 0);
3110 I915_WRITE16(IMR, 0xffff);
3111 I915_WRITE16(IER, 0x0);
3112 POSTING_READ16(IER);
3113}
3114
3115static int i8xx_irq_postinstall(struct drm_device *dev)
3116{
3117 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter379ef822013-10-16 22:55:56 +02003118 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003119
Chris Wilsonc2798b12012-04-22 21:13:57 +01003120 I915_WRITE16(EMR,
3121 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3122
3123 /* Unmask the interrupts that we always want on. */
3124 dev_priv->irq_mask =
3125 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3126 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3127 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3128 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3129 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3130 I915_WRITE16(IMR, dev_priv->irq_mask);
3131
3132 I915_WRITE16(IER,
3133 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3134 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3135 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3136 I915_USER_INTERRUPT);
3137 POSTING_READ16(IER);
3138
Daniel Vetter379ef822013-10-16 22:55:56 +02003139 /* Interrupt setup is already guaranteed to be single-threaded, this is
3140 * just to make the assert_spin_locked check happy. */
3141 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003142 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3143 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003144 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3145
Chris Wilsonc2798b12012-04-22 21:13:57 +01003146 return 0;
3147}
3148
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003149/*
3150 * Returns true when a page flip has completed.
3151 */
3152static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003153 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003154{
3155 drm_i915_private_t *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003156 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003157
3158 if (!drm_handle_vblank(dev, pipe))
3159 return false;
3160
3161 if ((iir & flip_pending) == 0)
3162 return false;
3163
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003164 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003165
3166 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3167 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3168 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3169 * the flip is completed (no longer pending). Since this doesn't raise
3170 * an interrupt per se, we watch for the change at vblank.
3171 */
3172 if (I915_READ16(ISR) & flip_pending)
3173 return false;
3174
3175 intel_finish_page_flip(dev, pipe);
3176
3177 return true;
3178}
3179
Daniel Vetterff1f5252012-10-02 15:10:55 +02003180static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003181{
3182 struct drm_device *dev = (struct drm_device *) arg;
3183 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003184 u16 iir, new_iir;
3185 u32 pipe_stats[2];
3186 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003187 int pipe;
3188 u16 flip_mask =
3189 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3190 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3191
3192 atomic_inc(&dev_priv->irq_received);
3193
3194 iir = I915_READ16(IIR);
3195 if (iir == 0)
3196 return IRQ_NONE;
3197
3198 while (iir & ~flip_mask) {
3199 /* Can't rely on pipestat interrupt bit in iir as it might
3200 * have been cleared after the pipestat interrupt was received.
3201 * It doesn't set the bit in iir again, but it still produces
3202 * interrupts (for non-MSI).
3203 */
3204 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3205 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3206 i915_handle_error(dev, false);
3207
3208 for_each_pipe(pipe) {
3209 int reg = PIPESTAT(pipe);
3210 pipe_stats[pipe] = I915_READ(reg);
3211
3212 /*
3213 * Clear the PIPE*STAT regs before the IIR
3214 */
3215 if (pipe_stats[pipe] & 0x8000ffff) {
3216 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3217 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3218 pipe_name(pipe));
3219 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003220 }
3221 }
3222 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3223
3224 I915_WRITE16(IIR, iir & ~flip_mask);
3225 new_iir = I915_READ16(IIR); /* Flush posted writes */
3226
Daniel Vetterd05c6172012-04-26 23:28:09 +02003227 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003228
3229 if (iir & I915_USER_INTERRUPT)
3230 notify_ring(dev, &dev_priv->ring[RCS]);
3231
Daniel Vetter4356d582013-10-16 22:55:55 +02003232 for_each_pipe(pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003233 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003234 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003235 plane = !plane;
3236
Daniel Vetter4356d582013-10-16 22:55:55 +02003237 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003238 i8xx_handle_vblank(dev, plane, pipe, iir))
3239 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003240
Daniel Vetter4356d582013-10-16 22:55:55 +02003241 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003242 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003243 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003244
3245 iir = new_iir;
3246 }
3247
3248 return IRQ_HANDLED;
3249}
3250
3251static void i8xx_irq_uninstall(struct drm_device * dev)
3252{
3253 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3254 int pipe;
3255
Chris Wilsonc2798b12012-04-22 21:13:57 +01003256 for_each_pipe(pipe) {
3257 /* Clear enable bits; then clear status bits */
3258 I915_WRITE(PIPESTAT(pipe), 0);
3259 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3260 }
3261 I915_WRITE16(IMR, 0xffff);
3262 I915_WRITE16(IER, 0x0);
3263 I915_WRITE16(IIR, I915_READ16(IIR));
3264}
3265
Chris Wilsona266c7d2012-04-24 22:59:44 +01003266static void i915_irq_preinstall(struct drm_device * dev)
3267{
3268 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3269 int pipe;
3270
3271 atomic_set(&dev_priv->irq_received, 0);
3272
3273 if (I915_HAS_HOTPLUG(dev)) {
3274 I915_WRITE(PORT_HOTPLUG_EN, 0);
3275 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3276 }
3277
Chris Wilson00d98eb2012-04-24 22:59:48 +01003278 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003279 for_each_pipe(pipe)
3280 I915_WRITE(PIPESTAT(pipe), 0);
3281 I915_WRITE(IMR, 0xffffffff);
3282 I915_WRITE(IER, 0x0);
3283 POSTING_READ(IER);
3284}
3285
3286static int i915_irq_postinstall(struct drm_device *dev)
3287{
3288 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003289 u32 enable_mask;
Daniel Vetter379ef822013-10-16 22:55:56 +02003290 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003291
Chris Wilson38bde182012-04-24 22:59:50 +01003292 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3293
3294 /* Unmask the interrupts that we always want on. */
3295 dev_priv->irq_mask =
3296 ~(I915_ASLE_INTERRUPT |
3297 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3298 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3299 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3300 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3301 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3302
3303 enable_mask =
3304 I915_ASLE_INTERRUPT |
3305 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3306 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3307 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3308 I915_USER_INTERRUPT;
3309
Chris Wilsona266c7d2012-04-24 22:59:44 +01003310 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003311 I915_WRITE(PORT_HOTPLUG_EN, 0);
3312 POSTING_READ(PORT_HOTPLUG_EN);
3313
Chris Wilsona266c7d2012-04-24 22:59:44 +01003314 /* Enable in IER... */
3315 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3316 /* and unmask in IMR */
3317 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3318 }
3319
Chris Wilsona266c7d2012-04-24 22:59:44 +01003320 I915_WRITE(IMR, dev_priv->irq_mask);
3321 I915_WRITE(IER, enable_mask);
3322 POSTING_READ(IER);
3323
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003324 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003325
Daniel Vetter379ef822013-10-16 22:55:56 +02003326 /* Interrupt setup is already guaranteed to be single-threaded, this is
3327 * just to make the assert_spin_locked check happy. */
3328 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003329 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3330 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetter379ef822013-10-16 22:55:56 +02003331 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3332
Daniel Vetter20afbda2012-12-11 14:05:07 +01003333 return 0;
3334}
3335
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003336/*
3337 * Returns true when a page flip has completed.
3338 */
3339static bool i915_handle_vblank(struct drm_device *dev,
3340 int plane, int pipe, u32 iir)
3341{
3342 drm_i915_private_t *dev_priv = dev->dev_private;
3343 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3344
3345 if (!drm_handle_vblank(dev, pipe))
3346 return false;
3347
3348 if ((iir & flip_pending) == 0)
3349 return false;
3350
3351 intel_prepare_page_flip(dev, plane);
3352
3353 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3354 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3355 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3356 * the flip is completed (no longer pending). Since this doesn't raise
3357 * an interrupt per se, we watch for the change at vblank.
3358 */
3359 if (I915_READ(ISR) & flip_pending)
3360 return false;
3361
3362 intel_finish_page_flip(dev, pipe);
3363
3364 return true;
3365}
3366
Daniel Vetterff1f5252012-10-02 15:10:55 +02003367static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003368{
3369 struct drm_device *dev = (struct drm_device *) arg;
3370 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003371 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003372 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01003373 u32 flip_mask =
3374 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3375 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003376 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003377
3378 atomic_inc(&dev_priv->irq_received);
3379
3380 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003381 do {
3382 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003383 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003384
3385 /* Can't rely on pipestat interrupt bit in iir as it might
3386 * have been cleared after the pipestat interrupt was received.
3387 * It doesn't set the bit in iir again, but it still produces
3388 * interrupts (for non-MSI).
3389 */
3390 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3391 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3392 i915_handle_error(dev, false);
3393
3394 for_each_pipe(pipe) {
3395 int reg = PIPESTAT(pipe);
3396 pipe_stats[pipe] = I915_READ(reg);
3397
Chris Wilson38bde182012-04-24 22:59:50 +01003398 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003399 if (pipe_stats[pipe] & 0x8000ffff) {
3400 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3401 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3402 pipe_name(pipe));
3403 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003404 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003405 }
3406 }
3407 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3408
3409 if (!irq_received)
3410 break;
3411
Chris Wilsona266c7d2012-04-24 22:59:44 +01003412 /* Consume port. Then clear IIR or we'll miss events */
3413 if ((I915_HAS_HOTPLUG(dev)) &&
3414 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
3415 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003416 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003417
3418 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3419 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003420
3421 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
3422
Chris Wilsona266c7d2012-04-24 22:59:44 +01003423 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01003424 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003425 }
3426
Chris Wilson38bde182012-04-24 22:59:50 +01003427 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003428 new_iir = I915_READ(IIR); /* Flush posted writes */
3429
Chris Wilsona266c7d2012-04-24 22:59:44 +01003430 if (iir & I915_USER_INTERRUPT)
3431 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003432
Chris Wilsona266c7d2012-04-24 22:59:44 +01003433 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003434 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003435 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003436 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003437
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003438 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3439 i915_handle_vblank(dev, plane, pipe, iir))
3440 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003441
3442 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3443 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003444
3445 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003446 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003447 }
3448
Chris Wilsona266c7d2012-04-24 22:59:44 +01003449 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3450 intel_opregion_asle_intr(dev);
3451
3452 /* With MSI, interrupts are only generated when iir
3453 * transitions from zero to nonzero. If another bit got
3454 * set while we were handling the existing iir bits, then
3455 * we would never get another interrupt.
3456 *
3457 * This is fine on non-MSI as well, as if we hit this path
3458 * we avoid exiting the interrupt handler only to generate
3459 * another one.
3460 *
3461 * Note that for MSI this could cause a stray interrupt report
3462 * if an interrupt landed in the time between writing IIR and
3463 * the posting read. This should be rare enough to never
3464 * trigger the 99% of 100,000 interrupts test for disabling
3465 * stray interrupts.
3466 */
Chris Wilson38bde182012-04-24 22:59:50 +01003467 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003468 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003469 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003470
Daniel Vetterd05c6172012-04-26 23:28:09 +02003471 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01003472
Chris Wilsona266c7d2012-04-24 22:59:44 +01003473 return ret;
3474}
3475
3476static void i915_irq_uninstall(struct drm_device * dev)
3477{
3478 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3479 int pipe;
3480
Egbert Eichac4c16c2013-04-16 13:36:58 +02003481 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3482
Chris Wilsona266c7d2012-04-24 22:59:44 +01003483 if (I915_HAS_HOTPLUG(dev)) {
3484 I915_WRITE(PORT_HOTPLUG_EN, 0);
3485 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3486 }
3487
Chris Wilson00d98eb2012-04-24 22:59:48 +01003488 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01003489 for_each_pipe(pipe) {
3490 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003491 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003492 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3493 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003494 I915_WRITE(IMR, 0xffffffff);
3495 I915_WRITE(IER, 0x0);
3496
Chris Wilsona266c7d2012-04-24 22:59:44 +01003497 I915_WRITE(IIR, I915_READ(IIR));
3498}
3499
3500static void i965_irq_preinstall(struct drm_device * dev)
3501{
3502 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3503 int pipe;
3504
3505 atomic_set(&dev_priv->irq_received, 0);
3506
Chris Wilsonadca4732012-05-11 18:01:31 +01003507 I915_WRITE(PORT_HOTPLUG_EN, 0);
3508 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003509
3510 I915_WRITE(HWSTAM, 0xeffe);
3511 for_each_pipe(pipe)
3512 I915_WRITE(PIPESTAT(pipe), 0);
3513 I915_WRITE(IMR, 0xffffffff);
3514 I915_WRITE(IER, 0x0);
3515 POSTING_READ(IER);
3516}
3517
3518static int i965_irq_postinstall(struct drm_device *dev)
3519{
3520 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003521 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003522 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02003523 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003524
Chris Wilsona266c7d2012-04-24 22:59:44 +01003525 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003526 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003527 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003528 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3529 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3530 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3531 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3532 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3533
3534 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003535 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3536 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003537 enable_mask |= I915_USER_INTERRUPT;
3538
3539 if (IS_G4X(dev))
3540 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003541
Daniel Vetterb79480b2013-06-27 17:52:10 +02003542 /* Interrupt setup is already guaranteed to be single-threaded, this is
3543 * just to make the assert_spin_locked check happy. */
3544 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter3b6c42e2013-10-21 18:04:35 +02003545 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_EVENT_ENABLE);
3546 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_ENABLE);
3547 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02003548 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003549
Chris Wilsona266c7d2012-04-24 22:59:44 +01003550 /*
3551 * Enable some error detection, note the instruction error mask
3552 * bit is reserved, so we leave it masked.
3553 */
3554 if (IS_G4X(dev)) {
3555 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3556 GM45_ERROR_MEM_PRIV |
3557 GM45_ERROR_CP_PRIV |
3558 I915_ERROR_MEMORY_REFRESH);
3559 } else {
3560 error_mask = ~(I915_ERROR_PAGE_TABLE |
3561 I915_ERROR_MEMORY_REFRESH);
3562 }
3563 I915_WRITE(EMR, error_mask);
3564
3565 I915_WRITE(IMR, dev_priv->irq_mask);
3566 I915_WRITE(IER, enable_mask);
3567 POSTING_READ(IER);
3568
Daniel Vetter20afbda2012-12-11 14:05:07 +01003569 I915_WRITE(PORT_HOTPLUG_EN, 0);
3570 POSTING_READ(PORT_HOTPLUG_EN);
3571
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003572 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003573
3574 return 0;
3575}
3576
Egbert Eichbac56d52013-02-25 12:06:51 -05003577static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003578{
3579 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05003580 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02003581 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003582 u32 hotplug_en;
3583
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003584 assert_spin_locked(&dev_priv->irq_lock);
3585
Egbert Eichbac56d52013-02-25 12:06:51 -05003586 if (I915_HAS_HOTPLUG(dev)) {
3587 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
3588 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
3589 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05003590 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02003591 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
3592 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
3593 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05003594 /* Programming the CRT detection parameters tends
3595 to generate a spurious hotplug event about three
3596 seconds later. So just do it once.
3597 */
3598 if (IS_G4X(dev))
3599 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01003600 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05003601 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003602
Egbert Eichbac56d52013-02-25 12:06:51 -05003603 /* Ignore TV since it's buggy */
3604 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
3605 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003606}
3607
Daniel Vetterff1f5252012-10-02 15:10:55 +02003608static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003609{
3610 struct drm_device *dev = (struct drm_device *) arg;
3611 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003612 u32 iir, new_iir;
3613 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01003614 unsigned long irqflags;
3615 int irq_received;
3616 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003617 u32 flip_mask =
3618 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3619 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003620
3621 atomic_inc(&dev_priv->irq_received);
3622
3623 iir = I915_READ(IIR);
3624
Chris Wilsona266c7d2012-04-24 22:59:44 +01003625 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003626 bool blc_event = false;
3627
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003628 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003629
3630 /* Can't rely on pipestat interrupt bit in iir as it might
3631 * have been cleared after the pipestat interrupt was received.
3632 * It doesn't set the bit in iir again, but it still produces
3633 * interrupts (for non-MSI).
3634 */
3635 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3636 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3637 i915_handle_error(dev, false);
3638
3639 for_each_pipe(pipe) {
3640 int reg = PIPESTAT(pipe);
3641 pipe_stats[pipe] = I915_READ(reg);
3642
3643 /*
3644 * Clear the PIPE*STAT regs before the IIR
3645 */
3646 if (pipe_stats[pipe] & 0x8000ffff) {
3647 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3648 DRM_DEBUG_DRIVER("pipe %c underrun\n",
3649 pipe_name(pipe));
3650 I915_WRITE(reg, pipe_stats[pipe]);
3651 irq_received = 1;
3652 }
3653 }
3654 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3655
3656 if (!irq_received)
3657 break;
3658
3659 ret = IRQ_HANDLED;
3660
3661 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01003662 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003663 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02003664 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
3665 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02003666 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003667
3668 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
3669 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003670
3671 intel_hpd_irq_handler(dev, hotplug_trigger,
Daniel Vetter704cfb82013-12-18 09:08:43 +01003672 IS_G4X(dev) ? hpd_status_g4x : hpd_status_i915);
Daniel Vetter91d131d2013-06-27 17:52:14 +02003673
Daniel Vetter4aeebd72013-10-31 09:53:36 +01003674 if (IS_G4X(dev) &&
3675 (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X))
3676 dp_aux_irq_handler(dev);
3677
Chris Wilsona266c7d2012-04-24 22:59:44 +01003678 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
3679 I915_READ(PORT_HOTPLUG_STAT);
3680 }
3681
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003682 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003683 new_iir = I915_READ(IIR); /* Flush posted writes */
3684
Chris Wilsona266c7d2012-04-24 22:59:44 +01003685 if (iir & I915_USER_INTERRUPT)
3686 notify_ring(dev, &dev_priv->ring[RCS]);
3687 if (iir & I915_BSD_USER_INTERRUPT)
3688 notify_ring(dev, &dev_priv->ring[VCS]);
3689
Chris Wilsona266c7d2012-04-24 22:59:44 +01003690 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01003691 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003692 i915_handle_vblank(dev, pipe, pipe, iir))
3693 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003694
3695 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3696 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003697
3698 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003699 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003700 }
3701
3702
3703 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3704 intel_opregion_asle_intr(dev);
3705
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003706 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
3707 gmbus_irq_handler(dev);
3708
Chris Wilsona266c7d2012-04-24 22:59:44 +01003709 /* With MSI, interrupts are only generated when iir
3710 * transitions from zero to nonzero. If another bit got
3711 * set while we were handling the existing iir bits, then
3712 * we would never get another interrupt.
3713 *
3714 * This is fine on non-MSI as well, as if we hit this path
3715 * we avoid exiting the interrupt handler only to generate
3716 * another one.
3717 *
3718 * Note that for MSI this could cause a stray interrupt report
3719 * if an interrupt landed in the time between writing IIR and
3720 * the posting read. This should be rare enough to never
3721 * trigger the 99% of 100,000 interrupts test for disabling
3722 * stray interrupts.
3723 */
3724 iir = new_iir;
3725 }
3726
Daniel Vetterd05c6172012-04-26 23:28:09 +02003727 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003728
Chris Wilsona266c7d2012-04-24 22:59:44 +01003729 return ret;
3730}
3731
3732static void i965_irq_uninstall(struct drm_device * dev)
3733{
3734 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3735 int pipe;
3736
3737 if (!dev_priv)
3738 return;
3739
Egbert Eichac4c16c2013-04-16 13:36:58 +02003740 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3741
Chris Wilsonadca4732012-05-11 18:01:31 +01003742 I915_WRITE(PORT_HOTPLUG_EN, 0);
3743 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003744
3745 I915_WRITE(HWSTAM, 0xffffffff);
3746 for_each_pipe(pipe)
3747 I915_WRITE(PIPESTAT(pipe), 0);
3748 I915_WRITE(IMR, 0xffffffff);
3749 I915_WRITE(IER, 0x0);
3750
3751 for_each_pipe(pipe)
3752 I915_WRITE(PIPESTAT(pipe),
3753 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3754 I915_WRITE(IIR, I915_READ(IIR));
3755}
3756
Egbert Eichac4c16c2013-04-16 13:36:58 +02003757static void i915_reenable_hotplug_timer_func(unsigned long data)
3758{
3759 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3760 struct drm_device *dev = dev_priv->dev;
3761 struct drm_mode_config *mode_config = &dev->mode_config;
3762 unsigned long irqflags;
3763 int i;
3764
3765 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3766 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3767 struct drm_connector *connector;
3768
3769 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3770 continue;
3771
3772 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3773
3774 list_for_each_entry(connector, &mode_config->connector_list, head) {
3775 struct intel_connector *intel_connector = to_intel_connector(connector);
3776
3777 if (intel_connector->encoder->hpd_pin == i) {
3778 if (connector->polled != intel_connector->polled)
3779 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3780 drm_get_connector_name(connector));
3781 connector->polled = intel_connector->polled;
3782 if (!connector->polled)
3783 connector->polled = DRM_CONNECTOR_POLL_HPD;
3784 }
3785 }
3786 }
3787 if (dev_priv->display.hpd_irq_setup)
3788 dev_priv->display.hpd_irq_setup(dev);
3789 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3790}
3791
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003792void intel_irq_init(struct drm_device *dev)
3793{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003794 struct drm_i915_private *dev_priv = dev->dev_private;
3795
3796 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003797 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003798 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003799 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003800
Daniel Vetter99584db2012-11-14 17:14:04 +01003801 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3802 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003803 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003804 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3805 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003806
Tomas Janousek97a19a22012-12-08 13:48:13 +01003807 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003808
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003809 if (IS_GEN2(dev)) {
3810 dev->max_vblank_count = 0;
3811 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
3812 } else if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003813 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3814 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003815 } else {
3816 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3817 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003818 }
3819
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003820 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07003821 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03003822 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3823 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003824
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003825 if (IS_VALLEYVIEW(dev)) {
3826 dev->driver->irq_handler = valleyview_irq_handler;
3827 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3828 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3829 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3830 dev->driver->enable_vblank = valleyview_enable_vblank;
3831 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003832 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003833 } else if (IS_GEN8(dev)) {
3834 dev->driver->irq_handler = gen8_irq_handler;
3835 dev->driver->irq_preinstall = gen8_irq_preinstall;
3836 dev->driver->irq_postinstall = gen8_irq_postinstall;
3837 dev->driver->irq_uninstall = gen8_irq_uninstall;
3838 dev->driver->enable_vblank = gen8_enable_vblank;
3839 dev->driver->disable_vblank = gen8_disable_vblank;
3840 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003841 } else if (HAS_PCH_SPLIT(dev)) {
3842 dev->driver->irq_handler = ironlake_irq_handler;
3843 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3844 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3845 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3846 dev->driver->enable_vblank = ironlake_enable_vblank;
3847 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003848 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003849 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003850 if (INTEL_INFO(dev)->gen == 2) {
3851 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3852 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3853 dev->driver->irq_handler = i8xx_irq_handler;
3854 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003855 } else if (INTEL_INFO(dev)->gen == 3) {
3856 dev->driver->irq_preinstall = i915_irq_preinstall;
3857 dev->driver->irq_postinstall = i915_irq_postinstall;
3858 dev->driver->irq_uninstall = i915_irq_uninstall;
3859 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003860 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003861 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003862 dev->driver->irq_preinstall = i965_irq_preinstall;
3863 dev->driver->irq_postinstall = i965_irq_postinstall;
3864 dev->driver->irq_uninstall = i965_irq_uninstall;
3865 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003866 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003867 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003868 dev->driver->enable_vblank = i915_enable_vblank;
3869 dev->driver->disable_vblank = i915_disable_vblank;
3870 }
3871}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003872
3873void intel_hpd_init(struct drm_device *dev)
3874{
3875 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003876 struct drm_mode_config *mode_config = &dev->mode_config;
3877 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003878 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003879 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003880
Egbert Eich821450c2013-04-16 13:36:55 +02003881 for (i = 1; i < HPD_NUM_PINS; i++) {
3882 dev_priv->hpd_stats[i].hpd_cnt = 0;
3883 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3884 }
3885 list_for_each_entry(connector, &mode_config->connector_list, head) {
3886 struct intel_connector *intel_connector = to_intel_connector(connector);
3887 connector->polled = intel_connector->polled;
3888 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3889 connector->polled = DRM_CONNECTOR_POLL_HPD;
3890 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003891
3892 /* Interrupt setup is already guaranteed to be single-threaded, this is
3893 * just to make the assert_spin_locked checks happy. */
3894 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003895 if (dev_priv->display.hpd_irq_setup)
3896 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003897 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003898}
Paulo Zanonic67a4702013-08-19 13:18:09 -03003899
3900/* Disable interrupts so we can allow Package C8+. */
3901void hsw_pc8_disable_interrupts(struct drm_device *dev)
3902{
3903 struct drm_i915_private *dev_priv = dev->dev_private;
3904 unsigned long irqflags;
3905
3906 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3907
3908 dev_priv->pc8.regsave.deimr = I915_READ(DEIMR);
3909 dev_priv->pc8.regsave.sdeimr = I915_READ(SDEIMR);
3910 dev_priv->pc8.regsave.gtimr = I915_READ(GTIMR);
3911 dev_priv->pc8.regsave.gtier = I915_READ(GTIER);
3912 dev_priv->pc8.regsave.gen6_pmimr = I915_READ(GEN6_PMIMR);
3913
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003914 ironlake_disable_display_irq(dev_priv, 0xffffffff);
3915 ibx_disable_display_interrupt(dev_priv, 0xffffffff);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003916 ilk_disable_gt_irq(dev_priv, 0xffffffff);
3917 snb_disable_pm_irq(dev_priv, 0xffffffff);
3918
3919 dev_priv->pc8.irqs_disabled = true;
3920
3921 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3922}
3923
3924/* Restore interrupts so we can recover from Package C8+. */
3925void hsw_pc8_restore_interrupts(struct drm_device *dev)
3926{
3927 struct drm_i915_private *dev_priv = dev->dev_private;
3928 unsigned long irqflags;
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003929 uint32_t val;
Paulo Zanonic67a4702013-08-19 13:18:09 -03003930
3931 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3932
3933 val = I915_READ(DEIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003934 WARN(val != 0xffffffff, "DEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003935
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003936 val = I915_READ(SDEIMR);
3937 WARN(val != 0xffffffff, "SDEIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003938
3939 val = I915_READ(GTIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003940 WARN(val != 0xffffffff, "GTIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003941
3942 val = I915_READ(GEN6_PMIMR);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003943 WARN(val != 0xffffffff, "GEN6_PMIMR is 0x%08x\n", val);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003944
3945 dev_priv->pc8.irqs_disabled = false;
3946
3947 ironlake_enable_display_irq(dev_priv, ~dev_priv->pc8.regsave.deimr);
Paulo Zanoni1f2d4532013-11-21 13:47:25 -02003948 ibx_enable_display_interrupt(dev_priv, ~dev_priv->pc8.regsave.sdeimr);
Paulo Zanonic67a4702013-08-19 13:18:09 -03003949 ilk_enable_gt_irq(dev_priv, ~dev_priv->pc8.regsave.gtimr);
3950 snb_enable_pm_irq(dev_priv, ~dev_priv->pc8.regsave.gen6_pmimr);
3951 I915_WRITE(GTIER, dev_priv->pc8.regsave.gtier);
3952
3953 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3954}