blob: e3dd2d62c992173e3e8916bc16cd193ba596cda9 [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Daniel Vetterfca52a52014-09-30 10:56:45 +020040/**
41 * DOC: interrupt handling
42 *
43 * These functions provide the basic support for enabling and disabling the
44 * interrupt handling support. There's a lot more functionality in i915_irq.c
45 * and related files, but that will be described in separate chapters.
46 */
47
Egbert Eiche5868a32013-02-28 04:17:12 -050048static const u32 hpd_ibx[] = {
49 [HPD_CRT] = SDE_CRT_HOTPLUG,
50 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
51 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
54};
55
56static const u32 hpd_cpt[] = {
57 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010058 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050059 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
60 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
61 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
62};
63
64static const u32 hpd_mask_i915[] = {
65 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
66 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
67 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
68 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
69 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
70 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
71};
72
Daniel Vetter704cfb82013-12-18 09:08:43 +010073static const u32 hpd_status_g4x[] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050074 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
75 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
76 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
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
Egbert Eiche5868a32013-02-28 04:17:12 -050082static const u32 hpd_status_i915[] = { /* i915 and valleyview are the same */
83 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
84 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
85 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
86 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
87 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
88 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
89};
90
Paulo Zanoni5c502442014-04-01 15:37:11 -030091/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -030092#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -030093 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
94 POSTING_READ(GEN8_##type##_IMR(which)); \
95 I915_WRITE(GEN8_##type##_IER(which), 0); \
96 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
97 POSTING_READ(GEN8_##type##_IIR(which)); \
98 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
99 POSTING_READ(GEN8_##type##_IIR(which)); \
100} while (0)
101
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300102#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300103 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300104 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300105 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300106 I915_WRITE(type##IIR, 0xffffffff); \
107 POSTING_READ(type##IIR); \
108 I915_WRITE(type##IIR, 0xffffffff); \
109 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300110} while (0)
111
Paulo Zanoni337ba012014-04-01 15:37:16 -0300112/*
113 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
114 */
115#define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
116 u32 val = I915_READ(reg); \
117 if (val) { \
118 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
119 (reg), val); \
120 I915_WRITE((reg), 0xffffffff); \
121 POSTING_READ(reg); \
122 I915_WRITE((reg), 0xffffffff); \
123 POSTING_READ(reg); \
124 } \
125} while (0)
126
Paulo Zanoni35079892014-04-01 15:37:15 -0300127#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300128 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300129 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200130 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
131 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300132} while (0)
133
134#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300135 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300136 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200137 I915_WRITE(type##IMR, (imr_val)); \
138 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300139} while (0)
140
Imre Deakc9a9a262014-11-05 20:48:37 +0200141static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
142
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800143/* For display hotplug interrupt */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200144void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300145ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800146{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200147 assert_spin_locked(&dev_priv->irq_lock);
148
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700149 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300150 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300151
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000152 if ((dev_priv->irq_mask & mask) != 0) {
153 dev_priv->irq_mask &= ~mask;
154 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000155 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800156 }
157}
158
Daniel Vetter47339cd2014-09-30 10:56:46 +0200159void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300160ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800161{
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200162 assert_spin_locked(&dev_priv->irq_lock);
163
Paulo Zanoni06ffc772014-07-17 17:43:46 -0300164 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300165 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300166
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000167 if ((dev_priv->irq_mask & mask) != mask) {
168 dev_priv->irq_mask |= mask;
169 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000170 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800171 }
172}
173
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300174/**
175 * ilk_update_gt_irq - update GTIMR
176 * @dev_priv: driver private
177 * @interrupt_mask: mask of interrupt bits to update
178 * @enabled_irq_mask: mask of interrupt bits to enable
179 */
180static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
181 uint32_t interrupt_mask,
182 uint32_t enabled_irq_mask)
183{
184 assert_spin_locked(&dev_priv->irq_lock);
185
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100186 WARN_ON(enabled_irq_mask & ~interrupt_mask);
187
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700188 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300189 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300190
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300191 dev_priv->gt_irq_mask &= ~interrupt_mask;
192 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
193 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
194 POSTING_READ(GTIMR);
195}
196
Daniel Vetter480c8032014-07-16 09:49:40 +0200197void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300198{
199 ilk_update_gt_irq(dev_priv, mask, mask);
200}
201
Daniel Vetter480c8032014-07-16 09:49:40 +0200202void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300203{
204 ilk_update_gt_irq(dev_priv, mask, 0);
205}
206
Imre Deakb900b942014-11-05 20:48:48 +0200207static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
208{
209 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
210}
211
Imre Deaka72fbc32014-11-05 20:48:31 +0200212static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
213{
214 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
215}
216
Imre Deakb900b942014-11-05 20:48:48 +0200217static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
218{
219 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
220}
221
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300222/**
223 * snb_update_pm_irq - update GEN6_PMIMR
224 * @dev_priv: driver private
225 * @interrupt_mask: mask of interrupt bits to update
226 * @enabled_irq_mask: mask of interrupt bits to enable
227 */
228static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
229 uint32_t interrupt_mask,
230 uint32_t enabled_irq_mask)
231{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300232 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300233
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100234 WARN_ON(enabled_irq_mask & ~interrupt_mask);
235
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300236 assert_spin_locked(&dev_priv->irq_lock);
237
Paulo Zanoni605cd252013-08-06 18:57:15 -0300238 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300239 new_val &= ~interrupt_mask;
240 new_val |= (~enabled_irq_mask & interrupt_mask);
241
Paulo Zanoni605cd252013-08-06 18:57:15 -0300242 if (new_val != dev_priv->pm_irq_mask) {
243 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200244 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
245 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300246 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300247}
248
Daniel Vetter480c8032014-07-16 09:49:40 +0200249void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300250{
Imre Deak9939fba2014-11-20 23:01:47 +0200251 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
252 return;
253
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300254 snb_update_pm_irq(dev_priv, mask, mask);
255}
256
Imre Deak9939fba2014-11-20 23:01:47 +0200257static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
258 uint32_t mask)
259{
260 snb_update_pm_irq(dev_priv, mask, 0);
261}
262
Daniel Vetter480c8032014-07-16 09:49:40 +0200263void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300264{
Imre Deak9939fba2014-11-20 23:01:47 +0200265 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
266 return;
267
268 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300269}
270
Imre Deak3cc134e2014-11-19 15:30:03 +0200271void gen6_reset_rps_interrupts(struct drm_device *dev)
272{
273 struct drm_i915_private *dev_priv = dev->dev_private;
274 uint32_t reg = gen6_pm_iir(dev_priv);
275
276 spin_lock_irq(&dev_priv->irq_lock);
277 I915_WRITE(reg, dev_priv->pm_rps_events);
278 I915_WRITE(reg, dev_priv->pm_rps_events);
279 POSTING_READ(reg);
280 spin_unlock_irq(&dev_priv->irq_lock);
281}
282
Imre Deakb900b942014-11-05 20:48:48 +0200283void gen6_enable_rps_interrupts(struct drm_device *dev)
284{
285 struct drm_i915_private *dev_priv = dev->dev_private;
286
287 spin_lock_irq(&dev_priv->irq_lock);
288 WARN_ON(dev_priv->rps.pm_iir);
Imre Deak3cc134e2014-11-19 15:30:03 +0200289 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200290 dev_priv->rps.interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200291 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200292 spin_unlock_irq(&dev_priv->irq_lock);
293}
294
295void gen6_disable_rps_interrupts(struct drm_device *dev)
296{
297 struct drm_i915_private *dev_priv = dev->dev_private;
298
Imre Deakd4d70aa2014-11-19 15:30:04 +0200299 spin_lock_irq(&dev_priv->irq_lock);
300 dev_priv->rps.interrupts_enabled = false;
301 spin_unlock_irq(&dev_priv->irq_lock);
302
303 cancel_work_sync(&dev_priv->rps.work);
304
Imre Deak9939fba2014-11-20 23:01:47 +0200305 spin_lock_irq(&dev_priv->irq_lock);
306
Imre Deakb900b942014-11-05 20:48:48 +0200307 I915_WRITE(GEN6_PMINTRMSK, INTEL_INFO(dev_priv)->gen >= 8 ?
308 ~GEN8_PMINTR_REDIRECT_TO_NON_DISP : ~0);
Imre Deak9939fba2014-11-20 23:01:47 +0200309
310 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200311 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
312 ~dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200313 I915_WRITE(gen6_pm_iir(dev_priv), dev_priv->pm_rps_events);
Imre Deak9939fba2014-11-20 23:01:47 +0200314 I915_WRITE(gen6_pm_iir(dev_priv), dev_priv->pm_rps_events);
315
316 dev_priv->rps.pm_iir = 0;
317
318 spin_unlock_irq(&dev_priv->irq_lock);
Imre Deakb900b942014-11-05 20:48:48 +0200319}
320
Ben Widawsky09610212014-05-15 20:58:08 +0300321/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200322 * ibx_display_interrupt_update - update SDEIMR
323 * @dev_priv: driver private
324 * @interrupt_mask: mask of interrupt bits to update
325 * @enabled_irq_mask: mask of interrupt bits to enable
326 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200327void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
328 uint32_t interrupt_mask,
329 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200330{
331 uint32_t sdeimr = I915_READ(SDEIMR);
332 sdeimr &= ~interrupt_mask;
333 sdeimr |= (~enabled_irq_mask & interrupt_mask);
334
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100335 WARN_ON(enabled_irq_mask & ~interrupt_mask);
336
Daniel Vetterfee884e2013-07-04 23:35:21 +0200337 assert_spin_locked(&dev_priv->irq_lock);
338
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700339 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300340 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300341
Daniel Vetterfee884e2013-07-04 23:35:21 +0200342 I915_WRITE(SDEIMR, sdeimr);
343 POSTING_READ(SDEIMR);
344}
Paulo Zanoni86642812013-04-12 17:57:57 -0300345
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100346static void
Imre Deak755e9012014-02-10 18:42:47 +0200347__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
348 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800349{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200350 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200351 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800352
Daniel Vetterb79480b2013-06-27 17:52:10 +0200353 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200354 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200355
Ville Syrjälä04feced2014-04-03 13:28:33 +0300356 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
357 status_mask & ~PIPESTAT_INT_STATUS_MASK,
358 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
359 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200360 return;
361
362 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200363 return;
364
Imre Deak91d181d2014-02-10 18:42:49 +0200365 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
366
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200367 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200368 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200369 I915_WRITE(reg, pipestat);
370 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800371}
372
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100373static void
Imre Deak755e9012014-02-10 18:42:47 +0200374__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
375 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800376{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200377 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200378 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800379
Daniel Vetterb79480b2013-06-27 17:52:10 +0200380 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200381 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200382
Ville Syrjälä04feced2014-04-03 13:28:33 +0300383 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
384 status_mask & ~PIPESTAT_INT_STATUS_MASK,
385 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
386 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200387 return;
388
Imre Deak755e9012014-02-10 18:42:47 +0200389 if ((pipestat & enable_mask) == 0)
390 return;
391
Imre Deak91d181d2014-02-10 18:42:49 +0200392 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
393
Imre Deak755e9012014-02-10 18:42:47 +0200394 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200395 I915_WRITE(reg, pipestat);
396 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800397}
398
Imre Deak10c59c52014-02-10 18:42:48 +0200399static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
400{
401 u32 enable_mask = status_mask << 16;
402
403 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300404 * On pipe A we don't support the PSR interrupt yet,
405 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200406 */
407 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
408 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300409 /*
410 * On pipe B and C we don't support the PSR interrupt yet, on pipe
411 * A the same bit is for perf counters which we don't use either.
412 */
413 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
414 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200415
416 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
417 SPRITE0_FLIP_DONE_INT_EN_VLV |
418 SPRITE1_FLIP_DONE_INT_EN_VLV);
419 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
420 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
421 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
422 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
423
424 return enable_mask;
425}
426
Imre Deak755e9012014-02-10 18:42:47 +0200427void
428i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
429 u32 status_mask)
430{
431 u32 enable_mask;
432
Imre Deak10c59c52014-02-10 18:42:48 +0200433 if (IS_VALLEYVIEW(dev_priv->dev))
434 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
435 status_mask);
436 else
437 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200438 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
439}
440
441void
442i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
443 u32 status_mask)
444{
445 u32 enable_mask;
446
Imre Deak10c59c52014-02-10 18:42:48 +0200447 if (IS_VALLEYVIEW(dev_priv->dev))
448 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
449 status_mask);
450 else
451 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200452 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
453}
454
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000455/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300456 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000457 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300458static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000459{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300460 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000461
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300462 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
463 return;
464
Daniel Vetter13321782014-09-15 14:55:29 +0200465 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000466
Imre Deak755e9012014-02-10 18:42:47 +0200467 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300468 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200469 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200470 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000471
Daniel Vetter13321782014-09-15 14:55:29 +0200472 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000473}
474
475/**
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700476 * i915_pipe_enabled - check if a pipe is enabled
477 * @dev: DRM device
478 * @pipe: pipe to check
479 *
480 * Reading certain registers when the pipe is disabled can hang the chip.
481 * Use this routine to make sure the PLL is running and the pipe is active
482 * before reading such registers if unsure.
483 */
484static int
485i915_pipe_enabled(struct drm_device *dev, int pipe)
486{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300487 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni702e7a52012-10-23 18:29:59 -0200488
Daniel Vettera01025a2013-05-22 00:50:23 +0200489 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
490 /* Locking is horribly broken here, but whatever. */
491 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
492 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Paulo Zanoni71f8ba62013-05-03 12:15:39 -0300493
Daniel Vettera01025a2013-05-22 00:50:23 +0200494 return intel_crtc->active;
495 } else {
496 return I915_READ(PIPECONF(pipe)) & PIPECONF_ENABLE;
497 }
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700498}
499
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300500/*
501 * This timing diagram depicts the video signal in and
502 * around the vertical blanking period.
503 *
504 * Assumptions about the fictitious mode used in this example:
505 * vblank_start >= 3
506 * vsync_start = vblank_start + 1
507 * vsync_end = vblank_start + 2
508 * vtotal = vblank_start + 3
509 *
510 * start of vblank:
511 * latch double buffered registers
512 * increment frame counter (ctg+)
513 * generate start of vblank interrupt (gen4+)
514 * |
515 * | frame start:
516 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
517 * | may be shifted forward 1-3 extra lines via PIPECONF
518 * | |
519 * | | start of vsync:
520 * | | generate vsync interrupt
521 * | | |
522 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
523 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
524 * ----va---> <-----------------vb--------------------> <--------va-------------
525 * | | <----vs-----> |
526 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
527 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
528 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
529 * | | |
530 * last visible pixel first visible pixel
531 * | increment frame counter (gen3/4)
532 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
533 *
534 * x = horizontal active
535 * _ = horizontal blanking
536 * hs = horizontal sync
537 * va = vertical active
538 * vb = vertical blanking
539 * vs = vertical sync
540 * vbs = vblank_start (number)
541 *
542 * Summary:
543 * - most events happen at the start of horizontal sync
544 * - frame start happens at the start of horizontal blank, 1-4 lines
545 * (depending on PIPECONF settings) after the start of vblank
546 * - gen3/4 pixel and frame counter are synchronized with the start
547 * of horizontal active on the first line of vertical active
548 */
549
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300550static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
551{
552 /* Gen2 doesn't have a hardware frame counter */
553 return 0;
554}
555
Keith Packard42f52ef2008-10-18 19:39:29 -0700556/* Called from drm generic code, passed a 'crtc', which
557 * we use as a pipe index
558 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700559static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700560{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300561 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700562 unsigned long high_frame;
563 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300564 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700565
566 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800567 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800568 "pipe %c\n", pipe_name(pipe));
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700569 return 0;
570 }
571
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300572 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
573 struct intel_crtc *intel_crtc =
574 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
575 const struct drm_display_mode *mode =
576 &intel_crtc->config.adjusted_mode;
577
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300578 htotal = mode->crtc_htotal;
579 hsync_start = mode->crtc_hsync_start;
580 vbl_start = mode->crtc_vblank_start;
581 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
582 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300583 } else {
Daniel Vettera2d213d2014-02-07 16:34:05 +0100584 enum transcoder cpu_transcoder = (enum transcoder) pipe;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300585
586 htotal = ((I915_READ(HTOTAL(cpu_transcoder)) >> 16) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300587 hsync_start = (I915_READ(HSYNC(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300588 vbl_start = (I915_READ(VBLANK(cpu_transcoder)) & 0x1fff) + 1;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300589 if ((I915_READ(PIPECONF(cpu_transcoder)) &
590 PIPECONF_INTERLACE_MASK) != PIPECONF_PROGRESSIVE)
591 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300592 }
593
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300594 /* Convert to pixel count */
595 vbl_start *= htotal;
596
597 /* Start of vblank event occurs at start of hsync */
598 vbl_start -= htotal - hsync_start;
599
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800600 high_frame = PIPEFRAME(pipe);
601 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100602
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700603 /*
604 * High & low register fields aren't synchronized, so make sure
605 * we get a low value that's stable across two reads of the high
606 * register.
607 */
608 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100609 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300610 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100611 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700612 } while (high1 != high2);
613
Chris Wilson5eddb702010-09-11 13:48:45 +0100614 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300615 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100616 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300617
618 /*
619 * The frame counter increments at beginning of active.
620 * Cook up a vblank counter by also checking the pixel
621 * counter against vblank start.
622 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200623 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700624}
625
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700626static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800627{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300628 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800629 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800630
631 if (!i915_pipe_enabled(dev, pipe)) {
Zhao Yakui44d98a62009-10-09 11:39:40 +0800632 DRM_DEBUG_DRIVER("trying to get vblank count for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800633 "pipe %c\n", pipe_name(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800634 return 0;
635 }
636
637 return I915_READ(reg);
638}
639
Mario Kleinerad3543e2013-10-30 05:13:08 +0100640/* raw reads, only for fast reads of display block, no need for forcewake etc. */
641#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100642
Ville Syrjäläa225f072014-04-29 13:35:45 +0300643static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
644{
645 struct drm_device *dev = crtc->base.dev;
646 struct drm_i915_private *dev_priv = dev->dev_private;
647 const struct drm_display_mode *mode = &crtc->config.adjusted_mode;
648 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300649 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300650
Ville Syrjälä80715b22014-05-15 20:23:23 +0300651 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300652 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
653 vtotal /= 2;
654
655 if (IS_GEN2(dev))
656 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
657 else
658 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
659
660 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300661 * See update_scanline_offset() for the details on the
662 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300663 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300664 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300665}
666
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700667static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200668 unsigned int flags, int *vpos, int *hpos,
669 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100670{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300671 struct drm_i915_private *dev_priv = dev->dev_private;
672 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
673 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
674 const struct drm_display_mode *mode = &intel_crtc->config.adjusted_mode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300675 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300676 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100677 bool in_vbl = true;
678 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100679 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100680
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300681 if (!intel_crtc->active) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100682 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800683 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100684 return 0;
685 }
686
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300687 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300688 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300689 vtotal = mode->crtc_vtotal;
690 vbl_start = mode->crtc_vblank_start;
691 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100692
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200693 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
694 vbl_start = DIV_ROUND_UP(vbl_start, 2);
695 vbl_end /= 2;
696 vtotal /= 2;
697 }
698
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300699 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
700
Mario Kleinerad3543e2013-10-30 05:13:08 +0100701 /*
702 * Lock uncore.lock, as we will do multiple timing critical raw
703 * register reads, potentially with preemption disabled, so the
704 * following code must not block on uncore.lock.
705 */
706 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300707
Mario Kleinerad3543e2013-10-30 05:13:08 +0100708 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
709
710 /* Get optional system timestamp before query. */
711 if (stime)
712 *stime = ktime_get();
713
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300714 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100715 /* No obvious pixelcount register. Only query vertical
716 * scanout position from Display scan line register.
717 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300718 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100719 } else {
720 /* Have access to pixelcount since start of frame.
721 * We can split this into vertical and horizontal
722 * scanout position.
723 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100724 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100725
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300726 /* convert to pixel counts */
727 vbl_start *= htotal;
728 vbl_end *= htotal;
729 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300730
731 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300732 * In interlaced modes, the pixel counter counts all pixels,
733 * so one field will have htotal more pixels. In order to avoid
734 * the reported position from jumping backwards when the pixel
735 * counter is beyond the length of the shorter field, just
736 * clamp the position the length of the shorter field. This
737 * matches how the scanline counter based position works since
738 * the scanline counter doesn't count the two half lines.
739 */
740 if (position >= vtotal)
741 position = vtotal - 1;
742
743 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300744 * Start of vblank interrupt is triggered at start of hsync,
745 * just prior to the first active line of vblank. However we
746 * consider lines to start at the leading edge of horizontal
747 * active. So, should we get here before we've crossed into
748 * the horizontal active of the first line in vblank, we would
749 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
750 * always add htotal-hsync_start to the current pixel position.
751 */
752 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300753 }
754
Mario Kleinerad3543e2013-10-30 05:13:08 +0100755 /* Get optional system timestamp after query. */
756 if (etime)
757 *etime = ktime_get();
758
759 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
760
761 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
762
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300763 in_vbl = position >= vbl_start && position < vbl_end;
764
765 /*
766 * While in vblank, position will be negative
767 * counting up towards 0 at vbl_end. And outside
768 * vblank, position will be positive counting
769 * up since vbl_end.
770 */
771 if (position >= vbl_start)
772 position -= vbl_end;
773 else
774 position += vtotal - vbl_end;
775
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300776 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300777 *vpos = position;
778 *hpos = 0;
779 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100780 *vpos = position / htotal;
781 *hpos = position - (*vpos * htotal);
782 }
783
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100784 /* In vblank? */
785 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200786 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100787
788 return ret;
789}
790
Ville Syrjäläa225f072014-04-29 13:35:45 +0300791int intel_get_crtc_scanline(struct intel_crtc *crtc)
792{
793 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
794 unsigned long irqflags;
795 int position;
796
797 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
798 position = __intel_get_crtc_scanline(crtc);
799 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
800
801 return position;
802}
803
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700804static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100805 int *max_error,
806 struct timeval *vblank_time,
807 unsigned flags)
808{
Chris Wilson4041b852011-01-22 10:07:56 +0000809 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100810
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700811 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000812 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100813 return -EINVAL;
814 }
815
816 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000817 crtc = intel_get_crtc_for_pipe(dev, pipe);
818 if (crtc == NULL) {
819 DRM_ERROR("Invalid crtc %d\n", pipe);
820 return -EINVAL;
821 }
822
823 if (!crtc->enabled) {
824 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
825 return -EBUSY;
826 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100827
828 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000829 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
830 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300831 crtc,
832 &to_intel_crtc(crtc)->config.adjusted_mode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100833}
834
Jani Nikula67c347f2013-09-17 14:26:34 +0300835static bool intel_hpd_irq_event(struct drm_device *dev,
836 struct drm_connector *connector)
Egbert Eich321a1b32013-04-11 16:00:26 +0200837{
838 enum drm_connector_status old_status;
839
840 WARN_ON(!mutex_is_locked(&dev->mode_config.mutex));
841 old_status = connector->status;
842
843 connector->status = connector->funcs->detect(connector, false);
Jani Nikula67c347f2013-09-17 14:26:34 +0300844 if (old_status == connector->status)
845 return false;
846
847 DRM_DEBUG_KMS("[CONNECTOR:%d:%s] status updated from %s to %s\n",
Egbert Eich321a1b32013-04-11 16:00:26 +0200848 connector->base.id,
Jani Nikulac23cc412014-06-03 14:56:17 +0300849 connector->name,
Jani Nikula67c347f2013-09-17 14:26:34 +0300850 drm_get_connector_status_name(old_status),
851 drm_get_connector_status_name(connector->status));
852
853 return true;
Egbert Eich321a1b32013-04-11 16:00:26 +0200854}
855
Dave Airlie13cf5502014-06-18 11:29:35 +1000856static void i915_digport_work_func(struct work_struct *work)
857{
858 struct drm_i915_private *dev_priv =
859 container_of(work, struct drm_i915_private, dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +1000860 u32 long_port_mask, short_port_mask;
861 struct intel_digital_port *intel_dig_port;
862 int i, ret;
863 u32 old_bits = 0;
864
Daniel Vetter4cb21832014-09-15 14:55:26 +0200865 spin_lock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +1000866 long_port_mask = dev_priv->long_hpd_port_mask;
867 dev_priv->long_hpd_port_mask = 0;
868 short_port_mask = dev_priv->short_hpd_port_mask;
869 dev_priv->short_hpd_port_mask = 0;
Daniel Vetter4cb21832014-09-15 14:55:26 +0200870 spin_unlock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +1000871
872 for (i = 0; i < I915_MAX_PORTS; i++) {
873 bool valid = false;
874 bool long_hpd = false;
875 intel_dig_port = dev_priv->hpd_irq_port[i];
876 if (!intel_dig_port || !intel_dig_port->hpd_pulse)
877 continue;
878
879 if (long_port_mask & (1 << i)) {
880 valid = true;
881 long_hpd = true;
882 } else if (short_port_mask & (1 << i))
883 valid = true;
884
885 if (valid) {
886 ret = intel_dig_port->hpd_pulse(intel_dig_port, long_hpd);
887 if (ret == true) {
888 /* if we get true fallback to old school hpd */
889 old_bits |= (1 << intel_dig_port->base.hpd_pin);
890 }
891 }
892 }
893
894 if (old_bits) {
Daniel Vetter4cb21832014-09-15 14:55:26 +0200895 spin_lock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +1000896 dev_priv->hpd_event_bits |= old_bits;
Daniel Vetter4cb21832014-09-15 14:55:26 +0200897 spin_unlock_irq(&dev_priv->irq_lock);
Dave Airlie13cf5502014-06-18 11:29:35 +1000898 schedule_work(&dev_priv->hotplug_work);
899 }
900}
901
Jesse Barnes5ca58282009-03-31 14:11:15 -0700902/*
903 * Handle hotplug events outside the interrupt handler proper.
904 */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200905#define I915_REENABLE_HOTPLUG_DELAY (2*60*1000)
906
Jesse Barnes5ca58282009-03-31 14:11:15 -0700907static void i915_hotplug_work_func(struct work_struct *work)
908{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300909 struct drm_i915_private *dev_priv =
910 container_of(work, struct drm_i915_private, hotplug_work);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700911 struct drm_device *dev = dev_priv->dev;
Keith Packardc31c4ba2009-05-06 11:48:58 -0700912 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200913 struct intel_connector *intel_connector;
914 struct intel_encoder *intel_encoder;
915 struct drm_connector *connector;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200916 bool hpd_disabled = false;
Egbert Eich321a1b32013-04-11 16:00:26 +0200917 bool changed = false;
Egbert Eich142e2392013-04-11 15:57:57 +0200918 u32 hpd_event_bits;
Jesse Barnes5ca58282009-03-31 14:11:15 -0700919
Keith Packarda65e34c2011-07-25 10:04:56 -0700920 mutex_lock(&mode_config->mutex);
Jesse Barnese67189ab2011-02-11 14:44:51 -0800921 DRM_DEBUG_KMS("running encoder hotplug functions\n");
922
Daniel Vetter4cb21832014-09-15 14:55:26 +0200923 spin_lock_irq(&dev_priv->irq_lock);
Egbert Eich142e2392013-04-11 15:57:57 +0200924
925 hpd_event_bits = dev_priv->hpd_event_bits;
926 dev_priv->hpd_event_bits = 0;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200927 list_for_each_entry(connector, &mode_config->connector_list, head) {
928 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +1000929 if (!intel_connector->encoder)
930 continue;
Egbert Eichcd569ae2013-04-16 13:36:57 +0200931 intel_encoder = intel_connector->encoder;
932 if (intel_encoder->hpd_pin > HPD_NONE &&
933 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_MARK_DISABLED &&
934 connector->polled == DRM_CONNECTOR_POLL_HPD) {
935 DRM_INFO("HPD interrupt storm detected on connector %s: "
936 "switching from hotplug detection to polling\n",
Jani Nikulac23cc412014-06-03 14:56:17 +0300937 connector->name);
Egbert Eichcd569ae2013-04-16 13:36:57 +0200938 dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark = HPD_DISABLED;
939 connector->polled = DRM_CONNECTOR_POLL_CONNECT
940 | DRM_CONNECTOR_POLL_DISCONNECT;
941 hpd_disabled = true;
942 }
Egbert Eich142e2392013-04-11 15:57:57 +0200943 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
944 DRM_DEBUG_KMS("Connector %s (pin %i) received hotplug event.\n",
Jani Nikulac23cc412014-06-03 14:56:17 +0300945 connector->name, intel_encoder->hpd_pin);
Egbert Eich142e2392013-04-11 15:57:57 +0200946 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200947 }
948 /* if there were no outputs to poll, poll was disabled,
949 * therefore make sure it's enabled when disabling HPD on
950 * some connectors */
Egbert Eichac4c16c2013-04-16 13:36:58 +0200951 if (hpd_disabled) {
Egbert Eichcd569ae2013-04-16 13:36:57 +0200952 drm_kms_helper_poll_enable(dev);
Imre Deak63237512014-08-18 15:37:02 +0300953 mod_delayed_work(system_wq, &dev_priv->hotplug_reenable_work,
954 msecs_to_jiffies(I915_REENABLE_HOTPLUG_DELAY));
Egbert Eichac4c16c2013-04-16 13:36:58 +0200955 }
Egbert Eichcd569ae2013-04-16 13:36:57 +0200956
Daniel Vetter4cb21832014-09-15 14:55:26 +0200957 spin_unlock_irq(&dev_priv->irq_lock);
Egbert Eichcd569ae2013-04-16 13:36:57 +0200958
Egbert Eich321a1b32013-04-11 16:00:26 +0200959 list_for_each_entry(connector, &mode_config->connector_list, head) {
960 intel_connector = to_intel_connector(connector);
Dave Airlie36cd7442014-05-02 13:44:18 +1000961 if (!intel_connector->encoder)
962 continue;
Egbert Eich321a1b32013-04-11 16:00:26 +0200963 intel_encoder = intel_connector->encoder;
964 if (hpd_event_bits & (1 << intel_encoder->hpd_pin)) {
965 if (intel_encoder->hot_plug)
966 intel_encoder->hot_plug(intel_encoder);
967 if (intel_hpd_irq_event(dev, connector))
968 changed = true;
969 }
970 }
Keith Packard40ee3382011-07-28 15:31:19 -0700971 mutex_unlock(&mode_config->mutex);
972
Egbert Eich321a1b32013-04-11 16:00:26 +0200973 if (changed)
974 drm_kms_helper_hotplug_event(dev);
Jesse Barnes5ca58282009-03-31 14:11:15 -0700975}
976
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200977static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800978{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300979 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000980 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200981 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200982
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200983 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800984
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200985 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
986
Daniel Vetter20e4d402012-08-08 23:35:39 +0200987 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200988
Jesse Barnes7648fa92010-05-20 14:28:11 -0700989 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000990 busy_up = I915_READ(RCPREVBSYTUPAVG);
991 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800992 max_avg = I915_READ(RCBMAXAVG);
993 min_avg = I915_READ(RCBMINAVG);
994
995 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000996 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200997 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
998 new_delay = dev_priv->ips.cur_delay - 1;
999 if (new_delay < dev_priv->ips.max_delay)
1000 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001001 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001002 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1003 new_delay = dev_priv->ips.cur_delay + 1;
1004 if (new_delay > dev_priv->ips.min_delay)
1005 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001006 }
1007
Jesse Barnes7648fa92010-05-20 14:28:11 -07001008 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001009 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001010
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001011 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001012
Jesse Barnesf97108d2010-01-29 11:27:07 -08001013 return;
1014}
1015
Chris Wilson549f7362010-10-19 11:19:32 +01001016static void notify_ring(struct drm_device *dev,
Oscar Mateoa4872ba2014-05-22 14:13:33 +01001017 struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +01001018{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +01001019 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +00001020 return;
1021
John Harrisonbcfcc8b2014-12-05 13:49:36 +00001022 trace_i915_gem_request_notify(ring);
Chris Wilson9862e602011-01-04 22:22:17 +00001023
Chris Wilson549f7362010-10-19 11:19:32 +01001024 wake_up_all(&ring->irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +01001025}
1026
Deepak S31685c22014-07-03 17:33:01 -04001027static u32 vlv_c0_residency(struct drm_i915_private *dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001028 struct intel_rps_ei *rps_ei)
Deepak S31685c22014-07-03 17:33:01 -04001029{
1030 u32 cz_ts, cz_freq_khz;
1031 u32 render_count, media_count;
1032 u32 elapsed_render, elapsed_media, elapsed_time;
1033 u32 residency = 0;
1034
1035 cz_ts = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
1036 cz_freq_khz = DIV_ROUND_CLOSEST(dev_priv->mem_freq * 1000, 4);
1037
1038 render_count = I915_READ(VLV_RENDER_C0_COUNT_REG);
1039 media_count = I915_READ(VLV_MEDIA_C0_COUNT_REG);
1040
Chris Wilsonbf225f22014-07-10 20:31:18 +01001041 if (rps_ei->cz_clock == 0) {
1042 rps_ei->cz_clock = cz_ts;
1043 rps_ei->render_c0 = render_count;
1044 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001045
1046 return dev_priv->rps.cur_freq;
1047 }
1048
Chris Wilsonbf225f22014-07-10 20:31:18 +01001049 elapsed_time = cz_ts - rps_ei->cz_clock;
1050 rps_ei->cz_clock = cz_ts;
Deepak S31685c22014-07-03 17:33:01 -04001051
Chris Wilsonbf225f22014-07-10 20:31:18 +01001052 elapsed_render = render_count - rps_ei->render_c0;
1053 rps_ei->render_c0 = render_count;
Deepak S31685c22014-07-03 17:33:01 -04001054
Chris Wilsonbf225f22014-07-10 20:31:18 +01001055 elapsed_media = media_count - rps_ei->media_c0;
1056 rps_ei->media_c0 = media_count;
Deepak S31685c22014-07-03 17:33:01 -04001057
1058 /* Convert all the counters into common unit of milli sec */
1059 elapsed_time /= VLV_CZ_CLOCK_TO_MILLI_SEC;
1060 elapsed_render /= cz_freq_khz;
1061 elapsed_media /= cz_freq_khz;
1062
1063 /*
1064 * Calculate overall C0 residency percentage
1065 * only if elapsed time is non zero
1066 */
1067 if (elapsed_time) {
1068 residency =
1069 ((max(elapsed_render, elapsed_media) * 100)
1070 / elapsed_time);
1071 }
1072
1073 return residency;
1074}
1075
1076/**
1077 * vlv_calc_delay_from_C0_counters - Increase/Decrease freq based on GPU
1078 * busy-ness calculated from C0 counters of render & media power wells
1079 * @dev_priv: DRM device private
1080 *
1081 */
Damien Lespiau4fa79042014-08-08 19:25:57 +01001082static int vlv_calc_delay_from_C0_counters(struct drm_i915_private *dev_priv)
Deepak S31685c22014-07-03 17:33:01 -04001083{
1084 u32 residency_C0_up = 0, residency_C0_down = 0;
Damien Lespiau4fa79042014-08-08 19:25:57 +01001085 int new_delay, adj;
Deepak S31685c22014-07-03 17:33:01 -04001086
1087 dev_priv->rps.ei_interrupt_count++;
1088
1089 WARN_ON(!mutex_is_locked(&dev_priv->rps.hw_lock));
1090
1091
Chris Wilsonbf225f22014-07-10 20:31:18 +01001092 if (dev_priv->rps.up_ei.cz_clock == 0) {
1093 vlv_c0_residency(dev_priv, &dev_priv->rps.up_ei);
1094 vlv_c0_residency(dev_priv, &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001095 return dev_priv->rps.cur_freq;
1096 }
1097
1098
1099 /*
1100 * To down throttle, C0 residency should be less than down threshold
1101 * for continous EI intervals. So calculate down EI counters
1102 * once in VLV_INT_COUNT_FOR_DOWN_EI
1103 */
1104 if (dev_priv->rps.ei_interrupt_count == VLV_INT_COUNT_FOR_DOWN_EI) {
1105
1106 dev_priv->rps.ei_interrupt_count = 0;
1107
1108 residency_C0_down = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001109 &dev_priv->rps.down_ei);
Deepak S31685c22014-07-03 17:33:01 -04001110 } else {
1111 residency_C0_up = vlv_c0_residency(dev_priv,
Chris Wilsonbf225f22014-07-10 20:31:18 +01001112 &dev_priv->rps.up_ei);
Deepak S31685c22014-07-03 17:33:01 -04001113 }
1114
1115 new_delay = dev_priv->rps.cur_freq;
1116
1117 adj = dev_priv->rps.last_adj;
1118 /* C0 residency is greater than UP threshold. Increase Frequency */
1119 if (residency_C0_up >= VLV_RP_UP_EI_THRESHOLD) {
1120 if (adj > 0)
1121 adj *= 2;
1122 else
1123 adj = 1;
1124
1125 if (dev_priv->rps.cur_freq < dev_priv->rps.max_freq_softlimit)
1126 new_delay = dev_priv->rps.cur_freq + adj;
1127
1128 /*
1129 * For better performance, jump directly
1130 * to RPe if we're below it.
1131 */
1132 if (new_delay < dev_priv->rps.efficient_freq)
1133 new_delay = dev_priv->rps.efficient_freq;
1134
1135 } else if (!dev_priv->rps.ei_interrupt_count &&
1136 (residency_C0_down < VLV_RP_DOWN_EI_THRESHOLD)) {
1137 if (adj < 0)
1138 adj *= 2;
1139 else
1140 adj = -1;
1141 /*
1142 * This means, C0 residency is less than down threshold over
1143 * a period of VLV_INT_COUNT_FOR_DOWN_EI. So, reduce the freq
1144 */
1145 if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
1146 new_delay = dev_priv->rps.cur_freq + adj;
1147 }
1148
1149 return new_delay;
1150}
1151
Ben Widawsky4912d042011-04-25 11:25:20 -07001152static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001153{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001154 struct drm_i915_private *dev_priv =
1155 container_of(work, struct drm_i915_private, rps.work);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001156 u32 pm_iir;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001157 int new_delay, adj;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001158
Daniel Vetter59cdb632013-07-04 23:35:28 +02001159 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001160 /* Speed up work cancelation during disabling rps interrupts. */
1161 if (!dev_priv->rps.interrupts_enabled) {
1162 spin_unlock_irq(&dev_priv->irq_lock);
1163 return;
1164 }
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001165 pm_iir = dev_priv->rps.pm_iir;
1166 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001167 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1168 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Daniel Vetter59cdb632013-07-04 23:35:28 +02001169 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001170
Paulo Zanoni60611c12013-08-15 11:50:01 -03001171 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301172 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001173
Deepak Sa6706b42014-03-15 20:23:22 +05301174 if ((pm_iir & dev_priv->pm_rps_events) == 0)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001175 return;
1176
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001177 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001178
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001179 adj = dev_priv->rps.last_adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001180 if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001181 if (adj > 0)
1182 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301183 else {
1184 /* CHV needs even encode values */
1185 adj = IS_CHERRYVIEW(dev_priv->dev) ? 2 : 1;
1186 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001187 new_delay = dev_priv->rps.cur_freq + adj;
Ville Syrjälä74250342013-06-25 21:38:11 +03001188
1189 /*
1190 * For better performance, jump directly
1191 * to RPe if we're below it.
1192 */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001193 if (new_delay < dev_priv->rps.efficient_freq)
1194 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001195 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001196 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1197 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001198 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001199 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001200 adj = 0;
Deepak S31685c22014-07-03 17:33:01 -04001201 } else if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1202 new_delay = vlv_calc_delay_from_C0_counters(dev_priv);
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001203 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1204 if (adj < 0)
1205 adj *= 2;
Deepak S13a56602014-05-23 21:00:21 +05301206 else {
1207 /* CHV needs even encode values */
1208 adj = IS_CHERRYVIEW(dev_priv->dev) ? -2 : -1;
1209 }
Ben Widawskyb39fb292014-03-19 18:31:11 -07001210 new_delay = dev_priv->rps.cur_freq + adj;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001211 } else { /* unknown event */
Ben Widawskyb39fb292014-03-19 18:31:11 -07001212 new_delay = dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001213 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214
Ben Widawsky79249632012-09-07 19:43:42 -07001215 /* sysfs frequency interfaces may have snuck in while servicing the
1216 * interrupt
1217 */
Ville Syrjälä1272e7b2013-11-07 19:57:49 +02001218 new_delay = clamp_t(int, new_delay,
Ben Widawskyb39fb292014-03-19 18:31:11 -07001219 dev_priv->rps.min_freq_softlimit,
1220 dev_priv->rps.max_freq_softlimit);
Deepak S27544362014-01-27 21:35:05 +05301221
Ben Widawskyb39fb292014-03-19 18:31:11 -07001222 dev_priv->rps.last_adj = new_delay - dev_priv->rps.cur_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001223
1224 if (IS_VALLEYVIEW(dev_priv->dev))
1225 valleyview_set_rps(dev_priv->dev, new_delay);
1226 else
1227 gen6_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001228
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001229 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001230}
1231
Ben Widawskye3689192012-05-25 16:56:22 -07001232
1233/**
1234 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1235 * occurred.
1236 * @work: workqueue struct
1237 *
1238 * Doesn't actually do anything except notify userspace. As a consequence of
1239 * this event, userspace should try to remap the bad rows since statistically
1240 * it is likely the same row is more likely to go bad again.
1241 */
1242static void ivybridge_parity_work(struct work_struct *work)
1243{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001244 struct drm_i915_private *dev_priv =
1245 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001246 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001247 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001248 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001249 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001250
1251 /* We must turn off DOP level clock gating to access the L3 registers.
1252 * In order to prevent a get/put style interface, acquire struct mutex
1253 * any time we access those registers.
1254 */
1255 mutex_lock(&dev_priv->dev->struct_mutex);
1256
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001257 /* If we've screwed up tracking, just let the interrupt fire again */
1258 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1259 goto out;
1260
Ben Widawskye3689192012-05-25 16:56:22 -07001261 misccpctl = I915_READ(GEN7_MISCCPCTL);
1262 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1263 POSTING_READ(GEN7_MISCCPCTL);
1264
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001265 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1266 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001267
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001268 slice--;
1269 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1270 break;
1271
1272 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1273
1274 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1275
1276 error_status = I915_READ(reg);
1277 row = GEN7_PARITY_ERROR_ROW(error_status);
1278 bank = GEN7_PARITY_ERROR_BANK(error_status);
1279 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1280
1281 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1282 POSTING_READ(reg);
1283
1284 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1285 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1286 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1287 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1288 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1289 parity_event[5] = NULL;
1290
Dave Airlie5bdebb12013-10-11 14:07:25 +10001291 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001292 KOBJ_CHANGE, parity_event);
1293
1294 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1295 slice, row, bank, subbank);
1296
1297 kfree(parity_event[4]);
1298 kfree(parity_event[3]);
1299 kfree(parity_event[2]);
1300 kfree(parity_event[1]);
1301 }
Ben Widawskye3689192012-05-25 16:56:22 -07001302
1303 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1304
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001305out:
1306 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001307 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001308 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001309 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001310
1311 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001312}
1313
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001314static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001315{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001316 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001317
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001318 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001319 return;
1320
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001321 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001322 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001323 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001324
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001325 iir &= GT_PARITY_ERROR(dev);
1326 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1327 dev_priv->l3_parity.which_slice |= 1 << 1;
1328
1329 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1330 dev_priv->l3_parity.which_slice |= 1 << 0;
1331
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001332 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001333}
1334
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001335static void ilk_gt_irq_handler(struct drm_device *dev,
1336 struct drm_i915_private *dev_priv,
1337 u32 gt_iir)
1338{
1339 if (gt_iir &
1340 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
1341 notify_ring(dev, &dev_priv->ring[RCS]);
1342 if (gt_iir & ILK_BSD_USER_INTERRUPT)
1343 notify_ring(dev, &dev_priv->ring[VCS]);
1344}
1345
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001346static void snb_gt_irq_handler(struct drm_device *dev,
1347 struct drm_i915_private *dev_priv,
1348 u32 gt_iir)
1349{
1350
Ben Widawskycc609d52013-05-28 19:22:29 -07001351 if (gt_iir &
1352 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001353 notify_ring(dev, &dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001354 if (gt_iir & GT_BSD_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001355 notify_ring(dev, &dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001356 if (gt_iir & GT_BLT_USER_INTERRUPT)
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001357 notify_ring(dev, &dev_priv->ring[BCS]);
1358
Ben Widawskycc609d52013-05-28 19:22:29 -07001359 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1360 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001361 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1362 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001363
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001364 if (gt_iir & GT_PARITY_ERROR(dev))
1365 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001366}
1367
Ben Widawskyabd58f02013-11-02 21:07:09 -07001368static irqreturn_t gen8_gt_irq_handler(struct drm_device *dev,
1369 struct drm_i915_private *dev_priv,
1370 u32 master_ctl)
1371{
Thomas Daniele981e7b2014-07-24 17:04:39 +01001372 struct intel_engine_cs *ring;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001373 u32 rcs, bcs, vcs;
1374 uint32_t tmp = 0;
1375 irqreturn_t ret = IRQ_NONE;
1376
1377 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
1378 tmp = I915_READ(GEN8_GT_IIR(0));
1379 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001380 I915_WRITE(GEN8_GT_IIR(0), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001381 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001382
Ben Widawskyabd58f02013-11-02 21:07:09 -07001383 rcs = tmp >> GEN8_RCS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001384 ring = &dev_priv->ring[RCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001385 if (rcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001386 notify_ring(dev, ring);
1387 if (rcs & GT_CONTEXT_SWITCH_INTERRUPT)
Daniel Vetter3f7531c2014-12-10 17:41:43 +01001388 intel_lrc_irq_handler(ring);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001389
1390 bcs = tmp >> GEN8_BCS_IRQ_SHIFT;
1391 ring = &dev_priv->ring[BCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001392 if (bcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001393 notify_ring(dev, ring);
1394 if (bcs & GT_CONTEXT_SWITCH_INTERRUPT)
Daniel Vetter3f7531c2014-12-10 17:41:43 +01001395 intel_lrc_irq_handler(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001396 } else
1397 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1398 }
1399
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001400 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07001401 tmp = I915_READ(GEN8_GT_IIR(1));
1402 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001403 I915_WRITE(GEN8_GT_IIR(1), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001404 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001405
Ben Widawskyabd58f02013-11-02 21:07:09 -07001406 vcs = tmp >> GEN8_VCS1_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001407 ring = &dev_priv->ring[VCS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001408 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001409 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001410 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Daniel Vetter3f7531c2014-12-10 17:41:43 +01001411 intel_lrc_irq_handler(ring);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001412
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001413 vcs = tmp >> GEN8_VCS2_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001414 ring = &dev_priv->ring[VCS2];
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001415 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001416 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001417 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Daniel Vetter3f7531c2014-12-10 17:41:43 +01001418 intel_lrc_irq_handler(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001419 } else
1420 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1421 }
1422
Ben Widawsky09610212014-05-15 20:58:08 +03001423 if (master_ctl & GEN8_GT_PM_IRQ) {
1424 tmp = I915_READ(GEN8_GT_IIR(2));
1425 if (tmp & dev_priv->pm_rps_events) {
Ben Widawsky09610212014-05-15 20:58:08 +03001426 I915_WRITE(GEN8_GT_IIR(2),
1427 tmp & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001428 ret = IRQ_HANDLED;
Imre Deakc9a9a262014-11-05 20:48:37 +02001429 gen6_rps_irq_handler(dev_priv, tmp);
Ben Widawsky09610212014-05-15 20:58:08 +03001430 } else
1431 DRM_ERROR("The master control interrupt lied (PM)!\n");
1432 }
1433
Ben Widawskyabd58f02013-11-02 21:07:09 -07001434 if (master_ctl & GEN8_GT_VECS_IRQ) {
1435 tmp = I915_READ(GEN8_GT_IIR(3));
1436 if (tmp) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001437 I915_WRITE(GEN8_GT_IIR(3), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001438 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001439
Ben Widawskyabd58f02013-11-02 21:07:09 -07001440 vcs = tmp >> GEN8_VECS_IRQ_SHIFT;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001441 ring = &dev_priv->ring[VECS];
Ben Widawskyabd58f02013-11-02 21:07:09 -07001442 if (vcs & GT_RENDER_USER_INTERRUPT)
Thomas Daniele981e7b2014-07-24 17:04:39 +01001443 notify_ring(dev, ring);
Oscar Mateo73d477f2014-07-24 17:04:31 +01001444 if (vcs & GT_CONTEXT_SWITCH_INTERRUPT)
Daniel Vetter3f7531c2014-12-10 17:41:43 +01001445 intel_lrc_irq_handler(ring);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001446 } else
1447 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1448 }
1449
1450 return ret;
1451}
1452
Egbert Eichb543fb02013-04-16 13:36:54 +02001453#define HPD_STORM_DETECT_PERIOD 1000
1454#define HPD_STORM_THRESHOLD 5
1455
Jani Nikula07c338c2014-10-02 11:16:32 +03001456static int pch_port_to_hotplug_shift(enum port port)
Dave Airlie13cf5502014-06-18 11:29:35 +10001457{
1458 switch (port) {
1459 case PORT_A:
1460 case PORT_E:
1461 default:
1462 return -1;
1463 case PORT_B:
1464 return 0;
1465 case PORT_C:
1466 return 8;
1467 case PORT_D:
1468 return 16;
1469 }
1470}
1471
Jani Nikula07c338c2014-10-02 11:16:32 +03001472static int i915_port_to_hotplug_shift(enum port port)
Dave Airlie13cf5502014-06-18 11:29:35 +10001473{
1474 switch (port) {
1475 case PORT_A:
1476 case PORT_E:
1477 default:
1478 return -1;
1479 case PORT_B:
1480 return 17;
1481 case PORT_C:
1482 return 19;
1483 case PORT_D:
1484 return 21;
1485 }
1486}
1487
1488static inline enum port get_port_from_pin(enum hpd_pin pin)
1489{
1490 switch (pin) {
1491 case HPD_PORT_B:
1492 return PORT_B;
1493 case HPD_PORT_C:
1494 return PORT_C;
1495 case HPD_PORT_D:
1496 return PORT_D;
1497 default:
1498 return PORT_A; /* no hpd */
1499 }
1500}
1501
Daniel Vetter10a504d2013-06-27 17:52:12 +02001502static inline void intel_hpd_irq_handler(struct drm_device *dev,
Daniel Vetter22062db2013-06-27 17:52:11 +02001503 u32 hotplug_trigger,
Dave Airlie13cf5502014-06-18 11:29:35 +10001504 u32 dig_hotplug_reg,
Daniel Vetter22062db2013-06-27 17:52:11 +02001505 const u32 *hpd)
Egbert Eichb543fb02013-04-16 13:36:54 +02001506{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001507 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichb543fb02013-04-16 13:36:54 +02001508 int i;
Dave Airlie13cf5502014-06-18 11:29:35 +10001509 enum port port;
Daniel Vetter10a504d2013-06-27 17:52:12 +02001510 bool storm_detected = false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001511 bool queue_dig = false, queue_hp = false;
1512 u32 dig_shift;
1513 u32 dig_port_mask = 0;
Egbert Eichb543fb02013-04-16 13:36:54 +02001514
Daniel Vetter91d131d2013-06-27 17:52:14 +02001515 if (!hotplug_trigger)
1516 return;
1517
Dave Airlie13cf5502014-06-18 11:29:35 +10001518 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x\n",
1519 hotplug_trigger, dig_hotplug_reg);
Imre Deakcc9bd492014-01-16 19:56:54 +02001520
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001521 spin_lock(&dev_priv->irq_lock);
Egbert Eichb543fb02013-04-16 13:36:54 +02001522 for (i = 1; i < HPD_NUM_PINS; i++) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001523 if (!(hpd[i] & hotplug_trigger))
1524 continue;
Egbert Eich821450c2013-04-16 13:36:55 +02001525
Dave Airlie13cf5502014-06-18 11:29:35 +10001526 port = get_port_from_pin(i);
1527 if (port && dev_priv->hpd_irq_port[port]) {
1528 bool long_hpd;
1529
Jani Nikula07c338c2014-10-02 11:16:32 +03001530 if (HAS_PCH_SPLIT(dev)) {
1531 dig_shift = pch_port_to_hotplug_shift(port);
Dave Airlie13cf5502014-06-18 11:29:35 +10001532 long_hpd = (dig_hotplug_reg >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
Jani Nikula07c338c2014-10-02 11:16:32 +03001533 } else {
1534 dig_shift = i915_port_to_hotplug_shift(port);
1535 long_hpd = (hotplug_trigger >> dig_shift) & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001536 }
1537
Ville Syrjälä26fbb772014-08-11 18:37:37 +03001538 DRM_DEBUG_DRIVER("digital hpd port %c - %s\n",
1539 port_name(port),
1540 long_hpd ? "long" : "short");
Dave Airlie13cf5502014-06-18 11:29:35 +10001541 /* for long HPD pulses we want to have the digital queue happen,
1542 but we still want HPD storm detection to function. */
1543 if (long_hpd) {
1544 dev_priv->long_hpd_port_mask |= (1 << port);
1545 dig_port_mask |= hpd[i];
1546 } else {
1547 /* for short HPD just trigger the digital queue */
1548 dev_priv->short_hpd_port_mask |= (1 << port);
1549 hotplug_trigger &= ~hpd[i];
1550 }
1551 queue_dig = true;
1552 }
1553 }
1554
1555 for (i = 1; i < HPD_NUM_PINS; i++) {
Daniel Vetter3ff04a162014-04-24 12:03:17 +02001556 if (hpd[i] & hotplug_trigger &&
1557 dev_priv->hpd_stats[i].hpd_mark == HPD_DISABLED) {
1558 /*
1559 * On GMCH platforms the interrupt mask bits only
1560 * prevent irq generation, not the setting of the
1561 * hotplug bits itself. So only WARN about unexpected
1562 * interrupts on saner platforms.
1563 */
1564 WARN_ONCE(INTEL_INFO(dev)->gen >= 5 && !IS_VALLEYVIEW(dev),
1565 "Received HPD interrupt (0x%08x) on pin %d (0x%08x) although disabled\n",
1566 hotplug_trigger, i, hpd[i]);
1567
1568 continue;
1569 }
Egbert Eichb8f102e2013-07-26 14:14:24 +02001570
Egbert Eichb543fb02013-04-16 13:36:54 +02001571 if (!(hpd[i] & hotplug_trigger) ||
1572 dev_priv->hpd_stats[i].hpd_mark != HPD_ENABLED)
1573 continue;
1574
Dave Airlie13cf5502014-06-18 11:29:35 +10001575 if (!(dig_port_mask & hpd[i])) {
1576 dev_priv->hpd_event_bits |= (1 << i);
1577 queue_hp = true;
1578 }
1579
Egbert Eichb543fb02013-04-16 13:36:54 +02001580 if (!time_in_range(jiffies, dev_priv->hpd_stats[i].hpd_last_jiffies,
1581 dev_priv->hpd_stats[i].hpd_last_jiffies
1582 + msecs_to_jiffies(HPD_STORM_DETECT_PERIOD))) {
1583 dev_priv->hpd_stats[i].hpd_last_jiffies = jiffies;
1584 dev_priv->hpd_stats[i].hpd_cnt = 0;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001585 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: 0\n", i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001586 } else if (dev_priv->hpd_stats[i].hpd_cnt > HPD_STORM_THRESHOLD) {
1587 dev_priv->hpd_stats[i].hpd_mark = HPD_MARK_DISABLED;
Egbert Eich142e2392013-04-11 15:57:57 +02001588 dev_priv->hpd_event_bits &= ~(1 << i);
Egbert Eichb543fb02013-04-16 13:36:54 +02001589 DRM_DEBUG_KMS("HPD interrupt storm detected on PIN %d\n", i);
Daniel Vetter10a504d2013-06-27 17:52:12 +02001590 storm_detected = true;
Egbert Eichb543fb02013-04-16 13:36:54 +02001591 } else {
1592 dev_priv->hpd_stats[i].hpd_cnt++;
Egbert Eichb8f102e2013-07-26 14:14:24 +02001593 DRM_DEBUG_KMS("Received HPD interrupt on PIN %d - cnt: %d\n", i,
1594 dev_priv->hpd_stats[i].hpd_cnt);
Egbert Eichb543fb02013-04-16 13:36:54 +02001595 }
1596 }
1597
Daniel Vetter10a504d2013-06-27 17:52:12 +02001598 if (storm_detected)
1599 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02001600 spin_unlock(&dev_priv->irq_lock);
Daniel Vetter5876fa02013-06-27 17:52:13 +02001601
Daniel Vetter645416f2013-09-02 16:22:25 +02001602 /*
1603 * Our hotplug handler can grab modeset locks (by calling down into the
1604 * fb helpers). Hence it must not be run on our own dev-priv->wq work
1605 * queue for otherwise the flush_work in the pageflip code will
1606 * deadlock.
1607 */
Dave Airlie13cf5502014-06-18 11:29:35 +10001608 if (queue_dig)
Dave Airlie0e32b392014-05-02 14:02:48 +10001609 queue_work(dev_priv->dp_wq, &dev_priv->dig_port_work);
Dave Airlie13cf5502014-06-18 11:29:35 +10001610 if (queue_hp)
1611 schedule_work(&dev_priv->hotplug_work);
Egbert Eichb543fb02013-04-16 13:36:54 +02001612}
1613
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001614static void gmbus_irq_handler(struct drm_device *dev)
1615{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001616 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001617
Daniel Vetter28c70f12012-12-01 13:53:45 +01001618 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001619}
1620
Daniel Vetterce99c252012-12-01 13:53:47 +01001621static void dp_aux_irq_handler(struct drm_device *dev)
1622{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001623 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001624
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001625 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001626}
1627
Shuang He8bf1e9f2013-10-15 18:55:27 +01001628#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001629static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1630 uint32_t crc0, uint32_t crc1,
1631 uint32_t crc2, uint32_t crc3,
1632 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001633{
1634 struct drm_i915_private *dev_priv = dev->dev_private;
1635 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1636 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001637 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001638
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001639 spin_lock(&pipe_crc->lock);
1640
Damien Lespiau0c912c72013-10-15 18:55:37 +01001641 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001642 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001643 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001644 return;
1645 }
1646
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001647 head = pipe_crc->head;
1648 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001649
1650 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001651 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001652 DRM_ERROR("CRC buffer overflowing\n");
1653 return;
1654 }
1655
1656 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001657
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001658 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001659 entry->crc[0] = crc0;
1660 entry->crc[1] = crc1;
1661 entry->crc[2] = crc2;
1662 entry->crc[3] = crc3;
1663 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001664
1665 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001666 pipe_crc->head = head;
1667
1668 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001669
1670 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001671}
Daniel Vetter277de952013-10-18 16:37:07 +02001672#else
1673static inline void
1674display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1675 uint32_t crc0, uint32_t crc1,
1676 uint32_t crc2, uint32_t crc3,
1677 uint32_t crc4) {}
1678#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001679
Daniel Vetter277de952013-10-18 16:37:07 +02001680
1681static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001682{
1683 struct drm_i915_private *dev_priv = dev->dev_private;
1684
Daniel Vetter277de952013-10-18 16:37:07 +02001685 display_pipe_crc_irq_handler(dev, pipe,
1686 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1687 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001688}
1689
Daniel Vetter277de952013-10-18 16:37:07 +02001690static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001691{
1692 struct drm_i915_private *dev_priv = dev->dev_private;
1693
Daniel Vetter277de952013-10-18 16:37:07 +02001694 display_pipe_crc_irq_handler(dev, pipe,
1695 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1696 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1697 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1698 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1699 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001700}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001701
Daniel Vetter277de952013-10-18 16:37:07 +02001702static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001703{
1704 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001705 uint32_t res1, res2;
1706
1707 if (INTEL_INFO(dev)->gen >= 3)
1708 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1709 else
1710 res1 = 0;
1711
1712 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1713 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1714 else
1715 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001716
Daniel Vetter277de952013-10-18 16:37:07 +02001717 display_pipe_crc_irq_handler(dev, pipe,
1718 I915_READ(PIPE_CRC_RES_RED(pipe)),
1719 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1720 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1721 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001722}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001723
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001724/* The RPS events need forcewake, so we add them to a work queue and mask their
1725 * IMR bits until the work is done. Other interrupts can be processed without
1726 * the work queue. */
1727static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001728{
Imre Deak4a74de82014-11-19 15:30:01 +02001729 /* TODO: RPS on GEN9+ is not supported yet. */
1730 if (WARN_ONCE(INTEL_INFO(dev_priv)->gen >= 9,
1731 "GEN9+: unexpected RPS IRQ\n"))
Imre Deak132f3f12014-11-10 15:34:33 +02001732 return;
1733
Deepak Sa6706b42014-03-15 20:23:22 +05301734 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001735 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001736 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001737 if (dev_priv->rps.interrupts_enabled) {
1738 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1739 queue_work(dev_priv->wq, &dev_priv->rps.work);
1740 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001741 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001742 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001743
Imre Deakc9a9a262014-11-05 20:48:37 +02001744 if (INTEL_INFO(dev_priv)->gen >= 8)
1745 return;
1746
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001747 if (HAS_VEBOX(dev_priv->dev)) {
1748 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
1749 notify_ring(dev_priv->dev, &dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001750
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001751 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1752 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001753 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001754}
1755
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001756static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1757{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001758 if (!drm_handle_vblank(dev, pipe))
1759 return false;
1760
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001761 return true;
1762}
1763
Imre Deakc1874ed2014-02-04 21:35:46 +02001764static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1765{
1766 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001767 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001768 int pipe;
1769
Imre Deak58ead0d2014-02-04 21:35:47 +02001770 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01001771 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001772 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001773 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001774
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001775 /*
1776 * PIPESTAT bits get signalled even when the interrupt is
1777 * disabled with the mask bits, and some of the status bits do
1778 * not generate interrupts at all (like the underrun bit). Hence
1779 * we need to be careful that we only handle what we want to
1780 * handle.
1781 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001782
1783 /* fifo underruns are filterered in the underrun handler. */
1784 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001785
1786 switch (pipe) {
1787 case PIPE_A:
1788 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1789 break;
1790 case PIPE_B:
1791 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1792 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001793 case PIPE_C:
1794 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1795 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001796 }
1797 if (iir & iir_bit)
1798 mask |= dev_priv->pipestat_irq_mask[pipe];
1799
1800 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001801 continue;
1802
1803 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001804 mask |= PIPESTAT_INT_ENABLE_MASK;
1805 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001806
1807 /*
1808 * Clear the PIPE*STAT regs before the IIR
1809 */
Imre Deak91d181d2014-02-10 18:42:49 +02001810 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1811 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001812 I915_WRITE(reg, pipe_stats[pipe]);
1813 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001814 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001815
Damien Lespiau055e3932014-08-18 13:49:10 +01001816 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001817 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1818 intel_pipe_handle_vblank(dev, pipe))
1819 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001820
Imre Deak579a9b02014-02-04 21:35:48 +02001821 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001822 intel_prepare_page_flip(dev, pipe);
1823 intel_finish_page_flip(dev, pipe);
1824 }
1825
1826 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1827 i9xx_pipe_crc_irq_handler(dev, pipe);
1828
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001829 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1830 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001831 }
1832
1833 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1834 gmbus_irq_handler(dev);
1835}
1836
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001837static void i9xx_hpd_irq_handler(struct drm_device *dev)
1838{
1839 struct drm_i915_private *dev_priv = dev->dev_private;
1840 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
1841
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001842 if (hotplug_status) {
1843 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1844 /*
1845 * Make sure hotplug status is cleared before we clear IIR, or else we
1846 * may miss hotplug events.
1847 */
1848 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001849
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001850 if (IS_G4X(dev)) {
1851 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001852
Dave Airlie13cf5502014-06-18 11:29:35 +10001853 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_g4x);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001854 } else {
1855 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
1856
Dave Airlie13cf5502014-06-18 11:29:35 +10001857 intel_hpd_irq_handler(dev, hotplug_trigger, 0, hpd_status_i915);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001858 }
1859
1860 if ((IS_G4X(dev) || IS_VALLEYVIEW(dev)) &&
1861 hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1862 dp_aux_irq_handler(dev);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001863 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001864}
1865
Daniel Vetterff1f5252012-10-02 15:10:55 +02001866static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001867{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001868 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001869 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001870 u32 iir, gt_iir, pm_iir;
1871 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001872
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001873 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001874 /* Find, clear, then process each source of interrupt */
1875
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001876 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001877 if (gt_iir)
1878 I915_WRITE(GTIIR, gt_iir);
1879
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001880 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001881 if (pm_iir)
1882 I915_WRITE(GEN6_PMIIR, pm_iir);
1883
1884 iir = I915_READ(VLV_IIR);
1885 if (iir) {
1886 /* Consume port before clearing IIR or we'll miss events */
1887 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1888 i9xx_hpd_irq_handler(dev);
1889 I915_WRITE(VLV_IIR, iir);
1890 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001891
1892 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1893 goto out;
1894
1895 ret = IRQ_HANDLED;
1896
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001897 if (gt_iir)
1898 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001899 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001900 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001901 /* Call regardless, as some status bits might not be
1902 * signalled in iir */
1903 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001904 }
1905
1906out:
1907 return ret;
1908}
1909
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001910static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1911{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001912 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001913 struct drm_i915_private *dev_priv = dev->dev_private;
1914 u32 master_ctl, iir;
1915 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001916
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001917 for (;;) {
1918 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1919 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001920
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001921 if (master_ctl == 0 && iir == 0)
1922 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001923
Oscar Mateo27b6c122014-06-16 16:11:00 +01001924 ret = IRQ_HANDLED;
1925
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001926 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001927
Oscar Mateo27b6c122014-06-16 16:11:00 +01001928 /* Find, clear, then process each source of interrupt */
1929
1930 if (iir) {
1931 /* Consume port before clearing IIR or we'll miss events */
1932 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1933 i9xx_hpd_irq_handler(dev);
1934 I915_WRITE(VLV_IIR, iir);
1935 }
1936
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001937 gen8_gt_irq_handler(dev, dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001938
Oscar Mateo27b6c122014-06-16 16:11:00 +01001939 /* Call regardless, as some status bits might not be
1940 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001941 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001942
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001943 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1944 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001945 }
1946
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001947 return ret;
1948}
1949
Adam Jackson23e81d62012-06-06 15:45:44 -04001950static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001951{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001952 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001953 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001954 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Dave Airlie13cf5502014-06-18 11:29:35 +10001955 u32 dig_hotplug_reg;
Jesse Barnes776ad802011-01-04 15:09:39 -08001956
Dave Airlie13cf5502014-06-18 11:29:35 +10001957 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1958 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1959
1960 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001961
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001962 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1963 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1964 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001965 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001966 port_name(port));
1967 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001968
Daniel Vetterce99c252012-12-01 13:53:47 +01001969 if (pch_iir & SDE_AUX_MASK)
1970 dp_aux_irq_handler(dev);
1971
Jesse Barnes776ad802011-01-04 15:09:39 -08001972 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001973 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001974
1975 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1976 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1977
1978 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1979 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1980
1981 if (pch_iir & SDE_POISON)
1982 DRM_ERROR("PCH poison interrupt\n");
1983
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001984 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001985 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001986 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1987 pipe_name(pipe),
1988 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001989
1990 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1991 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1992
1993 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1994 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1995
Jesse Barnes776ad802011-01-04 15:09:39 -08001996 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001997 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001998
1999 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002000 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002001}
2002
2003static void ivb_err_int_handler(struct drm_device *dev)
2004{
2005 struct drm_i915_private *dev_priv = dev->dev_private;
2006 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002007 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002008
Paulo Zanonide032bf2013-04-12 17:57:58 -03002009 if (err_int & ERR_INT_POISON)
2010 DRM_ERROR("Poison interrupt\n");
2011
Damien Lespiau055e3932014-08-18 13:49:10 +01002012 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002013 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2014 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002015
Daniel Vetter5a69b892013-10-16 22:55:52 +02002016 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
2017 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02002018 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002019 else
Daniel Vetter277de952013-10-18 16:37:07 +02002020 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002021 }
2022 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002023
Paulo Zanoni86642812013-04-12 17:57:57 -03002024 I915_WRITE(GEN7_ERR_INT, err_int);
2025}
2026
2027static void cpt_serr_int_handler(struct drm_device *dev)
2028{
2029 struct drm_i915_private *dev_priv = dev->dev_private;
2030 u32 serr_int = I915_READ(SERR_INT);
2031
Paulo Zanonide032bf2013-04-12 17:57:58 -03002032 if (serr_int & SERR_INT_POISON)
2033 DRM_ERROR("PCH poison interrupt\n");
2034
Paulo Zanoni86642812013-04-12 17:57:57 -03002035 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002036 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002037
2038 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002039 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002040
2041 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002042 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002043
2044 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002045}
2046
Adam Jackson23e81d62012-06-06 15:45:44 -04002047static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
2048{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002049 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04002050 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002051 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Dave Airlie13cf5502014-06-18 11:29:35 +10002052 u32 dig_hotplug_reg;
Adam Jackson23e81d62012-06-06 15:45:44 -04002053
Dave Airlie13cf5502014-06-18 11:29:35 +10002054 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2055 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2056
2057 intel_hpd_irq_handler(dev, hotplug_trigger, dig_hotplug_reg, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002058
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002059 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2060 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2061 SDE_AUDIO_POWER_SHIFT_CPT);
2062 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2063 port_name(port));
2064 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002065
2066 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01002067 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002068
2069 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01002070 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002071
2072 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2073 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2074
2075 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2076 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2077
2078 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002079 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002080 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2081 pipe_name(pipe),
2082 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002083
2084 if (pch_iir & SDE_ERROR_CPT)
2085 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04002086}
2087
Paulo Zanonic008bc62013-07-12 16:35:10 -03002088static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2089{
2090 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c22013-10-21 18:04:36 +02002091 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03002092
2093 if (de_iir & DE_AUX_CHANNEL_A)
2094 dp_aux_irq_handler(dev);
2095
2096 if (de_iir & DE_GSE)
2097 intel_opregion_asle_intr(dev);
2098
Paulo Zanonic008bc62013-07-12 16:35:10 -03002099 if (de_iir & DE_POISON)
2100 DRM_ERROR("Poison interrupt\n");
2101
Damien Lespiau055e3932014-08-18 13:49:10 +01002102 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002103 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2104 intel_pipe_handle_vblank(dev, pipe))
2105 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002106
Daniel Vetter40da17c22013-10-21 18:04:36 +02002107 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002108 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002109
Daniel Vetter40da17c22013-10-21 18:04:36 +02002110 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2111 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002112
Daniel Vetter40da17c22013-10-21 18:04:36 +02002113 /* plane/pipes map 1:1 on ilk+ */
2114 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2115 intel_prepare_page_flip(dev, pipe);
2116 intel_finish_page_flip_plane(dev, pipe);
2117 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03002118 }
2119
2120 /* check event from PCH */
2121 if (de_iir & DE_PCH_EVENT) {
2122 u32 pch_iir = I915_READ(SDEIIR);
2123
2124 if (HAS_PCH_CPT(dev))
2125 cpt_irq_handler(dev, pch_iir);
2126 else
2127 ibx_irq_handler(dev, pch_iir);
2128
2129 /* should clear PCH hotplug event before clear CPU irq */
2130 I915_WRITE(SDEIIR, pch_iir);
2131 }
2132
2133 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2134 ironlake_rps_change_irq_handler(dev);
2135}
2136
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002137static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2138{
2139 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002140 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002141
2142 if (de_iir & DE_ERR_INT_IVB)
2143 ivb_err_int_handler(dev);
2144
2145 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2146 dp_aux_irq_handler(dev);
2147
2148 if (de_iir & DE_GSE_IVB)
2149 intel_opregion_asle_intr(dev);
2150
Damien Lespiau055e3932014-08-18 13:49:10 +01002151 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002152 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2153 intel_pipe_handle_vblank(dev, pipe))
2154 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c22013-10-21 18:04:36 +02002155
2156 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002157 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2158 intel_prepare_page_flip(dev, pipe);
2159 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002160 }
2161 }
2162
2163 /* check event from PCH */
2164 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2165 u32 pch_iir = I915_READ(SDEIIR);
2166
2167 cpt_irq_handler(dev, pch_iir);
2168
2169 /* clear PCH hotplug event before clear CPU irq */
2170 I915_WRITE(SDEIIR, pch_iir);
2171 }
2172}
2173
Oscar Mateo72c90f62014-06-16 16:10:57 +01002174/*
2175 * To handle irqs with the minimum potential races with fresh interrupts, we:
2176 * 1 - Disable Master Interrupt Control.
2177 * 2 - Find the source(s) of the interrupt.
2178 * 3 - Clear the Interrupt Identity bits (IIR).
2179 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2180 * 5 - Re-enable Master Interrupt Control.
2181 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002182static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002183{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002184 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002185 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002186 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002187 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002188
Paulo Zanoni86642812013-04-12 17:57:57 -03002189 /* We get interrupts on unclaimed registers, so check for this before we
2190 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002191 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002192
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002193 /* disable master interrupt before clearing iir */
2194 de_ier = I915_READ(DEIER);
2195 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002196 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002197
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002198 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2199 * interrupts will will be stored on its back queue, and then we'll be
2200 * able to process them after we restore SDEIER (as soon as we restore
2201 * it, we'll get an interrupt if SDEIIR still has something to process
2202 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002203 if (!HAS_PCH_NOP(dev)) {
2204 sde_ier = I915_READ(SDEIER);
2205 I915_WRITE(SDEIER, 0);
2206 POSTING_READ(SDEIER);
2207 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002208
Oscar Mateo72c90f62014-06-16 16:10:57 +01002209 /* Find, clear, then process each source of interrupt */
2210
Chris Wilson0e434062012-05-09 21:45:44 +01002211 gt_iir = I915_READ(GTIIR);
2212 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002213 I915_WRITE(GTIIR, gt_iir);
2214 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002215 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002216 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002217 else
2218 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002219 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002220
2221 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002222 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002223 I915_WRITE(DEIIR, de_iir);
2224 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002225 if (INTEL_INFO(dev)->gen >= 7)
2226 ivb_display_irq_handler(dev, de_iir);
2227 else
2228 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002229 }
2230
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002231 if (INTEL_INFO(dev)->gen >= 6) {
2232 u32 pm_iir = I915_READ(GEN6_PMIIR);
2233 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002234 I915_WRITE(GEN6_PMIIR, pm_iir);
2235 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002236 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002237 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002238 }
2239
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002240 I915_WRITE(DEIER, de_ier);
2241 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002242 if (!HAS_PCH_NOP(dev)) {
2243 I915_WRITE(SDEIER, sde_ier);
2244 POSTING_READ(SDEIER);
2245 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002246
2247 return ret;
2248}
2249
Ben Widawskyabd58f02013-11-02 21:07:09 -07002250static irqreturn_t gen8_irq_handler(int irq, void *arg)
2251{
2252 struct drm_device *dev = arg;
2253 struct drm_i915_private *dev_priv = dev->dev_private;
2254 u32 master_ctl;
2255 irqreturn_t ret = IRQ_NONE;
2256 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002257 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002258 u32 aux_mask = GEN8_AUX_CHANNEL_A;
2259
2260 if (IS_GEN9(dev))
2261 aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
2262 GEN9_AUX_CHANNEL_D;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002263
Ben Widawskyabd58f02013-11-02 21:07:09 -07002264 master_ctl = I915_READ(GEN8_MASTER_IRQ);
2265 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2266 if (!master_ctl)
2267 return IRQ_NONE;
2268
2269 I915_WRITE(GEN8_MASTER_IRQ, 0);
2270 POSTING_READ(GEN8_MASTER_IRQ);
2271
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002272 /* Find, clear, then process each source of interrupt */
2273
Ben Widawskyabd58f02013-11-02 21:07:09 -07002274 ret = gen8_gt_irq_handler(dev, dev_priv, master_ctl);
2275
2276 if (master_ctl & GEN8_DE_MISC_IRQ) {
2277 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002278 if (tmp) {
2279 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2280 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002281 if (tmp & GEN8_DE_MISC_GSE)
2282 intel_opregion_asle_intr(dev);
2283 else
2284 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002285 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002286 else
2287 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002288 }
2289
Daniel Vetter6d766f02013-11-07 14:49:55 +01002290 if (master_ctl & GEN8_DE_PORT_IRQ) {
2291 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002292 if (tmp) {
2293 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2294 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002295
2296 if (tmp & aux_mask)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002297 dp_aux_irq_handler(dev);
2298 else
2299 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002300 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002301 else
2302 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002303 }
2304
Damien Lespiau055e3932014-08-18 13:49:10 +01002305 for_each_pipe(dev_priv, pipe) {
Damien Lespiau770de832014-03-20 20:45:01 +00002306 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002307
Daniel Vetterc42664c2013-11-07 11:05:40 +01002308 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2309 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002310
Daniel Vetterc42664c2013-11-07 11:05:40 +01002311 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002312 if (pipe_iir) {
2313 ret = IRQ_HANDLED;
2314 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Damien Lespiau770de832014-03-20 20:45:01 +00002315
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002316 if (pipe_iir & GEN8_PIPE_VBLANK &&
2317 intel_pipe_handle_vblank(dev, pipe))
2318 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002319
Damien Lespiau770de832014-03-20 20:45:01 +00002320 if (IS_GEN9(dev))
2321 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2322 else
2323 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2324
2325 if (flip_done) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002326 intel_prepare_page_flip(dev, pipe);
2327 intel_finish_page_flip_plane(dev, pipe);
2328 }
2329
2330 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2331 hsw_pipe_crc_irq_handler(dev, pipe);
2332
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002333 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
2334 intel_cpu_fifo_underrun_irq_handler(dev_priv,
2335 pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002336
Damien Lespiau770de832014-03-20 20:45:01 +00002337
2338 if (IS_GEN9(dev))
2339 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2340 else
2341 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2342
2343 if (fault_errors)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002344 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2345 pipe_name(pipe),
2346 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
Daniel Vetterc42664c2013-11-07 11:05:40 +01002347 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002348 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2349 }
2350
Daniel Vetter92d03a82013-11-07 11:05:43 +01002351 if (!HAS_PCH_NOP(dev) && master_ctl & GEN8_DE_PCH_IRQ) {
2352 /*
2353 * FIXME(BDW): Assume for now that the new interrupt handling
2354 * scheme also closed the SDE interrupt handling race we've seen
2355 * on older pch-split platforms. But this needs testing.
2356 */
2357 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002358 if (pch_iir) {
2359 I915_WRITE(SDEIIR, pch_iir);
2360 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002361 cpt_irq_handler(dev, pch_iir);
2362 } else
2363 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2364
Daniel Vetter92d03a82013-11-07 11:05:43 +01002365 }
2366
Ben Widawskyabd58f02013-11-02 21:07:09 -07002367 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2368 POSTING_READ(GEN8_MASTER_IRQ);
2369
2370 return ret;
2371}
2372
Daniel Vetter17e1df02013-09-08 21:57:13 +02002373static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2374 bool reset_completed)
2375{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002376 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002377 int i;
2378
2379 /*
2380 * Notify all waiters for GPU completion events that reset state has
2381 * been changed, and that they need to restart their wait after
2382 * checking for potential errors (and bail out to drop locks if there is
2383 * a gpu reset pending so that i915_error_work_func can acquire them).
2384 */
2385
2386 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2387 for_each_ring(ring, dev_priv, i)
2388 wake_up_all(&ring->irq_queue);
2389
2390 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2391 wake_up_all(&dev_priv->pending_flip_queue);
2392
2393 /*
2394 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2395 * reset state is cleared.
2396 */
2397 if (reset_completed)
2398 wake_up_all(&dev_priv->gpu_error.reset_queue);
2399}
2400
Jesse Barnes8a905232009-07-11 16:48:03 -04002401/**
2402 * i915_error_work_func - do process context error handling work
2403 * @work: work struct
2404 *
2405 * Fire an error uevent so userspace can see that a hang or error
2406 * was detected.
2407 */
2408static void i915_error_work_func(struct work_struct *work)
2409{
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002410 struct i915_gpu_error *error = container_of(work, struct i915_gpu_error,
2411 work);
Jani Nikula2d1013d2014-03-31 14:27:17 +03002412 struct drm_i915_private *dev_priv =
2413 container_of(error, struct drm_i915_private, gpu_error);
Jesse Barnes8a905232009-07-11 16:48:03 -04002414 struct drm_device *dev = dev_priv->dev;
Ben Widawskycce723e2013-07-19 09:16:42 -07002415 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2416 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2417 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002418 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002419
Dave Airlie5bdebb12013-10-11 14:07:25 +10002420 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002421
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002422 /*
2423 * Note that there's only one work item which does gpu resets, so we
2424 * need not worry about concurrent gpu resets potentially incrementing
2425 * error->reset_counter twice. We only need to take care of another
2426 * racing irq/hangcheck declaring the gpu dead for a second time. A
2427 * quick check for that is good enough: schedule_work ensures the
2428 * correct ordering between hang detection and this work item, and since
2429 * the reset in-progress bit is only ever set by code outside of this
2430 * work we don't need to worry about any other races.
2431 */
2432 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002433 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002434 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002435 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002436
Daniel Vetter17e1df02013-09-08 21:57:13 +02002437 /*
Imre Deakf454c692014-04-23 01:09:04 +03002438 * In most cases it's guaranteed that we get here with an RPM
2439 * reference held, for example because there is a pending GPU
2440 * request that won't finish until the reset is done. This
2441 * isn't the case at least when we get here by doing a
2442 * simulated reset via debugs, so get an RPM reference.
2443 */
2444 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002445
2446 intel_prepare_reset(dev);
2447
Imre Deakf454c692014-04-23 01:09:04 +03002448 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002449 * All state reset _must_ be completed before we update the
2450 * reset counter, for otherwise waiters might miss the reset
2451 * pending state and not properly drop locks, resulting in
2452 * deadlocks with the reset work.
2453 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002454 ret = i915_reset(dev);
2455
Ville Syrjälä75147472014-11-24 18:28:11 +02002456 intel_finish_reset(dev);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002457
Imre Deakf454c692014-04-23 01:09:04 +03002458 intel_runtime_pm_put(dev_priv);
2459
Daniel Vetterf69061b2012-12-06 09:01:42 +01002460 if (ret == 0) {
2461 /*
2462 * After all the gem state is reset, increment the reset
2463 * counter and wake up everyone waiting for the reset to
2464 * complete.
2465 *
2466 * Since unlock operations are a one-sided barrier only,
2467 * we need to insert a barrier here to order any seqno
2468 * updates before
2469 * the counter increment.
2470 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002471 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002472 atomic_inc(&dev_priv->gpu_error.reset_counter);
2473
Dave Airlie5bdebb12013-10-11 14:07:25 +10002474 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002475 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002476 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002477 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002478 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002479
Daniel Vetter17e1df02013-09-08 21:57:13 +02002480 /*
2481 * Note: The wake_up also serves as a memory barrier so that
2482 * waiters see the update value of the reset counter atomic_t.
2483 */
2484 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002485 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002486}
2487
Chris Wilson35aed2e2010-05-27 13:18:12 +01002488static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002489{
2490 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002491 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002492 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002493 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002494
Chris Wilson35aed2e2010-05-27 13:18:12 +01002495 if (!eir)
2496 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002497
Joe Perchesa70491c2012-03-18 13:00:11 -07002498 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002499
Ben Widawskybd9854f2012-08-23 15:18:09 -07002500 i915_get_extra_instdone(dev, instdone);
2501
Jesse Barnes8a905232009-07-11 16:48:03 -04002502 if (IS_G4X(dev)) {
2503 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2504 u32 ipeir = I915_READ(IPEIR_I965);
2505
Joe Perchesa70491c2012-03-18 13:00:11 -07002506 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2507 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002508 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2509 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002510 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002511 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002512 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002513 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002514 }
2515 if (eir & GM45_ERROR_PAGE_TABLE) {
2516 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002517 pr_err("page table error\n");
2518 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002519 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002520 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002521 }
2522 }
2523
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002524 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002525 if (eir & I915_ERROR_PAGE_TABLE) {
2526 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002527 pr_err("page table error\n");
2528 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002529 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002530 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002531 }
2532 }
2533
2534 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002535 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002536 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002537 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002538 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002539 /* pipestat has already been acked */
2540 }
2541 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002542 pr_err("instruction error\n");
2543 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002544 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2545 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002546 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002547 u32 ipeir = I915_READ(IPEIR);
2548
Joe Perchesa70491c2012-03-18 13:00:11 -07002549 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2550 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002551 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002552 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002553 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002554 } else {
2555 u32 ipeir = I915_READ(IPEIR_I965);
2556
Joe Perchesa70491c2012-03-18 13:00:11 -07002557 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2558 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002559 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002560 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002561 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002562 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002563 }
2564 }
2565
2566 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002567 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002568 eir = I915_READ(EIR);
2569 if (eir) {
2570 /*
2571 * some errors might have become stuck,
2572 * mask them.
2573 */
2574 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2575 I915_WRITE(EMR, I915_READ(EMR) | eir);
2576 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2577 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002578}
2579
2580/**
2581 * i915_handle_error - handle an error interrupt
2582 * @dev: drm device
2583 *
2584 * Do some basic checking of regsiter state at error interrupt time and
2585 * dump it to the syslog. Also call i915_capture_error_state() to make
2586 * sure we get a record and make it available in debugfs. Fire a uevent
2587 * so userspace knows something bad happened (should trigger collection
2588 * of a ring dump etc.).
2589 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002590void i915_handle_error(struct drm_device *dev, bool wedged,
2591 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002592{
2593 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002594 va_list args;
2595 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002596
Mika Kuoppala58174462014-02-25 17:11:26 +02002597 va_start(args, fmt);
2598 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2599 va_end(args);
2600
2601 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002602 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002603
Ben Gamariba1234d2009-09-14 17:48:47 -04002604 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002605 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2606 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002607
Ben Gamari11ed50e2009-09-14 17:48:45 -04002608 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002609 * Wakeup waiting processes so that the reset work function
2610 * i915_error_work_func doesn't deadlock trying to grab various
2611 * locks. By bumping the reset counter first, the woken
2612 * processes will see a reset in progress and back off,
2613 * releasing their locks and then wait for the reset completion.
2614 * We must do this for _all_ gpu waiters that might hold locks
2615 * that the reset work needs to acquire.
2616 *
2617 * Note: The wake_up serves as the required memory barrier to
2618 * ensure that the waiters see the updated value of the reset
2619 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002620 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002621 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002622 }
2623
Daniel Vetter122f46b2013-09-04 17:36:14 +02002624 /*
2625 * Our reset work can grab modeset locks (since it needs to reset the
2626 * state of outstanding pagelips). Hence it must not be run on our own
2627 * dev-priv->wq work queue for otherwise the flush_work in the pageflip
2628 * code will deadlock.
2629 */
2630 schedule_work(&dev_priv->gpu_error.work);
Jesse Barnes8a905232009-07-11 16:48:03 -04002631}
2632
Keith Packard42f52ef2008-10-18 19:39:29 -07002633/* Called from drm generic code, passed 'crtc' which
2634 * we use as a pipe index
2635 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002636static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002637{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002638 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002639 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002640
Chris Wilson5eddb702010-09-11 13:48:45 +01002641 if (!i915_pipe_enabled(dev, pipe))
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002642 return -EINVAL;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002643
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002644 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002645 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002646 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002647 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002648 else
Keith Packard7c463582008-11-04 02:03:27 -08002649 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002650 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002651 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002652
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002653 return 0;
2654}
2655
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002656static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002657{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002658 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002659 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002660 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002661 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002662
2663 if (!i915_pipe_enabled(dev, pipe))
2664 return -EINVAL;
2665
2666 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002667 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002668 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2669
2670 return 0;
2671}
2672
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002673static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2674{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002675 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002676 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002677
2678 if (!i915_pipe_enabled(dev, pipe))
2679 return -EINVAL;
2680
2681 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002682 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002683 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002684 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2685
2686 return 0;
2687}
2688
Ben Widawskyabd58f02013-11-02 21:07:09 -07002689static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2690{
2691 struct drm_i915_private *dev_priv = dev->dev_private;
2692 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002693
2694 if (!i915_pipe_enabled(dev, pipe))
2695 return -EINVAL;
2696
2697 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002698 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2699 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2700 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002701 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2702 return 0;
2703}
2704
Keith Packard42f52ef2008-10-18 19:39:29 -07002705/* Called from drm generic code, passed 'crtc' which
2706 * we use as a pipe index
2707 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002708static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002709{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002710 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002711 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002712
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002713 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002714 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002715 PIPE_VBLANK_INTERRUPT_STATUS |
2716 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002717 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2718}
2719
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002720static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002721{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002722 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002723 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002724 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002725 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002726
2727 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002728 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002729 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2730}
2731
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002732static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2733{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002734 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002735 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002736
2737 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002738 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002739 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002740 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2741}
2742
Ben Widawskyabd58f02013-11-02 21:07:09 -07002743static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2744{
2745 struct drm_i915_private *dev_priv = dev->dev_private;
2746 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002747
2748 if (!i915_pipe_enabled(dev, pipe))
2749 return;
2750
2751 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002752 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2753 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2754 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002755 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2756}
2757
John Harrison44cdd6d2014-11-24 18:49:40 +00002758static struct drm_i915_gem_request *
2759ring_last_request(struct intel_engine_cs *ring)
Zou Nan hai852835f2010-05-21 09:08:56 +08002760{
Chris Wilson893eead2010-10-27 14:44:35 +01002761 return list_entry(ring->request_list.prev,
John Harrison44cdd6d2014-11-24 18:49:40 +00002762 struct drm_i915_gem_request, list);
Chris Wilson893eead2010-10-27 14:44:35 +01002763}
2764
Chris Wilson9107e9d2013-06-10 11:20:20 +01002765static bool
John Harrison44cdd6d2014-11-24 18:49:40 +00002766ring_idle(struct intel_engine_cs *ring)
Chris Wilson893eead2010-10-27 14:44:35 +01002767{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002768 return (list_empty(&ring->request_list) ||
John Harrison1b5a4332014-11-24 18:49:42 +00002769 i915_gem_request_completed(ring_last_request(ring), false));
Ben Gamarif65d9422009-09-14 17:48:44 -04002770}
2771
Daniel Vettera028c4b2014-03-15 00:08:56 +01002772static bool
2773ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2774{
2775 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002776 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002777 } else {
2778 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2779 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2780 MI_SEMAPHORE_REGISTER);
2781 }
2782}
2783
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002784static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002785semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002786{
2787 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002788 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002789 int i;
2790
2791 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002792 for_each_ring(signaller, dev_priv, i) {
2793 if (ring == signaller)
2794 continue;
2795
2796 if (offset == signaller->semaphore.signal_ggtt[ring->id])
2797 return signaller;
2798 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002799 } else {
2800 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2801
2802 for_each_ring(signaller, dev_priv, i) {
2803 if(ring == signaller)
2804 continue;
2805
Ben Widawskyebc348b2014-04-29 14:52:28 -07002806 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002807 return signaller;
2808 }
2809 }
2810
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002811 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
2812 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002813
2814 return NULL;
2815}
2816
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002817static struct intel_engine_cs *
2818semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002819{
2820 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002821 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002822 u64 offset = 0;
2823 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002824
2825 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002826 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002827 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002828
Daniel Vetter88fe4292014-03-15 00:08:55 +01002829 /*
2830 * HEAD is likely pointing to the dword after the actual command,
2831 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002832 * or 4 dwords depending on the semaphore wait command size.
2833 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002834 * point at at batch, and semaphores are always emitted into the
2835 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002836 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002837 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002838 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002839
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002840 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002841 /*
2842 * Be paranoid and presume the hw has gone off into the wild -
2843 * our ring is smaller than what the hardware (and hence
2844 * HEAD_ADDR) allows. Also handles wrap-around.
2845 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002846 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002847
2848 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002849 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002850 if (cmd == ipehr)
2851 break;
2852
Daniel Vetter88fe4292014-03-15 00:08:55 +01002853 head -= 4;
2854 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002855
Daniel Vetter88fe4292014-03-15 00:08:55 +01002856 if (!i)
2857 return NULL;
2858
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002859 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002860 if (INTEL_INFO(ring->dev)->gen >= 8) {
2861 offset = ioread32(ring->buffer->virtual_start + head + 12);
2862 offset <<= 32;
2863 offset = ioread32(ring->buffer->virtual_start + head + 8);
2864 }
2865 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002866}
2867
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002868static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01002869{
2870 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002871 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002872 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002873
Chris Wilson4be17382014-06-06 10:22:29 +01002874 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002875
2876 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002877 if (signaller == NULL)
2878 return -1;
2879
2880 /* Prevent pathological recursion due to driver bugs */
2881 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01002882 return -1;
2883
Chris Wilson4be17382014-06-06 10:22:29 +01002884 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
2885 return 1;
2886
Chris Wilsona0d036b2014-07-19 12:40:42 +01002887 /* cursory check for an unkickable deadlock */
2888 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2889 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002890 return -1;
2891
2892 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002893}
2894
2895static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2896{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002897 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01002898 int i;
2899
2900 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01002901 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002902}
2903
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002904static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002905ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002906{
2907 struct drm_device *dev = ring->dev;
2908 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002909 u32 tmp;
2910
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002911 if (acthd != ring->hangcheck.acthd) {
2912 if (acthd > ring->hangcheck.max_acthd) {
2913 ring->hangcheck.max_acthd = acthd;
2914 return HANGCHECK_ACTIVE;
2915 }
2916
2917 return HANGCHECK_ACTIVE_LOOP;
2918 }
Chris Wilson6274f212013-06-10 11:20:21 +01002919
Chris Wilson9107e9d2013-06-10 11:20:20 +01002920 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002921 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002922
2923 /* Is the chip hanging on a WAIT_FOR_EVENT?
2924 * If so we can simply poke the RB_WAIT bit
2925 * and break the hang. This should work on
2926 * all but the second generation chipsets.
2927 */
2928 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002929 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002930 i915_handle_error(dev, false,
2931 "Kicking stuck wait on %s",
2932 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002933 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002934 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002935 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002936
Chris Wilson6274f212013-06-10 11:20:21 +01002937 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2938 switch (semaphore_passed(ring)) {
2939 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002940 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002941 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002942 i915_handle_error(dev, false,
2943 "Kicking stuck semaphore on %s",
2944 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002945 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002946 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002947 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002948 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002949 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002950 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002951
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002952 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002953}
2954
Ben Gamarif65d9422009-09-14 17:48:44 -04002955/**
2956 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002957 * batchbuffers in a long time. We keep track per ring seqno progress and
2958 * if there are no progress, hangcheck score for that ring is increased.
2959 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2960 * we kick the ring. If we see no progress on three subsequent calls
2961 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002962 */
Damien Lespiaua658b5d2013-08-08 22:28:56 +01002963static void i915_hangcheck_elapsed(unsigned long data)
Ben Gamarif65d9422009-09-14 17:48:44 -04002964{
2965 struct drm_device *dev = (struct drm_device *)data;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002966 struct drm_i915_private *dev_priv = dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002967 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002968 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002969 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002970 bool stuck[I915_NUM_RINGS] = { 0 };
2971#define BUSY 1
2972#define KICK 5
2973#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002974
Jani Nikulad330a952014-01-21 11:24:25 +02002975 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002976 return;
2977
Chris Wilsonb4519512012-05-11 14:29:30 +01002978 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002979 u64 acthd;
2980 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002981 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002982
Chris Wilson6274f212013-06-10 11:20:21 +01002983 semaphore_clear_deadlocks(dev_priv);
2984
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002985 seqno = ring->get_seqno(ring, false);
2986 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002987
Chris Wilson9107e9d2013-06-10 11:20:20 +01002988 if (ring->hangcheck.seqno == seqno) {
John Harrison44cdd6d2014-11-24 18:49:40 +00002989 if (ring_idle(ring)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002990 ring->hangcheck.action = HANGCHECK_IDLE;
2991
Chris Wilson9107e9d2013-06-10 11:20:20 +01002992 if (waitqueue_active(&ring->irq_queue)) {
2993 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002994 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002995 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2996 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2997 ring->name);
2998 else
2999 DRM_INFO("Fake missed irq on %s\n",
3000 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01003001 wake_up_all(&ring->irq_queue);
3002 }
3003 /* Safeguard against driver failure */
3004 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003005 } else
3006 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003007 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003008 /* We always increment the hangcheck score
3009 * if the ring is busy and still processing
3010 * the same request, so that no single request
3011 * can run indefinitely (such as a chain of
3012 * batches). The only time we do not increment
3013 * the hangcheck score on this ring, if this
3014 * ring is in a legitimate wait for another
3015 * ring. In that case the waiting ring is a
3016 * victim and we want to be sure we catch the
3017 * right culprit. Then every time we do kick
3018 * the ring, add a small increment to the
3019 * score so that we can catch a batch that is
3020 * being repeatedly kicked and so responsible
3021 * for stalling the machine.
3022 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003023 ring->hangcheck.action = ring_stuck(ring,
3024 acthd);
3025
3026 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003027 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003028 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003029 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003030 break;
3031 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003032 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003033 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003034 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003035 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003036 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003037 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003038 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003039 stuck[i] = true;
3040 break;
3041 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003042 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003043 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03003044 ring->hangcheck.action = HANGCHECK_ACTIVE;
3045
Chris Wilson9107e9d2013-06-10 11:20:20 +01003046 /* Gradually reduce the count so that we catch DoS
3047 * attempts across multiple batches.
3048 */
3049 if (ring->hangcheck.score > 0)
3050 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003051
3052 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01003053 }
3054
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003055 ring->hangcheck.seqno = seqno;
3056 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003057 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003058 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003059
Mika Kuoppala92cab732013-05-24 17:16:07 +03003060 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02003061 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003062 DRM_INFO("%s on %s\n",
3063 stuck[i] ? "stuck" : "no progress",
3064 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01003065 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003066 }
3067 }
3068
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003069 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02003070 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003071
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003072 if (busy_count)
3073 /* Reset timer case chip hangs without another request
3074 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003075 i915_queue_hangcheck(dev);
3076}
3077
3078void i915_queue_hangcheck(struct drm_device *dev)
3079{
3080 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson672e7b72014-11-19 09:47:19 +00003081 struct timer_list *timer = &dev_priv->gpu_error.hangcheck_timer;
3082
Jani Nikulad330a952014-01-21 11:24:25 +02003083 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003084 return;
3085
Chris Wilson672e7b72014-11-19 09:47:19 +00003086 /* Don't continually defer the hangcheck, but make sure it is active */
Chris Wilsond9e600b2014-11-20 20:10:33 +00003087 if (timer_pending(timer))
3088 return;
3089 mod_timer(timer,
3090 round_jiffies_up(jiffies + DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003091}
3092
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003093static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003094{
3095 struct drm_i915_private *dev_priv = dev->dev_private;
3096
3097 if (HAS_PCH_NOP(dev))
3098 return;
3099
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003100 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003101
3102 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3103 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003104}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003105
Paulo Zanoni622364b2014-04-01 15:37:22 -03003106/*
3107 * SDEIER is also touched by the interrupt handler to work around missed PCH
3108 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3109 * instead we unconditionally enable all PCH interrupt sources here, but then
3110 * only unmask them as needed with SDEIMR.
3111 *
3112 * This function needs to be called before interrupts are enabled.
3113 */
3114static void ibx_irq_pre_postinstall(struct drm_device *dev)
3115{
3116 struct drm_i915_private *dev_priv = dev->dev_private;
3117
3118 if (HAS_PCH_NOP(dev))
3119 return;
3120
3121 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003122 I915_WRITE(SDEIER, 0xffffffff);
3123 POSTING_READ(SDEIER);
3124}
3125
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003126static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003127{
3128 struct drm_i915_private *dev_priv = dev->dev_private;
3129
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003130 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003131 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003132 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003133}
3134
Linus Torvalds1da177e2005-04-16 15:20:36 -07003135/* drm_dma.h hooks
3136*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003137static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003138{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003139 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003140
Paulo Zanoni0c841212014-04-01 15:37:27 -03003141 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003142
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003143 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003144 if (IS_GEN7(dev))
3145 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003146
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003147 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003148
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003149 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003150}
3151
Ville Syrjälä70591a42014-10-30 19:42:58 +02003152static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3153{
3154 enum pipe pipe;
3155
3156 I915_WRITE(PORT_HOTPLUG_EN, 0);
3157 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3158
3159 for_each_pipe(dev_priv, pipe)
3160 I915_WRITE(PIPESTAT(pipe), 0xffff);
3161
3162 GEN5_IRQ_RESET(VLV_);
3163}
3164
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003165static void valleyview_irq_preinstall(struct drm_device *dev)
3166{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003167 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003168
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003169 /* VLV magic */
3170 I915_WRITE(VLV_IMR, 0);
3171 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3172 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3173 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3174
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003175 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003176
Ville Syrjälä7c4cde32014-10-30 19:42:51 +02003177 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003178
Ville Syrjälä70591a42014-10-30 19:42:58 +02003179 vlv_display_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003180}
3181
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003182static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3183{
3184 GEN8_IRQ_RESET_NDX(GT, 0);
3185 GEN8_IRQ_RESET_NDX(GT, 1);
3186 GEN8_IRQ_RESET_NDX(GT, 2);
3187 GEN8_IRQ_RESET_NDX(GT, 3);
3188}
3189
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003190static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003191{
3192 struct drm_i915_private *dev_priv = dev->dev_private;
3193 int pipe;
3194
Ben Widawskyabd58f02013-11-02 21:07:09 -07003195 I915_WRITE(GEN8_MASTER_IRQ, 0);
3196 POSTING_READ(GEN8_MASTER_IRQ);
3197
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003198 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003199
Damien Lespiau055e3932014-08-18 13:49:10 +01003200 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003201 if (intel_display_power_is_enabled(dev_priv,
3202 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003203 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003204
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003205 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3206 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3207 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003208
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003209 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003210}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003211
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003212void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv)
3213{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003214 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003215
Daniel Vetter13321782014-09-15 14:55:29 +02003216 spin_lock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003217 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B, dev_priv->de_irq_mask[PIPE_B],
Paulo Zanoni1180e202014-10-07 18:02:52 -03003218 ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003219 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C, dev_priv->de_irq_mask[PIPE_C],
Paulo Zanoni1180e202014-10-07 18:02:52 -03003220 ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003221 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003222}
3223
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003224static void cherryview_irq_preinstall(struct drm_device *dev)
3225{
3226 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003227
3228 I915_WRITE(GEN8_MASTER_IRQ, 0);
3229 POSTING_READ(GEN8_MASTER_IRQ);
3230
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003231 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003232
3233 GEN5_IRQ_RESET(GEN8_PCU_);
3234
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003235 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3236
Ville Syrjälä70591a42014-10-30 19:42:58 +02003237 vlv_display_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003238}
3239
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003240static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003241{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003242 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003243 struct intel_encoder *intel_encoder;
Daniel Vetterfee884e2013-07-04 23:35:21 +02003244 u32 hotplug_irqs, hotplug, enabled_irqs = 0;
Keith Packard7fe0b972011-09-19 13:31:02 -07003245
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003246 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003247 hotplug_irqs = SDE_HOTPLUG_MASK;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003248 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003249 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003250 enabled_irqs |= hpd_ibx[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003251 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003252 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Damien Lespiaub2784e12014-08-05 11:29:37 +01003253 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02003254 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
Daniel Vetterfee884e2013-07-04 23:35:21 +02003255 enabled_irqs |= hpd_cpt[intel_encoder->hpd_pin];
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003256 }
3257
Daniel Vetterfee884e2013-07-04 23:35:21 +02003258 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003259
3260 /*
3261 * Enable digital hotplug on the PCH, and configure the DP short pulse
3262 * duration to 2ms (which is the minimum in the Display Port spec)
3263 *
3264 * This register is the same on all known PCH chips.
3265 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003266 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3267 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3268 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3269 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3270 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3271 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3272}
3273
Paulo Zanonid46da432013-02-08 17:35:15 -02003274static void ibx_irq_postinstall(struct drm_device *dev)
3275{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003276 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003277 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003278
Daniel Vetter692a04c2013-05-29 21:43:05 +02003279 if (HAS_PCH_NOP(dev))
3280 return;
3281
Paulo Zanoni105b1222014-04-01 15:37:17 -03003282 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003283 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003284 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003285 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003286
Paulo Zanoni337ba012014-04-01 15:37:16 -03003287 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003288 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003289}
3290
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003291static void gen5_gt_irq_postinstall(struct drm_device *dev)
3292{
3293 struct drm_i915_private *dev_priv = dev->dev_private;
3294 u32 pm_irqs, gt_irqs;
3295
3296 pm_irqs = gt_irqs = 0;
3297
3298 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003299 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003300 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003301 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3302 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003303 }
3304
3305 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3306 if (IS_GEN5(dev)) {
3307 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3308 ILK_BSD_USER_INTERRUPT;
3309 } else {
3310 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3311 }
3312
Paulo Zanoni35079892014-04-01 15:37:15 -03003313 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003314
3315 if (INTEL_INFO(dev)->gen >= 6) {
Deepak Sa6706b42014-03-15 20:23:22 +05303316 pm_irqs |= dev_priv->pm_rps_events;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003317
3318 if (HAS_VEBOX(dev))
3319 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3320
Paulo Zanoni605cd252013-08-06 18:57:15 -03003321 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003322 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003323 }
3324}
3325
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003326static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003327{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003328 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003329 u32 display_mask, extra_mask;
3330
3331 if (INTEL_INFO(dev)->gen >= 7) {
3332 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3333 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3334 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003335 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003336 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003337 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003338 } else {
3339 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3340 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003341 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003342 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3343 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003344 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3345 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003346 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003347
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003348 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003349
Paulo Zanoni0c841212014-04-01 15:37:27 -03003350 I915_WRITE(HWSTAM, 0xeffe);
3351
Paulo Zanoni622364b2014-04-01 15:37:22 -03003352 ibx_irq_pre_postinstall(dev);
3353
Paulo Zanoni35079892014-04-01 15:37:15 -03003354 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003355
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003356 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003357
Paulo Zanonid46da432013-02-08 17:35:15 -02003358 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003359
Jesse Barnesf97108d2010-01-29 11:27:07 -08003360 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003361 /* Enable PCU event interrupts
3362 *
3363 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003364 * setup is guaranteed to run in single-threaded context. But we
3365 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003366 spin_lock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003367 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003368 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003369 }
3370
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003371 return 0;
3372}
3373
Imre Deakf8b79e52014-03-04 19:23:07 +02003374static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3375{
3376 u32 pipestat_mask;
3377 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003378 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003379
3380 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3381 PIPE_FIFO_UNDERRUN_STATUS;
3382
Ville Syrjälä120dda42014-10-30 19:42:57 +02003383 for_each_pipe(dev_priv, pipe)
3384 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003385 POSTING_READ(PIPESTAT(PIPE_A));
3386
3387 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3388 PIPE_CRC_DONE_INTERRUPT_STATUS;
3389
Ville Syrjälä120dda42014-10-30 19:42:57 +02003390 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3391 for_each_pipe(dev_priv, pipe)
3392 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003393
3394 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3395 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3396 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003397 if (IS_CHERRYVIEW(dev_priv))
3398 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003399 dev_priv->irq_mask &= ~iir_mask;
3400
3401 I915_WRITE(VLV_IIR, iir_mask);
3402 I915_WRITE(VLV_IIR, iir_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003403 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003404 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3405 POSTING_READ(VLV_IMR);
Imre Deakf8b79e52014-03-04 19:23:07 +02003406}
3407
3408static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3409{
3410 u32 pipestat_mask;
3411 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003412 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003413
3414 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3415 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003416 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003417 if (IS_CHERRYVIEW(dev_priv))
3418 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003419
3420 dev_priv->irq_mask |= iir_mask;
Imre Deakf8b79e52014-03-04 19:23:07 +02003421 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003422 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003423 I915_WRITE(VLV_IIR, iir_mask);
3424 I915_WRITE(VLV_IIR, iir_mask);
3425 POSTING_READ(VLV_IIR);
3426
3427 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3428 PIPE_CRC_DONE_INTERRUPT_STATUS;
3429
Ville Syrjälä120dda42014-10-30 19:42:57 +02003430 i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3431 for_each_pipe(dev_priv, pipe)
3432 i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003433
3434 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3435 PIPE_FIFO_UNDERRUN_STATUS;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003436
3437 for_each_pipe(dev_priv, pipe)
3438 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003439 POSTING_READ(PIPESTAT(PIPE_A));
3440}
3441
3442void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3443{
3444 assert_spin_locked(&dev_priv->irq_lock);
3445
3446 if (dev_priv->display_irqs_enabled)
3447 return;
3448
3449 dev_priv->display_irqs_enabled = true;
3450
Imre Deak950eaba2014-09-08 15:21:09 +03003451 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003452 valleyview_display_irqs_install(dev_priv);
3453}
3454
3455void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3456{
3457 assert_spin_locked(&dev_priv->irq_lock);
3458
3459 if (!dev_priv->display_irqs_enabled)
3460 return;
3461
3462 dev_priv->display_irqs_enabled = false;
3463
Imre Deak950eaba2014-09-08 15:21:09 +03003464 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003465 valleyview_display_irqs_uninstall(dev_priv);
3466}
3467
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003468static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003469{
Imre Deakf8b79e52014-03-04 19:23:07 +02003470 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003471
Daniel Vetter20afbda2012-12-11 14:05:07 +01003472 I915_WRITE(PORT_HOTPLUG_EN, 0);
3473 POSTING_READ(PORT_HOTPLUG_EN);
3474
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003475 I915_WRITE(VLV_IIR, 0xffffffff);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003476 I915_WRITE(VLV_IIR, 0xffffffff);
3477 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3478 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3479 POSTING_READ(VLV_IMR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003480
Daniel Vetterb79480b2013-06-27 17:52:10 +02003481 /* Interrupt setup is already guaranteed to be single-threaded, this is
3482 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003483 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003484 if (dev_priv->display_irqs_enabled)
3485 valleyview_display_irqs_install(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003486 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003487}
3488
3489static int valleyview_irq_postinstall(struct drm_device *dev)
3490{
3491 struct drm_i915_private *dev_priv = dev->dev_private;
3492
3493 vlv_display_irq_postinstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003494
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003495 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003496
3497 /* ack & enable invalid PTE error interrupts */
3498#if 0 /* FIXME: add support to irq handler for checking these bits */
3499 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3500 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3501#endif
3502
3503 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003504
3505 return 0;
3506}
3507
Ben Widawskyabd58f02013-11-02 21:07:09 -07003508static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3509{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003510 /* These are interrupts we'll toggle with the ring mask register */
3511 uint32_t gt_interrupts[] = {
3512 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003513 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003514 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003515 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3516 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003517 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003518 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3519 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3520 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003521 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003522 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3523 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003524 };
3525
Ben Widawsky09610212014-05-15 20:58:08 +03003526 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303527 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3528 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
3529 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, dev_priv->pm_rps_events);
3530 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003531}
3532
3533static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3534{
Damien Lespiau770de832014-03-20 20:45:01 +00003535 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3536 uint32_t de_pipe_enables;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003537 int pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00003538 u32 aux_en = GEN8_AUX_CHANNEL_A;
Damien Lespiau770de832014-03-20 20:45:01 +00003539
Jesse Barnes88e04702014-11-13 17:51:48 +00003540 if (IS_GEN9(dev_priv)) {
Damien Lespiau770de832014-03-20 20:45:01 +00003541 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3542 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Jesse Barnes88e04702014-11-13 17:51:48 +00003543 aux_en |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3544 GEN9_AUX_CHANNEL_D;
3545 } else
Damien Lespiau770de832014-03-20 20:45:01 +00003546 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3547 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3548
3549 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3550 GEN8_PIPE_FIFO_UNDERRUN;
3551
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003552 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3553 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3554 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003555
Damien Lespiau055e3932014-08-18 13:49:10 +01003556 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003557 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003558 POWER_DOMAIN_PIPE(pipe)))
3559 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3560 dev_priv->de_irq_mask[pipe],
3561 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003562
Jesse Barnes88e04702014-11-13 17:51:48 +00003563 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~aux_en, aux_en);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003564}
3565
3566static int gen8_irq_postinstall(struct drm_device *dev)
3567{
3568 struct drm_i915_private *dev_priv = dev->dev_private;
3569
Paulo Zanoni622364b2014-04-01 15:37:22 -03003570 ibx_irq_pre_postinstall(dev);
3571
Ben Widawskyabd58f02013-11-02 21:07:09 -07003572 gen8_gt_irq_postinstall(dev_priv);
3573 gen8_de_irq_postinstall(dev_priv);
3574
3575 ibx_irq_postinstall(dev);
3576
3577 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3578 POSTING_READ(GEN8_MASTER_IRQ);
3579
3580 return 0;
3581}
3582
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003583static int cherryview_irq_postinstall(struct drm_device *dev)
3584{
3585 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003586
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003587 vlv_display_irq_postinstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003588
3589 gen8_gt_irq_postinstall(dev_priv);
3590
3591 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3592 POSTING_READ(GEN8_MASTER_IRQ);
3593
3594 return 0;
3595}
3596
Ben Widawskyabd58f02013-11-02 21:07:09 -07003597static void gen8_irq_uninstall(struct drm_device *dev)
3598{
3599 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003600
3601 if (!dev_priv)
3602 return;
3603
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003604 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003605}
3606
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003607static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
3608{
3609 /* Interrupt setup is already guaranteed to be single-threaded, this is
3610 * just to make the assert_spin_locked check happy. */
3611 spin_lock_irq(&dev_priv->irq_lock);
3612 if (dev_priv->display_irqs_enabled)
3613 valleyview_display_irqs_uninstall(dev_priv);
3614 spin_unlock_irq(&dev_priv->irq_lock);
3615
3616 vlv_display_irq_reset(dev_priv);
3617
3618 dev_priv->irq_mask = 0;
3619}
3620
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003621static void valleyview_irq_uninstall(struct drm_device *dev)
3622{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003623 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003624
3625 if (!dev_priv)
3626 return;
3627
Imre Deak843d0e72014-04-14 20:24:23 +03003628 I915_WRITE(VLV_MASTER_IER, 0);
3629
Ville Syrjälä893fce82014-10-30 19:42:56 +02003630 gen5_gt_irq_reset(dev);
3631
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003632 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003633
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003634 vlv_display_irq_uninstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003635}
3636
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003637static void cherryview_irq_uninstall(struct drm_device *dev)
3638{
3639 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003640
3641 if (!dev_priv)
3642 return;
3643
3644 I915_WRITE(GEN8_MASTER_IRQ, 0);
3645 POSTING_READ(GEN8_MASTER_IRQ);
3646
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003647 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003648
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003649 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003650
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003651 vlv_display_irq_uninstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003652}
3653
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003654static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003655{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003656 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003657
3658 if (!dev_priv)
3659 return;
3660
Paulo Zanonibe30b292014-04-01 15:37:25 -03003661 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003662}
3663
Chris Wilsonc2798b12012-04-22 21:13:57 +01003664static void i8xx_irq_preinstall(struct drm_device * dev)
3665{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003666 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003667 int pipe;
3668
Damien Lespiau055e3932014-08-18 13:49:10 +01003669 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003670 I915_WRITE(PIPESTAT(pipe), 0);
3671 I915_WRITE16(IMR, 0xffff);
3672 I915_WRITE16(IER, 0x0);
3673 POSTING_READ16(IER);
3674}
3675
3676static int i8xx_irq_postinstall(struct drm_device *dev)
3677{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003678 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003679
Chris Wilsonc2798b12012-04-22 21:13:57 +01003680 I915_WRITE16(EMR,
3681 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3682
3683 /* Unmask the interrupts that we always want on. */
3684 dev_priv->irq_mask =
3685 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3686 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3687 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3688 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3689 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3690 I915_WRITE16(IMR, dev_priv->irq_mask);
3691
3692 I915_WRITE16(IER,
3693 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3694 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3695 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3696 I915_USER_INTERRUPT);
3697 POSTING_READ16(IER);
3698
Daniel Vetter379ef822013-10-16 22:55:56 +02003699 /* Interrupt setup is already guaranteed to be single-threaded, this is
3700 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003701 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003702 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3703 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003704 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003705
Chris Wilsonc2798b12012-04-22 21:13:57 +01003706 return 0;
3707}
3708
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003709/*
3710 * Returns true when a page flip has completed.
3711 */
3712static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003713 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003714{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003715 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003716 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003717
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003718 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003719 return false;
3720
3721 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003722 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003723
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003724 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003725
3726 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3727 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3728 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3729 * the flip is completed (no longer pending). Since this doesn't raise
3730 * an interrupt per se, we watch for the change at vblank.
3731 */
3732 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003733 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003734
3735 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003736 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003737
3738check_page_flip:
3739 intel_check_page_flip(dev, pipe);
3740 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003741}
3742
Daniel Vetterff1f5252012-10-02 15:10:55 +02003743static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003744{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003745 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003746 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003747 u16 iir, new_iir;
3748 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003749 int pipe;
3750 u16 flip_mask =
3751 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3752 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3753
Chris Wilsonc2798b12012-04-22 21:13:57 +01003754 iir = I915_READ16(IIR);
3755 if (iir == 0)
3756 return IRQ_NONE;
3757
3758 while (iir & ~flip_mask) {
3759 /* Can't rely on pipestat interrupt bit in iir as it might
3760 * have been cleared after the pipestat interrupt was received.
3761 * It doesn't set the bit in iir again, but it still produces
3762 * interrupts (for non-MSI).
3763 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003764 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003765 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003766 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003767
Damien Lespiau055e3932014-08-18 13:49:10 +01003768 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003769 int reg = PIPESTAT(pipe);
3770 pipe_stats[pipe] = I915_READ(reg);
3771
3772 /*
3773 * Clear the PIPE*STAT regs before the IIR
3774 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003775 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003776 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003777 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003778 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003779
3780 I915_WRITE16(IIR, iir & ~flip_mask);
3781 new_iir = I915_READ16(IIR); /* Flush posted writes */
3782
Chris Wilsonc2798b12012-04-22 21:13:57 +01003783 if (iir & I915_USER_INTERRUPT)
3784 notify_ring(dev, &dev_priv->ring[RCS]);
3785
Damien Lespiau055e3932014-08-18 13:49:10 +01003786 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003787 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003788 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003789 plane = !plane;
3790
Daniel Vetter4356d582013-10-16 22:55:55 +02003791 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003792 i8xx_handle_vblank(dev, plane, pipe, iir))
3793 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003794
Daniel Vetter4356d582013-10-16 22:55:55 +02003795 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003796 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003797
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003798 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3799 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3800 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003801 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003802
3803 iir = new_iir;
3804 }
3805
3806 return IRQ_HANDLED;
3807}
3808
3809static void i8xx_irq_uninstall(struct drm_device * dev)
3810{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003811 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003812 int pipe;
3813
Damien Lespiau055e3932014-08-18 13:49:10 +01003814 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003815 /* Clear enable bits; then clear status bits */
3816 I915_WRITE(PIPESTAT(pipe), 0);
3817 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3818 }
3819 I915_WRITE16(IMR, 0xffff);
3820 I915_WRITE16(IER, 0x0);
3821 I915_WRITE16(IIR, I915_READ16(IIR));
3822}
3823
Chris Wilsona266c7d2012-04-24 22:59:44 +01003824static void i915_irq_preinstall(struct drm_device * dev)
3825{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003826 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003827 int pipe;
3828
Chris Wilsona266c7d2012-04-24 22:59:44 +01003829 if (I915_HAS_HOTPLUG(dev)) {
3830 I915_WRITE(PORT_HOTPLUG_EN, 0);
3831 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3832 }
3833
Chris Wilson00d98eb2012-04-24 22:59:48 +01003834 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01003835 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003836 I915_WRITE(PIPESTAT(pipe), 0);
3837 I915_WRITE(IMR, 0xffffffff);
3838 I915_WRITE(IER, 0x0);
3839 POSTING_READ(IER);
3840}
3841
3842static int i915_irq_postinstall(struct drm_device *dev)
3843{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003844 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003845 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003846
Chris Wilson38bde182012-04-24 22:59:50 +01003847 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3848
3849 /* Unmask the interrupts that we always want on. */
3850 dev_priv->irq_mask =
3851 ~(I915_ASLE_INTERRUPT |
3852 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3853 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3854 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3855 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3856 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3857
3858 enable_mask =
3859 I915_ASLE_INTERRUPT |
3860 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3861 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3862 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3863 I915_USER_INTERRUPT;
3864
Chris Wilsona266c7d2012-04-24 22:59:44 +01003865 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003866 I915_WRITE(PORT_HOTPLUG_EN, 0);
3867 POSTING_READ(PORT_HOTPLUG_EN);
3868
Chris Wilsona266c7d2012-04-24 22:59:44 +01003869 /* Enable in IER... */
3870 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3871 /* and unmask in IMR */
3872 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3873 }
3874
Chris Wilsona266c7d2012-04-24 22:59:44 +01003875 I915_WRITE(IMR, dev_priv->irq_mask);
3876 I915_WRITE(IER, enable_mask);
3877 POSTING_READ(IER);
3878
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003879 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003880
Daniel Vetter379ef822013-10-16 22:55:56 +02003881 /* Interrupt setup is already guaranteed to be single-threaded, this is
3882 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003883 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003884 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3885 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003886 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003887
Daniel Vetter20afbda2012-12-11 14:05:07 +01003888 return 0;
3889}
3890
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003891/*
3892 * Returns true when a page flip has completed.
3893 */
3894static bool i915_handle_vblank(struct drm_device *dev,
3895 int plane, int pipe, u32 iir)
3896{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003897 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003898 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3899
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003900 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003901 return false;
3902
3903 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003904 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003905
3906 intel_prepare_page_flip(dev, plane);
3907
3908 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3909 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3910 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3911 * the flip is completed (no longer pending). Since this doesn't raise
3912 * an interrupt per se, we watch for the change at vblank.
3913 */
3914 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003915 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003916
3917 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003918 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003919
3920check_page_flip:
3921 intel_check_page_flip(dev, pipe);
3922 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003923}
3924
Daniel Vetterff1f5252012-10-02 15:10:55 +02003925static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003926{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003927 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003928 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003929 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01003930 u32 flip_mask =
3931 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3932 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003933 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003934
Chris Wilsona266c7d2012-04-24 22:59:44 +01003935 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003936 do {
3937 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003938 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003939
3940 /* Can't rely on pipestat interrupt bit in iir as it might
3941 * have been cleared after the pipestat interrupt was received.
3942 * It doesn't set the bit in iir again, but it still produces
3943 * interrupts (for non-MSI).
3944 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003945 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003946 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003947 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003948
Damien Lespiau055e3932014-08-18 13:49:10 +01003949 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003950 int reg = PIPESTAT(pipe);
3951 pipe_stats[pipe] = I915_READ(reg);
3952
Chris Wilson38bde182012-04-24 22:59:50 +01003953 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003954 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003955 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003956 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003957 }
3958 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003959 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003960
3961 if (!irq_received)
3962 break;
3963
Chris Wilsona266c7d2012-04-24 22:59:44 +01003964 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003965 if (I915_HAS_HOTPLUG(dev) &&
3966 iir & I915_DISPLAY_PORT_INTERRUPT)
3967 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003968
Chris Wilson38bde182012-04-24 22:59:50 +01003969 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003970 new_iir = I915_READ(IIR); /* Flush posted writes */
3971
Chris Wilsona266c7d2012-04-24 22:59:44 +01003972 if (iir & I915_USER_INTERRUPT)
3973 notify_ring(dev, &dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003974
Damien Lespiau055e3932014-08-18 13:49:10 +01003975 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003976 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003977 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003978 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003979
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003980 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3981 i915_handle_vblank(dev, plane, pipe, iir))
3982 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003983
3984 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3985 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003986
3987 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003988 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003989
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003990 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3991 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3992 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003993 }
3994
Chris Wilsona266c7d2012-04-24 22:59:44 +01003995 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3996 intel_opregion_asle_intr(dev);
3997
3998 /* With MSI, interrupts are only generated when iir
3999 * transitions from zero to nonzero. If another bit got
4000 * set while we were handling the existing iir bits, then
4001 * we would never get another interrupt.
4002 *
4003 * This is fine on non-MSI as well, as if we hit this path
4004 * we avoid exiting the interrupt handler only to generate
4005 * another one.
4006 *
4007 * Note that for MSI this could cause a stray interrupt report
4008 * if an interrupt landed in the time between writing IIR and
4009 * the posting read. This should be rare enough to never
4010 * trigger the 99% of 100,000 interrupts test for disabling
4011 * stray interrupts.
4012 */
Chris Wilson38bde182012-04-24 22:59:50 +01004013 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004014 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004015 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004016
4017 return ret;
4018}
4019
4020static void i915_irq_uninstall(struct drm_device * dev)
4021{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004022 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004023 int pipe;
4024
Chris Wilsona266c7d2012-04-24 22:59:44 +01004025 if (I915_HAS_HOTPLUG(dev)) {
4026 I915_WRITE(PORT_HOTPLUG_EN, 0);
4027 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4028 }
4029
Chris Wilson00d98eb2012-04-24 22:59:48 +01004030 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004031 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004032 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004033 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004034 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4035 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004036 I915_WRITE(IMR, 0xffffffff);
4037 I915_WRITE(IER, 0x0);
4038
Chris Wilsona266c7d2012-04-24 22:59:44 +01004039 I915_WRITE(IIR, I915_READ(IIR));
4040}
4041
4042static void i965_irq_preinstall(struct drm_device * dev)
4043{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004044 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004045 int pipe;
4046
Chris Wilsonadca4732012-05-11 18:01:31 +01004047 I915_WRITE(PORT_HOTPLUG_EN, 0);
4048 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004049
4050 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004051 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004052 I915_WRITE(PIPESTAT(pipe), 0);
4053 I915_WRITE(IMR, 0xffffffff);
4054 I915_WRITE(IER, 0x0);
4055 POSTING_READ(IER);
4056}
4057
4058static int i965_irq_postinstall(struct drm_device *dev)
4059{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004060 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004061 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004062 u32 error_mask;
4063
Chris Wilsona266c7d2012-04-24 22:59:44 +01004064 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004065 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004066 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004067 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4068 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4069 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4070 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4071 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4072
4073 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004074 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4075 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004076 enable_mask |= I915_USER_INTERRUPT;
4077
4078 if (IS_G4X(dev))
4079 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004080
Daniel Vetterb79480b2013-06-27 17:52:10 +02004081 /* Interrupt setup is already guaranteed to be single-threaded, this is
4082 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004083 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004084 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4085 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4086 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004087 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004088
Chris Wilsona266c7d2012-04-24 22:59:44 +01004089 /*
4090 * Enable some error detection, note the instruction error mask
4091 * bit is reserved, so we leave it masked.
4092 */
4093 if (IS_G4X(dev)) {
4094 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4095 GM45_ERROR_MEM_PRIV |
4096 GM45_ERROR_CP_PRIV |
4097 I915_ERROR_MEMORY_REFRESH);
4098 } else {
4099 error_mask = ~(I915_ERROR_PAGE_TABLE |
4100 I915_ERROR_MEMORY_REFRESH);
4101 }
4102 I915_WRITE(EMR, error_mask);
4103
4104 I915_WRITE(IMR, dev_priv->irq_mask);
4105 I915_WRITE(IER, enable_mask);
4106 POSTING_READ(IER);
4107
Daniel Vetter20afbda2012-12-11 14:05:07 +01004108 I915_WRITE(PORT_HOTPLUG_EN, 0);
4109 POSTING_READ(PORT_HOTPLUG_EN);
4110
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004111 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004112
4113 return 0;
4114}
4115
Egbert Eichbac56d52013-02-25 12:06:51 -05004116static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004117{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004118 struct drm_i915_private *dev_priv = dev->dev_private;
Egbert Eichcd569ae2013-04-16 13:36:57 +02004119 struct intel_encoder *intel_encoder;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004120 u32 hotplug_en;
4121
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004122 assert_spin_locked(&dev_priv->irq_lock);
4123
Egbert Eichbac56d52013-02-25 12:06:51 -05004124 if (I915_HAS_HOTPLUG(dev)) {
4125 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4126 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4127 /* Note HDMI and DP share hotplug bits */
Egbert Eiche5868a32013-02-28 04:17:12 -05004128 /* enable bits are the same for all generations */
Damien Lespiaub2784e12014-08-05 11:29:37 +01004129 for_each_intel_encoder(dev, intel_encoder)
Egbert Eichcd569ae2013-04-16 13:36:57 +02004130 if (dev_priv->hpd_stats[intel_encoder->hpd_pin].hpd_mark == HPD_ENABLED)
4131 hotplug_en |= hpd_mask_i915[intel_encoder->hpd_pin];
Egbert Eichbac56d52013-02-25 12:06:51 -05004132 /* Programming the CRT detection parameters tends
4133 to generate a spurious hotplug event about three
4134 seconds later. So just do it once.
4135 */
4136 if (IS_G4X(dev))
4137 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Daniel Vetter85fc95b2013-03-27 15:47:11 +01004138 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
Egbert Eichbac56d52013-02-25 12:06:51 -05004139 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004140
Egbert Eichbac56d52013-02-25 12:06:51 -05004141 /* Ignore TV since it's buggy */
4142 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
4143 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004144}
4145
Daniel Vetterff1f5252012-10-02 15:10:55 +02004146static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004147{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004148 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004149 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004150 u32 iir, new_iir;
4151 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004152 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004153 u32 flip_mask =
4154 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4155 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004156
Chris Wilsona266c7d2012-04-24 22:59:44 +01004157 iir = I915_READ(IIR);
4158
Chris Wilsona266c7d2012-04-24 22:59:44 +01004159 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004160 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004161 bool blc_event = false;
4162
Chris Wilsona266c7d2012-04-24 22:59:44 +01004163 /* Can't rely on pipestat interrupt bit in iir as it might
4164 * have been cleared after the pipestat interrupt was received.
4165 * It doesn't set the bit in iir again, but it still produces
4166 * interrupts (for non-MSI).
4167 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004168 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004169 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004170 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004171
Damien Lespiau055e3932014-08-18 13:49:10 +01004172 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004173 int reg = PIPESTAT(pipe);
4174 pipe_stats[pipe] = I915_READ(reg);
4175
4176 /*
4177 * Clear the PIPE*STAT regs before the IIR
4178 */
4179 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004181 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004182 }
4183 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004184 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004185
4186 if (!irq_received)
4187 break;
4188
4189 ret = IRQ_HANDLED;
4190
4191 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004192 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4193 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004194
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004195 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004196 new_iir = I915_READ(IIR); /* Flush posted writes */
4197
Chris Wilsona266c7d2012-04-24 22:59:44 +01004198 if (iir & I915_USER_INTERRUPT)
4199 notify_ring(dev, &dev_priv->ring[RCS]);
4200 if (iir & I915_BSD_USER_INTERRUPT)
4201 notify_ring(dev, &dev_priv->ring[VCS]);
4202
Damien Lespiau055e3932014-08-18 13:49:10 +01004203 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004204 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004205 i915_handle_vblank(dev, pipe, pipe, iir))
4206 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004207
4208 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4209 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004210
4211 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004212 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004213
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004214 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4215 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004216 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004217
4218 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4219 intel_opregion_asle_intr(dev);
4220
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004221 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4222 gmbus_irq_handler(dev);
4223
Chris Wilsona266c7d2012-04-24 22:59:44 +01004224 /* With MSI, interrupts are only generated when iir
4225 * transitions from zero to nonzero. If another bit got
4226 * set while we were handling the existing iir bits, then
4227 * we would never get another interrupt.
4228 *
4229 * This is fine on non-MSI as well, as if we hit this path
4230 * we avoid exiting the interrupt handler only to generate
4231 * another one.
4232 *
4233 * Note that for MSI this could cause a stray interrupt report
4234 * if an interrupt landed in the time between writing IIR and
4235 * the posting read. This should be rare enough to never
4236 * trigger the 99% of 100,000 interrupts test for disabling
4237 * stray interrupts.
4238 */
4239 iir = new_iir;
4240 }
4241
4242 return ret;
4243}
4244
4245static void i965_irq_uninstall(struct drm_device * dev)
4246{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004247 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004248 int pipe;
4249
4250 if (!dev_priv)
4251 return;
4252
Chris Wilsonadca4732012-05-11 18:01:31 +01004253 I915_WRITE(PORT_HOTPLUG_EN, 0);
4254 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004255
4256 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004257 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004258 I915_WRITE(PIPESTAT(pipe), 0);
4259 I915_WRITE(IMR, 0xffffffff);
4260 I915_WRITE(IER, 0x0);
4261
Damien Lespiau055e3932014-08-18 13:49:10 +01004262 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004263 I915_WRITE(PIPESTAT(pipe),
4264 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4265 I915_WRITE(IIR, I915_READ(IIR));
4266}
4267
Daniel Vetter4cb21832014-09-15 14:55:26 +02004268static void intel_hpd_irq_reenable_work(struct work_struct *work)
Egbert Eichac4c16c2013-04-16 13:36:58 +02004269{
Imre Deak63237512014-08-18 15:37:02 +03004270 struct drm_i915_private *dev_priv =
4271 container_of(work, typeof(*dev_priv),
4272 hotplug_reenable_work.work);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004273 struct drm_device *dev = dev_priv->dev;
4274 struct drm_mode_config *mode_config = &dev->mode_config;
Egbert Eichac4c16c2013-04-16 13:36:58 +02004275 int i;
4276
Imre Deak63237512014-08-18 15:37:02 +03004277 intel_runtime_pm_get(dev_priv);
4278
Daniel Vetter4cb21832014-09-15 14:55:26 +02004279 spin_lock_irq(&dev_priv->irq_lock);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004280 for (i = (HPD_NONE + 1); i < HPD_NUM_PINS; i++) {
4281 struct drm_connector *connector;
4282
4283 if (dev_priv->hpd_stats[i].hpd_mark != HPD_DISABLED)
4284 continue;
4285
4286 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4287
4288 list_for_each_entry(connector, &mode_config->connector_list, head) {
4289 struct intel_connector *intel_connector = to_intel_connector(connector);
4290
4291 if (intel_connector->encoder->hpd_pin == i) {
4292 if (connector->polled != intel_connector->polled)
4293 DRM_DEBUG_DRIVER("Reenabling HPD on connector %s\n",
Jani Nikulac23cc412014-06-03 14:56:17 +03004294 connector->name);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004295 connector->polled = intel_connector->polled;
4296 if (!connector->polled)
4297 connector->polled = DRM_CONNECTOR_POLL_HPD;
4298 }
4299 }
4300 }
4301 if (dev_priv->display.hpd_irq_setup)
4302 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetter4cb21832014-09-15 14:55:26 +02004303 spin_unlock_irq(&dev_priv->irq_lock);
Imre Deak63237512014-08-18 15:37:02 +03004304
4305 intel_runtime_pm_put(dev_priv);
Egbert Eichac4c16c2013-04-16 13:36:58 +02004306}
4307
Daniel Vetterfca52a52014-09-30 10:56:45 +02004308/**
4309 * intel_irq_init - initializes irq support
4310 * @dev_priv: i915 device instance
4311 *
4312 * This function initializes all the irq support including work items, timers
4313 * and all the vtables. It does not setup the interrupt itself though.
4314 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004315void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004316{
Daniel Vetterb9632912014-09-30 10:56:44 +02004317 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004318
4319 INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func);
Dave Airlie13cf5502014-06-18 11:29:35 +10004320 INIT_WORK(&dev_priv->dig_port_work, i915_digport_work_func);
Daniel Vetter99584db2012-11-14 17:14:04 +01004321 INIT_WORK(&dev_priv->gpu_error.work, i915_error_work_func);
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004322 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004323 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004324
Deepak Sa6706b42014-03-15 20:23:22 +05304325 /* Let's track the enabled rps events */
Daniel Vetterb9632912014-09-30 10:56:44 +02004326 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004327 /* WaGsvRC0ResidencyMethod:vlv */
Deepak S31685c22014-07-03 17:33:01 -04004328 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
4329 else
4330 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304331
Daniel Vetter99584db2012-11-14 17:14:04 +01004332 setup_timer(&dev_priv->gpu_error.hangcheck_timer,
4333 i915_hangcheck_elapsed,
Daniel Vetter61bac782012-12-01 21:03:21 +01004334 (unsigned long) dev);
Imre Deak63237512014-08-18 15:37:02 +03004335 INIT_DELAYED_WORK(&dev_priv->hotplug_reenable_work,
Daniel Vetter4cb21832014-09-15 14:55:26 +02004336 intel_hpd_irq_reenable_work);
Daniel Vetter61bac782012-12-01 21:03:21 +01004337
Tomas Janousek97a19a22012-12-08 13:48:13 +01004338 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004339
Daniel Vetterb9632912014-09-30 10:56:44 +02004340 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004341 dev->max_vblank_count = 0;
4342 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004343 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004344 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4345 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004346 } else {
4347 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4348 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004349 }
4350
Ville Syrjälä21da2702014-08-06 14:49:55 +03004351 /*
4352 * Opt out of the vblank disable timer on everything except gen2.
4353 * Gen2 doesn't have a hardware frame counter and so depends on
4354 * vblank interrupts to produce sane vblank seuquence numbers.
4355 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004356 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004357 dev->vblank_disable_immediate = true;
4358
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004359 if (drm_core_check_feature(dev, DRIVER_MODESET)) {
Keith Packardc3613de2011-08-12 17:05:54 -07004360 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03004361 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
4362 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004363
Daniel Vetterb9632912014-09-30 10:56:44 +02004364 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004365 dev->driver->irq_handler = cherryview_irq_handler;
4366 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4367 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4368 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4369 dev->driver->enable_vblank = valleyview_enable_vblank;
4370 dev->driver->disable_vblank = valleyview_disable_vblank;
4371 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004372 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004373 dev->driver->irq_handler = valleyview_irq_handler;
4374 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4375 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4376 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4377 dev->driver->enable_vblank = valleyview_enable_vblank;
4378 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004379 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004380 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004381 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004382 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004383 dev->driver->irq_postinstall = gen8_irq_postinstall;
4384 dev->driver->irq_uninstall = gen8_irq_uninstall;
4385 dev->driver->enable_vblank = gen8_enable_vblank;
4386 dev->driver->disable_vblank = gen8_disable_vblank;
4387 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004388 } else if (HAS_PCH_SPLIT(dev)) {
4389 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004390 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004391 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4392 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4393 dev->driver->enable_vblank = ironlake_enable_vblank;
4394 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004395 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004396 } else {
Daniel Vetterb9632912014-09-30 10:56:44 +02004397 if (INTEL_INFO(dev_priv)->gen == 2) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004398 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4399 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4400 dev->driver->irq_handler = i8xx_irq_handler;
4401 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Daniel Vetterb9632912014-09-30 10:56:44 +02004402 } else if (INTEL_INFO(dev_priv)->gen == 3) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004403 dev->driver->irq_preinstall = i915_irq_preinstall;
4404 dev->driver->irq_postinstall = i915_irq_postinstall;
4405 dev->driver->irq_uninstall = i915_irq_uninstall;
4406 dev->driver->irq_handler = i915_irq_handler;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004407 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004408 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004409 dev->driver->irq_preinstall = i965_irq_preinstall;
4410 dev->driver->irq_postinstall = i965_irq_postinstall;
4411 dev->driver->irq_uninstall = i965_irq_uninstall;
4412 dev->driver->irq_handler = i965_irq_handler;
Egbert Eichbac56d52013-02-25 12:06:51 -05004413 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004414 }
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004415 dev->driver->enable_vblank = i915_enable_vblank;
4416 dev->driver->disable_vblank = i915_disable_vblank;
4417 }
4418}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004419
Daniel Vetterfca52a52014-09-30 10:56:45 +02004420/**
4421 * intel_hpd_init - initializes and enables hpd support
4422 * @dev_priv: i915 device instance
4423 *
4424 * This function enables the hotplug support. It requires that interrupts have
4425 * already been enabled with intel_irq_init_hw(). From this point on hotplug and
4426 * poll request can run concurrently to other code, so locking rules must be
4427 * obeyed.
4428 *
4429 * This is a separate step from interrupt enabling to simplify the locking rules
4430 * in the driver load and resume code.
4431 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004432void intel_hpd_init(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004433{
Daniel Vetterb9632912014-09-30 10:56:44 +02004434 struct drm_device *dev = dev_priv->dev;
Egbert Eich821450c2013-04-16 13:36:55 +02004435 struct drm_mode_config *mode_config = &dev->mode_config;
4436 struct drm_connector *connector;
4437 int i;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004438
Egbert Eich821450c2013-04-16 13:36:55 +02004439 for (i = 1; i < HPD_NUM_PINS; i++) {
4440 dev_priv->hpd_stats[i].hpd_cnt = 0;
4441 dev_priv->hpd_stats[i].hpd_mark = HPD_ENABLED;
4442 }
4443 list_for_each_entry(connector, &mode_config->connector_list, head) {
4444 struct intel_connector *intel_connector = to_intel_connector(connector);
4445 connector->polled = intel_connector->polled;
Dave Airlie0e32b392014-05-02 14:02:48 +10004446 if (connector->encoder && !connector->polled && I915_HAS_HOTPLUG(dev) && intel_connector->encoder->hpd_pin > HPD_NONE)
4447 connector->polled = DRM_CONNECTOR_POLL_HPD;
4448 if (intel_connector->mst_port)
Egbert Eich821450c2013-04-16 13:36:55 +02004449 connector->polled = DRM_CONNECTOR_POLL_HPD;
4450 }
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004451
4452 /* Interrupt setup is already guaranteed to be single-threaded, this is
4453 * just to make the assert_spin_locked checks happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004454 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004455 if (dev_priv->display.hpd_irq_setup)
4456 dev_priv->display.hpd_irq_setup(dev);
Daniel Vetterd6207432014-09-15 14:55:27 +02004457 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004458}
Paulo Zanonic67a4702013-08-19 13:18:09 -03004459
Daniel Vetterfca52a52014-09-30 10:56:45 +02004460/**
4461 * intel_irq_install - enables the hardware interrupt
4462 * @dev_priv: i915 device instance
4463 *
4464 * This function enables the hardware interrupt handling, but leaves the hotplug
4465 * handling still disabled. It is called after intel_irq_init().
4466 *
4467 * In the driver load and resume code we need working interrupts in a few places
4468 * but don't want to deal with the hassle of concurrent probe and hotplug
4469 * workers. Hence the split into this two-stage approach.
4470 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004471int intel_irq_install(struct drm_i915_private *dev_priv)
4472{
4473 /*
4474 * We enable some interrupt sources in our postinstall hooks, so mark
4475 * interrupts as enabled _before_ actually enabling them to avoid
4476 * special cases in our ordering checks.
4477 */
4478 dev_priv->pm.irqs_enabled = true;
4479
4480 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4481}
4482
Daniel Vetterfca52a52014-09-30 10:56:45 +02004483/**
4484 * intel_irq_uninstall - finilizes all irq handling
4485 * @dev_priv: i915 device instance
4486 *
4487 * This stops interrupt and hotplug handling and unregisters and frees all
4488 * resources acquired in the init functions.
4489 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004490void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4491{
4492 drm_irq_uninstall(dev_priv->dev);
4493 intel_hpd_cancel_work(dev_priv);
4494 dev_priv->pm.irqs_enabled = false;
4495}
4496
Daniel Vetterfca52a52014-09-30 10:56:45 +02004497/**
4498 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4499 * @dev_priv: i915 device instance
4500 *
4501 * This function is used to disable interrupts at runtime, both in the runtime
4502 * pm and the system suspend/resume code.
4503 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004504void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004505{
Daniel Vetterb9632912014-09-30 10:56:44 +02004506 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004507 dev_priv->pm.irqs_enabled = false;
Paulo Zanonic67a4702013-08-19 13:18:09 -03004508}
4509
Daniel Vetterfca52a52014-09-30 10:56:45 +02004510/**
4511 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4512 * @dev_priv: i915 device instance
4513 *
4514 * This function is used to enable interrupts at runtime, both in the runtime
4515 * pm and the system suspend/resume code.
4516 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004517void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004518{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004519 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004520 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4521 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004522}