blob: 28d57477aa4202c0be661b9aedef1fe39eadcef8 [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>
David Howells760285e2012-10-02 18:01:07 +010033#include <drm/drmP.h>
34#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070035#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010036#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080037#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070038
Egbert Eiche5868a32013-02-28 04:17:12 -050039static const u32 hpd_ibx[] = {
40 [HPD_CRT] = SDE_CRT_HOTPLUG,
41 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
42 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
43 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
44 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
45};
46
47static const u32 hpd_cpt[] = {
48 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010049 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050050 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
51 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
52 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
53};
54
55static const u32 hpd_mask_i915[] = {
56 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
57 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
58 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
59 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
60 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
61 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
62};
63
64static const u32 hpd_status_gen4[] = {
65 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
68 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
69 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
71};
72
Egbert Eiche5868a32013-02-28 04:17:12 -050073static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
74 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
77 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
78 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
79 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
80};
81
Zhenyu Wang036a4a72009-06-08 14:40:19 +080082/* For display hotplug interrupt */
Chris Wilson995b6762010-08-20 13:23:26 +010083static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050084ironlake_enable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080085{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020086 assert_spin_locked(&dev_priv->irq_lock);
87
Chris Wilson1ec14ad2010-12-04 11:30:53 +000088 if ((dev_priv->irq_mask & mask) != 0) {
89 dev_priv->irq_mask &= ~mask;
90 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +000091 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +080092 }
93}
94
Paulo Zanoni0ff98002013-02-22 17:05:31 -030095static void
Adam Jacksonf2b115e2009-12-03 17:14:42 -050096ironlake_disable_display_irq(drm_i915_private_t *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +080097{
Daniel Vetter4bc9d432013-06-27 13:44:58 +020098 assert_spin_locked(&dev_priv->irq_lock);
99
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000100 if ((dev_priv->irq_mask & mask) != mask) {
101 dev_priv->irq_mask |= mask;
102 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000103 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800104 }
105}
106
Paulo Zanoni86642812013-04-12 17:57:57 -0300107static bool ivb_can_enable_err_int(struct drm_device *dev)
108{
109 struct drm_i915_private *dev_priv = dev->dev_private;
110 struct intel_crtc *crtc;
111 enum pipe pipe;
112
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200113 assert_spin_locked(&dev_priv->irq_lock);
114
Paulo Zanoni86642812013-04-12 17:57:57 -0300115 for_each_pipe(pipe) {
116 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
117
118 if (crtc->cpu_fifo_underrun_disabled)
119 return false;
120 }
121
122 return true;
123}
124
125static bool cpt_can_enable_serr_int(struct drm_device *dev)
126{
127 struct drm_i915_private *dev_priv = dev->dev_private;
128 enum pipe pipe;
129 struct intel_crtc *crtc;
130
Daniel Vetterfee884e2013-07-04 23:35:21 +0200131 assert_spin_locked(&dev_priv->irq_lock);
132
Paulo Zanoni86642812013-04-12 17:57:57 -0300133 for_each_pipe(pipe) {
134 crtc = to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
135
136 if (crtc->pch_fifo_underrun_disabled)
137 return false;
138 }
139
140 return true;
141}
142
143static void ironlake_set_fifo_underrun_reporting(struct drm_device *dev,
144 enum pipe pipe, bool enable)
145{
146 struct drm_i915_private *dev_priv = dev->dev_private;
147 uint32_t bit = (pipe == PIPE_A) ? DE_PIPEA_FIFO_UNDERRUN :
148 DE_PIPEB_FIFO_UNDERRUN;
149
150 if (enable)
151 ironlake_enable_display_irq(dev_priv, bit);
152 else
153 ironlake_disable_display_irq(dev_priv, bit);
154}
155
156static void ivybridge_set_fifo_underrun_reporting(struct drm_device *dev,
Daniel Vetter7336df62013-07-09 22:59:16 +0200157 enum pipe pipe, bool enable)
Paulo Zanoni86642812013-04-12 17:57:57 -0300158{
159 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni86642812013-04-12 17:57:57 -0300160 if (enable) {
Daniel Vetter7336df62013-07-09 22:59:16 +0200161 I915_WRITE(GEN7_ERR_INT, ERR_INT_FIFO_UNDERRUN(pipe));
162
Paulo Zanoni86642812013-04-12 17:57:57 -0300163 if (!ivb_can_enable_err_int(dev))
164 return;
165
Paulo Zanoni86642812013-04-12 17:57:57 -0300166 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
167 } else {
Daniel Vetter7336df62013-07-09 22:59:16 +0200168 bool was_enabled = !(I915_READ(DEIMR) & DE_ERR_INT_IVB);
169
170 /* Change the state _after_ we've read out the current one. */
Paulo Zanoni86642812013-04-12 17:57:57 -0300171 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter7336df62013-07-09 22:59:16 +0200172
173 if (!was_enabled &&
174 (I915_READ(GEN7_ERR_INT) & ERR_INT_FIFO_UNDERRUN(pipe))) {
175 DRM_DEBUG_KMS("uncleared fifo underrun on pipe %c\n",
176 pipe_name(pipe));
177 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300178 }
179}
180
Daniel Vetterfee884e2013-07-04 23:35:21 +0200181/**
182 * ibx_display_interrupt_update - update SDEIMR
183 * @dev_priv: driver private
184 * @interrupt_mask: mask of interrupt bits to update
185 * @enabled_irq_mask: mask of interrupt bits to enable
186 */
187static void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
188 uint32_t interrupt_mask,
189 uint32_t enabled_irq_mask)
190{
191 uint32_t sdeimr = I915_READ(SDEIMR);
192 sdeimr &= ~interrupt_mask;
193 sdeimr |= (~enabled_irq_mask & interrupt_mask);
194
195 assert_spin_locked(&dev_priv->irq_lock);
196
197 I915_WRITE(SDEIMR, sdeimr);
198 POSTING_READ(SDEIMR);
199}
200#define ibx_enable_display_interrupt(dev_priv, bits) \
201 ibx_display_interrupt_update((dev_priv), (bits), (bits))
202#define ibx_disable_display_interrupt(dev_priv, bits) \
203 ibx_display_interrupt_update((dev_priv), (bits), 0)
204
Daniel Vetterde280752013-07-04 23:35:24 +0200205static void ibx_set_fifo_underrun_reporting(struct drm_device *dev,
206 enum transcoder pch_transcoder,
Paulo Zanoni86642812013-04-12 17:57:57 -0300207 bool enable)
208{
Paulo Zanoni86642812013-04-12 17:57:57 -0300209 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200210 uint32_t bit = (pch_transcoder == TRANSCODER_A) ?
211 SDE_TRANSA_FIFO_UNDER : SDE_TRANSB_FIFO_UNDER;
Paulo Zanoni86642812013-04-12 17:57:57 -0300212
213 if (enable)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200214 ibx_enable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300215 else
Daniel Vetterfee884e2013-07-04 23:35:21 +0200216 ibx_disable_display_interrupt(dev_priv, bit);
Paulo Zanoni86642812013-04-12 17:57:57 -0300217}
218
219static void cpt_set_fifo_underrun_reporting(struct drm_device *dev,
220 enum transcoder pch_transcoder,
221 bool enable)
222{
223 struct drm_i915_private *dev_priv = dev->dev_private;
224
225 if (enable) {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200226 I915_WRITE(SERR_INT,
227 SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder));
228
Paulo Zanoni86642812013-04-12 17:57:57 -0300229 if (!cpt_can_enable_serr_int(dev))
230 return;
231
Daniel Vetterfee884e2013-07-04 23:35:21 +0200232 ibx_enable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Paulo Zanoni86642812013-04-12 17:57:57 -0300233 } else {
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200234 uint32_t tmp = I915_READ(SERR_INT);
235 bool was_enabled = !(I915_READ(SDEIMR) & SDE_ERROR_CPT);
236
237 /* Change the state _after_ we've read out the current one. */
Daniel Vetterfee884e2013-07-04 23:35:21 +0200238 ibx_disable_display_interrupt(dev_priv, SDE_ERROR_CPT);
Daniel Vetter1dd246f2013-07-10 08:30:23 +0200239
240 if (!was_enabled &&
241 (tmp & SERR_INT_TRANS_FIFO_UNDERRUN(pch_transcoder))) {
242 DRM_DEBUG_KMS("uncleared pch fifo underrun on pch transcoder %c\n",
243 transcoder_name(pch_transcoder));
244 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300245 }
Paulo Zanoni86642812013-04-12 17:57:57 -0300246}
247
248/**
249 * intel_set_cpu_fifo_underrun_reporting - enable/disable FIFO underrun messages
250 * @dev: drm device
251 * @pipe: pipe
252 * @enable: true if we want to report FIFO underrun errors, false otherwise
253 *
254 * This function makes us disable or enable CPU fifo underruns for a specific
255 * pipe. Notice that on some Gens (e.g. IVB, HSW), disabling FIFO underrun
256 * reporting for one pipe may also disable all the other CPU error interruts for
257 * the other pipes, due to the fact that there's just one interrupt mask/enable
258 * bit for all the pipes.
259 *
260 * Returns the previous state of underrun reporting.
261 */
262bool intel_set_cpu_fifo_underrun_reporting(struct drm_device *dev,
263 enum pipe pipe, bool enable)
264{
265 struct drm_i915_private *dev_priv = dev->dev_private;
266 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
267 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
268 unsigned long flags;
269 bool ret;
270
271 spin_lock_irqsave(&dev_priv->irq_lock, flags);
272
273 ret = !intel_crtc->cpu_fifo_underrun_disabled;
274
275 if (enable == ret)
276 goto done;
277
278 intel_crtc->cpu_fifo_underrun_disabled = !enable;
279
280 if (IS_GEN5(dev) || IS_GEN6(dev))
281 ironlake_set_fifo_underrun_reporting(dev, pipe, enable);
282 else if (IS_GEN7(dev))
Daniel Vetter7336df62013-07-09 22:59:16 +0200283 ivybridge_set_fifo_underrun_reporting(dev, pipe, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300284
285done:
286 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
287 return ret;
288}
289
290/**
291 * intel_set_pch_fifo_underrun_reporting - enable/disable FIFO underrun messages
292 * @dev: drm device
293 * @pch_transcoder: the PCH transcoder (same as pipe on IVB and older)
294 * @enable: true if we want to report FIFO underrun errors, false otherwise
295 *
296 * This function makes us disable or enable PCH fifo underruns for a specific
297 * PCH transcoder. Notice that on some PCHs (e.g. CPT/PPT), disabling FIFO
298 * underrun reporting for one transcoder may also disable all the other PCH
299 * error interruts for the other transcoders, due to the fact that there's just
300 * one interrupt mask/enable bit for all the transcoders.
301 *
302 * Returns the previous state of underrun reporting.
303 */
304bool intel_set_pch_fifo_underrun_reporting(struct drm_device *dev,
305 enum transcoder pch_transcoder,
306 bool enable)
307{
308 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetterde280752013-07-04 23:35:24 +0200309 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pch_transcoder];
310 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni86642812013-04-12 17:57:57 -0300311 unsigned long flags;
312 bool ret;
313
Daniel Vetterde280752013-07-04 23:35:24 +0200314 /*
315 * NOTE: Pre-LPT has a fixed cpu pipe -> pch transcoder mapping, but LPT
316 * has only one pch transcoder A that all pipes can use. To avoid racy
317 * pch transcoder -> pipe lookups from interrupt code simply store the
318 * underrun statistics in crtc A. Since we never expose this anywhere
319 * nor use it outside of the fifo underrun code here using the "wrong"
320 * crtc on LPT won't cause issues.
321 */
Paulo Zanoni86642812013-04-12 17:57:57 -0300322
323 spin_lock_irqsave(&dev_priv->irq_lock, flags);
324
325 ret = !intel_crtc->pch_fifo_underrun_disabled;
326
327 if (enable == ret)
328 goto done;
329
330 intel_crtc->pch_fifo_underrun_disabled = !enable;
331
332 if (HAS_PCH_IBX(dev))
Daniel Vetterde280752013-07-04 23:35:24 +0200333 ibx_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
Paulo Zanoni86642812013-04-12 17:57:57 -0300334 else
335 cpt_set_fifo_underrun_reporting(dev, pch_transcoder, enable);
336
337done:
338 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
339 return ret;
340}
341
342
Keith Packard7c463582008-11-04 02:03:27 -0800343void
344i915_enable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
345{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200346 u32 reg = PIPESTAT(pipe);
347 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800348
Daniel Vetterb79480b2013-06-27 17:52:10 +0200349 assert_spin_locked(&dev_priv->irq_lock);
350
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200351 if ((pipestat & mask) == mask)
352 return;
353
354 /* Enable the interrupt, clear any pending status */
355 pipestat |= mask | (mask >> 16);
356 I915_WRITE(reg, pipestat);
357 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800358}
359
360void
361i915_disable_pipestat(drm_i915_private_t *dev_priv, int pipe, u32 mask)
362{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200363 u32 reg = PIPESTAT(pipe);
364 u32 pipestat = I915_READ(reg) & 0x7fff0000;
Keith Packard7c463582008-11-04 02:03:27 -0800365
Daniel Vetterb79480b2013-06-27 17:52:10 +0200366 assert_spin_locked(&dev_priv->irq_lock);
367
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200368 if ((pipestat & mask) == 0)
369 return;
370
371 pipestat &= ~mask;
372 I915_WRITE(reg, pipestat);
373 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800374}
375
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000376/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300377 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000378 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300379static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000380{
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000381 drm_i915_private_t *dev_priv = dev->dev_private;
382 unsigned long irqflags;
383
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300384 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
385 return;
386
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000387 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000388
Jani Nikulaf8987802013-04-29 13:02:53 +0300389 i915_enable_pipestat(dev_priv, 1, PIPE_LEGACY_BLC_EVENT_ENABLE);
390 if (INTEL_INFO(dev)->gen >= 4)
391 i915_enable_pipestat(dev_priv, 0, PIPE_LEGACY_BLC_EVENT_ENABLE);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000392
393 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Zhao Yakui01c66882009-10-28 05:10:00 +0000394}
395
396/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700397 * i915_pipe_enabled - check if a pipe is enabled
398 * @dev: DRM device
399 * @pipe: pipe to check
400 *
401 * Reading certain registers when the pipe is disabled can hang the chip.
402 * Use this routine to make sure the PLL is running and the pipe is active
403 * before reading such registers if unsure.
404 */
405static int
406i915_pipe_enabled(struct drm_device *dev, int pipe)
407{
408 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200409
Daniel Vettera01025a2013-05-22 00:50:23 +0200410 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
411 /* Locking is horribly broken here, but whatever. */
412 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
413 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300414
Daniel Vettera01025a2013-05-22 00:50:23 +0200415 return intel_crtc->active;
416 } else {
417 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
418 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700419}
420
Keith Packard42f52ef2008-10-18 19:39:29 -0700421/* Called from drm generic code, passed a 'crtc', which
422 * we use as a pipe index
423 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700424static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700425{
426 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
427 unsigned long high_frame;
428 unsigned long low_frame;
Chris Wilson5eddb702010-09-11 13:48:45 +0100429 u32 high1, high2, low;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700430
431 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800432 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800433 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700434 return 0;
435 }
436
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800437 high_frame = PIPEFRAME(pipe);
438 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100439
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700440 /*
441 * High & low register fields aren't synchronized, so make sure
442 * we get a low value that's stable across two reads of the high
443 * register.
444 */
445 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100446 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
447 low = I915_READ(low_frame) & PIPE_FRAME_LOW_MASK;
448 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700449 } while (high1 != high2);
450
Chris Wilson5eddb702010-09-11 13:48:45 +0100451 high1 >>= PIPE_FRAME_HIGH_SHIFT;
452 low >>= PIPE_FRAME_LOW_SHIFT;
453 return (high1 << 8) | low;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700454}
455
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700456static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800457{
458 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800459 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800460
461 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800462 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800463 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800464 return 0;
465 }
466
467 return I915_READ(reg);
468}
469
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700470static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100471 int *vpos, int *hpos)
472{
473 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
474 u32 vbl = 0, position = 0;
475 int vbl_start, vbl_end, htotal, vtotal;
476 bool in_vbl = true;
477 int ret = 0;
Paulo Zanonife2b8f92012-10-23 18:30:02 -0200478 enum transcoder cpu_transcoder = intel_pipe_to_cpu_transcoder(dev_priv,
479 pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100480
481 if (!i915_pipe_enabled(dev, pipe)) {
482 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800483 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100484 return 0;
485 }
486
487 /* Get vtotal. */
Paulo Zanonife2b8f92012-10-23 18:30:02 -0200488 vtotal = 1 + ((I915_READ(VTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100489
490 if (INTEL_INFO(dev)->gen >= 4) {
491 /* No obvious pixelcount register. Only query vertical
492 * scanout position from Display scan line register.
493 */
494 position = I915_READ(PIPEDSL(pipe));
495
496 /* Decode into vertical scanout position. Don't have
497 * horizontal scanout position.
498 */
499 *vpos = position & 0x1fff;
500 *hpos = 0;
501 } else {
502 /* Have access to pixelcount since start of frame.
503 * We can split this into vertical and horizontal
504 * scanout position.
505 */
506 position = (I915_READ(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
507
Paulo Zanonife2b8f92012-10-23 18:30:02 -0200508 htotal = 1 + ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100509 *vpos = position / htotal;
510 *hpos = position - (*vpos * htotal);
511 }
512
513 /* Query vblank area. */
Paulo Zanonife2b8f92012-10-23 18:30:02 -0200514 vbl = I915_READ(VBLANK(cpu_transcoder));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100515
516 /* Test position against vblank region. */
517 vbl_start = vbl & 0x1fff;
518 vbl_end = (vbl >> 16) & 0x1fff;
519
520 if ((*vpos < vbl_start) || (*vpos > vbl_end))
521 in_vbl = false;
522
523 /* Inside "upper part" of vblank area? Apply corrective offset: */
524 if (in_vbl && (*vpos >= vbl_start))
525 *vpos = *vpos - vtotal;
526
527 /* Readouts valid? */
528 if (vbl > 0)
529 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
530
531 /* In vblank? */
532 if (in_vbl)
533 ret |= DRM_SCANOUTPOS_INVBL;
534
535 return ret;
536}
537
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700538static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100539 int *max_error,
540 struct timeval *vblank_time,
541 unsigned flags)
542{
Chris Wilson4041b852011-01-22 10:07:56 +0000543 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100544
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700545 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000546 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100547 return -EINVAL;
548 }
549
550 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000551 crtc = intel_get_crtc_for_pipe(dev, pipe);
552 if (crtc == NULL) {
553 DRM_ERROR("Invalid crtc %d\n", pipe);
554 return -EINVAL;
555 }
556
557 if (!crtc->enabled) {
558 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
559 return -EBUSY;
560 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100561
562 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000563 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
564 vblank_time, flags,
565 crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100566}
567
Egbert Eich321a1b32013-04-11 16:00:26 +0200568static int intel_hpd_irq_event(struct drm_device *dev, struct drm_connector *connector)
569{
570 enum drm_connector_status old_status;
571
572 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
573 old_status = connector->status;
574
575 connector->status = connector->funcs->detect(connector, false);
576 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %d to %d\n",
577 connector->base.id,
578 drm_get_connector_name(connector),
579 old_status, connector->status);
580 return (old_status != connector->status);
581}
582
Jesse Barnes5ca58282009-03-31 14:11:15 -0700583/*
584 * Handle hotplug events outside the interrupt handler proper.
585 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200586#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
587
Jesse Barnes5ca58282009-03-31 14:11:15 -0700588static void i915_hotplug_work_func(struct work_struct *work)
589{
590 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
591 hotplug_work);
592 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700593 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200594 struct intel_connector *intel_connector;
595 struct intel_encoder *intel_encoder;
596 struct drm_connector *connector;
597 unsigned long irqflags;
598 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200599 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200600 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700601
Daniel Vetter52d7ece2012-12-01 21:03:22 +0100602 /* HPD irq before everything is fully set up. */
603 if (!dev_priv->enable_hotplug_processing)
604 return;
605
Keith Packarda65e34c2011-07-25 10:04:56 -0700606 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800607 DRM_DEBUG_KMS("running encoder hotplug functions\n");
608
Egbert Eichcd569ae2013-04-16 13:36:57 +0200609 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Egbert Eich142e2392013-04-11 15:57:57 +0200610
611 hpd_event_bits = dev_priv->hpd_event_bits;
612 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200613 list_for_each_entry(connector, &mode_config->connector_list, head) {
614 intel_connector = to_intel_connector(connector);
615 intel_encoder = intel_connector->encoder;
616 if (intel_encoder->hpd_pin > HPD_NONE &&
617 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
618 connector->polled == DRM_CONNECTOR_POLL_HPD) {
619 DRM_INFO("HPD interrupt storm detected on connector %s: "
620 "switching from hotplug detection to polling\n",
621 drm_get_connector_name(connector));
622 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
623 connector->polled = DRM_CONNECTOR_POLL_CONNECT
624 | DRM_CONNECTOR_POLL_DISCONNECT;
625 hpd_disabled = true;
626 }
Egbert Eich142e2392013-04-11 15:57:57 +0200627 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
628 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
629 drm_get_connector_name(connector), intel_encoder->hpd_pin);
630 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200631 }
632 /* if there were no outputs to poll, poll was disabled,
633 * therefore make sure it's enabled when disabling HPD on
634 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200635 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200636 drm_kms_helper_poll_enable(dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +0200637 mod_timer(&dev_priv->hotplug_reenable_timer,
638 jiffies + msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
639 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200640
641 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
642
Egbert Eich321a1b32013-04-11 16:00:26 +0200643 list_for_each_entry(connector, &mode_config->connector_list, head) {
644 intel_connector = to_intel_connector(connector);
645 intel_encoder = intel_connector->encoder;
646 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
647 if (intel_encoder->hot_plug)
648 intel_encoder->hot_plug(intel_encoder);
649 if (intel_hpd_irq_event(dev, connector))
650 changed = true;
651 }
652 }
Keith Packard40ee3382011-07-28 15:31:19 -0700653 mutex_unlock(&mode_config->mutex);
654
Egbert Eich321a1b32013-04-11 16:00:26 +0200655 if (changed)
656 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700657}
658
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200659static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800660{
661 drm_i915_private_t *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000662 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200663 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200664
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200665 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800666
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200667 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
668
Daniel Vetter20e4d402012-08-08 23:35:39 +0200669 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200670
Jesse Barnes7648fa92010-05-20 14:28:11 -0700671 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000672 busy_up = I915_READ(RCPREVBSYTUPAVG);
673 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800674 max_avg = I915_READ(RCBMAXAVG);
675 min_avg = I915_READ(RCBMINAVG);
676
677 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000678 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200679 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
680 new_delay = dev_priv->ips.cur_delay - 1;
681 if (new_delay < dev_priv->ips.max_delay)
682 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000683 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200684 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
685 new_delay = dev_priv->ips.cur_delay + 1;
686 if (new_delay > dev_priv->ips.min_delay)
687 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800688 }
689
Jesse Barnes7648fa92010-05-20 14:28:11 -0700690 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200691 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800692
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200693 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200694
Jesse Barnesf97108d2010-01-29 11:27:07 -0800695 return;
696}
697
Chris Wilson549f7362010-10-19 11:19:32 +0100698static void notify_ring(struct drm_device *dev,
699 struct intel_ring_buffer *ring)
700{
Chris Wilson475553d2011-01-20 09:52:56 +0000701 if (ring->obj == NULL)
702 return;
703
Chris Wilsonb2eadbc2012-08-09 10:58:30 +0100704 trace_i915_gem_request_complete(ring, ring->get_seqno(ring, false));
Chris Wilson9862e602011-01-04 22:22:17 +0000705
Chris Wilson549f7362010-10-19 11:19:32 +0100706 wake_up_all(&ring->irq_queue);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +0300707 i915_queue_hangcheck(dev);
Chris Wilson549f7362010-10-19 11:19:32 +0100708}
709
Ben Widawsky4912d042011-04-25 11:25:20 -0700710static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800711{
Ben Widawsky4912d042011-04-25 11:25:20 -0700712 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200713 rps.work);
Ben Widawsky4912d042011-04-25 11:25:20 -0700714 u32 pm_iir, pm_imr;
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100715 u8 new_delay;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800716
Daniel Vetter59cdb632013-07-04 23:35:28 +0200717 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200718 pm_iir = dev_priv->rps.pm_iir;
719 dev_priv->rps.pm_iir = 0;
Ben Widawsky4912d042011-04-25 11:25:20 -0700720 pm_imr = I915_READ(GEN6_PMIMR);
Ben Widawsky48484052013-05-28 19:22:27 -0700721 /* Make sure not to corrupt PMIMR state used by ringbuffer code */
722 I915_WRITE(GEN6_PMIMR, pm_imr & ~GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200723 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700724
Ben Widawsky48484052013-05-28 19:22:27 -0700725 if ((pm_iir & GEN6_PM_RPS_EVENTS) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800726 return;
727
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700728 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100729
Ville Syrjälä74250342013-06-25 21:38:11 +0300730 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200731 new_delay = dev_priv->rps.cur_delay + 1;
Ville Syrjälä74250342013-06-25 21:38:11 +0300732
733 /*
734 * For better performance, jump directly
735 * to RPe if we're below it.
736 */
737 if (IS_VALLEYVIEW(dev_priv->dev) &&
738 dev_priv->rps.cur_delay < dev_priv->rps.rpe_delay)
739 new_delay = dev_priv->rps.rpe_delay;
740 } else
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200741 new_delay = dev_priv->rps.cur_delay - 1;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800742
Ben Widawsky79249632012-09-07 19:43:42 -0700743 /* sysfs frequency interfaces may have snuck in while servicing the
744 * interrupt
745 */
Ville Syrjäläd8289c92013-06-25 19:21:05 +0300746 if (new_delay >= dev_priv->rps.min_delay &&
747 new_delay <= dev_priv->rps.max_delay) {
Jesse Barnes0a073b82013-04-17 15:54:58 -0700748 if (IS_VALLEYVIEW(dev_priv->dev))
749 valleyview_set_rps(dev_priv->dev, new_delay);
750 else
751 gen6_set_rps(dev_priv->dev, new_delay);
Ben Widawsky79249632012-09-07 19:43:42 -0700752 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800753
Jesse Barnes52ceb902013-04-23 10:09:26 -0700754 if (IS_VALLEYVIEW(dev_priv->dev)) {
755 /*
756 * On VLV, when we enter RC6 we may not be at the minimum
757 * voltage level, so arm a timer to check. It should only
758 * fire when there's activity or once after we've entered
759 * RC6, and then won't be re-armed until the next RPS interrupt.
760 */
761 mod_delayed_work(dev_priv->wq, &dev_priv->rps.vlv_work,
762 msecs_to_jiffies(100));
763 }
764
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700765 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800766}
767
Ben Widawskye3689192012-05-25 16:56:22 -0700768
769/**
770 * ivybridge_parity_work - Workqueue called when a parity error interrupt
771 * occurred.
772 * @work: workqueue struct
773 *
774 * Doesn't actually do anything except notify userspace. As a consequence of
775 * this event, userspace should try to remap the bad rows since statistically
776 * it is likely the same row is more likely to go bad again.
777 */
778static void ivybridge_parity_work(struct work_struct *work)
779{
780 drm_i915_private_t *dev_priv = container_of(work, drm_i915_private_t,
Daniel Vettera4da4fa2012-11-02 19:55:07 +0100781 l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -0700782 u32 error_status, row, bank, subbank;
783 char *parity_event[5];
784 uint32_t misccpctl;
785 unsigned long flags;
786
787 /* We must turn off DOP level clock gating to access the L3 registers.
788 * In order to prevent a get/put style interface, acquire struct mutex
789 * any time we access those registers.
790 */
791 mutex_lock(&dev_priv->dev->struct_mutex);
792
793 misccpctl = I915_READ(GEN7_MISCCPCTL);
794 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
795 POSTING_READ(GEN7_MISCCPCTL);
796
797 error_status = I915_READ(GEN7_L3CDERRST1);
798 row = GEN7_PARITY_ERROR_ROW(error_status);
799 bank = GEN7_PARITY_ERROR_BANK(error_status);
800 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
801
802 I915_WRITE(GEN7_L3CDERRST1, GEN7_PARITY_ERROR_VALID |
803 GEN7_L3CDERRST1_ENABLE);
804 POSTING_READ(GEN7_L3CDERRST1);
805
806 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
807
808 spin_lock_irqsave(&dev_priv->irq_lock, flags);
Ben Widawskycc609d52013-05-28 19:22:29 -0700809 dev_priv->gt_irq_mask &= ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
Ben Widawskye3689192012-05-25 16:56:22 -0700810 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
811 spin_unlock_irqrestore(&dev_priv->irq_lock, flags);
812
813 mutex_unlock(&dev_priv->dev->struct_mutex);
814
Ben Widawskycce723e2013-07-19 09:16:42 -0700815 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
Ben Widawskye3689192012-05-25 16:56:22 -0700816 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
817 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
818 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
819 parity_event[4] = NULL;
820
821 kobject_uevent_env(&dev_priv->dev->primary->kdev.kobj,
822 KOBJ_CHANGE, parity_event);
823
824 DRM_DEBUG("Parity error: Row = %d, Bank = %d, Sub bank = %d.\n",
825 row, bank, subbank);
826
827 kfree(parity_event[3]);
828 kfree(parity_event[2]);
829 kfree(parity_event[1]);
830}
831
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200832static void ivybridge_parity_error_irq_handler(struct drm_device *dev)
Ben Widawskye3689192012-05-25 16:56:22 -0700833{
834 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -0700835
Ben Widawskye1ef7cc2012-07-24 20:47:31 -0700836 if (!HAS_L3_GPU_CACHE(dev))
Ben Widawskye3689192012-05-25 16:56:22 -0700837 return;
838
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200839 spin_lock(&dev_priv->irq_lock);
Ben Widawskycc609d52013-05-28 19:22:29 -0700840 dev_priv->gt_irq_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
Ben Widawskye3689192012-05-25 16:56:22 -0700841 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200842 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -0700843
Daniel Vettera4da4fa2012-11-02 19:55:07 +0100844 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -0700845}
846
Paulo Zanonif1af8fc2013-07-12 19:56:30 -0300847static void ilk_gt_irq_handler(struct drm_device *dev,
848 struct drm_i915_private *dev_priv,
849 u32 gt_iir)
850{
851 if (gt_iir &
852 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
853 notify_ring(dev, &dev_priv->ring[RCS]);
854 if (gt_iir & ILK_BSD_USER_INTERRUPT)
855 notify_ring(dev, &dev_priv->ring[VCS]);
856}
857
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200858static void snb_gt_irq_handler(struct drm_device *dev,
859 struct drm_i915_private *dev_priv,
860 u32 gt_iir)
861{
862
Ben Widawskycc609d52013-05-28 19:22:29 -0700863 if (gt_iir &
864 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200865 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -0700866 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200867 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -0700868 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200869 notify_ring(dev, &dev_priv->ring[BCS]);
870
Ben Widawskycc609d52013-05-28 19:22:29 -0700871 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
872 GT_BSD_CS_ERROR_INTERRUPT |
873 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200874 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
875 i915_handle_error(dev, false);
876 }
Ben Widawskye3689192012-05-25 16:56:22 -0700877
Ben Widawskycc609d52013-05-28 19:22:29 -0700878 if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200879 ivybridge_parity_error_irq_handler(dev);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200880}
881
Ben Widawskybaf02a12013-05-28 19:22:24 -0700882/* Legacy way of handling PM interrupts */
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200883static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv,
884 u32 pm_iir)
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100885{
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100886 /*
887 * IIR bits should never already be set because IMR should
888 * prevent an interrupt from being shown in IIR. The warning
889 * displays a case where we've unsafely cleared
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200890 * dev_priv->rps.pm_iir. Although missing an interrupt of the same
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100891 * type is not a problem, it displays a problem in the logic.
892 *
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200893 * The mask bit in IMR is cleared by dev_priv->rps.work.
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100894 */
895
Daniel Vetter59cdb632013-07-04 23:35:28 +0200896 spin_lock(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200897 dev_priv->rps.pm_iir |= pm_iir;
898 I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100899 POSTING_READ(GEN6_PMIMR);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200900 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100901
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200902 queue_work(dev_priv->wq, &dev_priv->rps.work);
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100903}
904
Egbert Eichb543fb02013-04-16 13:36:54 +0200905#define HPD_STORM_DETECT_PERIOD 1000
906#define HPD_STORM_THRESHOLD 5
907
Daniel Vetter10a504d2013-06-27 17:52:12 +0200908static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +0200909 u32 hotplug_trigger,
910 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +0200911{
912 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +0200913 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +0200914 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +0200915
Daniel Vetter91d131d2013-06-27 17:52:14 +0200916 if (!hotplug_trigger)
917 return;
918
Daniel Vetterb5ea2d52013-06-27 17:52:15 +0200919 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +0200920 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +0200921
Egbert Eichb8f102e2013-07-26 14:14:24 +0200922 WARN(((hpd[i] & hotplug_trigger) &&
923 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED),
924 "Received HPD interrupt although disabled\n");
925
Egbert Eichb543fb02013-04-16 13:36:54 +0200926 if (!(hpd[i] & hotplug_trigger) ||
927 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
928 continue;
929
Jani Nikulabc5ead8c2013-05-07 15:10:29 +0300930 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +0200931 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
932 dev_priv->hpd_stats[i].hpd_last_jiffies
933 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
934 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
935 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +0200936 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +0200937 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
938 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +0200939 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +0200940 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +0200941 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +0200942 } else {
943 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +0200944 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
945 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +0200946 }
947 }
948
Daniel Vetter10a504d2013-06-27 17:52:12 +0200949 if (storm_detected)
950 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +0200951 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +0200952
953 queue_work(dev_priv->wq,
954 &dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +0200955}
956
Daniel Vetter515ac2b2012-12-01 13:53:44 +0100957static void gmbus_irq_handler(struct drm_device *dev)
958{
Daniel Vetter28c70f12012-12-01 13:53:45 +0100959 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
960
Daniel Vetter28c70f12012-12-01 13:53:45 +0100961 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +0100962}
963
Daniel Vetterce99c252012-12-01 13:53:47 +0100964static void dp_aux_irq_handler(struct drm_device *dev)
965{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100966 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
967
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100968 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +0100969}
970
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200971/* Unlike gen6_rps_irq_handler() from which this function is originally derived,
Ben Widawskybaf02a12013-05-28 19:22:24 -0700972 * we must be able to deal with other PM interrupts. This is complicated because
973 * of the way in which we use the masks to defer the RPS work (which for
974 * posterity is necessary because of forcewake).
975 */
976static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv,
977 u32 pm_iir)
978{
Daniel Vetter41a05a32013-07-04 23:35:26 +0200979 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +0200980 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +0200981 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Ben Widawskybaf02a12013-05-28 19:22:24 -0700982 I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
983 /* never want to mask useful interrupts. (also posting read) */
Ben Widawsky48484052013-05-28 19:22:27 -0700984 WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200985 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +0200986
987 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -0700988 }
Ben Widawskybaf02a12013-05-28 19:22:24 -0700989
Daniel Vetter41a05a32013-07-04 23:35:26 +0200990 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
991 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -0700992
Daniel Vetter41a05a32013-07-04 23:35:26 +0200993 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
994 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
995 i915_handle_error(dev_priv->dev, false);
Ben Widawsky12638c52013-05-28 19:22:31 -0700996 }
Ben Widawskybaf02a12013-05-28 19:22:24 -0700997}
998
Daniel Vetterff1f5252012-10-02 15:10:55 +0200999static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001000{
1001 struct drm_device *dev = (struct drm_device *) arg;
1002 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1003 u32 iir, gt_iir, pm_iir;
1004 irqreturn_t ret = IRQ_NONE;
1005 unsigned long irqflags;
1006 int pipe;
1007 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001008
1009 atomic_inc(&dev_priv->irq_received);
1010
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001011 while (true) {
1012 iir = I915_READ(VLV_IIR);
1013 gt_iir = I915_READ(GTIIR);
1014 pm_iir = I915_READ(GEN6_PMIIR);
1015
1016 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1017 goto out;
1018
1019 ret = IRQ_HANDLED;
1020
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001021 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001022
1023 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1024 for_each_pipe(pipe) {
1025 int reg = PIPESTAT(pipe);
1026 pipe_stats[pipe] = I915_READ(reg);
1027
1028 /*
1029 * Clear the PIPE*STAT regs before the IIR
1030 */
1031 if (pipe_stats[pipe] & 0x8000ffff) {
1032 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1033 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1034 pipe_name(pipe));
1035 I915_WRITE(reg, pipe_stats[pipe]);
1036 }
1037 }
1038 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1039
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001040 for_each_pipe(pipe) {
1041 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1042 drm_handle_vblank(dev, pipe);
1043
1044 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1045 intel_prepare_page_flip(dev, pipe);
1046 intel_finish_page_flip(dev, pipe);
1047 }
1048 }
1049
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001050 /* Consume port. Then clear IIR or we'll miss events */
1051 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1052 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001053 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001054
1055 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1056 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001057
1058 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1059
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001060 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1061 I915_READ(PORT_HOTPLUG_STAT);
1062 }
1063
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001064 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1065 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001066
Ben Widawsky48484052013-05-28 19:22:27 -07001067 if (pm_iir & GEN6_PM_RPS_EVENTS)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001068 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001069
1070 I915_WRITE(GTIIR, gt_iir);
1071 I915_WRITE(GEN6_PMIIR, pm_iir);
1072 I915_WRITE(VLV_IIR, iir);
1073 }
1074
1075out:
1076 return ret;
1077}
1078
Adam Jackson23e81d62012-06-06 15:45:44 -04001079static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001080{
1081 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001082 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001083 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001084
Daniel Vetter91d131d2013-06-27 17:52:14 +02001085 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1086
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001087 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1088 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1089 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001090 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001091 port_name(port));
1092 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001093
Daniel Vetterce99c252012-12-01 13:53:47 +01001094 if (pch_iir & SDE_AUX_MASK)
1095 dp_aux_irq_handler(dev);
1096
Jesse Barnes776ad802011-01-04 15:09:39 -08001097 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001098 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001099
1100 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1101 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1102
1103 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1104 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1105
1106 if (pch_iir & SDE_POISON)
1107 DRM_ERROR("PCH poison interrupt\n");
1108
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001109 if (pch_iir & SDE_FDI_MASK)
1110 for_each_pipe(pipe)
1111 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1112 pipe_name(pipe),
1113 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001114
1115 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1116 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1117
1118 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1119 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1120
Jesse Barnes776ad802011-01-04 15:09:39 -08001121 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001122 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1123 false))
1124 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1125
1126 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1127 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1128 false))
1129 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1130}
1131
1132static void ivb_err_int_handler(struct drm_device *dev)
1133{
1134 struct drm_i915_private *dev_priv = dev->dev_private;
1135 u32 err_int = I915_READ(GEN7_ERR_INT);
1136
Paulo Zanonide032bf2013-04-12 17:57:58 -03001137 if (err_int & ERR_INT_POISON)
1138 DRM_ERROR("Poison interrupt\n");
1139
Paulo Zanoni86642812013-04-12 17:57:57 -03001140 if (err_int & ERR_INT_FIFO_UNDERRUN_A)
1141 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1142 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1143
1144 if (err_int & ERR_INT_FIFO_UNDERRUN_B)
1145 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1146 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1147
1148 if (err_int & ERR_INT_FIFO_UNDERRUN_C)
1149 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
1150 DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
1151
1152 I915_WRITE(GEN7_ERR_INT, err_int);
1153}
1154
1155static void cpt_serr_int_handler(struct drm_device *dev)
1156{
1157 struct drm_i915_private *dev_priv = dev->dev_private;
1158 u32 serr_int = I915_READ(SERR_INT);
1159
Paulo Zanonide032bf2013-04-12 17:57:58 -03001160 if (serr_int & SERR_INT_POISON)
1161 DRM_ERROR("PCH poison interrupt\n");
1162
Paulo Zanoni86642812013-04-12 17:57:57 -03001163 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1164 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1165 false))
1166 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1167
1168 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1169 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1170 false))
1171 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1172
1173 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1174 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1175 false))
1176 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1177
1178 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001179}
1180
Adam Jackson23e81d62012-06-06 15:45:44 -04001181static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1182{
1183 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1184 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001185 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001186
Daniel Vetter91d131d2013-06-27 17:52:14 +02001187 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1188
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001189 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1190 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1191 SDE_AUDIO_POWER_SHIFT_CPT);
1192 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1193 port_name(port));
1194 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001195
1196 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001197 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001198
1199 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001200 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001201
1202 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1203 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1204
1205 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1206 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1207
1208 if (pch_iir & SDE_FDI_MASK_CPT)
1209 for_each_pipe(pipe)
1210 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1211 pipe_name(pipe),
1212 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001213
1214 if (pch_iir & SDE_ERROR_CPT)
1215 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001216}
1217
Paulo Zanonic008bc62013-07-12 16:35:10 -03001218static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1219{
1220 struct drm_i915_private *dev_priv = dev->dev_private;
1221
1222 if (de_iir & DE_AUX_CHANNEL_A)
1223 dp_aux_irq_handler(dev);
1224
1225 if (de_iir & DE_GSE)
1226 intel_opregion_asle_intr(dev);
1227
1228 if (de_iir & DE_PIPEA_VBLANK)
1229 drm_handle_vblank(dev, 0);
1230
1231 if (de_iir & DE_PIPEB_VBLANK)
1232 drm_handle_vblank(dev, 1);
1233
1234 if (de_iir & DE_POISON)
1235 DRM_ERROR("Poison interrupt\n");
1236
1237 if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
1238 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1239 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1240
1241 if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
1242 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1243 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1244
1245 if (de_iir & DE_PLANEA_FLIP_DONE) {
1246 intel_prepare_page_flip(dev, 0);
1247 intel_finish_page_flip_plane(dev, 0);
1248 }
1249
1250 if (de_iir & DE_PLANEB_FLIP_DONE) {
1251 intel_prepare_page_flip(dev, 1);
1252 intel_finish_page_flip_plane(dev, 1);
1253 }
1254
1255 /* check event from PCH */
1256 if (de_iir & DE_PCH_EVENT) {
1257 u32 pch_iir = I915_READ(SDEIIR);
1258
1259 if (HAS_PCH_CPT(dev))
1260 cpt_irq_handler(dev, pch_iir);
1261 else
1262 ibx_irq_handler(dev, pch_iir);
1263
1264 /* should clear PCH hotplug event before clear CPU irq */
1265 I915_WRITE(SDEIIR, pch_iir);
1266 }
1267
1268 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1269 ironlake_rps_change_irq_handler(dev);
1270}
1271
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001272static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1273{
1274 struct drm_i915_private *dev_priv = dev->dev_private;
1275 int i;
1276
1277 if (de_iir & DE_ERR_INT_IVB)
1278 ivb_err_int_handler(dev);
1279
1280 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1281 dp_aux_irq_handler(dev);
1282
1283 if (de_iir & DE_GSE_IVB)
1284 intel_opregion_asle_intr(dev);
1285
1286 for (i = 0; i < 3; i++) {
1287 if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
1288 drm_handle_vblank(dev, i);
1289 if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
1290 intel_prepare_page_flip(dev, i);
1291 intel_finish_page_flip_plane(dev, i);
1292 }
1293 }
1294
1295 /* check event from PCH */
1296 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1297 u32 pch_iir = I915_READ(SDEIIR);
1298
1299 cpt_irq_handler(dev, pch_iir);
1300
1301 /* clear PCH hotplug event before clear CPU irq */
1302 I915_WRITE(SDEIIR, pch_iir);
1303 }
1304}
1305
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001306static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001307{
1308 struct drm_device *dev = (struct drm_device *) arg;
1309 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001310 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001311 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001312
1313 atomic_inc(&dev_priv->irq_received);
1314
Paulo Zanoni86642812013-04-12 17:57:57 -03001315 /* We get interrupts on unclaimed registers, so check for this before we
1316 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001317 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001318
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001319 /* disable master interrupt before clearing iir */
1320 de_ier = I915_READ(DEIER);
1321 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001322 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001323
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001324 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1325 * interrupts will will be stored on its back queue, and then we'll be
1326 * able to process them after we restore SDEIER (as soon as we restore
1327 * it, we'll get an interrupt if SDEIIR still has something to process
1328 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001329 if (!HAS_PCH_NOP(dev)) {
1330 sde_ier = I915_READ(SDEIER);
1331 I915_WRITE(SDEIER, 0);
1332 POSTING_READ(SDEIER);
1333 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001334
Paulo Zanoni86642812013-04-12 17:57:57 -03001335 /* On Haswell, also mask ERR_INT because we don't want to risk
1336 * generating "unclaimed register" interrupts from inside the interrupt
1337 * handler. */
Daniel Vetter4bc9d432013-06-27 13:44:58 +02001338 if (IS_HASWELL(dev)) {
1339 spin_lock(&dev_priv->irq_lock);
Paulo Zanoni86642812013-04-12 17:57:57 -03001340 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02001341 spin_unlock(&dev_priv->irq_lock);
1342 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001343
Chris Wilson0e434062012-05-09 21:45:44 +01001344 gt_iir = I915_READ(GTIIR);
1345 if (gt_iir) {
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001346 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001347 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001348 else
1349 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001350 I915_WRITE(GTIIR, gt_iir);
1351 ret = IRQ_HANDLED;
1352 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001353
1354 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001355 if (de_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001356 if (INTEL_INFO(dev)->gen >= 7)
1357 ivb_display_irq_handler(dev, de_iir);
1358 else
1359 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001360 I915_WRITE(DEIIR, de_iir);
1361 ret = IRQ_HANDLED;
1362 }
1363
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001364 if (INTEL_INFO(dev)->gen >= 6) {
1365 u32 pm_iir = I915_READ(GEN6_PMIIR);
1366 if (pm_iir) {
1367 if (IS_HASWELL(dev))
1368 hsw_pm_irq_handler(dev_priv, pm_iir);
1369 else if (pm_iir & GEN6_PM_RPS_EVENTS)
1370 gen6_rps_irq_handler(dev_priv, pm_iir);
1371 I915_WRITE(GEN6_PMIIR, pm_iir);
1372 ret = IRQ_HANDLED;
1373 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001374 }
1375
Daniel Vetter4bc9d432013-06-27 13:44:58 +02001376 if (IS_HASWELL(dev)) {
1377 spin_lock(&dev_priv->irq_lock);
1378 if (ivb_can_enable_err_int(dev))
1379 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
1380 spin_unlock(&dev_priv->irq_lock);
1381 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001382
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001383 I915_WRITE(DEIER, de_ier);
1384 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001385 if (!HAS_PCH_NOP(dev)) {
1386 I915_WRITE(SDEIER, sde_ier);
1387 POSTING_READ(SDEIER);
1388 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001389
1390 return ret;
1391}
1392
Jesse Barnes8a905232009-07-11 16:48:03 -04001393/**
1394 * i915_error_work_func - do process context error handling work
1395 * @work: work struct
1396 *
1397 * Fire an error uevent so userspace can see that a hang or error
1398 * was detected.
1399 */
1400static void i915_error_work_func(struct work_struct *work)
1401{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001402 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1403 work);
1404 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1405 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001406 struct drm_device *dev = dev_priv->dev;
Daniel Vetterf69061b2012-12-06 09:01:42 +01001407 struct intel_ring_buffer *ring;
Ben Widawskycce723e2013-07-19 09:16:42 -07001408 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
1409 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
1410 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetterf69061b2012-12-06 09:01:42 +01001411 int i, ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001412
Ben Gamarif316a422009-09-14 17:48:46 -04001413 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001414
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001415 /*
1416 * Note that there's only one work item which does gpu resets, so we
1417 * need not worry about concurrent gpu resets potentially incrementing
1418 * error->reset_counter twice. We only need to take care of another
1419 * racing irq/hangcheck declaring the gpu dead for a second time. A
1420 * quick check for that is good enough: schedule_work ensures the
1421 * correct ordering between hang detection and this work item, and since
1422 * the reset in-progress bit is only ever set by code outside of this
1423 * work we don't need to worry about any other races.
1424 */
1425 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001426 DRM_DEBUG_DRIVER("resetting chip\n");
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001427 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
1428 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001429
Daniel Vetterf69061b2012-12-06 09:01:42 +01001430 ret = i915_reset(dev);
1431
1432 if (ret == 0) {
1433 /*
1434 * After all the gem state is reset, increment the reset
1435 * counter and wake up everyone waiting for the reset to
1436 * complete.
1437 *
1438 * Since unlock operations are a one-sided barrier only,
1439 * we need to insert a barrier here to order any seqno
1440 * updates before
1441 * the counter increment.
1442 */
1443 smp_mb__before_atomic_inc();
1444 atomic_inc(&dev_priv->gpu_error.reset_counter);
1445
1446 kobject_uevent_env(&dev->primary->kdev.kobj,
1447 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001448 } else {
1449 atomic_set(&error->reset_counter, I915_WEDGED);
Ben Gamarif316a422009-09-14 17:48:46 -04001450 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001451
Daniel Vetterf69061b2012-12-06 09:01:42 +01001452 for_each_ring(ring, dev_priv, i)
1453 wake_up_all(&ring->irq_queue);
1454
Ville Syrjälä96a02912013-02-18 19:08:49 +02001455 intel_display_handle_reset(dev);
1456
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001457 wake_up_all(&dev_priv->gpu_error.reset_queue);
Ben Gamarif316a422009-09-14 17:48:46 -04001458 }
Jesse Barnes8a905232009-07-11 16:48:03 -04001459}
1460
Chris Wilson35aed2e2010-05-27 13:18:12 +01001461static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04001462{
1463 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07001464 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04001465 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07001466 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04001467
Chris Wilson35aed2e2010-05-27 13:18:12 +01001468 if (!eir)
1469 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04001470
Joe Perchesa70491c2012-03-18 13:00:11 -07001471 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04001472
Ben Widawskybd9854f2012-08-23 15:18:09 -07001473 i915_get_extra_instdone(dev, instdone);
1474
Jesse Barnes8a905232009-07-11 16:48:03 -04001475 if (IS_G4X(dev)) {
1476 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1477 u32 ipeir = I915_READ(IPEIR_I965);
1478
Joe Perchesa70491c2012-03-18 13:00:11 -07001479 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1480 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07001481 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1482 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07001483 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001484 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001485 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001486 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001487 }
1488 if (eir & GM45_ERROR_PAGE_TABLE) {
1489 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001490 pr_err("page table error\n");
1491 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001492 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001493 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001494 }
1495 }
1496
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001497 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001498 if (eir & I915_ERROR_PAGE_TABLE) {
1499 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001500 pr_err("page table error\n");
1501 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001502 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001503 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001504 }
1505 }
1506
1507 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001508 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001509 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07001510 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001511 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04001512 /* pipestat has already been acked */
1513 }
1514 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001515 pr_err("instruction error\n");
1516 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07001517 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1518 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001519 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001520 u32 ipeir = I915_READ(IPEIR);
1521
Joe Perchesa70491c2012-03-18 13:00:11 -07001522 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
1523 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07001524 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04001525 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001526 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001527 } else {
1528 u32 ipeir = I915_READ(IPEIR_I965);
1529
Joe Perchesa70491c2012-03-18 13:00:11 -07001530 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1531 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07001532 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001533 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001534 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001535 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001536 }
1537 }
1538
1539 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001540 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001541 eir = I915_READ(EIR);
1542 if (eir) {
1543 /*
1544 * some errors might have become stuck,
1545 * mask them.
1546 */
1547 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1548 I915_WRITE(EMR, I915_READ(EMR) | eir);
1549 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1550 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01001551}
1552
1553/**
1554 * i915_handle_error - handle an error interrupt
1555 * @dev: drm device
1556 *
1557 * Do some basic checking of regsiter state at error interrupt time and
1558 * dump it to the syslog. Also call i915_capture_error_state() to make
1559 * sure we get a record and make it available in debugfs. Fire a uevent
1560 * so userspace knows something bad happened (should trigger collection
1561 * of a ring dump etc.).
1562 */
Chris Wilson527f9e92010-11-11 01:16:58 +00001563void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01001564{
1565 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01001566 struct intel_ring_buffer *ring;
1567 int i;
Chris Wilson35aed2e2010-05-27 13:18:12 +01001568
1569 i915_capture_error_state(dev);
1570 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04001571
Ben Gamariba1234d2009-09-14 17:48:47 -04001572 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01001573 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
1574 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04001575
Ben Gamari11ed50e2009-09-14 17:48:45 -04001576 /*
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001577 * Wakeup waiting processes so that the reset work item
1578 * doesn't deadlock trying to grab various locks.
Ben Gamari11ed50e2009-09-14 17:48:45 -04001579 */
Chris Wilsonb4519512012-05-11 14:29:30 +01001580 for_each_ring(ring, dev_priv, i)
1581 wake_up_all(&ring->irq_queue);
Ben Gamari11ed50e2009-09-14 17:48:45 -04001582 }
1583
Daniel Vetter99584db2012-11-14 17:14:04 +01001584 queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04001585}
1586
Ville Syrjälä21ad8332013-02-19 15:16:39 +02001587static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001588{
1589 drm_i915_private_t *dev_priv = dev->dev_private;
1590 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1591 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00001592 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001593 struct intel_unpin_work *work;
1594 unsigned long flags;
1595 bool stall_detected;
1596
1597 /* Ignore early vblank irqs */
1598 if (intel_crtc == NULL)
1599 return;
1600
1601 spin_lock_irqsave(&dev->event_lock, flags);
1602 work = intel_crtc->unpin_work;
1603
Chris Wilsone7d841c2012-12-03 11:36:30 +00001604 if (work == NULL ||
1605 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
1606 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001607 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1608 spin_unlock_irqrestore(&dev->event_lock, flags);
1609 return;
1610 }
1611
1612 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00001613 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001614 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001615 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07001616 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001617 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001618 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001619 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001620 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02001621 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001622 crtc->x * crtc->fb->bits_per_pixel/8);
1623 }
1624
1625 spin_unlock_irqrestore(&dev->event_lock, flags);
1626
1627 if (stall_detected) {
1628 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1629 intel_prepare_page_flip(dev, intel_crtc->plane);
1630 }
1631}
1632
Keith Packard42f52ef2008-10-18 19:39:29 -07001633/* Called from drm generic code, passed 'crtc' which
1634 * we use as a pipe index
1635 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001636static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001637{
1638 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001639 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001640
Chris Wilson5eddb702010-09-11 13:48:45 +01001641 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001642 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001643
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001644 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07001645 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08001646 i915_enable_pipestat(dev_priv, pipe,
1647 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07001648 else
Keith Packard7c463582008-11-04 02:03:27 -08001649 i915_enable_pipestat(dev_priv, pipe,
1650 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001651
1652 /* maintain vblank delivery even in deep C-states */
1653 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02001654 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001655 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001656
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001657 return 0;
1658}
1659
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001660static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07001661{
1662 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1663 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03001664 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
1665 DE_PIPE_VBLANK_ILK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07001666
1667 if (!i915_pipe_enabled(dev, pipe))
1668 return -EINVAL;
1669
1670 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03001671 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001672 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1673
1674 return 0;
1675}
1676
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001677static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
1678{
1679 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1680 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001681 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001682
1683 if (!i915_pipe_enabled(dev, pipe))
1684 return -EINVAL;
1685
1686 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001687 imr = I915_READ(VLV_IMR);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001688 if (pipe == 0)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001689 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001690 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001691 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001692 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001693 i915_enable_pipestat(dev_priv, pipe,
1694 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001695 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1696
1697 return 0;
1698}
1699
Keith Packard42f52ef2008-10-18 19:39:29 -07001700/* Called from drm generic code, passed 'crtc' which
1701 * we use as a pipe index
1702 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001703static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001704{
1705 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001706 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001707
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001708 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001709 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02001710 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00001711
Jesse Barnesf796cf82011-04-07 13:58:17 -07001712 i915_disable_pipestat(dev_priv, pipe,
1713 PIPE_VBLANK_INTERRUPT_ENABLE |
1714 PIPE_START_VBLANK_INTERRUPT_ENABLE);
1715 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1716}
1717
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001718static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07001719{
1720 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1721 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03001722 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
1723 DE_PIPE_VBLANK_ILK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07001724
1725 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03001726 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001727 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1728}
1729
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001730static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
1731{
1732 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1733 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001734 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001735
1736 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001737 i915_disable_pipestat(dev_priv, pipe,
1738 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001739 imr = I915_READ(VLV_IMR);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001740 if (pipe == 0)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001741 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001742 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001743 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001744 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001745 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1746}
1747
Chris Wilson893eead2010-10-27 14:44:35 +01001748static u32
1749ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08001750{
Chris Wilson893eead2010-10-27 14:44:35 +01001751 return list_entry(ring->request_list.prev,
1752 struct drm_i915_gem_request, list)->seqno;
1753}
1754
Chris Wilson9107e9d2013-06-10 11:20:20 +01001755static bool
1756ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01001757{
Chris Wilson9107e9d2013-06-10 11:20:20 +01001758 return (list_empty(&ring->request_list) ||
1759 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04001760}
1761
Chris Wilson6274f212013-06-10 11:20:21 +01001762static struct intel_ring_buffer *
1763semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02001764{
1765 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01001766 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001767
1768 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
1769 if ((ipehr & ~(0x3 << 16)) !=
1770 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01001771 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001772
1773 /* ACTHD is likely pointing to the dword after the actual command,
1774 * so scan backwards until we find the MBOX.
1775 */
Chris Wilson6274f212013-06-10 11:20:21 +01001776 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001777 acthd_min = max((int)acthd - 3 * 4, 0);
1778 do {
1779 cmd = ioread32(ring->virtual_start + acthd);
1780 if (cmd == ipehr)
1781 break;
1782
1783 acthd -= 4;
1784 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01001785 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001786 } while (1);
1787
Chris Wilson6274f212013-06-10 11:20:21 +01001788 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
1789 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02001790}
1791
Chris Wilson6274f212013-06-10 11:20:21 +01001792static int semaphore_passed(struct intel_ring_buffer *ring)
1793{
1794 struct drm_i915_private *dev_priv = ring->dev->dev_private;
1795 struct intel_ring_buffer *signaller;
1796 u32 seqno, ctl;
1797
1798 ring->hangcheck.deadlock = true;
1799
1800 signaller = semaphore_waits_for(ring, &seqno);
1801 if (signaller == NULL || signaller->hangcheck.deadlock)
1802 return -1;
1803
1804 /* cursory check for an unkickable deadlock */
1805 ctl = I915_READ_CTL(signaller);
1806 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
1807 return -1;
1808
1809 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
1810}
1811
1812static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
1813{
1814 struct intel_ring_buffer *ring;
1815 int i;
1816
1817 for_each_ring(ring, dev_priv, i)
1818 ring->hangcheck.deadlock = false;
1819}
1820
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03001821static enum intel_ring_hangcheck_action
1822ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001823{
1824 struct drm_device *dev = ring->dev;
1825 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001826 u32 tmp;
1827
Chris Wilson6274f212013-06-10 11:20:21 +01001828 if (ring->hangcheck.acthd != acthd)
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001829 return HANGCHECK_ACTIVE;
Chris Wilson6274f212013-06-10 11:20:21 +01001830
Chris Wilson9107e9d2013-06-10 11:20:20 +01001831 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001832 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001833
1834 /* Is the chip hanging on a WAIT_FOR_EVENT?
1835 * If so we can simply poke the RB_WAIT bit
1836 * and break the hang. This should work on
1837 * all but the second generation chipsets.
1838 */
1839 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001840 if (tmp & RING_WAIT) {
1841 DRM_ERROR("Kicking stuck wait on %s\n",
1842 ring->name);
1843 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001844 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001845 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02001846
Chris Wilson6274f212013-06-10 11:20:21 +01001847 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
1848 switch (semaphore_passed(ring)) {
1849 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001850 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01001851 case 1:
1852 DRM_ERROR("Kicking stuck semaphore on %s\n",
1853 ring->name);
1854 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001855 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01001856 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001857 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01001858 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01001859 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03001860
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001861 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03001862}
1863
Ben Gamarif65d9422009-09-14 17:48:44 -04001864/**
1865 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001866 * batchbuffers in a long time. We keep track per ring seqno progress and
1867 * if there are no progress, hangcheck score for that ring is increased.
1868 * Further, acthd is inspected to see if the ring is stuck. On stuck case
1869 * we kick the ring. If we see no progress on three subsequent calls
1870 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04001871 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01001872static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04001873{
1874 struct drm_device *dev = (struct drm_device *)data;
1875 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01001876 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01001877 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001878 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001879 bool stuck[I915_NUM_RINGS] = { 0 };
1880#define BUSY 1
1881#define KICK 5
1882#define HUNG 20
1883#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01001884
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07001885 if (!i915_enable_hangcheck)
1886 return;
1887
Chris Wilsonb4519512012-05-11 14:29:30 +01001888 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001889 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001890 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01001891
Chris Wilson6274f212013-06-10 11:20:21 +01001892 semaphore_clear_deadlocks(dev_priv);
1893
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001894 seqno = ring->get_seqno(ring, false);
1895 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01001896
Chris Wilson9107e9d2013-06-10 11:20:20 +01001897 if (ring->hangcheck.seqno == seqno) {
1898 if (ring_idle(ring, seqno)) {
1899 if (waitqueue_active(&ring->irq_queue)) {
1900 /* Issue a wake-up to catch stuck h/w. */
1901 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
1902 ring->name);
1903 wake_up_all(&ring->irq_queue);
1904 ring->hangcheck.score += HUNG;
1905 } else
1906 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001907 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01001908 /* We always increment the hangcheck score
1909 * if the ring is busy and still processing
1910 * the same request, so that no single request
1911 * can run indefinitely (such as a chain of
1912 * batches). The only time we do not increment
1913 * the hangcheck score on this ring, if this
1914 * ring is in a legitimate wait for another
1915 * ring. In that case the waiting ring is a
1916 * victim and we want to be sure we catch the
1917 * right culprit. Then every time we do kick
1918 * the ring, add a small increment to the
1919 * score so that we can catch a batch that is
1920 * being repeatedly kicked and so responsible
1921 * for stalling the machine.
1922 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03001923 ring->hangcheck.action = ring_stuck(ring,
1924 acthd);
1925
1926 switch (ring->hangcheck.action) {
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001927 case HANGCHECK_WAIT:
Chris Wilson6274f212013-06-10 11:20:21 +01001928 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001929 case HANGCHECK_ACTIVE:
Jani Nikulaea04cb32013-08-11 12:44:02 +03001930 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01001931 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001932 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03001933 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01001934 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03001935 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03001936 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01001937 stuck[i] = true;
1938 break;
1939 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001940 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01001941 } else {
1942 /* Gradually reduce the count so that we catch DoS
1943 * attempts across multiple batches.
1944 */
1945 if (ring->hangcheck.score > 0)
1946 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01001947 }
1948
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001949 ring->hangcheck.seqno = seqno;
1950 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001951 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01001952 }
Eric Anholtb9201c12010-01-08 14:25:16 -08001953
Mika Kuoppala92cab732013-05-24 17:16:07 +03001954 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01001955 if (ring->hangcheck.score > FIRE) {
Ben Widawskyacd78c12013-06-13 21:33:33 -07001956 DRM_ERROR("%s on %s\n",
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001957 stuck[i] ? "stuck" : "no progress",
Chris Wilsona43adf02013-06-10 11:20:22 +01001958 ring->name);
1959 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03001960 }
1961 }
1962
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001963 if (rings_hung)
1964 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04001965
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001966 if (busy_count)
1967 /* Reset timer case chip hangs without another request
1968 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03001969 i915_queue_hangcheck(dev);
1970}
1971
1972void i915_queue_hangcheck(struct drm_device *dev)
1973{
1974 struct drm_i915_private *dev_priv = dev->dev_private;
1975 if (!i915_enable_hangcheck)
1976 return;
1977
1978 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
1979 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04001980}
1981
Paulo Zanoni91738a92013-06-05 14:21:51 -03001982static void ibx_irq_preinstall(struct drm_device *dev)
1983{
1984 struct drm_i915_private *dev_priv = dev->dev_private;
1985
1986 if (HAS_PCH_NOP(dev))
1987 return;
1988
1989 /* south display irq */
1990 I915_WRITE(SDEIMR, 0xffffffff);
1991 /*
1992 * SDEIER is also touched by the interrupt handler to work around missed
1993 * PCH interrupts. Hence we can't update it after the interrupt handler
1994 * is enabled - instead we unconditionally enable all PCH interrupt
1995 * sources here, but then only unmask them as needed with SDEIMR.
1996 */
1997 I915_WRITE(SDEIER, 0xffffffff);
1998 POSTING_READ(SDEIER);
1999}
2000
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002001static void gen5_gt_irq_preinstall(struct drm_device *dev)
2002{
2003 struct drm_i915_private *dev_priv = dev->dev_private;
2004
2005 /* and GT */
2006 I915_WRITE(GTIMR, 0xffffffff);
2007 I915_WRITE(GTIER, 0x0);
2008 POSTING_READ(GTIER);
2009
2010 if (INTEL_INFO(dev)->gen >= 6) {
2011 /* and PM */
2012 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2013 I915_WRITE(GEN6_PMIER, 0x0);
2014 POSTING_READ(GEN6_PMIER);
2015 }
2016}
2017
Linus Torvalds1da177e2005-04-16 15:20:36 -07002018/* drm_dma.h hooks
2019*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002020static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002021{
2022 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2023
Jesse Barnes46979952011-04-07 13:53:55 -07002024 atomic_set(&dev_priv->irq_received, 0);
2025
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002026 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002027
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002028 I915_WRITE(DEIMR, 0xffffffff);
2029 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002030 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002031
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002032 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002033
Paulo Zanoni91738a92013-06-05 14:21:51 -03002034 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002035}
2036
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002037static void valleyview_irq_preinstall(struct drm_device *dev)
2038{
2039 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2040 int pipe;
2041
2042 atomic_set(&dev_priv->irq_received, 0);
2043
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002044 /* VLV magic */
2045 I915_WRITE(VLV_IMR, 0);
2046 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2047 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2048 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2049
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002050 /* and GT */
2051 I915_WRITE(GTIIR, I915_READ(GTIIR));
2052 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002053
2054 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002055
2056 I915_WRITE(DPINVGTT, 0xff);
2057
2058 I915_WRITE(PORT_HOTPLUG_EN, 0);
2059 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2060 for_each_pipe(pipe)
2061 I915_WRITE(PIPESTAT(pipe), 0xffff);
2062 I915_WRITE(VLV_IIR, 0xffffffff);
2063 I915_WRITE(VLV_IMR, 0xffffffff);
2064 I915_WRITE(VLV_IER, 0x0);
2065 POSTING_READ(VLV_IER);
2066}
2067
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002068static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002069{
2070 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002071 struct drm_mode_config *mode_config = &dev->mode_config;
2072 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002073 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002074
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002075 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002076 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002077 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002078 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002079 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002080 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002081 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002082 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002083 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002084 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002085 }
2086
Daniel Vetterfee884e2013-07-04 23:35:21 +02002087 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002088
2089 /*
2090 * Enable digital hotplug on the PCH, and configure the DP short pulse
2091 * duration to 2ms (which is the minimum in the Display Port spec)
2092 *
2093 * This register is the same on all known PCH chips.
2094 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002095 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2096 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2097 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2098 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2099 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2100 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2101}
2102
Paulo Zanonid46da432013-02-08 17:35:15 -02002103static void ibx_irq_postinstall(struct drm_device *dev)
2104{
2105 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002106 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002107
Daniel Vetter692a04c2013-05-29 21:43:05 +02002108 if (HAS_PCH_NOP(dev))
2109 return;
2110
Paulo Zanoni86642812013-04-12 17:57:57 -03002111 if (HAS_PCH_IBX(dev)) {
2112 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002113 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002114 } else {
2115 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2116
2117 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2118 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002119
Paulo Zanonid46da432013-02-08 17:35:15 -02002120 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2121 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002122}
2123
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002124static void gen5_gt_irq_postinstall(struct drm_device *dev)
2125{
2126 struct drm_i915_private *dev_priv = dev->dev_private;
2127 u32 pm_irqs, gt_irqs;
2128
2129 pm_irqs = gt_irqs = 0;
2130
2131 dev_priv->gt_irq_mask = ~0;
2132 if (HAS_L3_GPU_CACHE(dev)) {
2133 /* L3 parity interrupt is always unmasked. */
2134 dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
2135 gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
2136 }
2137
2138 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2139 if (IS_GEN5(dev)) {
2140 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2141 ILK_BSD_USER_INTERRUPT;
2142 } else {
2143 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2144 }
2145
2146 I915_WRITE(GTIIR, I915_READ(GTIIR));
2147 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2148 I915_WRITE(GTIER, gt_irqs);
2149 POSTING_READ(GTIER);
2150
2151 if (INTEL_INFO(dev)->gen >= 6) {
2152 pm_irqs |= GEN6_PM_RPS_EVENTS;
2153
2154 if (HAS_VEBOX(dev))
2155 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2156
2157 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
2158 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2159 I915_WRITE(GEN6_PMIER, pm_irqs);
2160 POSTING_READ(GEN6_PMIER);
2161 }
2162}
2163
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002164static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002165{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002166 unsigned long irqflags;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002167 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002168 u32 display_mask, extra_mask;
2169
2170 if (INTEL_INFO(dev)->gen >= 7) {
2171 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
2172 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
2173 DE_PLANEB_FLIP_DONE_IVB |
2174 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB |
2175 DE_ERR_INT_IVB);
2176 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
2177 DE_PIPEA_VBLANK_IVB);
2178
2179 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
2180 } else {
2181 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
2182 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
2183 DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
2184 DE_PIPEA_FIFO_UNDERRUN | DE_POISON);
2185 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT;
2186 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002187
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002188 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002189
2190 /* should always can generate irq */
2191 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002192 I915_WRITE(DEIMR, dev_priv->irq_mask);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03002193 I915_WRITE(DEIER, display_mask | extra_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002194 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002195
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002196 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002197
Paulo Zanonid46da432013-02-08 17:35:15 -02002198 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002199
Jesse Barnesf97108d2010-01-29 11:27:07 -08002200 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002201 /* Enable PCU event interrupts
2202 *
2203 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002204 * setup is guaranteed to run in single-threaded context. But we
2205 * need it to make the assert_spin_locked happy. */
2206 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002207 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002208 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002209 }
2210
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002211 return 0;
2212}
2213
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002214static int valleyview_irq_postinstall(struct drm_device *dev)
2215{
2216 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002217 u32 enable_mask;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002218 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002219 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002220
2221 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002222 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2223 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2224 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002225 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2226
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002227 /*
2228 *Leave vblank interrupts masked initially. enable/disable will
2229 * toggle them based on usage.
2230 */
2231 dev_priv->irq_mask = (~enable_mask) |
2232 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2233 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002234
Daniel Vetter20afbda2012-12-11 14:05:07 +01002235 I915_WRITE(PORT_HOTPLUG_EN, 0);
2236 POSTING_READ(PORT_HOTPLUG_EN);
2237
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002238 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2239 I915_WRITE(VLV_IER, enable_mask);
2240 I915_WRITE(VLV_IIR, 0xffffffff);
2241 I915_WRITE(PIPESTAT(0), 0xffff);
2242 I915_WRITE(PIPESTAT(1), 0xffff);
2243 POSTING_READ(VLV_IER);
2244
Daniel Vetterb79480b2013-06-27 17:52:10 +02002245 /* Interrupt setup is already guaranteed to be single-threaded, this is
2246 * just to make the assert_spin_locked check happy. */
2247 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002248 i915_enable_pipestat(dev_priv, 0, pipestat_enable);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002249 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002250 i915_enable_pipestat(dev_priv, 1, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002251 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002252
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002253 I915_WRITE(VLV_IIR, 0xffffffff);
2254 I915_WRITE(VLV_IIR, 0xffffffff);
2255
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002256 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002257
2258 /* ack & enable invalid PTE error interrupts */
2259#if 0 /* FIXME: add support to irq handler for checking these bits */
2260 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2261 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2262#endif
2263
2264 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002265
2266 return 0;
2267}
2268
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002269static void valleyview_irq_uninstall(struct drm_device *dev)
2270{
2271 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2272 int pipe;
2273
2274 if (!dev_priv)
2275 return;
2276
Egbert Eichac4c16c2013-04-16 13:36:58 +02002277 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2278
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002279 for_each_pipe(pipe)
2280 I915_WRITE(PIPESTAT(pipe), 0xffff);
2281
2282 I915_WRITE(HWSTAM, 0xffffffff);
2283 I915_WRITE(PORT_HOTPLUG_EN, 0);
2284 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2285 for_each_pipe(pipe)
2286 I915_WRITE(PIPESTAT(pipe), 0xffff);
2287 I915_WRITE(VLV_IIR, 0xffffffff);
2288 I915_WRITE(VLV_IMR, 0xffffffff);
2289 I915_WRITE(VLV_IER, 0x0);
2290 POSTING_READ(VLV_IER);
2291}
2292
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002293static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002294{
2295 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07002296
2297 if (!dev_priv)
2298 return;
2299
Egbert Eichac4c16c2013-04-16 13:36:58 +02002300 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2301
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002302 I915_WRITE(HWSTAM, 0xffffffff);
2303
2304 I915_WRITE(DEIMR, 0xffffffff);
2305 I915_WRITE(DEIER, 0x0);
2306 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002307 if (IS_GEN7(dev))
2308 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002309
2310 I915_WRITE(GTIMR, 0xffffffff);
2311 I915_WRITE(GTIER, 0x0);
2312 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07002313
Ben Widawskyab5c6082013-04-05 13:12:41 -07002314 if (HAS_PCH_NOP(dev))
2315 return;
2316
Keith Packard192aac1f2011-09-20 10:12:44 -07002317 I915_WRITE(SDEIMR, 0xffffffff);
2318 I915_WRITE(SDEIER, 0x0);
2319 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002320 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
2321 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002322}
2323
Chris Wilsonc2798b12012-04-22 21:13:57 +01002324static void i8xx_irq_preinstall(struct drm_device * dev)
2325{
2326 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2327 int pipe;
2328
2329 atomic_set(&dev_priv->irq_received, 0);
2330
2331 for_each_pipe(pipe)
2332 I915_WRITE(PIPESTAT(pipe), 0);
2333 I915_WRITE16(IMR, 0xffff);
2334 I915_WRITE16(IER, 0x0);
2335 POSTING_READ16(IER);
2336}
2337
2338static int i8xx_irq_postinstall(struct drm_device *dev)
2339{
2340 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2341
Chris Wilsonc2798b12012-04-22 21:13:57 +01002342 I915_WRITE16(EMR,
2343 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2344
2345 /* Unmask the interrupts that we always want on. */
2346 dev_priv->irq_mask =
2347 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2348 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2349 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2350 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2351 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2352 I915_WRITE16(IMR, dev_priv->irq_mask);
2353
2354 I915_WRITE16(IER,
2355 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2356 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2357 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2358 I915_USER_INTERRUPT);
2359 POSTING_READ16(IER);
2360
2361 return 0;
2362}
2363
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002364/*
2365 * Returns true when a page flip has completed.
2366 */
2367static bool i8xx_handle_vblank(struct drm_device *dev,
2368 int pipe, u16 iir)
2369{
2370 drm_i915_private_t *dev_priv = dev->dev_private;
2371 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
2372
2373 if (!drm_handle_vblank(dev, pipe))
2374 return false;
2375
2376 if ((iir & flip_pending) == 0)
2377 return false;
2378
2379 intel_prepare_page_flip(dev, pipe);
2380
2381 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2382 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2383 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2384 * the flip is completed (no longer pending). Since this doesn't raise
2385 * an interrupt per se, we watch for the change at vblank.
2386 */
2387 if (I915_READ16(ISR) & flip_pending)
2388 return false;
2389
2390 intel_finish_page_flip(dev, pipe);
2391
2392 return true;
2393}
2394
Daniel Vetterff1f5252012-10-02 15:10:55 +02002395static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01002396{
2397 struct drm_device *dev = (struct drm_device *) arg;
2398 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002399 u16 iir, new_iir;
2400 u32 pipe_stats[2];
2401 unsigned long irqflags;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002402 int pipe;
2403 u16 flip_mask =
2404 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2405 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
2406
2407 atomic_inc(&dev_priv->irq_received);
2408
2409 iir = I915_READ16(IIR);
2410 if (iir == 0)
2411 return IRQ_NONE;
2412
2413 while (iir & ~flip_mask) {
2414 /* Can't rely on pipestat interrupt bit in iir as it might
2415 * have been cleared after the pipestat interrupt was received.
2416 * It doesn't set the bit in iir again, but it still produces
2417 * interrupts (for non-MSI).
2418 */
2419 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2420 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2421 i915_handle_error(dev, false);
2422
2423 for_each_pipe(pipe) {
2424 int reg = PIPESTAT(pipe);
2425 pipe_stats[pipe] = I915_READ(reg);
2426
2427 /*
2428 * Clear the PIPE*STAT regs before the IIR
2429 */
2430 if (pipe_stats[pipe] & 0x8000ffff) {
2431 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2432 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2433 pipe_name(pipe));
2434 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002435 }
2436 }
2437 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2438
2439 I915_WRITE16(IIR, iir & ~flip_mask);
2440 new_iir = I915_READ16(IIR); /* Flush posted writes */
2441
Daniel Vetterd05c6172012-04-26 23:28:09 +02002442 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002443
2444 if (iir & I915_USER_INTERRUPT)
2445 notify_ring(dev, &dev_priv->ring[RCS]);
2446
2447 if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002448 i8xx_handle_vblank(dev, 0, iir))
2449 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002450
2451 if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002452 i8xx_handle_vblank(dev, 1, iir))
2453 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002454
2455 iir = new_iir;
2456 }
2457
2458 return IRQ_HANDLED;
2459}
2460
2461static void i8xx_irq_uninstall(struct drm_device * dev)
2462{
2463 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2464 int pipe;
2465
Chris Wilsonc2798b12012-04-22 21:13:57 +01002466 for_each_pipe(pipe) {
2467 /* Clear enable bits; then clear status bits */
2468 I915_WRITE(PIPESTAT(pipe), 0);
2469 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2470 }
2471 I915_WRITE16(IMR, 0xffff);
2472 I915_WRITE16(IER, 0x0);
2473 I915_WRITE16(IIR, I915_READ16(IIR));
2474}
2475
Chris Wilsona266c7d2012-04-24 22:59:44 +01002476static void i915_irq_preinstall(struct drm_device * dev)
2477{
2478 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2479 int pipe;
2480
2481 atomic_set(&dev_priv->irq_received, 0);
2482
2483 if (I915_HAS_HOTPLUG(dev)) {
2484 I915_WRITE(PORT_HOTPLUG_EN, 0);
2485 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2486 }
2487
Chris Wilson00d98eb2012-04-24 22:59:48 +01002488 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002489 for_each_pipe(pipe)
2490 I915_WRITE(PIPESTAT(pipe), 0);
2491 I915_WRITE(IMR, 0xffffffff);
2492 I915_WRITE(IER, 0x0);
2493 POSTING_READ(IER);
2494}
2495
2496static int i915_irq_postinstall(struct drm_device *dev)
2497{
2498 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01002499 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002500
Chris Wilson38bde182012-04-24 22:59:50 +01002501 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2502
2503 /* Unmask the interrupts that we always want on. */
2504 dev_priv->irq_mask =
2505 ~(I915_ASLE_INTERRUPT |
2506 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2507 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2508 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2509 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2510 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2511
2512 enable_mask =
2513 I915_ASLE_INTERRUPT |
2514 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2515 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2516 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2517 I915_USER_INTERRUPT;
2518
Chris Wilsona266c7d2012-04-24 22:59:44 +01002519 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01002520 I915_WRITE(PORT_HOTPLUG_EN, 0);
2521 POSTING_READ(PORT_HOTPLUG_EN);
2522
Chris Wilsona266c7d2012-04-24 22:59:44 +01002523 /* Enable in IER... */
2524 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
2525 /* and unmask in IMR */
2526 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
2527 }
2528
Chris Wilsona266c7d2012-04-24 22:59:44 +01002529 I915_WRITE(IMR, dev_priv->irq_mask);
2530 I915_WRITE(IER, enable_mask);
2531 POSTING_READ(IER);
2532
Jani Nikulaf49e38d2013-04-29 13:02:54 +03002533 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002534
2535 return 0;
2536}
2537
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002538/*
2539 * Returns true when a page flip has completed.
2540 */
2541static bool i915_handle_vblank(struct drm_device *dev,
2542 int plane, int pipe, u32 iir)
2543{
2544 drm_i915_private_t *dev_priv = dev->dev_private;
2545 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
2546
2547 if (!drm_handle_vblank(dev, pipe))
2548 return false;
2549
2550 if ((iir & flip_pending) == 0)
2551 return false;
2552
2553 intel_prepare_page_flip(dev, plane);
2554
2555 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2556 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2557 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2558 * the flip is completed (no longer pending). Since this doesn't raise
2559 * an interrupt per se, we watch for the change at vblank.
2560 */
2561 if (I915_READ(ISR) & flip_pending)
2562 return false;
2563
2564 intel_finish_page_flip(dev, pipe);
2565
2566 return true;
2567}
2568
Daniel Vetterff1f5252012-10-02 15:10:55 +02002569static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01002570{
2571 struct drm_device *dev = (struct drm_device *) arg;
2572 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01002573 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01002574 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01002575 u32 flip_mask =
2576 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2577 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01002578 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002579
2580 atomic_inc(&dev_priv->irq_received);
2581
2582 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01002583 do {
2584 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01002585 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002586
2587 /* Can't rely on pipestat interrupt bit in iir as it might
2588 * have been cleared after the pipestat interrupt was received.
2589 * It doesn't set the bit in iir again, but it still produces
2590 * interrupts (for non-MSI).
2591 */
2592 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2593 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2594 i915_handle_error(dev, false);
2595
2596 for_each_pipe(pipe) {
2597 int reg = PIPESTAT(pipe);
2598 pipe_stats[pipe] = I915_READ(reg);
2599
Chris Wilson38bde182012-04-24 22:59:50 +01002600 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01002601 if (pipe_stats[pipe] & 0x8000ffff) {
2602 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2603 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2604 pipe_name(pipe));
2605 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01002606 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002607 }
2608 }
2609 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2610
2611 if (!irq_received)
2612 break;
2613
Chris Wilsona266c7d2012-04-24 22:59:44 +01002614 /* Consume port. Then clear IIR or we'll miss events */
2615 if ((I915_HAS_HOTPLUG(dev)) &&
2616 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
2617 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02002618 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002619
2620 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2621 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002622
2623 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
2624
Chris Wilsona266c7d2012-04-24 22:59:44 +01002625 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01002626 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002627 }
2628
Chris Wilson38bde182012-04-24 22:59:50 +01002629 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002630 new_iir = I915_READ(IIR); /* Flush posted writes */
2631
Chris Wilsona266c7d2012-04-24 22:59:44 +01002632 if (iir & I915_USER_INTERRUPT)
2633 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002634
Chris Wilsona266c7d2012-04-24 22:59:44 +01002635 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01002636 int plane = pipe;
2637 if (IS_MOBILE(dev))
2638 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02002639
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002640 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
2641 i915_handle_vblank(dev, plane, pipe, iir))
2642 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002643
2644 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2645 blc_event = true;
2646 }
2647
Chris Wilsona266c7d2012-04-24 22:59:44 +01002648 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2649 intel_opregion_asle_intr(dev);
2650
2651 /* With MSI, interrupts are only generated when iir
2652 * transitions from zero to nonzero. If another bit got
2653 * set while we were handling the existing iir bits, then
2654 * we would never get another interrupt.
2655 *
2656 * This is fine on non-MSI as well, as if we hit this path
2657 * we avoid exiting the interrupt handler only to generate
2658 * another one.
2659 *
2660 * Note that for MSI this could cause a stray interrupt report
2661 * if an interrupt landed in the time between writing IIR and
2662 * the posting read. This should be rare enough to never
2663 * trigger the 99% of 100,000 interrupts test for disabling
2664 * stray interrupts.
2665 */
Chris Wilson38bde182012-04-24 22:59:50 +01002666 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002667 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01002668 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002669
Daniel Vetterd05c6172012-04-26 23:28:09 +02002670 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01002671
Chris Wilsona266c7d2012-04-24 22:59:44 +01002672 return ret;
2673}
2674
2675static void i915_irq_uninstall(struct drm_device * dev)
2676{
2677 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2678 int pipe;
2679
Egbert Eichac4c16c2013-04-16 13:36:58 +02002680 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2681
Chris Wilsona266c7d2012-04-24 22:59:44 +01002682 if (I915_HAS_HOTPLUG(dev)) {
2683 I915_WRITE(PORT_HOTPLUG_EN, 0);
2684 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2685 }
2686
Chris Wilson00d98eb2012-04-24 22:59:48 +01002687 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01002688 for_each_pipe(pipe) {
2689 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01002690 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01002691 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2692 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01002693 I915_WRITE(IMR, 0xffffffff);
2694 I915_WRITE(IER, 0x0);
2695
Chris Wilsona266c7d2012-04-24 22:59:44 +01002696 I915_WRITE(IIR, I915_READ(IIR));
2697}
2698
2699static void i965_irq_preinstall(struct drm_device * dev)
2700{
2701 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2702 int pipe;
2703
2704 atomic_set(&dev_priv->irq_received, 0);
2705
Chris Wilsonadca4732012-05-11 18:01:31 +01002706 I915_WRITE(PORT_HOTPLUG_EN, 0);
2707 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01002708
2709 I915_WRITE(HWSTAM, 0xeffe);
2710 for_each_pipe(pipe)
2711 I915_WRITE(PIPESTAT(pipe), 0);
2712 I915_WRITE(IMR, 0xffffffff);
2713 I915_WRITE(IER, 0x0);
2714 POSTING_READ(IER);
2715}
2716
2717static int i965_irq_postinstall(struct drm_device *dev)
2718{
2719 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002720 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002721 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002722 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002723
Chris Wilsona266c7d2012-04-24 22:59:44 +01002724 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002725 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01002726 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002727 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2728 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2729 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2730 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2731 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2732
2733 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002734 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2735 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002736 enable_mask |= I915_USER_INTERRUPT;
2737
2738 if (IS_G4X(dev))
2739 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002740
Daniel Vetterb79480b2013-06-27 17:52:10 +02002741 /* Interrupt setup is already guaranteed to be single-threaded, this is
2742 * just to make the assert_spin_locked check happy. */
2743 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002744 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002745 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002746
Chris Wilsona266c7d2012-04-24 22:59:44 +01002747 /*
2748 * Enable some error detection, note the instruction error mask
2749 * bit is reserved, so we leave it masked.
2750 */
2751 if (IS_G4X(dev)) {
2752 error_mask = ~(GM45_ERROR_PAGE_TABLE |
2753 GM45_ERROR_MEM_PRIV |
2754 GM45_ERROR_CP_PRIV |
2755 I915_ERROR_MEMORY_REFRESH);
2756 } else {
2757 error_mask = ~(I915_ERROR_PAGE_TABLE |
2758 I915_ERROR_MEMORY_REFRESH);
2759 }
2760 I915_WRITE(EMR, error_mask);
2761
2762 I915_WRITE(IMR, dev_priv->irq_mask);
2763 I915_WRITE(IER, enable_mask);
2764 POSTING_READ(IER);
2765
Daniel Vetter20afbda2012-12-11 14:05:07 +01002766 I915_WRITE(PORT_HOTPLUG_EN, 0);
2767 POSTING_READ(PORT_HOTPLUG_EN);
2768
Jani Nikulaf49e38d2013-04-29 13:02:54 +03002769 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002770
2771 return 0;
2772}
2773
Egbert Eichbac56d52013-02-25 12:06:51 -05002774static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01002775{
2776 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05002777 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02002778 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01002779 u32 hotplug_en;
2780
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02002781 assert_spin_locked(&dev_priv->irq_lock);
2782
Egbert Eichbac56d52013-02-25 12:06:51 -05002783 if (I915_HAS_HOTPLUG(dev)) {
2784 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
2785 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
2786 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05002787 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02002788 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
2789 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
2790 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05002791 /* Programming the CRT detection parameters tends
2792 to generate a spurious hotplug event about three
2793 seconds later. So just do it once.
2794 */
2795 if (IS_G4X(dev))
2796 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01002797 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05002798 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002799
Egbert Eichbac56d52013-02-25 12:06:51 -05002800 /* Ignore TV since it's buggy */
2801 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
2802 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01002803}
2804
Daniel Vetterff1f5252012-10-02 15:10:55 +02002805static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01002806{
2807 struct drm_device *dev = (struct drm_device *) arg;
2808 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002809 u32 iir, new_iir;
2810 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01002811 unsigned long irqflags;
2812 int irq_received;
2813 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002814 u32 flip_mask =
2815 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2816 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002817
2818 atomic_inc(&dev_priv->irq_received);
2819
2820 iir = I915_READ(IIR);
2821
Chris Wilsona266c7d2012-04-24 22:59:44 +01002822 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01002823 bool blc_event = false;
2824
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002825 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002826
2827 /* Can't rely on pipestat interrupt bit in iir as it might
2828 * have been cleared after the pipestat interrupt was received.
2829 * It doesn't set the bit in iir again, but it still produces
2830 * interrupts (for non-MSI).
2831 */
2832 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2833 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2834 i915_handle_error(dev, false);
2835
2836 for_each_pipe(pipe) {
2837 int reg = PIPESTAT(pipe);
2838 pipe_stats[pipe] = I915_READ(reg);
2839
2840 /*
2841 * Clear the PIPE*STAT regs before the IIR
2842 */
2843 if (pipe_stats[pipe] & 0x8000ffff) {
2844 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2845 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2846 pipe_name(pipe));
2847 I915_WRITE(reg, pipe_stats[pipe]);
2848 irq_received = 1;
2849 }
2850 }
2851 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2852
2853 if (!irq_received)
2854 break;
2855
2856 ret = IRQ_HANDLED;
2857
2858 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01002859 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01002860 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02002861 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
2862 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02002863 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002864
2865 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2866 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002867
2868 intel_hpd_irq_handler(dev, hotplug_trigger,
2869 IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
2870
Chris Wilsona266c7d2012-04-24 22:59:44 +01002871 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2872 I915_READ(PORT_HOTPLUG_STAT);
2873 }
2874
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002875 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002876 new_iir = I915_READ(IIR); /* Flush posted writes */
2877
Chris Wilsona266c7d2012-04-24 22:59:44 +01002878 if (iir & I915_USER_INTERRUPT)
2879 notify_ring(dev, &dev_priv->ring[RCS]);
2880 if (iir & I915_BSD_USER_INTERRUPT)
2881 notify_ring(dev, &dev_priv->ring[VCS]);
2882
Chris Wilsona266c7d2012-04-24 22:59:44 +01002883 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01002884 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002885 i915_handle_vblank(dev, pipe, pipe, iir))
2886 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002887
2888 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2889 blc_event = true;
2890 }
2891
2892
2893 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2894 intel_opregion_asle_intr(dev);
2895
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002896 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2897 gmbus_irq_handler(dev);
2898
Chris Wilsona266c7d2012-04-24 22:59:44 +01002899 /* With MSI, interrupts are only generated when iir
2900 * transitions from zero to nonzero. If another bit got
2901 * set while we were handling the existing iir bits, then
2902 * we would never get another interrupt.
2903 *
2904 * This is fine on non-MSI as well, as if we hit this path
2905 * we avoid exiting the interrupt handler only to generate
2906 * another one.
2907 *
2908 * Note that for MSI this could cause a stray interrupt report
2909 * if an interrupt landed in the time between writing IIR and
2910 * the posting read. This should be rare enough to never
2911 * trigger the 99% of 100,000 interrupts test for disabling
2912 * stray interrupts.
2913 */
2914 iir = new_iir;
2915 }
2916
Daniel Vetterd05c6172012-04-26 23:28:09 +02002917 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01002918
Chris Wilsona266c7d2012-04-24 22:59:44 +01002919 return ret;
2920}
2921
2922static void i965_irq_uninstall(struct drm_device * dev)
2923{
2924 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2925 int pipe;
2926
2927 if (!dev_priv)
2928 return;
2929
Egbert Eichac4c16c2013-04-16 13:36:58 +02002930 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2931
Chris Wilsonadca4732012-05-11 18:01:31 +01002932 I915_WRITE(PORT_HOTPLUG_EN, 0);
2933 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01002934
2935 I915_WRITE(HWSTAM, 0xffffffff);
2936 for_each_pipe(pipe)
2937 I915_WRITE(PIPESTAT(pipe), 0);
2938 I915_WRITE(IMR, 0xffffffff);
2939 I915_WRITE(IER, 0x0);
2940
2941 for_each_pipe(pipe)
2942 I915_WRITE(PIPESTAT(pipe),
2943 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
2944 I915_WRITE(IIR, I915_READ(IIR));
2945}
2946
Egbert Eichac4c16c2013-04-16 13:36:58 +02002947static void i915_reenable_hotplug_timer_func(unsigned long data)
2948{
2949 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
2950 struct drm_device *dev = dev_priv->dev;
2951 struct drm_mode_config *mode_config = &dev->mode_config;
2952 unsigned long irqflags;
2953 int i;
2954
2955 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2956 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
2957 struct drm_connector *connector;
2958
2959 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
2960 continue;
2961
2962 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
2963
2964 list_for_each_entry(connector, &mode_config->connector_list, head) {
2965 struct intel_connector *intel_connector = to_intel_connector(connector);
2966
2967 if (intel_connector->encoder->hpd_pin == i) {
2968 if (connector->polled != intel_connector->polled)
2969 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
2970 drm_get_connector_name(connector));
2971 connector->polled = intel_connector->polled;
2972 if (!connector->polled)
2973 connector->polled = DRM_CONNECTOR_POLL_HPD;
2974 }
2975 }
2976 }
2977 if (dev_priv->display.hpd_irq_setup)
2978 dev_priv->display.hpd_irq_setup(dev);
2979 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2980}
2981
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002982void intel_irq_init(struct drm_device *dev)
2983{
Chris Wilson8b2e3262012-04-24 22:59:41 +01002984 struct drm_i915_private *dev_priv = dev->dev_private;
2985
2986 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01002987 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02002988 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01002989 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01002990
Daniel Vetter99584db2012-11-14 17:14:04 +01002991 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
2992 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01002993 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02002994 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
2995 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01002996
Tomas Janousek97a19a22012-12-08 13:48:13 +01002997 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01002998
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002999 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3000 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Eugeni Dodonov7d4e1462012-05-09 15:37:09 -03003001 if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003002 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3003 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
3004 }
3005
Keith Packardc3613de2011-08-12 17:05:54 -07003006 if (drm_core_check_feature(dev, DRIVER_MODESET))
3007 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
3008 else
3009 dev->driver->get_vblank_timestamp = NULL;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003010 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3011
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003012 if (IS_VALLEYVIEW(dev)) {
3013 dev->driver->irq_handler = valleyview_irq_handler;
3014 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3015 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3016 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3017 dev->driver->enable_vblank = valleyview_enable_vblank;
3018 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003019 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003020 } else if (HAS_PCH_SPLIT(dev)) {
3021 dev->driver->irq_handler = ironlake_irq_handler;
3022 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3023 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3024 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3025 dev->driver->enable_vblank = ironlake_enable_vblank;
3026 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003027 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003028 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003029 if (INTEL_INFO(dev)->gen == 2) {
3030 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3031 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3032 dev->driver->irq_handler = i8xx_irq_handler;
3033 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003034 } else if (INTEL_INFO(dev)->gen == 3) {
3035 dev->driver->irq_preinstall = i915_irq_preinstall;
3036 dev->driver->irq_postinstall = i915_irq_postinstall;
3037 dev->driver->irq_uninstall = i915_irq_uninstall;
3038 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003039 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003040 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003041 dev->driver->irq_preinstall = i965_irq_preinstall;
3042 dev->driver->irq_postinstall = i965_irq_postinstall;
3043 dev->driver->irq_uninstall = i965_irq_uninstall;
3044 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003045 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003046 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003047 dev->driver->enable_vblank = i915_enable_vblank;
3048 dev->driver->disable_vblank = i915_disable_vblank;
3049 }
3050}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003051
3052void intel_hpd_init(struct drm_device *dev)
3053{
3054 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003055 struct drm_mode_config *mode_config = &dev->mode_config;
3056 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003057 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003058 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003059
Egbert Eich821450c2013-04-16 13:36:55 +02003060 for (i = 1; i < HPD_NUM_PINS; i++) {
3061 dev_priv->hpd_stats[i].hpd_cnt = 0;
3062 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3063 }
3064 list_for_each_entry(connector, &mode_config->connector_list, head) {
3065 struct intel_connector *intel_connector = to_intel_connector(connector);
3066 connector->polled = intel_connector->polled;
3067 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3068 connector->polled = DRM_CONNECTOR_POLL_HPD;
3069 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003070
3071 /* Interrupt setup is already guaranteed to be single-threaded, this is
3072 * just to make the assert_spin_locked checks happy. */
3073 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003074 if (dev_priv->display.hpd_irq_setup)
3075 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003076 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003077}