blob: 99106990a3263097bdec92b762cb1de6f2d643c0 [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
815 parity_event[0] = "L3_PARITY_ERROR=1";
816 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
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200847static void snb_gt_irq_handler(struct drm_device *dev,
848 struct drm_i915_private *dev_priv,
849 u32 gt_iir)
850{
851
Ben Widawskycc609d52013-05-28 19:22:29 -0700852 if (gt_iir &
853 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200854 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -0700855 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200856 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -0700857 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200858 notify_ring(dev, &dev_priv->ring[BCS]);
859
Ben Widawskycc609d52013-05-28 19:22:29 -0700860 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
861 GT_BSD_CS_ERROR_INTERRUPT |
862 GT_RENDER_CS_MASTER_ERROR_INTERRUPT)) {
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200863 DRM_ERROR("GT error interrupt 0x%08x\n", gt_iir);
864 i915_handle_error(dev, false);
865 }
Ben Widawskye3689192012-05-25 16:56:22 -0700866
Ben Widawskycc609d52013-05-28 19:22:29 -0700867 if (gt_iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200868 ivybridge_parity_error_irq_handler(dev);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +0200869}
870
Ben Widawskybaf02a12013-05-28 19:22:24 -0700871/* Legacy way of handling PM interrupts */
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200872static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv,
873 u32 pm_iir)
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100874{
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100875 /*
876 * IIR bits should never already be set because IMR should
877 * prevent an interrupt from being shown in IIR. The warning
878 * displays a case where we've unsafely cleared
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200879 * dev_priv->rps.pm_iir. Although missing an interrupt of the same
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100880 * type is not a problem, it displays a problem in the logic.
881 *
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200882 * The mask bit in IMR is cleared by dev_priv->rps.work.
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100883 */
884
Daniel Vetter59cdb632013-07-04 23:35:28 +0200885 spin_lock(&dev_priv->irq_lock);
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200886 dev_priv->rps.pm_iir |= pm_iir;
887 I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100888 POSTING_READ(GEN6_PMIMR);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200889 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100890
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200891 queue_work(dev_priv->wq, &dev_priv->rps.work);
Chris Wilsonfc6826d2012-04-15 11:56:03 +0100892}
893
Egbert Eichb543fb02013-04-16 13:36:54 +0200894#define HPD_STORM_DETECT_PERIOD 1000
895#define HPD_STORM_THRESHOLD 5
896
Daniel Vetter10a504d2013-06-27 17:52:12 +0200897static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +0200898 u32 hotplug_trigger,
899 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +0200900{
901 drm_i915_private_t *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +0200902 int i;
Daniel Vetter10a504d2013-06-27 17:52:12 +0200903 bool storm_detected = false;
Egbert Eichb543fb02013-04-16 13:36:54 +0200904
Daniel Vetter91d131d2013-06-27 17:52:14 +0200905 if (!hotplug_trigger)
906 return;
907
Daniel Vetterb5ea2d52013-06-27 17:52:15 +0200908 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +0200909 for (i = 1; i < HPD_NUM_PINS; i++) {
Egbert Eich821450c2013-04-16 13:36:55 +0200910
Egbert Eichb543fb02013-04-16 13:36:54 +0200911 if (!(hpd[i] & hotplug_trigger) ||
912 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
913 continue;
914
Jani Nikulabc5ead8c2013-05-07 15:10:29 +0300915 dev_priv->hpd_event_bits |= (1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +0200916 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
917 dev_priv->hpd_stats[i].hpd_last_jiffies
918 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
919 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
920 dev_priv->hpd_stats[i].hpd_cnt = 0;
921 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
922 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +0200923 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +0200924 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +0200925 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +0200926 } else {
927 dev_priv->hpd_stats[i].hpd_cnt++;
928 }
929 }
930
Daniel Vetter10a504d2013-06-27 17:52:12 +0200931 if (storm_detected)
932 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +0200933 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +0200934
935 queue_work(dev_priv->wq,
936 &dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +0200937}
938
Daniel Vetter515ac2b2012-12-01 13:53:44 +0100939static void gmbus_irq_handler(struct drm_device *dev)
940{
Daniel Vetter28c70f12012-12-01 13:53:45 +0100941 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
942
Daniel Vetter28c70f12012-12-01 13:53:45 +0100943 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +0100944}
945
Daniel Vetterce99c252012-12-01 13:53:47 +0100946static void dp_aux_irq_handler(struct drm_device *dev)
947{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100948 struct drm_i915_private *dev_priv = (drm_i915_private_t *) dev->dev_private;
949
Daniel Vetter9ee32fea2012-12-01 13:53:48 +0100950 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +0100951}
952
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200953/* Unlike gen6_rps_irq_handler() from which this function is originally derived,
Ben Widawskybaf02a12013-05-28 19:22:24 -0700954 * we must be able to deal with other PM interrupts. This is complicated because
955 * of the way in which we use the masks to defer the RPS work (which for
956 * posterity is necessary because of forcewake).
957 */
958static void hsw_pm_irq_handler(struct drm_i915_private *dev_priv,
959 u32 pm_iir)
960{
Daniel Vetter41a05a32013-07-04 23:35:26 +0200961 if (pm_iir & GEN6_PM_RPS_EVENTS) {
Daniel Vetter59cdb632013-07-04 23:35:28 +0200962 spin_lock(&dev_priv->irq_lock);
Daniel Vetter41a05a32013-07-04 23:35:26 +0200963 dev_priv->rps.pm_iir |= pm_iir & GEN6_PM_RPS_EVENTS;
Ben Widawskybaf02a12013-05-28 19:22:24 -0700964 I915_WRITE(GEN6_PMIMR, dev_priv->rps.pm_iir);
965 /* never want to mask useful interrupts. (also posting read) */
Ben Widawsky48484052013-05-28 19:22:27 -0700966 WARN_ON(I915_READ_NOTRACE(GEN6_PMIMR) & ~GEN6_PM_RPS_EVENTS);
Daniel Vetter59cdb632013-07-04 23:35:28 +0200967 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter2adbee62013-07-04 23:35:27 +0200968
969 queue_work(dev_priv->wq, &dev_priv->rps.work);
Ben Widawskybaf02a12013-05-28 19:22:24 -0700970 }
Ben Widawskybaf02a12013-05-28 19:22:24 -0700971
Daniel Vetter41a05a32013-07-04 23:35:26 +0200972 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
973 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -0700974
Daniel Vetter41a05a32013-07-04 23:35:26 +0200975 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT) {
976 DRM_ERROR("VEBOX CS error interrupt 0x%08x\n", pm_iir);
977 i915_handle_error(dev_priv->dev, false);
Ben Widawsky12638c52013-05-28 19:22:31 -0700978 }
Ben Widawskybaf02a12013-05-28 19:22:24 -0700979}
980
Daniel Vetterff1f5252012-10-02 15:10:55 +0200981static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700982{
983 struct drm_device *dev = (struct drm_device *) arg;
984 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
985 u32 iir, gt_iir, pm_iir;
986 irqreturn_t ret = IRQ_NONE;
987 unsigned long irqflags;
988 int pipe;
989 u32 pipe_stats[I915_MAX_PIPES];
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700990
991 atomic_inc(&dev_priv->irq_received);
992
Jesse Barnes7e231dbe2012-03-28 13:39:38 -0700993 while (true) {
994 iir = I915_READ(VLV_IIR);
995 gt_iir = I915_READ(GTIIR);
996 pm_iir = I915_READ(GEN6_PMIIR);
997
998 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
999 goto out;
1000
1001 ret = IRQ_HANDLED;
1002
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001003 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001004
1005 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1006 for_each_pipe(pipe) {
1007 int reg = PIPESTAT(pipe);
1008 pipe_stats[pipe] = I915_READ(reg);
1009
1010 /*
1011 * Clear the PIPE*STAT regs before the IIR
1012 */
1013 if (pipe_stats[pipe] & 0x8000ffff) {
1014 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1015 DRM_DEBUG_DRIVER("pipe %c underrun\n",
1016 pipe_name(pipe));
1017 I915_WRITE(reg, pipe_stats[pipe]);
1018 }
1019 }
1020 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1021
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001022 for_each_pipe(pipe) {
1023 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1024 drm_handle_vblank(dev, pipe);
1025
1026 if (pipe_stats[pipe] & PLANE_FLIPDONE_INT_STATUS_VLV) {
1027 intel_prepare_page_flip(dev, pipe);
1028 intel_finish_page_flip(dev, pipe);
1029 }
1030 }
1031
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001032 /* Consume port. Then clear IIR or we'll miss events */
1033 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
1034 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02001035 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001036
1037 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
1038 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001039
1040 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
1041
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001042 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1043 I915_READ(PORT_HOTPLUG_STAT);
1044 }
1045
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001046 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1047 gmbus_irq_handler(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001048
Ben Widawsky48484052013-05-28 19:22:27 -07001049 if (pm_iir & GEN6_PM_RPS_EVENTS)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001050 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001051
1052 I915_WRITE(GTIIR, gt_iir);
1053 I915_WRITE(GEN6_PMIIR, pm_iir);
1054 I915_WRITE(VLV_IIR, iir);
1055 }
1056
1057out:
1058 return ret;
1059}
1060
Adam Jackson23e81d62012-06-06 15:45:44 -04001061static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001062{
1063 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001064 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001065 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001066
Daniel Vetter91d131d2013-06-27 17:52:14 +02001067 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
1068
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001069 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1070 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1071 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001072 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001073 port_name(port));
1074 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001075
Daniel Vetterce99c252012-12-01 13:53:47 +01001076 if (pch_iir & SDE_AUX_MASK)
1077 dp_aux_irq_handler(dev);
1078
Jesse Barnes776ad802011-01-04 15:09:39 -08001079 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001080 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001081
1082 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1083 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1084
1085 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1086 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1087
1088 if (pch_iir & SDE_POISON)
1089 DRM_ERROR("PCH poison interrupt\n");
1090
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001091 if (pch_iir & SDE_FDI_MASK)
1092 for_each_pipe(pipe)
1093 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1094 pipe_name(pipe),
1095 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001096
1097 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1098 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1099
1100 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1101 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1102
Jesse Barnes776ad802011-01-04 15:09:39 -08001103 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Paulo Zanoni86642812013-04-12 17:57:57 -03001104 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1105 false))
1106 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1107
1108 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
1109 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1110 false))
1111 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1112}
1113
1114static void ivb_err_int_handler(struct drm_device *dev)
1115{
1116 struct drm_i915_private *dev_priv = dev->dev_private;
1117 u32 err_int = I915_READ(GEN7_ERR_INT);
1118
Paulo Zanonide032bf2013-04-12 17:57:58 -03001119 if (err_int & ERR_INT_POISON)
1120 DRM_ERROR("Poison interrupt\n");
1121
Paulo Zanoni86642812013-04-12 17:57:57 -03001122 if (err_int & ERR_INT_FIFO_UNDERRUN_A)
1123 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1124 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1125
1126 if (err_int & ERR_INT_FIFO_UNDERRUN_B)
1127 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1128 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1129
1130 if (err_int & ERR_INT_FIFO_UNDERRUN_C)
1131 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_C, false))
1132 DRM_DEBUG_DRIVER("Pipe C FIFO underrun\n");
1133
1134 I915_WRITE(GEN7_ERR_INT, err_int);
1135}
1136
1137static void cpt_serr_int_handler(struct drm_device *dev)
1138{
1139 struct drm_i915_private *dev_priv = dev->dev_private;
1140 u32 serr_int = I915_READ(SERR_INT);
1141
Paulo Zanonide032bf2013-04-12 17:57:58 -03001142 if (serr_int & SERR_INT_POISON)
1143 DRM_ERROR("PCH poison interrupt\n");
1144
Paulo Zanoni86642812013-04-12 17:57:57 -03001145 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
1146 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_A,
1147 false))
1148 DRM_DEBUG_DRIVER("PCH transcoder A FIFO underrun\n");
1149
1150 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
1151 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_B,
1152 false))
1153 DRM_DEBUG_DRIVER("PCH transcoder B FIFO underrun\n");
1154
1155 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
1156 if (intel_set_pch_fifo_underrun_reporting(dev, TRANSCODER_C,
1157 false))
1158 DRM_DEBUG_DRIVER("PCH transcoder C FIFO underrun\n");
1159
1160 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001161}
1162
Adam Jackson23e81d62012-06-06 15:45:44 -04001163static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1164{
1165 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1166 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001167 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001168
Daniel Vetter91d131d2013-06-27 17:52:14 +02001169 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
1170
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001171 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1172 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1173 SDE_AUDIO_POWER_SHIFT_CPT);
1174 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1175 port_name(port));
1176 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001177
1178 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001179 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001180
1181 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001182 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001183
1184 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1185 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1186
1187 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1188 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1189
1190 if (pch_iir & SDE_FDI_MASK_CPT)
1191 for_each_pipe(pipe)
1192 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1193 pipe_name(pipe),
1194 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001195
1196 if (pch_iir & SDE_ERROR_CPT)
1197 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001198}
1199
Daniel Vetterff1f5252012-10-02 15:10:55 +02001200static irqreturn_t ivybridge_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001201{
1202 struct drm_device *dev = (struct drm_device *) arg;
1203 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Ben Widawskyab5c6082013-04-05 13:12:41 -07001204 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001205 irqreturn_t ret = IRQ_NONE;
1206 int i;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001207
1208 atomic_inc(&dev_priv->irq_received);
1209
Paulo Zanoni86642812013-04-12 17:57:57 -03001210 /* We get interrupts on unclaimed registers, so check for this before we
1211 * do any I915_{READ,WRITE}. */
1212 if (IS_HASWELL(dev) &&
1213 (I915_READ_NOTRACE(FPGA_DBG) & FPGA_DBG_RM_NOCLAIM)) {
1214 DRM_ERROR("Unclaimed register before interrupt\n");
1215 I915_WRITE_NOTRACE(FPGA_DBG, FPGA_DBG_RM_NOCLAIM);
1216 }
1217
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001218 /* disable master interrupt before clearing iir */
1219 de_ier = I915_READ(DEIER);
1220 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson0e434062012-05-09 21:45:44 +01001221
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001222 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1223 * interrupts will will be stored on its back queue, and then we'll be
1224 * able to process them after we restore SDEIER (as soon as we restore
1225 * it, we'll get an interrupt if SDEIIR still has something to process
1226 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001227 if (!HAS_PCH_NOP(dev)) {
1228 sde_ier = I915_READ(SDEIER);
1229 I915_WRITE(SDEIER, 0);
1230 POSTING_READ(SDEIER);
1231 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001232
Paulo Zanoni86642812013-04-12 17:57:57 -03001233 /* On Haswell, also mask ERR_INT because we don't want to risk
1234 * generating "unclaimed register" interrupts from inside the interrupt
1235 * handler. */
Daniel Vetter4bc9d432013-06-27 13:44:58 +02001236 if (IS_HASWELL(dev)) {
1237 spin_lock(&dev_priv->irq_lock);
Paulo Zanoni86642812013-04-12 17:57:57 -03001238 ironlake_disable_display_irq(dev_priv, DE_ERR_INT_IVB);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02001239 spin_unlock(&dev_priv->irq_lock);
1240 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001241
Chris Wilson0e434062012-05-09 21:45:44 +01001242 gt_iir = I915_READ(GTIIR);
1243 if (gt_iir) {
1244 snb_gt_irq_handler(dev, dev_priv, gt_iir);
1245 I915_WRITE(GTIIR, gt_iir);
1246 ret = IRQ_HANDLED;
1247 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001248
1249 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001250 if (de_iir) {
Paulo Zanoni86642812013-04-12 17:57:57 -03001251 if (de_iir & DE_ERR_INT_IVB)
1252 ivb_err_int_handler(dev);
1253
Daniel Vetterce99c252012-12-01 13:53:47 +01001254 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1255 dp_aux_irq_handler(dev);
1256
Chris Wilson0e434062012-05-09 21:45:44 +01001257 if (de_iir & DE_GSE_IVB)
Jani Nikula81a07802013-04-24 22:18:44 +03001258 intel_opregion_asle_intr(dev);
Chris Wilson0e434062012-05-09 21:45:44 +01001259
1260 for (i = 0; i < 3; i++) {
Daniel Vetter74d44442012-10-02 17:54:35 +02001261 if (de_iir & (DE_PIPEA_VBLANK_IVB << (5 * i)))
1262 drm_handle_vblank(dev, i);
Chris Wilson0e434062012-05-09 21:45:44 +01001263 if (de_iir & (DE_PLANEA_FLIP_DONE_IVB << (5 * i))) {
1264 intel_prepare_page_flip(dev, i);
1265 intel_finish_page_flip_plane(dev, i);
1266 }
Chris Wilson0e434062012-05-09 21:45:44 +01001267 }
1268
1269 /* check event from PCH */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001270 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
Chris Wilson0e434062012-05-09 21:45:44 +01001271 u32 pch_iir = I915_READ(SDEIIR);
1272
Adam Jackson23e81d62012-06-06 15:45:44 -04001273 cpt_irq_handler(dev, pch_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001274
1275 /* clear PCH hotplug event before clear CPU irq */
1276 I915_WRITE(SDEIIR, pch_iir);
1277 }
1278
1279 I915_WRITE(DEIIR, de_iir);
1280 ret = IRQ_HANDLED;
1281 }
1282
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001283 pm_iir = I915_READ(GEN6_PMIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01001284 if (pm_iir) {
Ben Widawskybaf02a12013-05-28 19:22:24 -07001285 if (IS_HASWELL(dev))
1286 hsw_pm_irq_handler(dev_priv, pm_iir);
Ben Widawsky48484052013-05-28 19:22:27 -07001287 else if (pm_iir & GEN6_PM_RPS_EVENTS)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001288 gen6_rps_irq_handler(dev_priv, pm_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01001289 I915_WRITE(GEN6_PMIIR, pm_iir);
1290 ret = IRQ_HANDLED;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001291 }
1292
Daniel Vetter4bc9d432013-06-27 13:44:58 +02001293 if (IS_HASWELL(dev)) {
1294 spin_lock(&dev_priv->irq_lock);
1295 if (ivb_can_enable_err_int(dev))
1296 ironlake_enable_display_irq(dev_priv, DE_ERR_INT_IVB);
1297 spin_unlock(&dev_priv->irq_lock);
1298 }
Paulo Zanoni86642812013-04-12 17:57:57 -03001299
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001300 I915_WRITE(DEIER, de_ier);
1301 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07001302 if (!HAS_PCH_NOP(dev)) {
1303 I915_WRITE(SDEIER, sde_ier);
1304 POSTING_READ(SDEIER);
1305 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001306
1307 return ret;
1308}
1309
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001310static void ilk_gt_irq_handler(struct drm_device *dev,
1311 struct drm_i915_private *dev_priv,
1312 u32 gt_iir)
1313{
Ben Widawskycc609d52013-05-28 19:22:29 -07001314 if (gt_iir &
1315 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001316 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001317 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001318 notify_ring(dev, &dev_priv->ring[VCS]);
1319}
1320
Daniel Vetterff1f5252012-10-02 15:10:55 +02001321static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001322{
Jesse Barnes46979952011-04-07 13:53:55 -07001323 struct drm_device *dev = (struct drm_device *) arg;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001324 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1325 int ret = IRQ_NONE;
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001326 u32 de_iir, gt_iir, de_ier, pm_iir, sde_ier;
Xiang, Haihao881f47b2010-09-19 14:40:43 +01001327
Jesse Barnes46979952011-04-07 13:53:55 -07001328 atomic_inc(&dev_priv->irq_received);
1329
Zou, Nanhai2d109a82009-11-06 02:13:01 +00001330 /* disable master interrupt before clearing iir */
1331 de_ier = I915_READ(DEIER);
1332 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001333 POSTING_READ(DEIER);
Zou, Nanhai2d109a82009-11-06 02:13:01 +00001334
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001335 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1336 * interrupts will will be stored on its back queue, and then we'll be
1337 * able to process them after we restore SDEIER (as soon as we restore
1338 * it, we'll get an interrupt if SDEIIR still has something to process
1339 * due to its back queue). */
1340 sde_ier = I915_READ(SDEIER);
1341 I915_WRITE(SDEIER, 0);
1342 POSTING_READ(SDEIER);
1343
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001344 de_iir = I915_READ(DEIIR);
1345 gt_iir = I915_READ(GTIIR);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001346 pm_iir = I915_READ(GEN6_PMIIR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001347
Daniel Vetteracd15b62012-11-30 11:24:50 +01001348 if (de_iir == 0 && gt_iir == 0 && (!IS_GEN6(dev) || pm_iir == 0))
Zou Nan haic7c85102010-01-15 10:29:06 +08001349 goto done;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001350
Zou Nan haic7c85102010-01-15 10:29:06 +08001351 ret = IRQ_HANDLED;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001352
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001353 if (IS_GEN5(dev))
1354 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
1355 else
1356 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Zou Nan haic7c85102010-01-15 10:29:06 +08001357
Daniel Vetterce99c252012-12-01 13:53:47 +01001358 if (de_iir & DE_AUX_CHANNEL_A)
1359 dp_aux_irq_handler(dev);
1360
Zou Nan haic7c85102010-01-15 10:29:06 +08001361 if (de_iir & DE_GSE)
Jani Nikula81a07802013-04-24 22:18:44 +03001362 intel_opregion_asle_intr(dev);
Zou Nan haic7c85102010-01-15 10:29:06 +08001363
Daniel Vetter74d44442012-10-02 17:54:35 +02001364 if (de_iir & DE_PIPEA_VBLANK)
1365 drm_handle_vblank(dev, 0);
1366
1367 if (de_iir & DE_PIPEB_VBLANK)
1368 drm_handle_vblank(dev, 1);
1369
Paulo Zanonide032bf2013-04-12 17:57:58 -03001370 if (de_iir & DE_POISON)
1371 DRM_ERROR("Poison interrupt\n");
1372
Paulo Zanoni86642812013-04-12 17:57:57 -03001373 if (de_iir & DE_PIPEA_FIFO_UNDERRUN)
1374 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_A, false))
1375 DRM_DEBUG_DRIVER("Pipe A FIFO underrun\n");
1376
1377 if (de_iir & DE_PIPEB_FIFO_UNDERRUN)
1378 if (intel_set_cpu_fifo_underrun_reporting(dev, PIPE_B, false))
1379 DRM_DEBUG_DRIVER("Pipe B FIFO underrun\n");
1380
Zhenyu Wangf072d2e2010-02-09 09:46:19 +08001381 if (de_iir & DE_PLANEA_FLIP_DONE) {
Jesse Barnes013d5aa2010-01-29 11:18:31 -08001382 intel_prepare_page_flip(dev, 0);
Chris Wilson2bbda382010-09-02 17:59:39 +01001383 intel_finish_page_flip_plane(dev, 0);
Jesse Barnes013d5aa2010-01-29 11:18:31 -08001384 }
1385
Zhenyu Wangf072d2e2010-02-09 09:46:19 +08001386 if (de_iir & DE_PLANEB_FLIP_DONE) {
1387 intel_prepare_page_flip(dev, 1);
Chris Wilson2bbda382010-09-02 17:59:39 +01001388 intel_finish_page_flip_plane(dev, 1);
Jesse Barnes013d5aa2010-01-29 11:18:31 -08001389 }
Li Pengc062df62010-01-23 00:12:58 +08001390
Zou Nan haic7c85102010-01-15 10:29:06 +08001391 /* check event from PCH */
Jesse Barnes776ad802011-01-04 15:09:39 -08001392 if (de_iir & DE_PCH_EVENT) {
Daniel Vetteracd15b62012-11-30 11:24:50 +01001393 u32 pch_iir = I915_READ(SDEIIR);
1394
Adam Jackson23e81d62012-06-06 15:45:44 -04001395 if (HAS_PCH_CPT(dev))
1396 cpt_irq_handler(dev, pch_iir);
1397 else
1398 ibx_irq_handler(dev, pch_iir);
Daniel Vetteracd15b62012-11-30 11:24:50 +01001399
1400 /* should clear PCH hotplug event before clear CPU irq */
1401 I915_WRITE(SDEIIR, pch_iir);
Jesse Barnes776ad802011-01-04 15:09:39 -08001402 }
Zou Nan haic7c85102010-01-15 10:29:06 +08001403
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001404 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001405 ironlake_rps_change_irq_handler(dev);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001406
Ben Widawsky48484052013-05-28 19:22:27 -07001407 if (IS_GEN6(dev) && pm_iir & GEN6_PM_RPS_EVENTS)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001408 gen6_rps_irq_handler(dev_priv, pm_iir);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001409
Zou Nan haic7c85102010-01-15 10:29:06 +08001410 I915_WRITE(GTIIR, gt_iir);
1411 I915_WRITE(DEIIR, de_iir);
Ben Widawsky4912d042011-04-25 11:25:20 -07001412 I915_WRITE(GEN6_PMIIR, pm_iir);
Zou Nan haic7c85102010-01-15 10:29:06 +08001413
1414done:
Zou, Nanhai2d109a82009-11-06 02:13:01 +00001415 I915_WRITE(DEIER, de_ier);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001416 POSTING_READ(DEIER);
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001417 I915_WRITE(SDEIER, sde_ier);
1418 POSTING_READ(SDEIER);
Zou, Nanhai2d109a82009-11-06 02:13:01 +00001419
Zhenyu Wang036a4a72009-06-08 14:40:19 +08001420 return ret;
1421}
1422
Jesse Barnes8a905232009-07-11 16:48:03 -04001423/**
1424 * i915_error_work_func - do process context error handling work
1425 * @work: work struct
1426 *
1427 * Fire an error uevent so userspace can see that a hang or error
1428 * was detected.
1429 */
1430static void i915_error_work_func(struct work_struct *work)
1431{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001432 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
1433 work);
1434 drm_i915_private_t *dev_priv = container_of(error, drm_i915_private_t,
1435 gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04001436 struct drm_device *dev = dev_priv->dev;
Daniel Vetterf69061b2012-12-06 09:01:42 +01001437 struct intel_ring_buffer *ring;
Ben Gamarif316a422009-09-14 17:48:46 -04001438 char *error_event[] = { "ERROR=1", NULL };
1439 char *reset_event[] = { "RESET=1", NULL };
1440 char *reset_done_event[] = { "ERROR=0", NULL };
Daniel Vetterf69061b2012-12-06 09:01:42 +01001441 int i, ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04001442
Ben Gamarif316a422009-09-14 17:48:46 -04001443 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04001444
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001445 /*
1446 * Note that there's only one work item which does gpu resets, so we
1447 * need not worry about concurrent gpu resets potentially incrementing
1448 * error->reset_counter twice. We only need to take care of another
1449 * racing irq/hangcheck declaring the gpu dead for a second time. A
1450 * quick check for that is good enough: schedule_work ensures the
1451 * correct ordering between hang detection and this work item, and since
1452 * the reset in-progress bit is only ever set by code outside of this
1453 * work we don't need to worry about any other races.
1454 */
1455 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01001456 DRM_DEBUG_DRIVER("resetting chip\n");
Daniel Vetter7db0ba22012-12-06 16:23:37 +01001457 kobject_uevent_env(&dev->primary->kdev.kobj, KOBJ_CHANGE,
1458 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001459
Daniel Vetterf69061b2012-12-06 09:01:42 +01001460 ret = i915_reset(dev);
1461
1462 if (ret == 0) {
1463 /*
1464 * After all the gem state is reset, increment the reset
1465 * counter and wake up everyone waiting for the reset to
1466 * complete.
1467 *
1468 * Since unlock operations are a one-sided barrier only,
1469 * we need to insert a barrier here to order any seqno
1470 * updates before
1471 * the counter increment.
1472 */
1473 smp_mb__before_atomic_inc();
1474 atomic_inc(&dev_priv->gpu_error.reset_counter);
1475
1476 kobject_uevent_env(&dev->primary->kdev.kobj,
1477 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001478 } else {
1479 atomic_set(&error->reset_counter, I915_WEDGED);
Ben Gamarif316a422009-09-14 17:48:46 -04001480 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001481
Daniel Vetterf69061b2012-12-06 09:01:42 +01001482 for_each_ring(ring, dev_priv, i)
1483 wake_up_all(&ring->irq_queue);
1484
Ville Syrjälä96a02912013-02-18 19:08:49 +02001485 intel_display_handle_reset(dev);
1486
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001487 wake_up_all(&dev_priv->gpu_error.reset_queue);
Ben Gamarif316a422009-09-14 17:48:46 -04001488 }
Jesse Barnes8a905232009-07-11 16:48:03 -04001489}
1490
Chris Wilson35aed2e2010-05-27 13:18:12 +01001491static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04001492{
1493 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07001494 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04001495 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07001496 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04001497
Chris Wilson35aed2e2010-05-27 13:18:12 +01001498 if (!eir)
1499 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04001500
Joe Perchesa70491c2012-03-18 13:00:11 -07001501 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04001502
Ben Widawskybd9854f2012-08-23 15:18:09 -07001503 i915_get_extra_instdone(dev, instdone);
1504
Jesse Barnes8a905232009-07-11 16:48:03 -04001505 if (IS_G4X(dev)) {
1506 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
1507 u32 ipeir = I915_READ(IPEIR_I965);
1508
Joe Perchesa70491c2012-03-18 13:00:11 -07001509 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1510 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07001511 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1512 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07001513 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001514 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001515 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001516 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001517 }
1518 if (eir & GM45_ERROR_PAGE_TABLE) {
1519 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001520 pr_err("page table error\n");
1521 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001522 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001523 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001524 }
1525 }
1526
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001527 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001528 if (eir & I915_ERROR_PAGE_TABLE) {
1529 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07001530 pr_err("page table error\n");
1531 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04001532 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001533 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04001534 }
1535 }
1536
1537 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001538 pr_err("memory refresh error:\n");
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001539 for_each_pipe(pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07001540 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001541 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04001542 /* pipestat has already been acked */
1543 }
1544 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07001545 pr_err("instruction error\n");
1546 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07001547 for (i = 0; i < ARRAY_SIZE(instdone); i++)
1548 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001549 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04001550 u32 ipeir = I915_READ(IPEIR);
1551
Joe Perchesa70491c2012-03-18 13:00:11 -07001552 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
1553 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07001554 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04001555 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001556 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001557 } else {
1558 u32 ipeir = I915_READ(IPEIR_I965);
1559
Joe Perchesa70491c2012-03-18 13:00:11 -07001560 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
1561 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07001562 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07001563 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04001564 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001565 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04001566 }
1567 }
1568
1569 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00001570 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04001571 eir = I915_READ(EIR);
1572 if (eir) {
1573 /*
1574 * some errors might have become stuck,
1575 * mask them.
1576 */
1577 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
1578 I915_WRITE(EMR, I915_READ(EMR) | eir);
1579 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
1580 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01001581}
1582
1583/**
1584 * i915_handle_error - handle an error interrupt
1585 * @dev: drm device
1586 *
1587 * Do some basic checking of regsiter state at error interrupt time and
1588 * dump it to the syslog. Also call i915_capture_error_state() to make
1589 * sure we get a record and make it available in debugfs. Fire a uevent
1590 * so userspace knows something bad happened (should trigger collection
1591 * of a ring dump etc.).
1592 */
Chris Wilson527f9e92010-11-11 01:16:58 +00001593void i915_handle_error(struct drm_device *dev, bool wedged)
Chris Wilson35aed2e2010-05-27 13:18:12 +01001594{
1595 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01001596 struct intel_ring_buffer *ring;
1597 int i;
Chris Wilson35aed2e2010-05-27 13:18:12 +01001598
1599 i915_capture_error_state(dev);
1600 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04001601
Ben Gamariba1234d2009-09-14 17:48:47 -04001602 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01001603 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
1604 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04001605
Ben Gamari11ed50e2009-09-14 17:48:45 -04001606 /*
Daniel Vetter1f83fee2012-11-15 17:17:22 +01001607 * Wakeup waiting processes so that the reset work item
1608 * doesn't deadlock trying to grab various locks.
Ben Gamari11ed50e2009-09-14 17:48:45 -04001609 */
Chris Wilsonb4519512012-05-11 14:29:30 +01001610 for_each_ring(ring, dev_priv, i)
1611 wake_up_all(&ring->irq_queue);
Ben Gamari11ed50e2009-09-14 17:48:45 -04001612 }
1613
Daniel Vetter99584db2012-11-14 17:14:04 +01001614 queue_work(dev_priv->wq, &dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04001615}
1616
Ville Syrjälä21ad8332013-02-19 15:16:39 +02001617static void __always_unused i915_pageflip_stall_check(struct drm_device *dev, int pipe)
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001618{
1619 drm_i915_private_t *dev_priv = dev->dev_private;
1620 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
1621 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Chris Wilson05394f32010-11-08 19:18:58 +00001622 struct drm_i915_gem_object *obj;
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001623 struct intel_unpin_work *work;
1624 unsigned long flags;
1625 bool stall_detected;
1626
1627 /* Ignore early vblank irqs */
1628 if (intel_crtc == NULL)
1629 return;
1630
1631 spin_lock_irqsave(&dev->event_lock, flags);
1632 work = intel_crtc->unpin_work;
1633
Chris Wilsone7d841c2012-12-03 11:36:30 +00001634 if (work == NULL ||
1635 atomic_read(&work->pending) >= INTEL_FLIP_COMPLETE ||
1636 !work->enable_stall_check) {
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001637 /* Either the pending flip IRQ arrived, or we're too early. Don't check */
1638 spin_unlock_irqrestore(&dev->event_lock, flags);
1639 return;
1640 }
1641
1642 /* Potential stall - if we see that the flip has happened, assume a missed interrupt */
Chris Wilson05394f32010-11-08 19:18:58 +00001643 obj = work->pending_flip_obj;
Chris Wilsona6c45cf2010-09-17 00:32:17 +01001644 if (INTEL_INFO(dev)->gen >= 4) {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001645 int dspsurf = DSPSURF(intel_crtc->plane);
Armin Reese446f2542012-03-30 16:20:16 -07001646 stall_detected = I915_HI_DISPBASE(I915_READ(dspsurf)) ==
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001647 i915_gem_obj_ggtt_offset(obj);
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001648 } else {
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001649 int dspaddr = DSPADDR(intel_crtc->plane);
Ben Widawskyf343c5f2013-07-05 14:41:04 -07001650 stall_detected = I915_READ(dspaddr) == (i915_gem_obj_ggtt_offset(obj) +
Ville Syrjälä01f2c772011-12-20 00:06:49 +02001651 crtc->y * crtc->fb->pitches[0] +
Simon Farnsworth4e5359c2010-09-01 17:47:52 +01001652 crtc->x * crtc->fb->bits_per_pixel/8);
1653 }
1654
1655 spin_unlock_irqrestore(&dev->event_lock, flags);
1656
1657 if (stall_detected) {
1658 DRM_DEBUG_DRIVER("Pageflip stall detected\n");
1659 intel_prepare_page_flip(dev, intel_crtc->plane);
1660 }
1661}
1662
Keith Packard42f52ef2008-10-18 19:39:29 -07001663/* Called from drm generic code, passed 'crtc' which
1664 * we use as a pipe index
1665 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001666static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001667{
1668 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001669 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001670
Chris Wilson5eddb702010-09-11 13:48:45 +01001671 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08001672 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001673
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001674 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07001675 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08001676 i915_enable_pipestat(dev_priv, pipe,
1677 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Keith Packarde9d21d72008-10-16 11:31:38 -07001678 else
Keith Packard7c463582008-11-04 02:03:27 -08001679 i915_enable_pipestat(dev_priv, pipe,
1680 PIPE_VBLANK_INTERRUPT_ENABLE);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001681
1682 /* maintain vblank delivery even in deep C-states */
1683 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02001684 I915_WRITE(INSTPM, _MASKED_BIT_DISABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001685 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001686
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001687 return 0;
1688}
1689
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001690static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07001691{
1692 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1693 unsigned long irqflags;
1694
1695 if (!i915_pipe_enabled(dev, pipe))
1696 return -EINVAL;
1697
1698 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1699 ironlake_enable_display_irq(dev_priv, (pipe == 0) ?
Akshay Joshi0206e352011-08-16 15:34:10 -04001700 DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
Jesse Barnesf796cf82011-04-07 13:58:17 -07001701 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1702
1703 return 0;
1704}
1705
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001706static int ivybridge_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001707{
1708 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1709 unsigned long irqflags;
1710
1711 if (!i915_pipe_enabled(dev, pipe))
1712 return -EINVAL;
1713
1714 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilsonb615b572012-05-02 09:52:12 +01001715 ironlake_enable_display_irq(dev_priv,
1716 DE_PIPEA_VBLANK_IVB << (5 * pipe));
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001717 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1718
1719 return 0;
1720}
1721
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001722static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
1723{
1724 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1725 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001726 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001727
1728 if (!i915_pipe_enabled(dev, pipe))
1729 return -EINVAL;
1730
1731 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001732 imr = I915_READ(VLV_IMR);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001733 if (pipe == 0)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001734 imr &= ~I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001735 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001736 imr &= ~I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001737 I915_WRITE(VLV_IMR, imr);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001738 i915_enable_pipestat(dev_priv, pipe,
1739 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001740 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1741
1742 return 0;
1743}
1744
Keith Packard42f52ef2008-10-18 19:39:29 -07001745/* Called from drm generic code, passed 'crtc' which
1746 * we use as a pipe index
1747 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001748static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001749{
1750 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07001751 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001752
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001753 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00001754 if (dev_priv->info->gen == 3)
Daniel Vetter6b26c862012-04-24 14:04:12 +02001755 I915_WRITE(INSTPM, _MASKED_BIT_ENABLE(INSTPM_AGPBUSY_DIS));
Chris Wilson8692d00e2011-02-05 10:08:21 +00001756
Jesse Barnesf796cf82011-04-07 13:58:17 -07001757 i915_disable_pipestat(dev_priv, pipe,
1758 PIPE_VBLANK_INTERRUPT_ENABLE |
1759 PIPE_START_VBLANK_INTERRUPT_ENABLE);
1760 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1761}
1762
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001763static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07001764{
1765 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1766 unsigned long irqflags;
1767
1768 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
1769 ironlake_disable_display_irq(dev_priv, (pipe == 0) ?
Akshay Joshi0206e352011-08-16 15:34:10 -04001770 DE_PIPEA_VBLANK : DE_PIPEB_VBLANK);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001771 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07001772}
1773
Jesse Barnesf71d4af2011-06-28 13:00:41 -07001774static void ivybridge_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001775{
1776 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1777 unsigned long irqflags;
1778
1779 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilsonb615b572012-05-02 09:52:12 +01001780 ironlake_disable_display_irq(dev_priv,
1781 DE_PIPEA_VBLANK_IVB << (pipe * 5));
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001782 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1783}
1784
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001785static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
1786{
1787 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
1788 unsigned long irqflags;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001789 u32 imr;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001790
1791 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001792 i915_disable_pipestat(dev_priv, pipe,
1793 PIPE_START_VBLANK_INTERRUPT_ENABLE);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001794 imr = I915_READ(VLV_IMR);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001795 if (pipe == 0)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001796 imr |= I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07001797 else
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001798 imr |= I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001799 I915_WRITE(VLV_IMR, imr);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001800 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
1801}
1802
Chris Wilson893eead2010-10-27 14:44:35 +01001803static u32
1804ring_last_seqno(struct intel_ring_buffer *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08001805{
Chris Wilson893eead2010-10-27 14:44:35 +01001806 return list_entry(ring->request_list.prev,
1807 struct drm_i915_gem_request, list)->seqno;
1808}
1809
Chris Wilson9107e9d2013-06-10 11:20:20 +01001810static bool
1811ring_idle(struct intel_ring_buffer *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01001812{
Chris Wilson9107e9d2013-06-10 11:20:20 +01001813 return (list_empty(&ring->request_list) ||
1814 i915_seqno_passed(seqno, ring_last_seqno(ring)));
Ben Gamarif65d9422009-09-14 17:48:44 -04001815}
1816
Chris Wilson6274f212013-06-10 11:20:21 +01001817static struct intel_ring_buffer *
1818semaphore_waits_for(struct intel_ring_buffer *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02001819{
1820 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Chris Wilson6274f212013-06-10 11:20:21 +01001821 u32 cmd, ipehr, acthd, acthd_min;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001822
1823 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
1824 if ((ipehr & ~(0x3 << 16)) !=
1825 (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE | MI_SEMAPHORE_REGISTER))
Chris Wilson6274f212013-06-10 11:20:21 +01001826 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001827
1828 /* ACTHD is likely pointing to the dword after the actual command,
1829 * so scan backwards until we find the MBOX.
1830 */
Chris Wilson6274f212013-06-10 11:20:21 +01001831 acthd = intel_ring_get_active_head(ring) & HEAD_ADDR;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001832 acthd_min = max((int)acthd - 3 * 4, 0);
1833 do {
1834 cmd = ioread32(ring->virtual_start + acthd);
1835 if (cmd == ipehr)
1836 break;
1837
1838 acthd -= 4;
1839 if (acthd < acthd_min)
Chris Wilson6274f212013-06-10 11:20:21 +01001840 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02001841 } while (1);
1842
Chris Wilson6274f212013-06-10 11:20:21 +01001843 *seqno = ioread32(ring->virtual_start+acthd+4)+1;
1844 return &dev_priv->ring[(ring->id + (((ipehr >> 17) & 1) + 1)) % 3];
Chris Wilsona24a11e2013-03-14 17:52:05 +02001845}
1846
Chris Wilson6274f212013-06-10 11:20:21 +01001847static int semaphore_passed(struct intel_ring_buffer *ring)
1848{
1849 struct drm_i915_private *dev_priv = ring->dev->dev_private;
1850 struct intel_ring_buffer *signaller;
1851 u32 seqno, ctl;
1852
1853 ring->hangcheck.deadlock = true;
1854
1855 signaller = semaphore_waits_for(ring, &seqno);
1856 if (signaller == NULL || signaller->hangcheck.deadlock)
1857 return -1;
1858
1859 /* cursory check for an unkickable deadlock */
1860 ctl = I915_READ_CTL(signaller);
1861 if (ctl & RING_WAIT_SEMAPHORE && semaphore_passed(signaller) < 0)
1862 return -1;
1863
1864 return i915_seqno_passed(signaller->get_seqno(signaller, false), seqno);
1865}
1866
1867static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
1868{
1869 struct intel_ring_buffer *ring;
1870 int i;
1871
1872 for_each_ring(ring, dev_priv, i)
1873 ring->hangcheck.deadlock = false;
1874}
1875
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03001876static enum intel_ring_hangcheck_action
1877ring_stuck(struct intel_ring_buffer *ring, u32 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001878{
1879 struct drm_device *dev = ring->dev;
1880 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001881 u32 tmp;
1882
Chris Wilson6274f212013-06-10 11:20:21 +01001883 if (ring->hangcheck.acthd != acthd)
1884 return active;
1885
Chris Wilson9107e9d2013-06-10 11:20:20 +01001886 if (IS_GEN2(dev))
Chris Wilson6274f212013-06-10 11:20:21 +01001887 return hung;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001888
1889 /* Is the chip hanging on a WAIT_FOR_EVENT?
1890 * If so we can simply poke the RB_WAIT bit
1891 * and break the hang. This should work on
1892 * all but the second generation chipsets.
1893 */
1894 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001895 if (tmp & RING_WAIT) {
1896 DRM_ERROR("Kicking stuck wait on %s\n",
1897 ring->name);
1898 I915_WRITE_CTL(ring, tmp);
Chris Wilson6274f212013-06-10 11:20:21 +01001899 return kick;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00001900 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02001901
Chris Wilson6274f212013-06-10 11:20:21 +01001902 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
1903 switch (semaphore_passed(ring)) {
1904 default:
1905 return hung;
1906 case 1:
1907 DRM_ERROR("Kicking stuck semaphore on %s\n",
1908 ring->name);
1909 I915_WRITE_CTL(ring, tmp);
1910 return kick;
1911 case 0:
1912 return wait;
1913 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01001914 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03001915
Chris Wilson6274f212013-06-10 11:20:21 +01001916 return hung;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03001917}
1918
Ben Gamarif65d9422009-09-14 17:48:44 -04001919/**
1920 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001921 * batchbuffers in a long time. We keep track per ring seqno progress and
1922 * if there are no progress, hangcheck score for that ring is increased.
1923 * Further, acthd is inspected to see if the ring is stuck. On stuck case
1924 * we kick the ring. If we see no progress on three subsequent calls
1925 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04001926 */
1927void i915_hangcheck_elapsed(unsigned long data)
1928{
1929 struct drm_device *dev = (struct drm_device *)data;
1930 drm_i915_private_t *dev_priv = dev->dev_private;
Chris Wilsonb4519512012-05-11 14:29:30 +01001931 struct intel_ring_buffer *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01001932 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001933 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001934 bool stuck[I915_NUM_RINGS] = { 0 };
1935#define BUSY 1
1936#define KICK 5
1937#define HUNG 20
1938#define FIRE 30
Chris Wilson893eead2010-10-27 14:44:35 +01001939
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07001940 if (!i915_enable_hangcheck)
1941 return;
1942
Chris Wilsonb4519512012-05-11 14:29:30 +01001943 for_each_ring(ring, dev_priv, i) {
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001944 u32 seqno, acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01001945 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01001946
Chris Wilson6274f212013-06-10 11:20:21 +01001947 semaphore_clear_deadlocks(dev_priv);
1948
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001949 seqno = ring->get_seqno(ring, false);
1950 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01001951
Chris Wilson9107e9d2013-06-10 11:20:20 +01001952 if (ring->hangcheck.seqno == seqno) {
1953 if (ring_idle(ring, seqno)) {
1954 if (waitqueue_active(&ring->irq_queue)) {
1955 /* Issue a wake-up to catch stuck h/w. */
1956 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
1957 ring->name);
1958 wake_up_all(&ring->irq_queue);
1959 ring->hangcheck.score += HUNG;
1960 } else
1961 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001962 } else {
Chris Wilson9107e9d2013-06-10 11:20:20 +01001963 int score;
1964
Chris Wilson6274f212013-06-10 11:20:21 +01001965 /* We always increment the hangcheck score
1966 * if the ring is busy and still processing
1967 * the same request, so that no single request
1968 * can run indefinitely (such as a chain of
1969 * batches). The only time we do not increment
1970 * the hangcheck score on this ring, if this
1971 * ring is in a legitimate wait for another
1972 * ring. In that case the waiting ring is a
1973 * victim and we want to be sure we catch the
1974 * right culprit. Then every time we do kick
1975 * the ring, add a small increment to the
1976 * score so that we can catch a batch that is
1977 * being repeatedly kicked and so responsible
1978 * for stalling the machine.
1979 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03001980 ring->hangcheck.action = ring_stuck(ring,
1981 acthd);
1982
1983 switch (ring->hangcheck.action) {
Chris Wilson6274f212013-06-10 11:20:21 +01001984 case wait:
1985 score = 0;
1986 break;
1987 case active:
Chris Wilson9107e9d2013-06-10 11:20:20 +01001988 score = BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01001989 break;
1990 case kick:
1991 score = KICK;
1992 break;
1993 case hung:
1994 score = HUNG;
1995 stuck[i] = true;
1996 break;
1997 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01001998 ring->hangcheck.score += score;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03001999 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002000 } else {
2001 /* Gradually reduce the count so that we catch DoS
2002 * attempts across multiple batches.
2003 */
2004 if (ring->hangcheck.score > 0)
2005 ring->hangcheck.score--;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002006 }
2007
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002008 ring->hangcheck.seqno = seqno;
2009 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002010 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002011 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002012
Mika Kuoppala92cab732013-05-24 17:16:07 +03002013 for_each_ring(ring, dev_priv, i) {
Chris Wilson9107e9d2013-06-10 11:20:20 +01002014 if (ring->hangcheck.score > FIRE) {
Ben Widawskyacd78c12013-06-13 21:33:33 -07002015 DRM_ERROR("%s on %s\n",
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002016 stuck[i] ? "stuck" : "no progress",
Chris Wilsona43adf02013-06-10 11:20:22 +01002017 ring->name);
2018 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002019 }
2020 }
2021
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002022 if (rings_hung)
2023 return i915_handle_error(dev, true);
Ben Gamarif65d9422009-09-14 17:48:44 -04002024
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002025 if (busy_count)
2026 /* Reset timer case chip hangs without another request
2027 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002028 i915_queue_hangcheck(dev);
2029}
2030
2031void i915_queue_hangcheck(struct drm_device *dev)
2032{
2033 struct drm_i915_private *dev_priv = dev->dev_private;
2034 if (!i915_enable_hangcheck)
2035 return;
2036
2037 mod_timer(&dev_priv->gpu_error.hangcheck_timer,
2038 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002039}
2040
Paulo Zanoni91738a92013-06-05 14:21:51 -03002041static void ibx_irq_preinstall(struct drm_device *dev)
2042{
2043 struct drm_i915_private *dev_priv = dev->dev_private;
2044
2045 if (HAS_PCH_NOP(dev))
2046 return;
2047
2048 /* south display irq */
2049 I915_WRITE(SDEIMR, 0xffffffff);
2050 /*
2051 * SDEIER is also touched by the interrupt handler to work around missed
2052 * PCH interrupts. Hence we can't update it after the interrupt handler
2053 * is enabled - instead we unconditionally enable all PCH interrupt
2054 * sources here, but then only unmask them as needed with SDEIMR.
2055 */
2056 I915_WRITE(SDEIER, 0xffffffff);
2057 POSTING_READ(SDEIER);
2058}
2059
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002060static void gen5_gt_irq_preinstall(struct drm_device *dev)
2061{
2062 struct drm_i915_private *dev_priv = dev->dev_private;
2063
2064 /* and GT */
2065 I915_WRITE(GTIMR, 0xffffffff);
2066 I915_WRITE(GTIER, 0x0);
2067 POSTING_READ(GTIER);
2068
2069 if (INTEL_INFO(dev)->gen >= 6) {
2070 /* and PM */
2071 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2072 I915_WRITE(GEN6_PMIER, 0x0);
2073 POSTING_READ(GEN6_PMIER);
2074 }
2075}
2076
Linus Torvalds1da177e2005-04-16 15:20:36 -07002077/* drm_dma.h hooks
2078*/
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002079static void ironlake_irq_preinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002080{
2081 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2082
Jesse Barnes46979952011-04-07 13:53:55 -07002083 atomic_set(&dev_priv->irq_received, 0);
2084
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002085 I915_WRITE(HWSTAM, 0xeffe);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002086
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002087 I915_WRITE(DEIMR, 0xffffffff);
2088 I915_WRITE(DEIER, 0x0);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002089 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002090
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002091 gen5_gt_irq_preinstall(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002092
Paulo Zanoni91738a92013-06-05 14:21:51 -03002093 ibx_irq_preinstall(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002094}
2095
2096static void ivybridge_irq_preinstall(struct drm_device *dev)
2097{
2098 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2099
2100 atomic_set(&dev_priv->irq_received, 0);
2101
2102 I915_WRITE(HWSTAM, 0xeffe);
2103
2104 /* XXX hotplug from PCH */
2105
2106 I915_WRITE(DEIMR, 0xffffffff);
2107 I915_WRITE(DEIER, 0x0);
2108 POSTING_READ(DEIER);
2109
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002110 gen5_gt_irq_preinstall(dev);
Ben Widawskyeda63ff2013-05-28 19:22:26 -07002111
Paulo Zanoni91738a92013-06-05 14:21:51 -03002112 ibx_irq_preinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002113}
2114
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002115static void valleyview_irq_preinstall(struct drm_device *dev)
2116{
2117 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2118 int pipe;
2119
2120 atomic_set(&dev_priv->irq_received, 0);
2121
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002122 /* VLV magic */
2123 I915_WRITE(VLV_IMR, 0);
2124 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2125 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2126 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2127
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002128 /* and GT */
2129 I915_WRITE(GTIIR, I915_READ(GTIIR));
2130 I915_WRITE(GTIIR, I915_READ(GTIIR));
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002131
2132 gen5_gt_irq_preinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002133
2134 I915_WRITE(DPINVGTT, 0xff);
2135
2136 I915_WRITE(PORT_HOTPLUG_EN, 0);
2137 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2138 for_each_pipe(pipe)
2139 I915_WRITE(PIPESTAT(pipe), 0xffff);
2140 I915_WRITE(VLV_IIR, 0xffffffff);
2141 I915_WRITE(VLV_IMR, 0xffffffff);
2142 I915_WRITE(VLV_IER, 0x0);
2143 POSTING_READ(VLV_IER);
2144}
2145
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002146static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07002147{
2148 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002149 struct drm_mode_config *mode_config = &dev->mode_config;
2150 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02002151 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07002152
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002153 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002154 hotplug_irqs = SDE_HOTPLUG_MASK;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002155 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002156 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002157 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002158 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02002159 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002160 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
Egbert Eichcd569ae2013-04-16 13:36:57 +02002161 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02002162 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002163 }
2164
Daniel Vetterfee884e2013-07-04 23:35:21 +02002165 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002166
2167 /*
2168 * Enable digital hotplug on the PCH, and configure the DP short pulse
2169 * duration to 2ms (which is the minimum in the Display Port spec)
2170 *
2171 * This register is the same on all known PCH chips.
2172 */
Keith Packard7fe0b972011-09-19 13:31:02 -07002173 hotplug = I915_READ(PCH_PORT_HOTPLUG);
2174 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
2175 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
2176 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
2177 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
2178 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
2179}
2180
Paulo Zanonid46da432013-02-08 17:35:15 -02002181static void ibx_irq_postinstall(struct drm_device *dev)
2182{
2183 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01002184 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02002185
Daniel Vetter692a04c2013-05-29 21:43:05 +02002186 if (HAS_PCH_NOP(dev))
2187 return;
2188
Paulo Zanoni86642812013-04-12 17:57:57 -03002189 if (HAS_PCH_IBX(dev)) {
2190 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_TRANSB_FIFO_UNDER |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002191 SDE_TRANSA_FIFO_UNDER | SDE_POISON;
Paulo Zanoni86642812013-04-12 17:57:57 -03002192 } else {
2193 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT | SDE_ERROR_CPT;
2194
2195 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
2196 }
Ben Widawskyab5c6082013-04-05 13:12:41 -07002197
Paulo Zanonid46da432013-02-08 17:35:15 -02002198 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
2199 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02002200}
2201
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002202static void gen5_gt_irq_postinstall(struct drm_device *dev)
2203{
2204 struct drm_i915_private *dev_priv = dev->dev_private;
2205 u32 pm_irqs, gt_irqs;
2206
2207 pm_irqs = gt_irqs = 0;
2208
2209 dev_priv->gt_irq_mask = ~0;
2210 if (HAS_L3_GPU_CACHE(dev)) {
2211 /* L3 parity interrupt is always unmasked. */
2212 dev_priv->gt_irq_mask = ~GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
2213 gt_irqs |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
2214 }
2215
2216 gt_irqs |= GT_RENDER_USER_INTERRUPT;
2217 if (IS_GEN5(dev)) {
2218 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
2219 ILK_BSD_USER_INTERRUPT;
2220 } else {
2221 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
2222 }
2223
2224 I915_WRITE(GTIIR, I915_READ(GTIIR));
2225 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
2226 I915_WRITE(GTIER, gt_irqs);
2227 POSTING_READ(GTIER);
2228
2229 if (INTEL_INFO(dev)->gen >= 6) {
2230 pm_irqs |= GEN6_PM_RPS_EVENTS;
2231
2232 if (HAS_VEBOX(dev))
2233 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
2234
2235 I915_WRITE(GEN6_PMIIR, I915_READ(GEN6_PMIIR));
2236 I915_WRITE(GEN6_PMIMR, 0xffffffff);
2237 I915_WRITE(GEN6_PMIER, pm_irqs);
2238 POSTING_READ(GEN6_PMIER);
2239 }
2240}
2241
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002242static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002243{
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002244 unsigned long irqflags;
2245
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002246 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2247 /* enable kind of interrupts always enabled */
Jesse Barnes013d5aa2010-01-29 11:18:31 -08002248 u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Daniel Vetterce99c252012-12-01 13:53:47 +01002249 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Paulo Zanoni86642812013-04-12 17:57:57 -03002250 DE_AUX_CHANNEL_A | DE_PIPEB_FIFO_UNDERRUN |
Paulo Zanonide032bf2013-04-12 17:57:58 -03002251 DE_PIPEA_FIFO_UNDERRUN | DE_POISON;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002252
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002253 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002254
2255 /* should always can generate irq */
2256 I915_WRITE(DEIIR, I915_READ(DEIIR));
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002257 I915_WRITE(DEIMR, dev_priv->irq_mask);
Daniel Vetter6005ce42013-06-27 13:44:59 +02002258 I915_WRITE(DEIER, display_mask |
2259 DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002260 POSTING_READ(DEIER);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002261
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002262 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002263
Paulo Zanonid46da432013-02-08 17:35:15 -02002264 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002265
Jesse Barnesf97108d2010-01-29 11:27:07 -08002266 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02002267 /* Enable PCU event interrupts
2268 *
2269 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002270 * setup is guaranteed to run in single-threaded context. But we
2271 * need it to make the assert_spin_locked happy. */
2272 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002273 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetter4bc9d432013-06-27 13:44:58 +02002274 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnesf97108d2010-01-29 11:27:07 -08002275 }
2276
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002277 return 0;
2278}
2279
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002280static int ivybridge_irq_postinstall(struct drm_device *dev)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002281{
2282 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2283 /* enable kind of interrupts always enabled */
Chris Wilsonb615b572012-05-02 09:52:12 +01002284 u32 display_mask =
2285 DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | DE_PCH_EVENT_IVB |
2286 DE_PLANEC_FLIP_DONE_IVB |
2287 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetterce99c252012-12-01 13:53:47 +01002288 DE_PLANEA_FLIP_DONE_IVB |
Paulo Zanoni86642812013-04-12 17:57:57 -03002289 DE_AUX_CHANNEL_A_IVB |
2290 DE_ERR_INT_IVB;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002291
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002292 dev_priv->irq_mask = ~display_mask;
2293
2294 /* should always can generate irq */
Paulo Zanoni86642812013-04-12 17:57:57 -03002295 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002296 I915_WRITE(DEIIR, I915_READ(DEIIR));
2297 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilsonb615b572012-05-02 09:52:12 +01002298 I915_WRITE(DEIER,
2299 display_mask |
2300 DE_PIPEC_VBLANK_IVB |
2301 DE_PIPEB_VBLANK_IVB |
2302 DE_PIPEA_VBLANK_IVB);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002303 POSTING_READ(DEIER);
2304
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002305 gen5_gt_irq_postinstall(dev);
Ben Widawskyeda63ff2013-05-28 19:22:26 -07002306
Paulo Zanonid46da432013-02-08 17:35:15 -02002307 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07002308
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002309 return 0;
2310}
2311
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002312static int valleyview_irq_postinstall(struct drm_device *dev)
2313{
2314 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002315 u32 enable_mask;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002316 u32 pipestat_enable = PLANE_FLIP_DONE_INT_EN_VLV;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002317 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002318
2319 enable_mask = I915_DISPLAY_PORT_INTERRUPT;
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002320 enable_mask |= I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2321 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2322 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002323 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
2324
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002325 /*
2326 *Leave vblank interrupts masked initially. enable/disable will
2327 * toggle them based on usage.
2328 */
2329 dev_priv->irq_mask = (~enable_mask) |
2330 I915_DISPLAY_PIPE_A_VBLANK_INTERRUPT |
2331 I915_DISPLAY_PIPE_B_VBLANK_INTERRUPT;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002332
Daniel Vetter20afbda2012-12-11 14:05:07 +01002333 I915_WRITE(PORT_HOTPLUG_EN, 0);
2334 POSTING_READ(PORT_HOTPLUG_EN);
2335
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002336 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
2337 I915_WRITE(VLV_IER, enable_mask);
2338 I915_WRITE(VLV_IIR, 0xffffffff);
2339 I915_WRITE(PIPESTAT(0), 0xffff);
2340 I915_WRITE(PIPESTAT(1), 0xffff);
2341 POSTING_READ(VLV_IER);
2342
Daniel Vetterb79480b2013-06-27 17:52:10 +02002343 /* Interrupt setup is already guaranteed to be single-threaded, this is
2344 * just to make the assert_spin_locked check happy. */
2345 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002346 i915_enable_pipestat(dev_priv, 0, pipestat_enable);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002347 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002348 i915_enable_pipestat(dev_priv, 1, pipestat_enable);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002349 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002350
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002351 I915_WRITE(VLV_IIR, 0xffffffff);
2352 I915_WRITE(VLV_IIR, 0xffffffff);
2353
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02002354 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002355
2356 /* ack & enable invalid PTE error interrupts */
2357#if 0 /* FIXME: add support to irq handler for checking these bits */
2358 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
2359 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
2360#endif
2361
2362 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002363
2364 return 0;
2365}
2366
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002367static void valleyview_irq_uninstall(struct drm_device *dev)
2368{
2369 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2370 int pipe;
2371
2372 if (!dev_priv)
2373 return;
2374
Egbert Eichac4c16c2013-04-16 13:36:58 +02002375 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2376
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002377 for_each_pipe(pipe)
2378 I915_WRITE(PIPESTAT(pipe), 0xffff);
2379
2380 I915_WRITE(HWSTAM, 0xffffffff);
2381 I915_WRITE(PORT_HOTPLUG_EN, 0);
2382 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2383 for_each_pipe(pipe)
2384 I915_WRITE(PIPESTAT(pipe), 0xffff);
2385 I915_WRITE(VLV_IIR, 0xffffffff);
2386 I915_WRITE(VLV_IMR, 0xffffffff);
2387 I915_WRITE(VLV_IER, 0x0);
2388 POSTING_READ(VLV_IER);
2389}
2390
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002391static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002392{
2393 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07002394
2395 if (!dev_priv)
2396 return;
2397
Egbert Eichac4c16c2013-04-16 13:36:58 +02002398 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2399
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002400 I915_WRITE(HWSTAM, 0xffffffff);
2401
2402 I915_WRITE(DEIMR, 0xffffffff);
2403 I915_WRITE(DEIER, 0x0);
2404 I915_WRITE(DEIIR, I915_READ(DEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002405 if (IS_GEN7(dev))
2406 I915_WRITE(GEN7_ERR_INT, I915_READ(GEN7_ERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002407
2408 I915_WRITE(GTIMR, 0xffffffff);
2409 I915_WRITE(GTIER, 0x0);
2410 I915_WRITE(GTIIR, I915_READ(GTIIR));
Keith Packard192aac1f2011-09-20 10:12:44 -07002411
Ben Widawskyab5c6082013-04-05 13:12:41 -07002412 if (HAS_PCH_NOP(dev))
2413 return;
2414
Keith Packard192aac1f2011-09-20 10:12:44 -07002415 I915_WRITE(SDEIMR, 0xffffffff);
2416 I915_WRITE(SDEIER, 0x0);
2417 I915_WRITE(SDEIIR, I915_READ(SDEIIR));
Paulo Zanoni86642812013-04-12 17:57:57 -03002418 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
2419 I915_WRITE(SERR_INT, I915_READ(SERR_INT));
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002420}
2421
Chris Wilsonc2798b12012-04-22 21:13:57 +01002422static void i8xx_irq_preinstall(struct drm_device * dev)
2423{
2424 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2425 int pipe;
2426
2427 atomic_set(&dev_priv->irq_received, 0);
2428
2429 for_each_pipe(pipe)
2430 I915_WRITE(PIPESTAT(pipe), 0);
2431 I915_WRITE16(IMR, 0xffff);
2432 I915_WRITE16(IER, 0x0);
2433 POSTING_READ16(IER);
2434}
2435
2436static int i8xx_irq_postinstall(struct drm_device *dev)
2437{
2438 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2439
Chris Wilsonc2798b12012-04-22 21:13:57 +01002440 I915_WRITE16(EMR,
2441 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2442
2443 /* Unmask the interrupts that we always want on. */
2444 dev_priv->irq_mask =
2445 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2446 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2447 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2448 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2449 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2450 I915_WRITE16(IMR, dev_priv->irq_mask);
2451
2452 I915_WRITE16(IER,
2453 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2454 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2455 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2456 I915_USER_INTERRUPT);
2457 POSTING_READ16(IER);
2458
2459 return 0;
2460}
2461
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002462/*
2463 * Returns true when a page flip has completed.
2464 */
2465static bool i8xx_handle_vblank(struct drm_device *dev,
2466 int pipe, u16 iir)
2467{
2468 drm_i915_private_t *dev_priv = dev->dev_private;
2469 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(pipe);
2470
2471 if (!drm_handle_vblank(dev, pipe))
2472 return false;
2473
2474 if ((iir & flip_pending) == 0)
2475 return false;
2476
2477 intel_prepare_page_flip(dev, pipe);
2478
2479 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2480 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2481 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2482 * the flip is completed (no longer pending). Since this doesn't raise
2483 * an interrupt per se, we watch for the change at vblank.
2484 */
2485 if (I915_READ16(ISR) & flip_pending)
2486 return false;
2487
2488 intel_finish_page_flip(dev, pipe);
2489
2490 return true;
2491}
2492
Daniel Vetterff1f5252012-10-02 15:10:55 +02002493static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01002494{
2495 struct drm_device *dev = (struct drm_device *) arg;
2496 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01002497 u16 iir, new_iir;
2498 u32 pipe_stats[2];
2499 unsigned long irqflags;
2500 int irq_received;
2501 int pipe;
2502 u16 flip_mask =
2503 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2504 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
2505
2506 atomic_inc(&dev_priv->irq_received);
2507
2508 iir = I915_READ16(IIR);
2509 if (iir == 0)
2510 return IRQ_NONE;
2511
2512 while (iir & ~flip_mask) {
2513 /* Can't rely on pipestat interrupt bit in iir as it might
2514 * have been cleared after the pipestat interrupt was received.
2515 * It doesn't set the bit in iir again, but it still produces
2516 * interrupts (for non-MSI).
2517 */
2518 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2519 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2520 i915_handle_error(dev, false);
2521
2522 for_each_pipe(pipe) {
2523 int reg = PIPESTAT(pipe);
2524 pipe_stats[pipe] = I915_READ(reg);
2525
2526 /*
2527 * Clear the PIPE*STAT regs before the IIR
2528 */
2529 if (pipe_stats[pipe] & 0x8000ffff) {
2530 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2531 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2532 pipe_name(pipe));
2533 I915_WRITE(reg, pipe_stats[pipe]);
2534 irq_received = 1;
2535 }
2536 }
2537 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2538
2539 I915_WRITE16(IIR, iir & ~flip_mask);
2540 new_iir = I915_READ16(IIR); /* Flush posted writes */
2541
Daniel Vetterd05c6172012-04-26 23:28:09 +02002542 i915_update_dri1_breadcrumb(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002543
2544 if (iir & I915_USER_INTERRUPT)
2545 notify_ring(dev, &dev_priv->ring[RCS]);
2546
2547 if (pipe_stats[0] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002548 i8xx_handle_vblank(dev, 0, iir))
2549 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002550
2551 if (pipe_stats[1] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002552 i8xx_handle_vblank(dev, 1, iir))
2553 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(1);
Chris Wilsonc2798b12012-04-22 21:13:57 +01002554
2555 iir = new_iir;
2556 }
2557
2558 return IRQ_HANDLED;
2559}
2560
2561static void i8xx_irq_uninstall(struct drm_device * dev)
2562{
2563 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2564 int pipe;
2565
Chris Wilsonc2798b12012-04-22 21:13:57 +01002566 for_each_pipe(pipe) {
2567 /* Clear enable bits; then clear status bits */
2568 I915_WRITE(PIPESTAT(pipe), 0);
2569 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2570 }
2571 I915_WRITE16(IMR, 0xffff);
2572 I915_WRITE16(IER, 0x0);
2573 I915_WRITE16(IIR, I915_READ16(IIR));
2574}
2575
Chris Wilsona266c7d2012-04-24 22:59:44 +01002576static void i915_irq_preinstall(struct drm_device * dev)
2577{
2578 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2579 int pipe;
2580
2581 atomic_set(&dev_priv->irq_received, 0);
2582
2583 if (I915_HAS_HOTPLUG(dev)) {
2584 I915_WRITE(PORT_HOTPLUG_EN, 0);
2585 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2586 }
2587
Chris Wilson00d98eb2012-04-24 22:59:48 +01002588 I915_WRITE16(HWSTAM, 0xeffe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002589 for_each_pipe(pipe)
2590 I915_WRITE(PIPESTAT(pipe), 0);
2591 I915_WRITE(IMR, 0xffffffff);
2592 I915_WRITE(IER, 0x0);
2593 POSTING_READ(IER);
2594}
2595
2596static int i915_irq_postinstall(struct drm_device *dev)
2597{
2598 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01002599 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002600
Chris Wilson38bde182012-04-24 22:59:50 +01002601 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
2602
2603 /* Unmask the interrupts that we always want on. */
2604 dev_priv->irq_mask =
2605 ~(I915_ASLE_INTERRUPT |
2606 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2607 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2608 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2609 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2610 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2611
2612 enable_mask =
2613 I915_ASLE_INTERRUPT |
2614 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2615 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2616 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
2617 I915_USER_INTERRUPT;
2618
Chris Wilsona266c7d2012-04-24 22:59:44 +01002619 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01002620 I915_WRITE(PORT_HOTPLUG_EN, 0);
2621 POSTING_READ(PORT_HOTPLUG_EN);
2622
Chris Wilsona266c7d2012-04-24 22:59:44 +01002623 /* Enable in IER... */
2624 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
2625 /* and unmask in IMR */
2626 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
2627 }
2628
Chris Wilsona266c7d2012-04-24 22:59:44 +01002629 I915_WRITE(IMR, dev_priv->irq_mask);
2630 I915_WRITE(IER, enable_mask);
2631 POSTING_READ(IER);
2632
Jani Nikulaf49e38d2013-04-29 13:02:54 +03002633 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002634
2635 return 0;
2636}
2637
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002638/*
2639 * Returns true when a page flip has completed.
2640 */
2641static bool i915_handle_vblank(struct drm_device *dev,
2642 int plane, int pipe, u32 iir)
2643{
2644 drm_i915_private_t *dev_priv = dev->dev_private;
2645 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
2646
2647 if (!drm_handle_vblank(dev, pipe))
2648 return false;
2649
2650 if ((iir & flip_pending) == 0)
2651 return false;
2652
2653 intel_prepare_page_flip(dev, plane);
2654
2655 /* We detect FlipDone by looking for the change in PendingFlip from '1'
2656 * to '0' on the following vblank, i.e. IIR has the Pendingflip
2657 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
2658 * the flip is completed (no longer pending). Since this doesn't raise
2659 * an interrupt per se, we watch for the change at vblank.
2660 */
2661 if (I915_READ(ISR) & flip_pending)
2662 return false;
2663
2664 intel_finish_page_flip(dev, pipe);
2665
2666 return true;
2667}
2668
Daniel Vetterff1f5252012-10-02 15:10:55 +02002669static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01002670{
2671 struct drm_device *dev = (struct drm_device *) arg;
2672 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01002673 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01002674 unsigned long irqflags;
Chris Wilson38bde182012-04-24 22:59:50 +01002675 u32 flip_mask =
2676 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2677 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01002678 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002679
2680 atomic_inc(&dev_priv->irq_received);
2681
2682 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01002683 do {
2684 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01002685 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002686
2687 /* Can't rely on pipestat interrupt bit in iir as it might
2688 * have been cleared after the pipestat interrupt was received.
2689 * It doesn't set the bit in iir again, but it still produces
2690 * interrupts (for non-MSI).
2691 */
2692 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2693 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2694 i915_handle_error(dev, false);
2695
2696 for_each_pipe(pipe) {
2697 int reg = PIPESTAT(pipe);
2698 pipe_stats[pipe] = I915_READ(reg);
2699
Chris Wilson38bde182012-04-24 22:59:50 +01002700 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01002701 if (pipe_stats[pipe] & 0x8000ffff) {
2702 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2703 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2704 pipe_name(pipe));
2705 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01002706 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002707 }
2708 }
2709 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2710
2711 if (!irq_received)
2712 break;
2713
Chris Wilsona266c7d2012-04-24 22:59:44 +01002714 /* Consume port. Then clear IIR or we'll miss events */
2715 if ((I915_HAS_HOTPLUG(dev)) &&
2716 (iir & I915_DISPLAY_PORT_INTERRUPT)) {
2717 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02002718 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002719
2720 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2721 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002722
2723 intel_hpd_irq_handler(dev, hotplug_trigger, hpd_status_i915);
2724
Chris Wilsona266c7d2012-04-24 22:59:44 +01002725 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Chris Wilson38bde182012-04-24 22:59:50 +01002726 POSTING_READ(PORT_HOTPLUG_STAT);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002727 }
2728
Chris Wilson38bde182012-04-24 22:59:50 +01002729 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002730 new_iir = I915_READ(IIR); /* Flush posted writes */
2731
Chris Wilsona266c7d2012-04-24 22:59:44 +01002732 if (iir & I915_USER_INTERRUPT)
2733 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002734
Chris Wilsona266c7d2012-04-24 22:59:44 +01002735 for_each_pipe(pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01002736 int plane = pipe;
2737 if (IS_MOBILE(dev))
2738 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02002739
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002740 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
2741 i915_handle_vblank(dev, plane, pipe, iir))
2742 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002743
2744 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2745 blc_event = true;
2746 }
2747
Chris Wilsona266c7d2012-04-24 22:59:44 +01002748 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2749 intel_opregion_asle_intr(dev);
2750
2751 /* With MSI, interrupts are only generated when iir
2752 * transitions from zero to nonzero. If another bit got
2753 * set while we were handling the existing iir bits, then
2754 * we would never get another interrupt.
2755 *
2756 * This is fine on non-MSI as well, as if we hit this path
2757 * we avoid exiting the interrupt handler only to generate
2758 * another one.
2759 *
2760 * Note that for MSI this could cause a stray interrupt report
2761 * if an interrupt landed in the time between writing IIR and
2762 * the posting read. This should be rare enough to never
2763 * trigger the 99% of 100,000 interrupts test for disabling
2764 * stray interrupts.
2765 */
Chris Wilson38bde182012-04-24 22:59:50 +01002766 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002767 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01002768 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002769
Daniel Vetterd05c6172012-04-26 23:28:09 +02002770 i915_update_dri1_breadcrumb(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01002771
Chris Wilsona266c7d2012-04-24 22:59:44 +01002772 return ret;
2773}
2774
2775static void i915_irq_uninstall(struct drm_device * dev)
2776{
2777 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2778 int pipe;
2779
Egbert Eichac4c16c2013-04-16 13:36:58 +02002780 del_timer_sync(&dev_priv->hotplug_reenable_timer);
2781
Chris Wilsona266c7d2012-04-24 22:59:44 +01002782 if (I915_HAS_HOTPLUG(dev)) {
2783 I915_WRITE(PORT_HOTPLUG_EN, 0);
2784 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2785 }
2786
Chris Wilson00d98eb2012-04-24 22:59:48 +01002787 I915_WRITE16(HWSTAM, 0xffff);
Chris Wilson55b39752012-04-24 22:59:49 +01002788 for_each_pipe(pipe) {
2789 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01002790 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01002791 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
2792 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01002793 I915_WRITE(IMR, 0xffffffff);
2794 I915_WRITE(IER, 0x0);
2795
Chris Wilsona266c7d2012-04-24 22:59:44 +01002796 I915_WRITE(IIR, I915_READ(IIR));
2797}
2798
2799static void i965_irq_preinstall(struct drm_device * dev)
2800{
2801 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
2802 int pipe;
2803
2804 atomic_set(&dev_priv->irq_received, 0);
2805
Chris Wilsonadca4732012-05-11 18:01:31 +01002806 I915_WRITE(PORT_HOTPLUG_EN, 0);
2807 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01002808
2809 I915_WRITE(HWSTAM, 0xeffe);
2810 for_each_pipe(pipe)
2811 I915_WRITE(PIPESTAT(pipe), 0);
2812 I915_WRITE(IMR, 0xffffffff);
2813 I915_WRITE(IER, 0x0);
2814 POSTING_READ(IER);
2815}
2816
2817static int i965_irq_postinstall(struct drm_device *dev)
2818{
2819 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002820 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002821 u32 error_mask;
Daniel Vetterb79480b2013-06-27 17:52:10 +02002822 unsigned long irqflags;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002823
Chris Wilsona266c7d2012-04-24 22:59:44 +01002824 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002825 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01002826 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002827 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
2828 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
2829 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2830 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
2831 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2832
2833 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002834 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2835 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01002836 enable_mask |= I915_USER_INTERRUPT;
2837
2838 if (IS_G4X(dev))
2839 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002840
Daniel Vetterb79480b2013-06-27 17:52:10 +02002841 /* Interrupt setup is already guaranteed to be single-threaded, this is
2842 * just to make the assert_spin_locked check happy. */
2843 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002844 i915_enable_pipestat(dev_priv, 0, PIPE_GMBUS_EVENT_ENABLE);
Daniel Vetterb79480b2013-06-27 17:52:10 +02002845 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002846
Chris Wilsona266c7d2012-04-24 22:59:44 +01002847 /*
2848 * Enable some error detection, note the instruction error mask
2849 * bit is reserved, so we leave it masked.
2850 */
2851 if (IS_G4X(dev)) {
2852 error_mask = ~(GM45_ERROR_PAGE_TABLE |
2853 GM45_ERROR_MEM_PRIV |
2854 GM45_ERROR_CP_PRIV |
2855 I915_ERROR_MEMORY_REFRESH);
2856 } else {
2857 error_mask = ~(I915_ERROR_PAGE_TABLE |
2858 I915_ERROR_MEMORY_REFRESH);
2859 }
2860 I915_WRITE(EMR, error_mask);
2861
2862 I915_WRITE(IMR, dev_priv->irq_mask);
2863 I915_WRITE(IER, enable_mask);
2864 POSTING_READ(IER);
2865
Daniel Vetter20afbda2012-12-11 14:05:07 +01002866 I915_WRITE(PORT_HOTPLUG_EN, 0);
2867 POSTING_READ(PORT_HOTPLUG_EN);
2868
Jani Nikulaf49e38d2013-04-29 13:02:54 +03002869 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01002870
2871 return 0;
2872}
2873
Egbert Eichbac56d52013-02-25 12:06:51 -05002874static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01002875{
2876 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Egbert Eiche5868a32013-02-28 04:17:12 -05002877 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +02002878 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01002879 u32 hotplug_en;
2880
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02002881 assert_spin_locked(&dev_priv->irq_lock);
2882
Egbert Eichbac56d52013-02-25 12:06:51 -05002883 if (I915_HAS_HOTPLUG(dev)) {
2884 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
2885 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
2886 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05002887 /* enable bits are the same for all generations */
Egbert Eichcd569ae2013-04-16 13:36:57 +02002888 list_for_each_entry(intel_encoder, &mode_config->encoder_list, base.head)
2889 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
2890 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05002891 /* Programming the CRT detection parameters tends
2892 to generate a spurious hotplug event about three
2893 seconds later. So just do it once.
2894 */
2895 if (IS_G4X(dev))
2896 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01002897 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05002898 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002899
Egbert Eichbac56d52013-02-25 12:06:51 -05002900 /* Ignore TV since it's buggy */
2901 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
2902 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01002903}
2904
Daniel Vetterff1f5252012-10-02 15:10:55 +02002905static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01002906{
2907 struct drm_device *dev = (struct drm_device *) arg;
2908 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002909 u32 iir, new_iir;
2910 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01002911 unsigned long irqflags;
2912 int irq_received;
2913 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002914 u32 flip_mask =
2915 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
2916 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002917
2918 atomic_inc(&dev_priv->irq_received);
2919
2920 iir = I915_READ(IIR);
2921
Chris Wilsona266c7d2012-04-24 22:59:44 +01002922 for (;;) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01002923 bool blc_event = false;
2924
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002925 irq_received = (iir & ~flip_mask) != 0;
Chris Wilsona266c7d2012-04-24 22:59:44 +01002926
2927 /* Can't rely on pipestat interrupt bit in iir as it might
2928 * have been cleared after the pipestat interrupt was received.
2929 * It doesn't set the bit in iir again, but it still produces
2930 * interrupts (for non-MSI).
2931 */
2932 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2933 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
2934 i915_handle_error(dev, false);
2935
2936 for_each_pipe(pipe) {
2937 int reg = PIPESTAT(pipe);
2938 pipe_stats[pipe] = I915_READ(reg);
2939
2940 /*
2941 * Clear the PIPE*STAT regs before the IIR
2942 */
2943 if (pipe_stats[pipe] & 0x8000ffff) {
2944 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2945 DRM_DEBUG_DRIVER("pipe %c underrun\n",
2946 pipe_name(pipe));
2947 I915_WRITE(reg, pipe_stats[pipe]);
2948 irq_received = 1;
2949 }
2950 }
2951 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2952
2953 if (!irq_received)
2954 break;
2955
2956 ret = IRQ_HANDLED;
2957
2958 /* Consume port. Then clear IIR or we'll miss events */
Chris Wilsonadca4732012-05-11 18:01:31 +01002959 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01002960 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Egbert Eichb543fb02013-04-16 13:36:54 +02002961 u32 hotplug_trigger = hotplug_status & (IS_G4X(dev) ?
2962 HOTPLUG_INT_STATUS_G4X :
Daniel Vetter4f7fd702013-06-24 21:33:28 +02002963 HOTPLUG_INT_STATUS_I915);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002964
2965 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x\n",
2966 hotplug_status);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002967
2968 intel_hpd_irq_handler(dev, hotplug_trigger,
2969 IS_G4X(dev) ? hpd_status_gen4 : hpd_status_i915);
2970
Chris Wilsona266c7d2012-04-24 22:59:44 +01002971 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2972 I915_READ(PORT_HOTPLUG_STAT);
2973 }
2974
Ville Syrjälä21ad8332013-02-19 15:16:39 +02002975 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002976 new_iir = I915_READ(IIR); /* Flush posted writes */
2977
Chris Wilsona266c7d2012-04-24 22:59:44 +01002978 if (iir & I915_USER_INTERRUPT)
2979 notify_ring(dev, &dev_priv->ring[RCS]);
2980 if (iir & I915_BSD_USER_INTERRUPT)
2981 notify_ring(dev, &dev_priv->ring[VCS]);
2982
Chris Wilsona266c7d2012-04-24 22:59:44 +01002983 for_each_pipe(pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01002984 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02002985 i915_handle_vblank(dev, pipe, pipe, iir))
2986 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01002987
2988 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2989 blc_event = true;
2990 }
2991
2992
2993 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2994 intel_opregion_asle_intr(dev);
2995
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002996 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2997 gmbus_irq_handler(dev);
2998
Chris Wilsona266c7d2012-04-24 22:59:44 +01002999 /* With MSI, interrupts are only generated when iir
3000 * transitions from zero to nonzero. If another bit got
3001 * set while we were handling the existing iir bits, then
3002 * we would never get another interrupt.
3003 *
3004 * This is fine on non-MSI as well, as if we hit this path
3005 * we avoid exiting the interrupt handler only to generate
3006 * another one.
3007 *
3008 * Note that for MSI this could cause a stray interrupt report
3009 * if an interrupt landed in the time between writing IIR and
3010 * the posting read. This should be rare enough to never
3011 * trigger the 99% of 100,000 interrupts test for disabling
3012 * stray interrupts.
3013 */
3014 iir = new_iir;
3015 }
3016
Daniel Vetterd05c6172012-04-26 23:28:09 +02003017 i915_update_dri1_breadcrumb(dev);
Chris Wilson2c8ba292012-04-24 22:59:46 +01003018
Chris Wilsona266c7d2012-04-24 22:59:44 +01003019 return ret;
3020}
3021
3022static void i965_irq_uninstall(struct drm_device * dev)
3023{
3024 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
3025 int pipe;
3026
3027 if (!dev_priv)
3028 return;
3029
Egbert Eichac4c16c2013-04-16 13:36:58 +02003030 del_timer_sync(&dev_priv->hotplug_reenable_timer);
3031
Chris Wilsonadca4732012-05-11 18:01:31 +01003032 I915_WRITE(PORT_HOTPLUG_EN, 0);
3033 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003034
3035 I915_WRITE(HWSTAM, 0xffffffff);
3036 for_each_pipe(pipe)
3037 I915_WRITE(PIPESTAT(pipe), 0);
3038 I915_WRITE(IMR, 0xffffffff);
3039 I915_WRITE(IER, 0x0);
3040
3041 for_each_pipe(pipe)
3042 I915_WRITE(PIPESTAT(pipe),
3043 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
3044 I915_WRITE(IIR, I915_READ(IIR));
3045}
3046
Egbert Eichac4c16c2013-04-16 13:36:58 +02003047static void i915_reenable_hotplug_timer_func(unsigned long data)
3048{
3049 drm_i915_private_t *dev_priv = (drm_i915_private_t *)data;
3050 struct drm_device *dev = dev_priv->dev;
3051 struct drm_mode_config *mode_config = &dev->mode_config;
3052 unsigned long irqflags;
3053 int i;
3054
3055 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3056 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
3057 struct drm_connector *connector;
3058
3059 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
3060 continue;
3061
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
3067 if (intel_connector->encoder->hpd_pin == i) {
3068 if (connector->polled != intel_connector->polled)
3069 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
3070 drm_get_connector_name(connector));
3071 connector->polled = intel_connector->polled;
3072 if (!connector->polled)
3073 connector->polled = DRM_CONNECTOR_POLL_HPD;
3074 }
3075 }
3076 }
3077 if (dev_priv->display.hpd_irq_setup)
3078 dev_priv->display.hpd_irq_setup(dev);
3079 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3080}
3081
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003082void intel_irq_init(struct drm_device *dev)
3083{
Chris Wilson8b2e3262012-04-24 22:59:41 +01003084 struct drm_i915_private *dev_priv = dev->dev_private;
3085
3086 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01003087 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003088 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003089 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01003090
Daniel Vetter99584db2012-11-14 17:14:04 +01003091 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
3092 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01003093 (unsigned long) dev);
Egbert Eichac4c16c2013-04-16 13:36:58 +02003094 setup_timer(&dev_priv->hotplug_reenable_timer, i915_reenable_hotplug_timer_func,
3095 (unsigned long) dev_priv);
Daniel Vetter61bac782012-12-01 21:03:21 +01003096
Tomas Janousek97a19a22012-12-08 13:48:13 +01003097 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01003098
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003099 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3100 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Eugeni Dodonov7d4e1462012-05-09 15:37:09 -03003101 if (IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003102 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
3103 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
3104 }
3105
Keith Packardc3613de2011-08-12 17:05:54 -07003106 if (drm_core_check_feature(dev, DRIVER_MODESET))
3107 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
3108 else
3109 dev->driver->get_vblank_timestamp = NULL;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003110 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
3111
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003112 if (IS_VALLEYVIEW(dev)) {
3113 dev->driver->irq_handler = valleyview_irq_handler;
3114 dev->driver->irq_preinstall = valleyview_irq_preinstall;
3115 dev->driver->irq_postinstall = valleyview_irq_postinstall;
3116 dev->driver->irq_uninstall = valleyview_irq_uninstall;
3117 dev->driver->enable_vblank = valleyview_enable_vblank;
3118 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05003119 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetter4a06e202012-12-01 13:53:40 +01003120 } else if (IS_IVYBRIDGE(dev) || IS_HASWELL(dev)) {
Ben Widawsky7d991632013-05-28 19:22:25 -07003121 /* Share uninstall handlers with ILK/SNB */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003122 dev->driver->irq_handler = ivybridge_irq_handler;
Ben Widawsky7d991632013-05-28 19:22:25 -07003123 dev->driver->irq_preinstall = ivybridge_irq_preinstall;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003124 dev->driver->irq_postinstall = ivybridge_irq_postinstall;
3125 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3126 dev->driver->enable_vblank = ivybridge_enable_vblank;
3127 dev->driver->disable_vblank = ivybridge_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003128 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003129 } else if (HAS_PCH_SPLIT(dev)) {
3130 dev->driver->irq_handler = ironlake_irq_handler;
3131 dev->driver->irq_preinstall = ironlake_irq_preinstall;
3132 dev->driver->irq_postinstall = ironlake_irq_postinstall;
3133 dev->driver->irq_uninstall = ironlake_irq_uninstall;
3134 dev->driver->enable_vblank = ironlake_enable_vblank;
3135 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003136 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003137 } else {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003138 if (INTEL_INFO(dev)->gen == 2) {
3139 dev->driver->irq_preinstall = i8xx_irq_preinstall;
3140 dev->driver->irq_postinstall = i8xx_irq_postinstall;
3141 dev->driver->irq_handler = i8xx_irq_handler;
3142 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003143 } else if (INTEL_INFO(dev)->gen == 3) {
3144 dev->driver->irq_preinstall = i915_irq_preinstall;
3145 dev->driver->irq_postinstall = i915_irq_postinstall;
3146 dev->driver->irq_uninstall = i915_irq_uninstall;
3147 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003148 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003149 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003150 dev->driver->irq_preinstall = i965_irq_preinstall;
3151 dev->driver->irq_postinstall = i965_irq_postinstall;
3152 dev->driver->irq_uninstall = i965_irq_uninstall;
3153 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05003154 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003155 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003156 dev->driver->enable_vblank = i915_enable_vblank;
3157 dev->driver->disable_vblank = i915_disable_vblank;
3158 }
3159}
Daniel Vetter20afbda2012-12-11 14:05:07 +01003160
3161void intel_hpd_init(struct drm_device *dev)
3162{
3163 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eich821450c2013-04-16 13:36:55 +02003164 struct drm_mode_config *mode_config = &dev->mode_config;
3165 struct drm_connector *connector;
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003166 unsigned long irqflags;
Egbert Eich821450c2013-04-16 13:36:55 +02003167 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003168
Egbert Eich821450c2013-04-16 13:36:55 +02003169 for (i = 1; i < HPD_NUM_PINS; i++) {
3170 dev_priv->hpd_stats[i].hpd_cnt = 0;
3171 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
3172 }
3173 list_for_each_entry(connector, &mode_config->connector_list, head) {
3174 struct intel_connector *intel_connector = to_intel_connector(connector);
3175 connector->polled = intel_connector->polled;
3176 if (!connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
3177 connector->polled = DRM_CONNECTOR_POLL_HPD;
3178 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003179
3180 /* Interrupt setup is already guaranteed to be single-threaded, this is
3181 * just to make the assert_spin_locked checks happy. */
3182 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003183 if (dev_priv->display.hpd_irq_setup)
3184 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003185 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003186}