blob: 5513c4cb02e0f8d92ea34393d0cae63ac2d54999 [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
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +030048static const u32 hpd_ilk[HPD_NUM_PINS] = {
49 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
50};
51
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +030052static const u32 hpd_ivb[HPD_NUM_PINS] = {
53 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
54};
55
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +030056static const u32 hpd_bdw[HPD_NUM_PINS] = {
57 [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
58};
59
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020060static const u32 hpd_ibx[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050061 [HPD_CRT] = SDE_CRT_HOTPLUG,
62 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
63 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
64 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
65 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
66};
67
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020068static const u32 hpd_cpt[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050069 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010070 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050071 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
72 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
73 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
74};
75
Xiong Zhang26951ca2015-08-17 15:55:50 +080076static const u32 hpd_spt[HPD_NUM_PINS] = {
Ville Syrjälä74c0b392015-08-27 23:56:07 +030077 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
Xiong Zhang26951ca2015-08-17 15:55:50 +080078 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
79 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
80 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
81 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
82};
83
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020084static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050085 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
86 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
87 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
88 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
89 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
90 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
91};
92
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020093static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050094 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
95 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
96 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
97 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
98 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
99 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
100};
101
Ville Syrjälä4bca26d2015-05-11 20:49:10 +0300102static const u32 hpd_status_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -0500103 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
104 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
105 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
106 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
107 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
108 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
109};
110
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200111/* BXT hpd list */
112static const u32 hpd_bxt[HPD_NUM_PINS] = {
Sonika Jindal7f3561b2015-08-10 10:35:35 +0530113 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200114 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
115 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
116};
117
Paulo Zanoni5c502442014-04-01 15:37:11 -0300118/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300119#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300120 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
121 POSTING_READ(GEN8_##type##_IMR(which)); \
122 I915_WRITE(GEN8_##type##_IER(which), 0); \
123 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
124 POSTING_READ(GEN8_##type##_IIR(which)); \
125 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
126 POSTING_READ(GEN8_##type##_IIR(which)); \
127} while (0)
128
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300129#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300130 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300131 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300132 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300133 I915_WRITE(type##IIR, 0xffffffff); \
134 POSTING_READ(type##IIR); \
135 I915_WRITE(type##IIR, 0xffffffff); \
136 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300137} while (0)
138
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +0200139static void
140intel_finish_page_flip_cs(struct drm_i915_private *dev_priv, unsigned pipe)
141{
142 DRM_DEBUG_KMS("Finished page flip\n");
143}
144
Paulo Zanoni337ba012014-04-01 15:37:16 -0300145/*
146 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
147 */
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200148static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv,
149 i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300150{
151 u32 val = I915_READ(reg);
152
153 if (val == 0)
154 return;
155
156 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200157 i915_mmio_reg_offset(reg), val);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300158 I915_WRITE(reg, 0xffffffff);
159 POSTING_READ(reg);
160 I915_WRITE(reg, 0xffffffff);
161 POSTING_READ(reg);
162}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300163
Paulo Zanoni35079892014-04-01 15:37:15 -0300164#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300165 gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300166 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200167 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
168 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300169} while (0)
170
171#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300172 gen5_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300173 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200174 I915_WRITE(type##IMR, (imr_val)); \
175 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300176} while (0)
177
Imre Deakc9a9a262014-11-05 20:48:37 +0200178static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
179
Egbert Eich0706f172015-09-23 16:15:27 +0200180/* For display hotplug interrupt */
181static inline void
182i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
183 uint32_t mask,
184 uint32_t bits)
185{
186 uint32_t val;
187
188 assert_spin_locked(&dev_priv->irq_lock);
189 WARN_ON(bits & ~mask);
190
191 val = I915_READ(PORT_HOTPLUG_EN);
192 val &= ~mask;
193 val |= bits;
194 I915_WRITE(PORT_HOTPLUG_EN, val);
195}
196
197/**
198 * i915_hotplug_interrupt_update - update hotplug interrupt enable
199 * @dev_priv: driver private
200 * @mask: bits to update
201 * @bits: bits to enable
202 * NOTE: the HPD enable bits are modified both inside and outside
203 * of an interrupt context. To avoid that read-modify-write cycles
204 * interfer, these bits are protected by a spinlock. Since this
205 * function is usually not called from a context where the lock is
206 * held already, this function acquires the lock itself. A non-locking
207 * version is also available.
208 */
209void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
210 uint32_t mask,
211 uint32_t bits)
212{
213 spin_lock_irq(&dev_priv->irq_lock);
214 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
215 spin_unlock_irq(&dev_priv->irq_lock);
216}
217
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300218/**
219 * ilk_update_display_irq - update DEIMR
220 * @dev_priv: driver private
221 * @interrupt_mask: mask of interrupt bits to update
222 * @enabled_irq_mask: mask of interrupt bits to enable
223 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200224void ilk_update_display_irq(struct drm_i915_private *dev_priv,
225 uint32_t interrupt_mask,
226 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800227{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300228 uint32_t new_val;
229
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200230 assert_spin_locked(&dev_priv->irq_lock);
231
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300232 WARN_ON(enabled_irq_mask & ~interrupt_mask);
233
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700234 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300235 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300236
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300237 new_val = dev_priv->irq_mask;
238 new_val &= ~interrupt_mask;
239 new_val |= (~enabled_irq_mask & interrupt_mask);
240
241 if (new_val != dev_priv->irq_mask) {
242 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000243 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000244 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800245 }
246}
247
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300248/**
249 * ilk_update_gt_irq - update GTIMR
250 * @dev_priv: driver private
251 * @interrupt_mask: mask of interrupt bits to update
252 * @enabled_irq_mask: mask of interrupt bits to enable
253 */
254static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
255 uint32_t interrupt_mask,
256 uint32_t enabled_irq_mask)
257{
258 assert_spin_locked(&dev_priv->irq_lock);
259
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100260 WARN_ON(enabled_irq_mask & ~interrupt_mask);
261
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700262 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300263 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300264
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300265 dev_priv->gt_irq_mask &= ~interrupt_mask;
266 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
267 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
268 POSTING_READ(GTIMR);
269}
270
Daniel Vetter480c8032014-07-16 09:49:40 +0200271void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300272{
273 ilk_update_gt_irq(dev_priv, mask, mask);
274}
275
Daniel Vetter480c8032014-07-16 09:49:40 +0200276void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300277{
278 ilk_update_gt_irq(dev_priv, mask, 0);
279}
280
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200281static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200282{
283 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
284}
285
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200286static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200287{
288 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
289}
290
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200291static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200292{
293 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
294}
295
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300296/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200297 * snb_update_pm_irq - update GEN6_PMIMR
298 * @dev_priv: driver private
299 * @interrupt_mask: mask of interrupt bits to update
300 * @enabled_irq_mask: mask of interrupt bits to enable
301 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300302static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
303 uint32_t interrupt_mask,
304 uint32_t enabled_irq_mask)
305{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300306 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300307
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100308 WARN_ON(enabled_irq_mask & ~interrupt_mask);
309
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300310 assert_spin_locked(&dev_priv->irq_lock);
311
Paulo Zanoni605cd252013-08-06 18:57:15 -0300312 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300313 new_val &= ~interrupt_mask;
314 new_val |= (~enabled_irq_mask & interrupt_mask);
315
Paulo Zanoni605cd252013-08-06 18:57:15 -0300316 if (new_val != dev_priv->pm_irq_mask) {
317 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200318 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
319 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300320 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300321}
322
Daniel Vetter480c8032014-07-16 09:49:40 +0200323void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300324{
Imre Deak9939fba2014-11-20 23:01:47 +0200325 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
326 return;
327
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300328 snb_update_pm_irq(dev_priv, mask, mask);
329}
330
Imre Deak9939fba2014-11-20 23:01:47 +0200331static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
332 uint32_t mask)
333{
334 snb_update_pm_irq(dev_priv, mask, 0);
335}
336
Daniel Vetter480c8032014-07-16 09:49:40 +0200337void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300338{
Imre Deak9939fba2014-11-20 23:01:47 +0200339 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
340 return;
341
342 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300343}
344
Chris Wilsondc979972016-05-10 14:10:04 +0100345void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200346{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200347 i915_reg_t reg = gen6_pm_iir(dev_priv);
Imre Deak3cc134e2014-11-19 15:30:03 +0200348
349 spin_lock_irq(&dev_priv->irq_lock);
350 I915_WRITE(reg, dev_priv->pm_rps_events);
351 I915_WRITE(reg, dev_priv->pm_rps_events);
352 POSTING_READ(reg);
Imre Deak096fad92015-03-23 19:11:35 +0200353 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200354 spin_unlock_irq(&dev_priv->irq_lock);
355}
356
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100357void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200358{
Imre Deakb900b942014-11-05 20:48:48 +0200359 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak78e68d32014-12-15 18:59:27 +0200360
Imre Deakb900b942014-11-05 20:48:48 +0200361 WARN_ON(dev_priv->rps.pm_iir);
Imre Deak3cc134e2014-11-19 15:30:03 +0200362 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200363 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200364 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
365 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200366 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200367
Imre Deakb900b942014-11-05 20:48:48 +0200368 spin_unlock_irq(&dev_priv->irq_lock);
369}
370
Imre Deak59d02a12014-12-19 19:33:26 +0200371u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
372{
373 /*
Imre Deakf24eeb12014-12-19 19:33:27 +0200374 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
Imre Deak59d02a12014-12-19 19:33:26 +0200375 * if GEN6_PM_UP_EI_EXPIRED is masked.
Imre Deakf24eeb12014-12-19 19:33:27 +0200376 *
377 * TODO: verify if this can be reproduced on VLV,CHV.
Imre Deak59d02a12014-12-19 19:33:26 +0200378 */
379 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
380 mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
381
382 if (INTEL_INFO(dev_priv)->gen >= 8)
383 mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
384
385 return mask;
386}
387
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100388void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200389{
Imre Deakd4d70aa2014-11-19 15:30:04 +0200390 spin_lock_irq(&dev_priv->irq_lock);
391 dev_priv->rps.interrupts_enabled = false;
392 spin_unlock_irq(&dev_priv->irq_lock);
393
394 cancel_work_sync(&dev_priv->rps.work);
395
Imre Deak9939fba2014-11-20 23:01:47 +0200396 spin_lock_irq(&dev_priv->irq_lock);
397
Imre Deak59d02a12014-12-19 19:33:26 +0200398 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200399
400 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200401 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
402 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200403
404 spin_unlock_irq(&dev_priv->irq_lock);
405
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100406 synchronize_irq(dev_priv->dev->irq);
Imre Deakb900b942014-11-05 20:48:48 +0200407}
408
Ben Widawsky09610212014-05-15 20:58:08 +0300409/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200410 * bdw_update_port_irq - update DE port interrupt
411 * @dev_priv: driver private
412 * @interrupt_mask: mask of interrupt bits to update
413 * @enabled_irq_mask: mask of interrupt bits to enable
414 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300415static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
416 uint32_t interrupt_mask,
417 uint32_t enabled_irq_mask)
418{
419 uint32_t new_val;
420 uint32_t old_val;
421
422 assert_spin_locked(&dev_priv->irq_lock);
423
424 WARN_ON(enabled_irq_mask & ~interrupt_mask);
425
426 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
427 return;
428
429 old_val = I915_READ(GEN8_DE_PORT_IMR);
430
431 new_val = old_val;
432 new_val &= ~interrupt_mask;
433 new_val |= (~enabled_irq_mask & interrupt_mask);
434
435 if (new_val != old_val) {
436 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
437 POSTING_READ(GEN8_DE_PORT_IMR);
438 }
439}
440
441/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200442 * bdw_update_pipe_irq - update DE pipe interrupt
443 * @dev_priv: driver private
444 * @pipe: pipe whose interrupt to update
445 * @interrupt_mask: mask of interrupt bits to update
446 * @enabled_irq_mask: mask of interrupt bits to enable
447 */
448void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
449 enum pipe pipe,
450 uint32_t interrupt_mask,
451 uint32_t enabled_irq_mask)
452{
453 uint32_t new_val;
454
455 assert_spin_locked(&dev_priv->irq_lock);
456
457 WARN_ON(enabled_irq_mask & ~interrupt_mask);
458
459 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
460 return;
461
462 new_val = dev_priv->de_irq_mask[pipe];
463 new_val &= ~interrupt_mask;
464 new_val |= (~enabled_irq_mask & interrupt_mask);
465
466 if (new_val != dev_priv->de_irq_mask[pipe]) {
467 dev_priv->de_irq_mask[pipe] = new_val;
468 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
469 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
470 }
471}
472
473/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200474 * ibx_display_interrupt_update - update SDEIMR
475 * @dev_priv: driver private
476 * @interrupt_mask: mask of interrupt bits to update
477 * @enabled_irq_mask: mask of interrupt bits to enable
478 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200479void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
480 uint32_t interrupt_mask,
481 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200482{
483 uint32_t sdeimr = I915_READ(SDEIMR);
484 sdeimr &= ~interrupt_mask;
485 sdeimr |= (~enabled_irq_mask & interrupt_mask);
486
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100487 WARN_ON(enabled_irq_mask & ~interrupt_mask);
488
Daniel Vetterfee884e2013-07-04 23:35:21 +0200489 assert_spin_locked(&dev_priv->irq_lock);
490
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700491 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300492 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300493
Daniel Vetterfee884e2013-07-04 23:35:21 +0200494 I915_WRITE(SDEIMR, sdeimr);
495 POSTING_READ(SDEIMR);
496}
Paulo Zanoni86642812013-04-12 17:57:57 -0300497
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100498static void
Imre Deak755e9012014-02-10 18:42:47 +0200499__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
500 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800501{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200502 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200503 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800504
Daniel Vetterb79480b2013-06-27 17:52:10 +0200505 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200506 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200507
Ville Syrjälä04feced2014-04-03 13:28:33 +0300508 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
509 status_mask & ~PIPESTAT_INT_STATUS_MASK,
510 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
511 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200512 return;
513
514 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200515 return;
516
Imre Deak91d181d2014-02-10 18:42:49 +0200517 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
518
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200519 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200520 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200521 I915_WRITE(reg, pipestat);
522 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800523}
524
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100525static void
Imre Deak755e9012014-02-10 18:42:47 +0200526__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
527 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800528{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200529 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200530 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800531
Daniel Vetterb79480b2013-06-27 17:52:10 +0200532 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200533 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200534
Ville Syrjälä04feced2014-04-03 13:28:33 +0300535 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
536 status_mask & ~PIPESTAT_INT_STATUS_MASK,
537 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
538 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200539 return;
540
Imre Deak755e9012014-02-10 18:42:47 +0200541 if ((pipestat & enable_mask) == 0)
542 return;
543
Imre Deak91d181d2014-02-10 18:42:49 +0200544 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
545
Imre Deak755e9012014-02-10 18:42:47 +0200546 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200547 I915_WRITE(reg, pipestat);
548 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800549}
550
Imre Deak10c59c52014-02-10 18:42:48 +0200551static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
552{
553 u32 enable_mask = status_mask << 16;
554
555 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300556 * On pipe A we don't support the PSR interrupt yet,
557 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200558 */
559 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
560 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300561 /*
562 * On pipe B and C we don't support the PSR interrupt yet, on pipe
563 * A the same bit is for perf counters which we don't use either.
564 */
565 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
566 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200567
568 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
569 SPRITE0_FLIP_DONE_INT_EN_VLV |
570 SPRITE1_FLIP_DONE_INT_EN_VLV);
571 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
572 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
573 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
574 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
575
576 return enable_mask;
577}
578
Imre Deak755e9012014-02-10 18:42:47 +0200579void
580i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
581 u32 status_mask)
582{
583 u32 enable_mask;
584
Wayne Boyer666a4532015-12-09 12:29:35 -0800585 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Imre Deak10c59c52014-02-10 18:42:48 +0200586 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
587 status_mask);
588 else
589 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200590 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
591}
592
593void
594i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
595 u32 status_mask)
596{
597 u32 enable_mask;
598
Wayne Boyer666a4532015-12-09 12:29:35 -0800599 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Imre Deak10c59c52014-02-10 18:42:48 +0200600 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
601 status_mask);
602 else
603 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200604 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
605}
606
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000607/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300608 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Javier Martinez Canillas468f9d22015-10-08 09:54:44 +0200609 * @dev: drm device
Zhao Yakui01c66882009-10-28 05:10:00 +0000610 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100611static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000612{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100613 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300614 return;
615
Daniel Vetter13321782014-09-15 14:55:29 +0200616 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000617
Imre Deak755e9012014-02-10 18:42:47 +0200618 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100619 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200620 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200621 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000622
Daniel Vetter13321782014-09-15 14:55:29 +0200623 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000624}
625
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300626/*
627 * This timing diagram depicts the video signal in and
628 * around the vertical blanking period.
629 *
630 * Assumptions about the fictitious mode used in this example:
631 * vblank_start >= 3
632 * vsync_start = vblank_start + 1
633 * vsync_end = vblank_start + 2
634 * vtotal = vblank_start + 3
635 *
636 * start of vblank:
637 * latch double buffered registers
638 * increment frame counter (ctg+)
639 * generate start of vblank interrupt (gen4+)
640 * |
641 * | frame start:
642 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
643 * | may be shifted forward 1-3 extra lines via PIPECONF
644 * | |
645 * | | start of vsync:
646 * | | generate vsync interrupt
647 * | | |
648 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
649 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
650 * ----va---> <-----------------vb--------------------> <--------va-------------
651 * | | <----vs-----> |
652 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
653 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
654 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
655 * | | |
656 * last visible pixel first visible pixel
657 * | increment frame counter (gen3/4)
658 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
659 *
660 * x = horizontal active
661 * _ = horizontal blanking
662 * hs = horizontal sync
663 * va = vertical active
664 * vb = vertical blanking
665 * vs = vertical sync
666 * vbs = vblank_start (number)
667 *
668 * Summary:
669 * - most events happen at the start of horizontal sync
670 * - frame start happens at the start of horizontal blank, 1-4 lines
671 * (depending on PIPECONF settings) after the start of vblank
672 * - gen3/4 pixel and frame counter are synchronized with the start
673 * of horizontal active on the first line of vertical active
674 */
675
Thierry Reding88e72712015-09-24 18:35:31 +0200676static u32 i8xx_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300677{
678 /* Gen2 doesn't have a hardware frame counter */
679 return 0;
680}
681
Keith Packard42f52ef2008-10-18 19:39:29 -0700682/* Called from drm generic code, passed a 'crtc', which
683 * we use as a pipe index
684 */
Thierry Reding88e72712015-09-24 18:35:31 +0200685static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700686{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300687 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200688 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300689 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100690 struct intel_crtc *intel_crtc =
691 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200692 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700693
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100694 htotal = mode->crtc_htotal;
695 hsync_start = mode->crtc_hsync_start;
696 vbl_start = mode->crtc_vblank_start;
697 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
698 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300699
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300700 /* Convert to pixel count */
701 vbl_start *= htotal;
702
703 /* Start of vblank event occurs at start of hsync */
704 vbl_start -= htotal - hsync_start;
705
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800706 high_frame = PIPEFRAME(pipe);
707 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100708
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700709 /*
710 * High & low register fields aren't synchronized, so make sure
711 * we get a low value that's stable across two reads of the high
712 * register.
713 */
714 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100715 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300716 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100717 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700718 } while (high1 != high2);
719
Chris Wilson5eddb702010-09-11 13:48:45 +0100720 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300721 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100722 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300723
724 /*
725 * The frame counter increments at beginning of active.
726 * Cook up a vblank counter by also checking the pixel
727 * counter against vblank start.
728 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200729 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700730}
731
Dave Airlie974e59b2015-10-30 09:45:33 +1000732static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800733{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300734 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800735
Ville Syrjälä649636e2015-09-22 19:50:01 +0300736 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800737}
738
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300739/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300740static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
741{
742 struct drm_device *dev = crtc->base.dev;
743 struct drm_i915_private *dev_priv = dev->dev_private;
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200744 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300745 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300746 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300747
Ville Syrjälä80715b22014-05-15 20:23:23 +0300748 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300749 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
750 vtotal /= 2;
751
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100752 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300753 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300754 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300755 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300756
757 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700758 * On HSW, the DSL reg (0x70000) appears to return 0 if we
759 * read it just before the start of vblank. So try it again
760 * so we don't accidentally end up spanning a vblank frame
761 * increment, causing the pipe_update_end() code to squak at us.
762 *
763 * The nature of this problem means we can't simply check the ISR
764 * bit and return the vblank start value; nor can we use the scanline
765 * debug register in the transcoder as it appears to have the same
766 * problem. We may need to extend this to include other platforms,
767 * but so far testing only shows the problem on HSW.
768 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100769 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700770 int i, temp;
771
772 for (i = 0; i < 100; i++) {
773 udelay(1);
774 temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) &
775 DSL_LINEMASK_GEN3;
776 if (temp != position) {
777 position = temp;
778 break;
779 }
780 }
781 }
782
783 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300784 * See update_scanline_offset() for the details on the
785 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300786 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300787 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300788}
789
Thierry Reding88e72712015-09-24 18:35:31 +0200790static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200791 unsigned int flags, int *vpos, int *hpos,
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300792 ktime_t *stime, ktime_t *etime,
793 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100794{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300795 struct drm_i915_private *dev_priv = dev->dev_private;
796 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
797 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300798 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300799 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100800 bool in_vbl = true;
801 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100802 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100803
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200804 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100805 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800806 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100807 return 0;
808 }
809
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300810 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300811 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300812 vtotal = mode->crtc_vtotal;
813 vbl_start = mode->crtc_vblank_start;
814 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100815
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200816 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
817 vbl_start = DIV_ROUND_UP(vbl_start, 2);
818 vbl_end /= 2;
819 vtotal /= 2;
820 }
821
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300822 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
823
Mario Kleinerad3543e2013-10-30 05:13:08 +0100824 /*
825 * Lock uncore.lock, as we will do multiple timing critical raw
826 * register reads, potentially with preemption disabled, so the
827 * following code must not block on uncore.lock.
828 */
829 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300830
Mario Kleinerad3543e2013-10-30 05:13:08 +0100831 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
832
833 /* Get optional system timestamp before query. */
834 if (stime)
835 *stime = ktime_get();
836
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100837 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100838 /* No obvious pixelcount register. Only query vertical
839 * scanout position from Display scan line register.
840 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300841 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100842 } else {
843 /* Have access to pixelcount since start of frame.
844 * We can split this into vertical and horizontal
845 * scanout position.
846 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300847 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100848
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300849 /* convert to pixel counts */
850 vbl_start *= htotal;
851 vbl_end *= htotal;
852 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300853
854 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300855 * In interlaced modes, the pixel counter counts all pixels,
856 * so one field will have htotal more pixels. In order to avoid
857 * the reported position from jumping backwards when the pixel
858 * counter is beyond the length of the shorter field, just
859 * clamp the position the length of the shorter field. This
860 * matches how the scanline counter based position works since
861 * the scanline counter doesn't count the two half lines.
862 */
863 if (position >= vtotal)
864 position = vtotal - 1;
865
866 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300867 * Start of vblank interrupt is triggered at start of hsync,
868 * just prior to the first active line of vblank. However we
869 * consider lines to start at the leading edge of horizontal
870 * active. So, should we get here before we've crossed into
871 * the horizontal active of the first line in vblank, we would
872 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
873 * always add htotal-hsync_start to the current pixel position.
874 */
875 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300876 }
877
Mario Kleinerad3543e2013-10-30 05:13:08 +0100878 /* Get optional system timestamp after query. */
879 if (etime)
880 *etime = ktime_get();
881
882 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
883
884 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
885
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300886 in_vbl = position >= vbl_start && position < vbl_end;
887
888 /*
889 * While in vblank, position will be negative
890 * counting up towards 0 at vbl_end. And outside
891 * vblank, position will be positive counting
892 * up since vbl_end.
893 */
894 if (position >= vbl_start)
895 position -= vbl_end;
896 else
897 position += vtotal - vbl_end;
898
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100899 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300900 *vpos = position;
901 *hpos = 0;
902 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100903 *vpos = position / htotal;
904 *hpos = position - (*vpos * htotal);
905 }
906
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100907 /* In vblank? */
908 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200909 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100910
911 return ret;
912}
913
Ville Syrjäläa225f072014-04-29 13:35:45 +0300914int intel_get_crtc_scanline(struct intel_crtc *crtc)
915{
916 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
917 unsigned long irqflags;
918 int position;
919
920 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
921 position = __intel_get_crtc_scanline(crtc);
922 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
923
924 return position;
925}
926
Thierry Reding88e72712015-09-24 18:35:31 +0200927static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100928 int *max_error,
929 struct timeval *vblank_time,
930 unsigned flags)
931{
Chris Wilson4041b852011-01-22 10:07:56 +0000932 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100933
Thierry Reding88e72712015-09-24 18:35:31 +0200934 if (pipe >= INTEL_INFO(dev)->num_pipes) {
935 DRM_ERROR("Invalid crtc %u\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100936 return -EINVAL;
937 }
938
939 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000940 crtc = intel_get_crtc_for_pipe(dev, pipe);
941 if (crtc == NULL) {
Thierry Reding88e72712015-09-24 18:35:31 +0200942 DRM_ERROR("Invalid crtc %u\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000943 return -EINVAL;
944 }
945
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200946 if (!crtc->hwmode.crtc_clock) {
Thierry Reding88e72712015-09-24 18:35:31 +0200947 DRM_DEBUG_KMS("crtc %u is disabled\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000948 return -EBUSY;
949 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100950
951 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000952 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
953 vblank_time, flags,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200954 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100955}
956
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100957static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800958{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000959 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200960 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200961
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200962 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800963
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200964 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
965
Daniel Vetter20e4d402012-08-08 23:35:39 +0200966 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200967
Jesse Barnes7648fa92010-05-20 14:28:11 -0700968 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000969 busy_up = I915_READ(RCPREVBSYTUPAVG);
970 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800971 max_avg = I915_READ(RCBMAXAVG);
972 min_avg = I915_READ(RCBMINAVG);
973
974 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000975 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200976 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
977 new_delay = dev_priv->ips.cur_delay - 1;
978 if (new_delay < dev_priv->ips.max_delay)
979 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000980 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200981 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
982 new_delay = dev_priv->ips.cur_delay + 1;
983 if (new_delay > dev_priv->ips.min_delay)
984 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800985 }
986
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100987 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200988 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800989
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200990 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200991
Jesse Barnesf97108d2010-01-29 11:27:07 -0800992 return;
993}
994
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000995static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +0100996{
Tvrtko Ursulin117897f2016-03-16 11:00:40 +0000997 if (!intel_engine_initialized(engine))
Chris Wilson475553d2011-01-20 09:52:56 +0000998 return;
999
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001000 trace_i915_gem_request_notify(engine);
Chris Wilson12471ba2016-04-09 10:57:55 +01001001 engine->user_interrupts++;
Chris Wilson9862e602011-01-04 22:22:17 +00001002
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001003 wake_up_all(&engine->irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +01001004}
1005
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001006static void vlv_c0_read(struct drm_i915_private *dev_priv,
1007 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001008{
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001009 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
1010 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1011 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001012}
1013
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001014static bool vlv_c0_above(struct drm_i915_private *dev_priv,
1015 const struct intel_rps_ei *old,
1016 const struct intel_rps_ei *now,
1017 int threshold)
Deepak S31685c22014-07-03 17:33:01 -04001018{
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001019 u64 time, c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001020 unsigned int mul = 100;
Deepak S31685c22014-07-03 17:33:01 -04001021
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001022 if (old->cz_clock == 0)
1023 return false;
Deepak S31685c22014-07-03 17:33:01 -04001024
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001025 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
1026 mul <<= 8;
1027
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001028 time = now->cz_clock - old->cz_clock;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001029 time *= threshold * dev_priv->czclk_freq;
Deepak S31685c22014-07-03 17:33:01 -04001030
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001031 /* Workload can be split between render + media, e.g. SwapBuffers
1032 * being blitted in X after being rendered in mesa. To account for
1033 * this we need to combine both engines into our activity counter.
1034 */
1035 c0 = now->render_c0 - old->render_c0;
1036 c0 += now->media_c0 - old->media_c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001037 c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC;
Deepak S31685c22014-07-03 17:33:01 -04001038
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001039 return c0 >= time;
1040}
Deepak S31685c22014-07-03 17:33:01 -04001041
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001042void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1043{
1044 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
1045 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001046}
1047
1048static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1049{
1050 struct intel_rps_ei now;
1051 u32 events = 0;
1052
Chris Wilson6f4b12f82015-03-18 09:48:23 +00001053 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001054 return 0;
1055
1056 vlv_c0_read(dev_priv, &now);
1057 if (now.cz_clock == 0)
1058 return 0;
Deepak S31685c22014-07-03 17:33:01 -04001059
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001060 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1061 if (!vlv_c0_above(dev_priv,
1062 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001063 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001064 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1065 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -04001066 }
1067
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001068 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1069 if (vlv_c0_above(dev_priv,
1070 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001071 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001072 events |= GEN6_PM_RP_UP_THRESHOLD;
1073 dev_priv->rps.up_ei = now;
1074 }
1075
1076 return events;
Deepak S31685c22014-07-03 17:33:01 -04001077}
1078
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001079static bool any_waiters(struct drm_i915_private *dev_priv)
1080{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001081 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001082
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001083 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001084 if (engine->irq_refcount)
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001085 return true;
1086
1087 return false;
1088}
1089
Ben Widawsky4912d042011-04-25 11:25:20 -07001090static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001091{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001092 struct drm_i915_private *dev_priv =
1093 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001094 bool client_boost;
1095 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001096 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001097
Daniel Vetter59cdb632013-07-04 23:35:28 +02001098 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001099 /* Speed up work cancelation during disabling rps interrupts. */
1100 if (!dev_priv->rps.interrupts_enabled) {
1101 spin_unlock_irq(&dev_priv->irq_lock);
1102 return;
1103 }
Imre Deak1f814da2015-12-16 02:52:19 +02001104
1105 /*
1106 * The RPS work is synced during runtime suspend, we don't require a
1107 * wakeref. TODO: instead of disabling the asserts make sure that we
1108 * always hold an RPM reference while the work is running.
1109 */
1110 DISABLE_RPM_WAKEREF_ASSERTS(dev_priv);
1111
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001112 pm_iir = dev_priv->rps.pm_iir;
1113 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001114 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1115 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001116 client_boost = dev_priv->rps.client_boost;
1117 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001118 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001119
Paulo Zanoni60611c12013-08-15 11:50:01 -03001120 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301121 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001122
Chris Wilson8d3afd72015-05-21 21:01:47 +01001123 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Imre Deak1f814da2015-12-16 02:52:19 +02001124 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001125
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001126 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001127
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001128 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1129
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001130 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001131 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001132 min = dev_priv->rps.min_freq_softlimit;
1133 max = dev_priv->rps.max_freq_softlimit;
1134
1135 if (client_boost) {
1136 new_delay = dev_priv->rps.max_freq_softlimit;
1137 adj = 0;
1138 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001139 if (adj > 0)
1140 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001141 else /* CHV needs even encode values */
1142 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001143 /*
1144 * For better performance, jump directly
1145 * to RPe if we're below it.
1146 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001147 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001148 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001149 adj = 0;
1150 }
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001151 } else if (any_waiters(dev_priv)) {
1152 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001153 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001154 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1155 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001156 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001157 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001158 adj = 0;
1159 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1160 if (adj < 0)
1161 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001162 else /* CHV needs even encode values */
1163 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001164 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001165 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001166 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001167
Chris Wilsonedcf2842015-04-07 16:20:29 +01001168 dev_priv->rps.last_adj = adj;
1169
Ben Widawsky79249632012-09-07 19:43:42 -07001170 /* sysfs frequency interfaces may have snuck in while servicing the
1171 * interrupt
1172 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001173 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001174 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301175
Chris Wilsondc979972016-05-10 14:10:04 +01001176 intel_set_rps(dev_priv, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001177
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001178 mutex_unlock(&dev_priv->rps.hw_lock);
Imre Deak1f814da2015-12-16 02:52:19 +02001179out:
1180 ENABLE_RPM_WAKEREF_ASSERTS(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001181}
1182
Ben Widawskye3689192012-05-25 16:56:22 -07001183
1184/**
1185 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1186 * occurred.
1187 * @work: workqueue struct
1188 *
1189 * Doesn't actually do anything except notify userspace. As a consequence of
1190 * this event, userspace should try to remap the bad rows since statistically
1191 * it is likely the same row is more likely to go bad again.
1192 */
1193static void ivybridge_parity_work(struct work_struct *work)
1194{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001195 struct drm_i915_private *dev_priv =
1196 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001197 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001198 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001199 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001200 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001201
1202 /* We must turn off DOP level clock gating to access the L3 registers.
1203 * In order to prevent a get/put style interface, acquire struct mutex
1204 * any time we access those registers.
1205 */
1206 mutex_lock(&dev_priv->dev->struct_mutex);
1207
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001208 /* If we've screwed up tracking, just let the interrupt fire again */
1209 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1210 goto out;
1211
Ben Widawskye3689192012-05-25 16:56:22 -07001212 misccpctl = I915_READ(GEN7_MISCCPCTL);
1213 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1214 POSTING_READ(GEN7_MISCCPCTL);
1215
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001216 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001217 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001218
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001219 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001220 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001221 break;
1222
1223 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1224
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001225 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001226
1227 error_status = I915_READ(reg);
1228 row = GEN7_PARITY_ERROR_ROW(error_status);
1229 bank = GEN7_PARITY_ERROR_BANK(error_status);
1230 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1231
1232 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1233 POSTING_READ(reg);
1234
1235 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1236 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1237 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1238 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1239 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1240 parity_event[5] = NULL;
1241
Dave Airlie5bdebb12013-10-11 14:07:25 +10001242 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001243 KOBJ_CHANGE, parity_event);
1244
1245 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1246 slice, row, bank, subbank);
1247
1248 kfree(parity_event[4]);
1249 kfree(parity_event[3]);
1250 kfree(parity_event[2]);
1251 kfree(parity_event[1]);
1252 }
Ben Widawskye3689192012-05-25 16:56:22 -07001253
1254 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1255
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001256out:
1257 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001258 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001259 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001260 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001261
1262 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001263}
1264
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001265static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1266 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001267{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001268 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001269 return;
1270
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001271 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001272 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001273 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001274
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001275 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001276 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1277 dev_priv->l3_parity.which_slice |= 1 << 1;
1278
1279 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1280 dev_priv->l3_parity.which_slice |= 1 << 0;
1281
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001282 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001283}
1284
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001285static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001286 u32 gt_iir)
1287{
1288 if (gt_iir &
1289 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001290 notify_ring(&dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001291 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001292 notify_ring(&dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001293}
1294
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001295static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001296 u32 gt_iir)
1297{
1298
Ben Widawskycc609d52013-05-28 19:22:29 -07001299 if (gt_iir &
1300 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001301 notify_ring(&dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001302 if (gt_iir & GT_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001303 notify_ring(&dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001304 if (gt_iir & GT_BLT_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001305 notify_ring(&dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001306
Ben Widawskycc609d52013-05-28 19:22:29 -07001307 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1308 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001309 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1310 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001311
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001312 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1313 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001314}
1315
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001316static __always_inline void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001317gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001318{
1319 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift))
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001320 notify_ring(engine);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001321 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift))
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01001322 tasklet_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001323}
1324
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001325static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1326 u32 master_ctl,
1327 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001328{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001329 irqreturn_t ret = IRQ_NONE;
1330
1331 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001332 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1333 if (gt_iir[0]) {
1334 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001335 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001336 } else
1337 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1338 }
1339
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001340 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001341 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1342 if (gt_iir[1]) {
1343 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001344 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001345 } else
1346 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1347 }
1348
Chris Wilson74cdb332015-04-07 16:21:05 +01001349 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001350 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1351 if (gt_iir[3]) {
1352 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001353 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001354 } else
1355 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1356 }
1357
Ben Widawsky09610212014-05-15 20:58:08 +03001358 if (master_ctl & GEN8_GT_PM_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001359 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
1360 if (gt_iir[2] & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001361 I915_WRITE_FW(GEN8_GT_IIR(2),
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001362 gt_iir[2] & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001363 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001364 } else
1365 DRM_ERROR("The master control interrupt lied (PM)!\n");
1366 }
1367
Ben Widawskyabd58f02013-11-02 21:07:09 -07001368 return ret;
1369}
1370
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001371static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1372 u32 gt_iir[4])
1373{
1374 if (gt_iir[0]) {
1375 gen8_cs_irq_handler(&dev_priv->engine[RCS],
1376 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
1377 gen8_cs_irq_handler(&dev_priv->engine[BCS],
1378 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1379 }
1380
1381 if (gt_iir[1]) {
1382 gen8_cs_irq_handler(&dev_priv->engine[VCS],
1383 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
1384 gen8_cs_irq_handler(&dev_priv->engine[VCS2],
1385 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1386 }
1387
1388 if (gt_iir[3])
1389 gen8_cs_irq_handler(&dev_priv->engine[VECS],
1390 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1391
1392 if (gt_iir[2] & dev_priv->pm_rps_events)
1393 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
1394}
1395
Imre Deak63c88d22015-07-20 14:43:39 -07001396static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1397{
1398 switch (port) {
1399 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001400 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001401 case PORT_B:
1402 return val & PORTB_HOTPLUG_LONG_DETECT;
1403 case PORT_C:
1404 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001405 default:
1406 return false;
1407 }
1408}
1409
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001410static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1411{
1412 switch (port) {
1413 case PORT_E:
1414 return val & PORTE_HOTPLUG_LONG_DETECT;
1415 default:
1416 return false;
1417 }
1418}
1419
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001420static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1421{
1422 switch (port) {
1423 case PORT_A:
1424 return val & PORTA_HOTPLUG_LONG_DETECT;
1425 case PORT_B:
1426 return val & PORTB_HOTPLUG_LONG_DETECT;
1427 case PORT_C:
1428 return val & PORTC_HOTPLUG_LONG_DETECT;
1429 case PORT_D:
1430 return val & PORTD_HOTPLUG_LONG_DETECT;
1431 default:
1432 return false;
1433 }
1434}
1435
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001436static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1437{
1438 switch (port) {
1439 case PORT_A:
1440 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1441 default:
1442 return false;
1443 }
1444}
1445
Jani Nikula676574d2015-05-28 15:43:53 +03001446static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001447{
1448 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001449 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001450 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001451 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001452 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001453 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001454 return val & PORTD_HOTPLUG_LONG_DETECT;
1455 default:
1456 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001457 }
1458}
1459
Jani Nikula676574d2015-05-28 15:43:53 +03001460static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001461{
1462 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001463 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001464 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001465 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001466 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001467 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001468 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1469 default:
1470 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001471 }
1472}
1473
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001474/*
1475 * Get a bit mask of pins that have triggered, and which ones may be long.
1476 * This can be called multiple times with the same masks to accumulate
1477 * hotplug detection results from several registers.
1478 *
1479 * Note that the caller is expected to zero out the masks initially.
1480 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001481static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001482 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001483 const u32 hpd[HPD_NUM_PINS],
1484 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001485{
Jani Nikula8c841e52015-06-18 13:06:17 +03001486 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001487 int i;
1488
Jani Nikula676574d2015-05-28 15:43:53 +03001489 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001490 if ((hpd[i] & hotplug_trigger) == 0)
1491 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001492
Jani Nikula8c841e52015-06-18 13:06:17 +03001493 *pin_mask |= BIT(i);
1494
Imre Deakcc24fcd2015-07-21 15:32:45 -07001495 if (!intel_hpd_pin_to_port(i, &port))
1496 continue;
1497
Imre Deakfd63e2a2015-07-21 15:32:44 -07001498 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001499 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001500 }
1501
1502 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1503 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1504
1505}
1506
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001507static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001508{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001509 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001510}
1511
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001512static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001513{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001514 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001515}
1516
Shuang He8bf1e9f2013-10-15 18:55:27 +01001517#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001518static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1519 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001520 uint32_t crc0, uint32_t crc1,
1521 uint32_t crc2, uint32_t crc3,
1522 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001523{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001524 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1525 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001526 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001527
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001528 spin_lock(&pipe_crc->lock);
1529
Damien Lespiau0c912c72013-10-15 18:55:37 +01001530 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001531 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001532 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001533 return;
1534 }
1535
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001536 head = pipe_crc->head;
1537 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001538
1539 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001540 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001541 DRM_ERROR("CRC buffer overflowing\n");
1542 return;
1543 }
1544
1545 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001546
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001547 entry->frame = dev_priv->dev->driver->get_vblank_counter(dev_priv->dev,
1548 pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001549 entry->crc[0] = crc0;
1550 entry->crc[1] = crc1;
1551 entry->crc[2] = crc2;
1552 entry->crc[3] = crc3;
1553 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001554
1555 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001556 pipe_crc->head = head;
1557
1558 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001559
1560 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001561}
Daniel Vetter277de952013-10-18 16:37:07 +02001562#else
1563static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001564display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1565 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001566 uint32_t crc0, uint32_t crc1,
1567 uint32_t crc2, uint32_t crc3,
1568 uint32_t crc4) {}
1569#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001570
Daniel Vetter277de952013-10-18 16:37:07 +02001571
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001572static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1573 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001574{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001575 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001576 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1577 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001578}
1579
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001580static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1581 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001582{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001583 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001584 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1585 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1586 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1587 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1588 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001589}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001590
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001591static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1592 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001593{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001594 uint32_t res1, res2;
1595
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001596 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001597 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1598 else
1599 res1 = 0;
1600
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001601 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001602 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1603 else
1604 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001605
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001606 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001607 I915_READ(PIPE_CRC_RES_RED(pipe)),
1608 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1609 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1610 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001611}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001612
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001613/* The RPS events need forcewake, so we add them to a work queue and mask their
1614 * IMR bits until the work is done. Other interrupts can be processed without
1615 * the work queue. */
1616static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001617{
Deepak Sa6706b42014-03-15 20:23:22 +05301618 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001619 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001620 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001621 if (dev_priv->rps.interrupts_enabled) {
1622 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1623 queue_work(dev_priv->wq, &dev_priv->rps.work);
1624 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001625 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001626 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001627
Imre Deakc9a9a262014-11-05 20:48:37 +02001628 if (INTEL_INFO(dev_priv)->gen >= 8)
1629 return;
1630
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001631 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001632 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001633 notify_ring(&dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001634
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001635 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1636 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001637 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001638}
1639
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02001640static void intel_pipe_handle_vblank(struct drm_i915_private *dev_priv,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001641 enum pipe pipe)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001642{
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02001643 if (drm_handle_vblank(dev_priv->dev, pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001644 intel_finish_page_flip_mmio(dev_priv, pipe);
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001645}
1646
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001647static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1648 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001649{
Imre Deakc1874ed2014-02-04 21:35:46 +02001650 int pipe;
1651
Imre Deak58ead0d2014-02-04 21:35:47 +02001652 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001653
1654 if (!dev_priv->display_irqs_enabled) {
1655 spin_unlock(&dev_priv->irq_lock);
1656 return;
1657 }
1658
Damien Lespiau055e3932014-08-18 13:49:10 +01001659 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001660 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001661 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001662
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001663 /*
1664 * PIPESTAT bits get signalled even when the interrupt is
1665 * disabled with the mask bits, and some of the status bits do
1666 * not generate interrupts at all (like the underrun bit). Hence
1667 * we need to be careful that we only handle what we want to
1668 * handle.
1669 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001670
1671 /* fifo underruns are filterered in the underrun handler. */
1672 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001673
1674 switch (pipe) {
1675 case PIPE_A:
1676 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1677 break;
1678 case PIPE_B:
1679 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1680 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001681 case PIPE_C:
1682 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1683 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001684 }
1685 if (iir & iir_bit)
1686 mask |= dev_priv->pipestat_irq_mask[pipe];
1687
1688 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001689 continue;
1690
1691 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001692 mask |= PIPESTAT_INT_ENABLE_MASK;
1693 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001694
1695 /*
1696 * Clear the PIPE*STAT regs before the IIR
1697 */
Imre Deak91d181d2014-02-10 18:42:49 +02001698 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1699 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001700 I915_WRITE(reg, pipe_stats[pipe]);
1701 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001702 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001703}
1704
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001705static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001706 u32 pipe_stats[I915_MAX_PIPES])
1707{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001708 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001709
Damien Lespiau055e3932014-08-18 13:49:10 +01001710 for_each_pipe(dev_priv, pipe) {
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02001711 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1712 intel_pipe_handle_vblank(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001713
Maarten Lankhorst5251f042016-05-17 15:07:47 +02001714 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001715 intel_finish_page_flip_cs(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001716
1717 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001718 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001719
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001720 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1721 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001722 }
1723
1724 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001725 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001726}
1727
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001728static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001729{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001730 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001731
1732 if (hotplug_status)
1733 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1734
1735 return hotplug_status;
1736}
1737
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001738static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001739 u32 hotplug_status)
1740{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001741 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001742
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001743 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1744 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001745 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001746
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001747 if (hotplug_trigger) {
1748 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1749 hotplug_trigger, hpd_status_g4x,
1750 i9xx_port_hotplug_long_detect);
1751
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001752 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001753 }
Jani Nikula369712e2015-05-27 15:03:40 +03001754
1755 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001756 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001757 } else {
1758 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001759
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001760 if (hotplug_trigger) {
1761 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001762 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001763 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001764 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001765 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001766 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001767}
1768
Daniel Vetterff1f5252012-10-02 15:10:55 +02001769static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001770{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001771 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001772 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001773 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001774
Imre Deak2dd2a882015-02-24 11:14:30 +02001775 if (!intel_irqs_enabled(dev_priv))
1776 return IRQ_NONE;
1777
Imre Deak1f814da2015-12-16 02:52:19 +02001778 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1779 disable_rpm_wakeref_asserts(dev_priv);
1780
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001781 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001782 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001783 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001784 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001785 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001786
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001787 gt_iir = I915_READ(GTIIR);
1788 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001789 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001790
1791 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001792 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001793
1794 ret = IRQ_HANDLED;
1795
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001796 /*
1797 * Theory on interrupt generation, based on empirical evidence:
1798 *
1799 * x = ((VLV_IIR & VLV_IER) ||
1800 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1801 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1802 *
1803 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1804 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1805 * guarantee the CPU interrupt will be raised again even if we
1806 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1807 * bits this time around.
1808 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001809 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001810 ier = I915_READ(VLV_IER);
1811 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001812
1813 if (gt_iir)
1814 I915_WRITE(GTIIR, gt_iir);
1815 if (pm_iir)
1816 I915_WRITE(GEN6_PMIIR, pm_iir);
1817
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001818 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001819 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001820
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001821 /* Call regardless, as some status bits might not be
1822 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001823 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001824
1825 /*
1826 * VLV_IIR is single buffered, and reflects the level
1827 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1828 */
1829 if (iir)
1830 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001831
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001832 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001833 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1834 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001835
Ville Syrjälä52894872016-04-13 21:19:56 +03001836 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001837 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03001838 if (pm_iir)
1839 gen6_rps_irq_handler(dev_priv, pm_iir);
1840
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001841 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001842 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001843
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001844 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001845 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001846
Imre Deak1f814da2015-12-16 02:52:19 +02001847 enable_rpm_wakeref_asserts(dev_priv);
1848
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001849 return ret;
1850}
1851
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001852static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1853{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001854 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001855 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001856 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001857
Imre Deak2dd2a882015-02-24 11:14:30 +02001858 if (!intel_irqs_enabled(dev_priv))
1859 return IRQ_NONE;
1860
Imre Deak1f814da2015-12-16 02:52:19 +02001861 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1862 disable_rpm_wakeref_asserts(dev_priv);
1863
Chris Wilson579de732016-03-14 09:01:57 +00001864 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001865 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001866 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001867 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001868 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001869 u32 ier = 0;
1870
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001871 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1872 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001873
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001874 if (master_ctl == 0 && iir == 0)
1875 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001876
Oscar Mateo27b6c122014-06-16 16:11:00 +01001877 ret = IRQ_HANDLED;
1878
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001879 /*
1880 * Theory on interrupt generation, based on empirical evidence:
1881 *
1882 * x = ((VLV_IIR & VLV_IER) ||
1883 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1884 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1885 *
1886 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1887 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1888 * guarantee the CPU interrupt will be raised again even if we
1889 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1890 * bits this time around.
1891 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001892 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001893 ier = I915_READ(VLV_IER);
1894 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001895
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001896 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001897
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001898 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001899 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001900
Oscar Mateo27b6c122014-06-16 16:11:00 +01001901 /* Call regardless, as some status bits might not be
1902 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001903 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001904
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001905 /*
1906 * VLV_IIR is single buffered, and reflects the level
1907 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1908 */
1909 if (iir)
1910 I915_WRITE(VLV_IIR, iir);
1911
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001912 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03001913 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001914 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001915
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001916 gen8_gt_irq_handler(dev_priv, gt_iir);
1917
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001918 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001919 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001920
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001921 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00001922 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001923
Imre Deak1f814da2015-12-16 02:52:19 +02001924 enable_rpm_wakeref_asserts(dev_priv);
1925
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001926 return ret;
1927}
1928
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001929static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1930 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03001931 const u32 hpd[HPD_NUM_PINS])
1932{
Ville Syrjälä40e56412015-08-27 23:56:10 +03001933 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1934
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001935 /*
1936 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1937 * unless we touch the hotplug register, even if hotplug_trigger is
1938 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1939 * errors.
1940 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03001941 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001942 if (!hotplug_trigger) {
1943 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1944 PORTD_HOTPLUG_STATUS_MASK |
1945 PORTC_HOTPLUG_STATUS_MASK |
1946 PORTB_HOTPLUG_STATUS_MASK;
1947 dig_hotplug_reg &= ~mask;
1948 }
1949
Ville Syrjälä40e56412015-08-27 23:56:10 +03001950 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001951 if (!hotplug_trigger)
1952 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03001953
1954 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1955 dig_hotplug_reg, hpd,
1956 pch_port_hotplug_long_detect);
1957
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001958 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03001959}
1960
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001961static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001962{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001963 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001964 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001965
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001966 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001967
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001968 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1969 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1970 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001971 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001972 port_name(port));
1973 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001974
Daniel Vetterce99c252012-12-01 13:53:47 +01001975 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001976 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01001977
Jesse Barnes776ad802011-01-04 15:09:39 -08001978 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001979 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08001980
1981 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1982 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1983
1984 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1985 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1986
1987 if (pch_iir & SDE_POISON)
1988 DRM_ERROR("PCH poison interrupt\n");
1989
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001990 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001991 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001992 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1993 pipe_name(pipe),
1994 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001995
1996 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1997 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1998
1999 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2000 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2001
Jesse Barnes776ad802011-01-04 15:09:39 -08002002 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002003 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002004
2005 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002006 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002007}
2008
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002009static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002010{
Paulo Zanoni86642812013-04-12 17:57:57 -03002011 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002012 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002013
Paulo Zanonide032bf2013-04-12 17:57:58 -03002014 if (err_int & ERR_INT_POISON)
2015 DRM_ERROR("Poison interrupt\n");
2016
Damien Lespiau055e3932014-08-18 13:49:10 +01002017 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002018 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2019 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002020
Daniel Vetter5a69b892013-10-16 22:55:52 +02002021 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002022 if (IS_IVYBRIDGE(dev_priv))
2023 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002024 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002025 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002026 }
2027 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002028
Paulo Zanoni86642812013-04-12 17:57:57 -03002029 I915_WRITE(GEN7_ERR_INT, err_int);
2030}
2031
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002032static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002033{
Paulo Zanoni86642812013-04-12 17:57:57 -03002034 u32 serr_int = I915_READ(SERR_INT);
2035
Paulo Zanonide032bf2013-04-12 17:57:58 -03002036 if (serr_int & SERR_INT_POISON)
2037 DRM_ERROR("PCH poison interrupt\n");
2038
Paulo Zanoni86642812013-04-12 17:57:57 -03002039 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002040 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002041
2042 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002043 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002044
2045 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002046 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002047
2048 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002049}
2050
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002051static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002052{
Adam Jackson23e81d62012-06-06 15:45:44 -04002053 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002054 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002055
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002056 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002057
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002058 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2059 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2060 SDE_AUDIO_POWER_SHIFT_CPT);
2061 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2062 port_name(port));
2063 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002064
2065 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002066 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002067
2068 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002069 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002070
2071 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2072 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2073
2074 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2075 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2076
2077 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002078 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002079 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2080 pipe_name(pipe),
2081 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002082
2083 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002084 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002085}
2086
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002087static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002088{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002089 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2090 ~SDE_PORTE_HOTPLUG_SPT;
2091 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2092 u32 pin_mask = 0, long_mask = 0;
2093
2094 if (hotplug_trigger) {
2095 u32 dig_hotplug_reg;
2096
2097 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2098 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2099
2100 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2101 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002102 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002103 }
2104
2105 if (hotplug2_trigger) {
2106 u32 dig_hotplug_reg;
2107
2108 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2109 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2110
2111 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2112 dig_hotplug_reg, hpd_spt,
2113 spt_port_hotplug2_long_detect);
2114 }
2115
2116 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002117 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002118
2119 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002120 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002121}
2122
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002123static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2124 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002125 const u32 hpd[HPD_NUM_PINS])
2126{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002127 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2128
2129 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2130 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2131
2132 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2133 dig_hotplug_reg, hpd,
2134 ilk_port_hotplug_long_detect);
2135
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002136 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002137}
2138
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002139static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2140 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002141{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002142 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002143 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2144
Ville Syrjälä40e56412015-08-27 23:56:10 +03002145 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002146 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002147
2148 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002149 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002150
2151 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002152 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002153
Paulo Zanonic008bc62013-07-12 16:35:10 -03002154 if (de_iir & DE_POISON)
2155 DRM_ERROR("Poison interrupt\n");
2156
Damien Lespiau055e3932014-08-18 13:49:10 +01002157 for_each_pipe(dev_priv, pipe) {
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02002158 if (de_iir & DE_PIPE_VBLANK(pipe))
2159 intel_pipe_handle_vblank(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002160
Daniel Vetter40da17c22013-10-21 18:04:36 +02002161 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002162 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002163
Daniel Vetter40da17c22013-10-21 18:04:36 +02002164 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002165 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002166
Daniel Vetter40da17c22013-10-21 18:04:36 +02002167 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002168 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002169 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002170 }
2171
2172 /* check event from PCH */
2173 if (de_iir & DE_PCH_EVENT) {
2174 u32 pch_iir = I915_READ(SDEIIR);
2175
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002176 if (HAS_PCH_CPT(dev_priv))
2177 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002178 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002179 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002180
2181 /* should clear PCH hotplug event before clear CPU irq */
2182 I915_WRITE(SDEIIR, pch_iir);
2183 }
2184
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002185 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2186 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002187}
2188
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002189static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2190 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002191{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002192 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002193 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2194
Ville Syrjälä40e56412015-08-27 23:56:10 +03002195 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002196 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002197
2198 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002199 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002200
2201 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002202 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002203
2204 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002205 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002206
Damien Lespiau055e3932014-08-18 13:49:10 +01002207 for_each_pipe(dev_priv, pipe) {
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02002208 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2209 intel_pipe_handle_vblank(dev_priv, pipe);
Daniel Vetter40da17c22013-10-21 18:04:36 +02002210
2211 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002212 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002213 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002214 }
2215
2216 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002217 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002218 u32 pch_iir = I915_READ(SDEIIR);
2219
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002220 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002221
2222 /* clear PCH hotplug event before clear CPU irq */
2223 I915_WRITE(SDEIIR, pch_iir);
2224 }
2225}
2226
Oscar Mateo72c90f62014-06-16 16:10:57 +01002227/*
2228 * To handle irqs with the minimum potential races with fresh interrupts, we:
2229 * 1 - Disable Master Interrupt Control.
2230 * 2 - Find the source(s) of the interrupt.
2231 * 3 - Clear the Interrupt Identity bits (IIR).
2232 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2233 * 5 - Re-enable Master Interrupt Control.
2234 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002235static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002236{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002237 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002238 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002239 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002240 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002241
Imre Deak2dd2a882015-02-24 11:14:30 +02002242 if (!intel_irqs_enabled(dev_priv))
2243 return IRQ_NONE;
2244
Imre Deak1f814da2015-12-16 02:52:19 +02002245 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2246 disable_rpm_wakeref_asserts(dev_priv);
2247
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002248 /* disable master interrupt before clearing iir */
2249 de_ier = I915_READ(DEIER);
2250 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002251 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002252
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002253 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2254 * interrupts will will be stored on its back queue, and then we'll be
2255 * able to process them after we restore SDEIER (as soon as we restore
2256 * it, we'll get an interrupt if SDEIIR still has something to process
2257 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002258 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002259 sde_ier = I915_READ(SDEIER);
2260 I915_WRITE(SDEIER, 0);
2261 POSTING_READ(SDEIER);
2262 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002263
Oscar Mateo72c90f62014-06-16 16:10:57 +01002264 /* Find, clear, then process each source of interrupt */
2265
Chris Wilson0e434062012-05-09 21:45:44 +01002266 gt_iir = I915_READ(GTIIR);
2267 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002268 I915_WRITE(GTIIR, gt_iir);
2269 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002270 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002271 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002272 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002273 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002274 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002275
2276 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002277 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002278 I915_WRITE(DEIIR, de_iir);
2279 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002280 if (INTEL_GEN(dev_priv) >= 7)
2281 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002282 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002283 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002284 }
2285
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002286 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002287 u32 pm_iir = I915_READ(GEN6_PMIIR);
2288 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002289 I915_WRITE(GEN6_PMIIR, pm_iir);
2290 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002291 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002292 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002293 }
2294
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002295 I915_WRITE(DEIER, de_ier);
2296 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002297 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002298 I915_WRITE(SDEIER, sde_ier);
2299 POSTING_READ(SDEIER);
2300 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002301
Imre Deak1f814da2015-12-16 02:52:19 +02002302 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2303 enable_rpm_wakeref_asserts(dev_priv);
2304
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002305 return ret;
2306}
2307
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002308static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2309 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002310 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302311{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002312 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302313
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002314 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2315 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302316
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002317 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002318 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002319 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002320
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002321 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302322}
2323
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002324static irqreturn_t
2325gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002326{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002327 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002328 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002329 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002330
Ben Widawskyabd58f02013-11-02 21:07:09 -07002331 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002332 iir = I915_READ(GEN8_DE_MISC_IIR);
2333 if (iir) {
2334 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002335 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002336 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002337 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002338 else
2339 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002340 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002341 else
2342 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002343 }
2344
Daniel Vetter6d766f02013-11-07 14:49:55 +01002345 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002346 iir = I915_READ(GEN8_DE_PORT_IIR);
2347 if (iir) {
2348 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302349 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002350
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002351 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002352 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002353
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002354 tmp_mask = GEN8_AUX_CHANNEL_A;
2355 if (INTEL_INFO(dev_priv)->gen >= 9)
2356 tmp_mask |= GEN9_AUX_CHANNEL_B |
2357 GEN9_AUX_CHANNEL_C |
2358 GEN9_AUX_CHANNEL_D;
2359
2360 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002361 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302362 found = true;
2363 }
2364
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002365 if (IS_BROXTON(dev_priv)) {
2366 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2367 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002368 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2369 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002370 found = true;
2371 }
2372 } else if (IS_BROADWELL(dev_priv)) {
2373 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2374 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002375 ilk_hpd_irq_handler(dev_priv,
2376 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002377 found = true;
2378 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302379 }
2380
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002381 if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
2382 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302383 found = true;
2384 }
2385
Shashank Sharmad04a4922014-08-22 17:40:41 +05302386 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002387 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002388 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002389 else
2390 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002391 }
2392
Damien Lespiau055e3932014-08-18 13:49:10 +01002393 for_each_pipe(dev_priv, pipe) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002394 u32 flip_done, fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002395
Daniel Vetterc42664c2013-11-07 11:05:40 +01002396 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2397 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002398
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002399 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2400 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002401 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002402 continue;
2403 }
2404
2405 ret = IRQ_HANDLED;
2406 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2407
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02002408 if (iir & GEN8_PIPE_VBLANK)
2409 intel_pipe_handle_vblank(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002410
2411 flip_done = iir;
2412 if (INTEL_INFO(dev_priv)->gen >= 9)
2413 flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE;
2414 else
2415 flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE;
2416
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002417 if (flip_done)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002418 intel_finish_page_flip_cs(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002419
2420 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002421 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002422
2423 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2424 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2425
2426 fault_errors = iir;
2427 if (INTEL_INFO(dev_priv)->gen >= 9)
2428 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2429 else
2430 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2431
2432 if (fault_errors)
2433 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2434 pipe_name(pipe),
2435 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002436 }
2437
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002438 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302439 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002440 /*
2441 * FIXME(BDW): Assume for now that the new interrupt handling
2442 * scheme also closed the SDE interrupt handling race we've seen
2443 * on older pch-split platforms. But this needs testing.
2444 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002445 iir = I915_READ(SDEIIR);
2446 if (iir) {
2447 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002448 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002449
2450 if (HAS_PCH_SPT(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002451 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002452 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002453 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002454 } else {
2455 /*
2456 * Like on previous PCH there seems to be something
2457 * fishy going on with forwarding PCH interrupts.
2458 */
2459 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2460 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002461 }
2462
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002463 return ret;
2464}
2465
2466static irqreturn_t gen8_irq_handler(int irq, void *arg)
2467{
2468 struct drm_device *dev = arg;
2469 struct drm_i915_private *dev_priv = dev->dev_private;
2470 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002471 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002472 irqreturn_t ret;
2473
2474 if (!intel_irqs_enabled(dev_priv))
2475 return IRQ_NONE;
2476
2477 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2478 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2479 if (!master_ctl)
2480 return IRQ_NONE;
2481
2482 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2483
2484 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2485 disable_rpm_wakeref_asserts(dev_priv);
2486
2487 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002488 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2489 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002490 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2491
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002492 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2493 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002494
Imre Deak1f814da2015-12-16 02:52:19 +02002495 enable_rpm_wakeref_asserts(dev_priv);
2496
Ben Widawskyabd58f02013-11-02 21:07:09 -07002497 return ret;
2498}
2499
Daniel Vetter17e1df02013-09-08 21:57:13 +02002500static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2501 bool reset_completed)
2502{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002503 struct intel_engine_cs *engine;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002504
2505 /*
2506 * Notify all waiters for GPU completion events that reset state has
2507 * been changed, and that they need to restart their wait after
2508 * checking for potential errors (and bail out to drop locks if there is
2509 * a gpu reset pending so that i915_error_work_func can acquire them).
2510 */
2511
2512 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002513 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002514 wake_up_all(&engine->irq_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002515
2516 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2517 wake_up_all(&dev_priv->pending_flip_queue);
2518
2519 /*
2520 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2521 * reset state is cleared.
2522 */
2523 if (reset_completed)
2524 wake_up_all(&dev_priv->gpu_error.reset_queue);
2525}
2526
Jesse Barnes8a905232009-07-11 16:48:03 -04002527/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002528 * i915_reset_and_wakeup - do process context error handling work
Javier Martinez Canillas468f9d22015-10-08 09:54:44 +02002529 * @dev: drm device
Jesse Barnes8a905232009-07-11 16:48:03 -04002530 *
2531 * Fire an error uevent so userspace can see that a hang or error
2532 * was detected.
2533 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002534static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002535{
Chris Wilsonc0336662016-05-06 15:40:21 +01002536 struct kobject *kobj = &dev_priv->dev->primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002537 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2538 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2539 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002540 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002541
Chris Wilsonc0336662016-05-06 15:40:21 +01002542 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002543
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002544 /*
2545 * Note that there's only one work item which does gpu resets, so we
2546 * need not worry about concurrent gpu resets potentially incrementing
2547 * error->reset_counter twice. We only need to take care of another
2548 * racing irq/hangcheck declaring the gpu dead for a second time. A
2549 * quick check for that is good enough: schedule_work ensures the
2550 * correct ordering between hang detection and this work item, and since
2551 * the reset in-progress bit is only ever set by code outside of this
2552 * work we don't need to worry about any other races.
2553 */
Chris Wilsond98c52c2016-04-13 17:35:05 +01002554 if (i915_reset_in_progress(&dev_priv->gpu_error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002555 DRM_DEBUG_DRIVER("resetting chip\n");
Chris Wilsonc0336662016-05-06 15:40:21 +01002556 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002557
Daniel Vetter17e1df02013-09-08 21:57:13 +02002558 /*
Imre Deakf454c692014-04-23 01:09:04 +03002559 * In most cases it's guaranteed that we get here with an RPM
2560 * reference held, for example because there is a pending GPU
2561 * request that won't finish until the reset is done. This
2562 * isn't the case at least when we get here by doing a
2563 * simulated reset via debugs, so get an RPM reference.
2564 */
2565 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002566
Chris Wilsonc0336662016-05-06 15:40:21 +01002567 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002568
Imre Deakf454c692014-04-23 01:09:04 +03002569 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002570 * All state reset _must_ be completed before we update the
2571 * reset counter, for otherwise waiters might miss the reset
2572 * pending state and not properly drop locks, resulting in
2573 * deadlocks with the reset work.
2574 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002575 ret = i915_reset(dev_priv);
Daniel Vetterf69061b2012-12-06 09:01:42 +01002576
Chris Wilsonc0336662016-05-06 15:40:21 +01002577 intel_finish_reset(dev_priv);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002578
Imre Deakf454c692014-04-23 01:09:04 +03002579 intel_runtime_pm_put(dev_priv);
2580
Chris Wilsond98c52c2016-04-13 17:35:05 +01002581 if (ret == 0)
Chris Wilsonc0336662016-05-06 15:40:21 +01002582 kobject_uevent_env(kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002583 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002584
Daniel Vetter17e1df02013-09-08 21:57:13 +02002585 /*
2586 * Note: The wake_up also serves as a memory barrier so that
2587 * waiters see the update value of the reset counter atomic_t.
2588 */
2589 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002590 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002591}
2592
Chris Wilsonc0336662016-05-06 15:40:21 +01002593static void i915_report_and_clear_eir(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002594{
Ben Widawskybd9854f2012-08-23 15:18:09 -07002595 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002596 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002597 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002598
Chris Wilson35aed2e2010-05-27 13:18:12 +01002599 if (!eir)
2600 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002601
Joe Perchesa70491c2012-03-18 13:00:11 -07002602 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002603
Chris Wilsonc0336662016-05-06 15:40:21 +01002604 i915_get_extra_instdone(dev_priv, instdone);
Ben Widawskybd9854f2012-08-23 15:18:09 -07002605
Chris Wilsonc0336662016-05-06 15:40:21 +01002606 if (IS_G4X(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002607 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2608 u32 ipeir = I915_READ(IPEIR_I965);
2609
Joe Perchesa70491c2012-03-18 13:00:11 -07002610 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2611 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002612 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2613 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002614 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002615 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002616 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002617 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002618 }
2619 if (eir & GM45_ERROR_PAGE_TABLE) {
2620 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002621 pr_err("page table error\n");
2622 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002623 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002624 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002625 }
2626 }
2627
Chris Wilsonc0336662016-05-06 15:40:21 +01002628 if (!IS_GEN2(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002629 if (eir & I915_ERROR_PAGE_TABLE) {
2630 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002631 pr_err("page table error\n");
2632 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002633 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002634 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002635 }
2636 }
2637
2638 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002639 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002640 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002641 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002642 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002643 /* pipestat has already been acked */
2644 }
2645 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002646 pr_err("instruction error\n");
2647 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002648 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2649 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsonc0336662016-05-06 15:40:21 +01002650 if (INTEL_GEN(dev_priv) < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002651 u32 ipeir = I915_READ(IPEIR);
2652
Joe Perchesa70491c2012-03-18 13:00:11 -07002653 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2654 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002655 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002656 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002657 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002658 } else {
2659 u32 ipeir = I915_READ(IPEIR_I965);
2660
Joe Perchesa70491c2012-03-18 13:00:11 -07002661 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2662 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002663 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002664 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002665 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002666 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002667 }
2668 }
2669
2670 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002671 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002672 eir = I915_READ(EIR);
2673 if (eir) {
2674 /*
2675 * some errors might have become stuck,
2676 * mask them.
2677 */
2678 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2679 I915_WRITE(EMR, I915_READ(EMR) | eir);
2680 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2681 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002682}
2683
2684/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002685 * i915_handle_error - handle a gpu error
Chris Wilson35aed2e2010-05-27 13:18:12 +01002686 * @dev: drm device
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002687 * @engine_mask: mask representing engines that are hung
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002688 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002689 * dump it to the syslog. Also call i915_capture_error_state() to make
2690 * sure we get a record and make it available in debugfs. Fire a uevent
2691 * so userspace knows something bad happened (should trigger collection
2692 * of a ring dump etc.).
2693 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002694void i915_handle_error(struct drm_i915_private *dev_priv,
2695 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002696 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002697{
Mika Kuoppala58174462014-02-25 17:11:26 +02002698 va_list args;
2699 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002700
Mika Kuoppala58174462014-02-25 17:11:26 +02002701 va_start(args, fmt);
2702 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2703 va_end(args);
2704
Chris Wilsonc0336662016-05-06 15:40:21 +01002705 i915_capture_error_state(dev_priv, engine_mask, error_msg);
2706 i915_report_and_clear_eir(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002707
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002708 if (engine_mask) {
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002709 atomic_or(I915_RESET_IN_PROGRESS_FLAG,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002710 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002711
Ben Gamari11ed50e2009-09-14 17:48:45 -04002712 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002713 * Wakeup waiting processes so that the reset function
2714 * i915_reset_and_wakeup doesn't deadlock trying to grab
2715 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002716 * processes will see a reset in progress and back off,
2717 * releasing their locks and then wait for the reset completion.
2718 * We must do this for _all_ gpu waiters that might hold locks
2719 * that the reset work needs to acquire.
2720 *
2721 * Note: The wake_up serves as the required memory barrier to
2722 * ensure that the waiters see the updated value of the reset
2723 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002724 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002725 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002726 }
2727
Chris Wilsonc0336662016-05-06 15:40:21 +01002728 i915_reset_and_wakeup(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002729}
2730
Keith Packard42f52ef2008-10-18 19:39:29 -07002731/* Called from drm generic code, passed 'crtc' which
2732 * we use as a pipe index
2733 */
Thierry Reding88e72712015-09-24 18:35:31 +02002734static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002735{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002736 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002737 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002738
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002739 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002740 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002741 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002742 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002743 else
Keith Packard7c463582008-11-04 02:03:27 -08002744 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002745 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002746 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002747
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002748 return 0;
2749}
2750
Thierry Reding88e72712015-09-24 18:35:31 +02002751static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002752{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002753 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002754 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002755 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002756 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002757
Jesse Barnesf796cf82011-04-07 13:58:17 -07002758 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002759 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002760 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2761
2762 return 0;
2763}
2764
Thierry Reding88e72712015-09-24 18:35:31 +02002765static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002766{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002767 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002768 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002769
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002770 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002771 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002772 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002773 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2774
2775 return 0;
2776}
2777
Thierry Reding88e72712015-09-24 18:35:31 +02002778static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002779{
2780 struct drm_i915_private *dev_priv = dev->dev_private;
2781 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002782
Ben Widawskyabd58f02013-11-02 21:07:09 -07002783 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002784 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002785 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002786
Ben Widawskyabd58f02013-11-02 21:07:09 -07002787 return 0;
2788}
2789
Keith Packard42f52ef2008-10-18 19:39:29 -07002790/* Called from drm generic code, passed 'crtc' which
2791 * we use as a pipe index
2792 */
Thierry Reding88e72712015-09-24 18:35:31 +02002793static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002794{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002795 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002796 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002797
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002798 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002799 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002800 PIPE_VBLANK_INTERRUPT_STATUS |
2801 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002802 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2803}
2804
Thierry Reding88e72712015-09-24 18:35:31 +02002805static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002806{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002807 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002808 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002809 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002810 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002811
2812 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002813 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002814 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2815}
2816
Thierry Reding88e72712015-09-24 18:35:31 +02002817static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002818{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002819 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002820 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002821
2822 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002823 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002824 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002825 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2826}
2827
Thierry Reding88e72712015-09-24 18:35:31 +02002828static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002829{
2830 struct drm_i915_private *dev_priv = dev->dev_private;
2831 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002832
Ben Widawskyabd58f02013-11-02 21:07:09 -07002833 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002834 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002835 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2836}
2837
Chris Wilson9107e9d2013-06-10 11:20:20 +01002838static bool
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002839ring_idle(struct intel_engine_cs *engine, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002840{
Chris Wilsoncffa7812016-04-07 07:29:18 +01002841 return i915_seqno_passed(seqno,
2842 READ_ONCE(engine->last_submitted_seqno));
Ben Gamarif65d9422009-09-14 17:48:44 -04002843}
2844
Daniel Vettera028c4b2014-03-15 00:08:56 +01002845static bool
Chris Wilsonc0336662016-05-06 15:40:21 +01002846ipehr_is_semaphore_wait(struct drm_i915_private *dev_priv, u32 ipehr)
Daniel Vettera028c4b2014-03-15 00:08:56 +01002847{
Chris Wilsonc0336662016-05-06 15:40:21 +01002848 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002849 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002850 } else {
2851 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2852 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2853 MI_SEMAPHORE_REGISTER);
2854 }
2855}
2856
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002857static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002858semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr,
2859 u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002860{
Chris Wilsonc0336662016-05-06 15:40:21 +01002861 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002862 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002863
Chris Wilsonc0336662016-05-06 15:40:21 +01002864 if (INTEL_GEN(dev_priv) >= 8) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002865 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002866 if (engine == signaller)
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002867 continue;
2868
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002869 if (offset == signaller->semaphore.signal_ggtt[engine->id])
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002870 return signaller;
2871 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002872 } else {
2873 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2874
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002875 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002876 if(engine == signaller)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002877 continue;
2878
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002879 if (sync_bits == signaller->semaphore.mbox.wait[engine->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002880 return signaller;
2881 }
2882 }
2883
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002884 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002885 engine->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002886
2887 return NULL;
2888}
2889
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002890static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002891semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002892{
Chris Wilsonc0336662016-05-06 15:40:21 +01002893 struct drm_i915_private *dev_priv = engine->i915;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002894 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002895 u64 offset = 0;
2896 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002897
Tomas Elf381e8ae2015-10-08 19:31:33 +01002898 /*
2899 * This function does not support execlist mode - any attempt to
2900 * proceed further into this function will result in a kernel panic
2901 * when dereferencing ring->buffer, which is not set up in execlist
2902 * mode.
2903 *
2904 * The correct way of doing it would be to derive the currently
2905 * executing ring buffer from the current context, which is derived
2906 * from the currently running request. Unfortunately, to get the
2907 * current request we would have to grab the struct_mutex before doing
2908 * anything else, which would be ill-advised since some other thread
2909 * might have grabbed it already and managed to hang itself, causing
2910 * the hang checker to deadlock.
2911 *
2912 * Therefore, this function does not support execlist mode in its
2913 * current form. Just return NULL and move on.
2914 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002915 if (engine->buffer == NULL)
Tomas Elf381e8ae2015-10-08 19:31:33 +01002916 return NULL;
2917
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002918 ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
Chris Wilsonc0336662016-05-06 15:40:21 +01002919 if (!ipehr_is_semaphore_wait(engine->i915, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002920 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002921
Daniel Vetter88fe4292014-03-15 00:08:55 +01002922 /*
2923 * HEAD is likely pointing to the dword after the actual command,
2924 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002925 * or 4 dwords depending on the semaphore wait command size.
2926 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002927 * point at at batch, and semaphores are always emitted into the
2928 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002929 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002930 head = I915_READ_HEAD(engine) & HEAD_ADDR;
Chris Wilsonc0336662016-05-06 15:40:21 +01002931 backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002932
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002933 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002934 /*
2935 * Be paranoid and presume the hw has gone off into the wild -
2936 * our ring is smaller than what the hardware (and hence
2937 * HEAD_ADDR) allows. Also handles wrap-around.
2938 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002939 head &= engine->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002940
2941 /* This here seems to blow up */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002942 cmd = ioread32(engine->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002943 if (cmd == ipehr)
2944 break;
2945
Daniel Vetter88fe4292014-03-15 00:08:55 +01002946 head -= 4;
2947 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002948
Daniel Vetter88fe4292014-03-15 00:08:55 +01002949 if (!i)
2950 return NULL;
2951
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002952 *seqno = ioread32(engine->buffer->virtual_start + head + 4) + 1;
Chris Wilsonc0336662016-05-06 15:40:21 +01002953 if (INTEL_GEN(dev_priv) >= 8) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002954 offset = ioread32(engine->buffer->virtual_start + head + 12);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002955 offset <<= 32;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002956 offset = ioread32(engine->buffer->virtual_start + head + 8);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002957 }
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002958 return semaphore_wait_to_signaller_ring(engine, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002959}
2960
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002961static int semaphore_passed(struct intel_engine_cs *engine)
Chris Wilson6274f212013-06-10 11:20:21 +01002962{
Chris Wilsonc0336662016-05-06 15:40:21 +01002963 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002964 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002965 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002966
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002967 engine->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002968
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002969 signaller = semaphore_waits_for(engine, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002970 if (signaller == NULL)
2971 return -1;
2972
2973 /* Prevent pathological recursion due to driver bugs */
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00002974 if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES)
Chris Wilson6274f212013-06-10 11:20:21 +01002975 return -1;
2976
Chris Wilsonc04e0f32016-04-09 10:57:54 +01002977 if (i915_seqno_passed(signaller->get_seqno(signaller), seqno))
Chris Wilson4be17382014-06-06 10:22:29 +01002978 return 1;
2979
Chris Wilsona0d036b2014-07-19 12:40:42 +01002980 /* cursory check for an unkickable deadlock */
2981 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2982 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002983 return -1;
2984
2985 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002986}
2987
2988static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2989{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002990 struct intel_engine_cs *engine;
Chris Wilson6274f212013-06-10 11:20:21 +01002991
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002992 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002993 engine->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002994}
2995
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002996static bool subunits_stuck(struct intel_engine_cs *engine)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002997{
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002998 u32 instdone[I915_NUM_INSTDONE_REG];
2999 bool stuck;
3000 int i;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003001
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003002 if (engine->id != RCS)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003003 return true;
3004
Chris Wilsonc0336662016-05-06 15:40:21 +01003005 i915_get_extra_instdone(engine->i915, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003006
3007 /* There might be unstable subunit states even when
3008 * actual head is not moving. Filter out the unstable ones by
3009 * accumulating the undone -> done transitions and only
3010 * consider those as progress.
3011 */
3012 stuck = true;
3013 for (i = 0; i < I915_NUM_INSTDONE_REG; i++) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003014 const u32 tmp = instdone[i] | engine->hangcheck.instdone[i];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003015
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003016 if (tmp != engine->hangcheck.instdone[i])
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003017 stuck = false;
3018
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003019 engine->hangcheck.instdone[i] |= tmp;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003020 }
3021
3022 return stuck;
3023}
3024
3025static enum intel_ring_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003026head_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003027{
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003028 if (acthd != engine->hangcheck.acthd) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003029
3030 /* Clear subunit states on head movement */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003031 memset(engine->hangcheck.instdone, 0,
3032 sizeof(engine->hangcheck.instdone));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003033
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003034 return HANGCHECK_ACTIVE;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003035 }
Chris Wilson6274f212013-06-10 11:20:21 +01003036
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003037 if (!subunits_stuck(engine))
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003038 return HANGCHECK_ACTIVE;
3039
3040 return HANGCHECK_HUNG;
3041}
3042
3043static enum intel_ring_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003044ring_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003045{
Chris Wilsonc0336662016-05-06 15:40:21 +01003046 struct drm_i915_private *dev_priv = engine->i915;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003047 enum intel_ring_hangcheck_action ha;
3048 u32 tmp;
3049
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003050 ha = head_stuck(engine, acthd);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003051 if (ha != HANGCHECK_HUNG)
3052 return ha;
3053
Chris Wilsonc0336662016-05-06 15:40:21 +01003054 if (IS_GEN2(dev_priv))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003055 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003056
3057 /* Is the chip hanging on a WAIT_FOR_EVENT?
3058 * If so we can simply poke the RB_WAIT bit
3059 * and break the hang. This should work on
3060 * all but the second generation chipsets.
3061 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003062 tmp = I915_READ_CTL(engine);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003063 if (tmp & RING_WAIT) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003064 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003065 "Kicking stuck wait on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003066 engine->name);
3067 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003068 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003069 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003070
Chris Wilsonc0336662016-05-06 15:40:21 +01003071 if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003072 switch (semaphore_passed(engine)) {
Chris Wilson6274f212013-06-10 11:20:21 +01003073 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003074 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003075 case 1:
Chris Wilsonc0336662016-05-06 15:40:21 +01003076 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003077 "Kicking stuck semaphore on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003078 engine->name);
3079 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003080 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003081 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003082 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003083 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003084 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003085
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003086 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003087}
3088
Chris Wilson12471ba2016-04-09 10:57:55 +01003089static unsigned kick_waiters(struct intel_engine_cs *engine)
3090{
Chris Wilsonc0336662016-05-06 15:40:21 +01003091 struct drm_i915_private *i915 = engine->i915;
Chris Wilson12471ba2016-04-09 10:57:55 +01003092 unsigned user_interrupts = READ_ONCE(engine->user_interrupts);
3093
3094 if (engine->hangcheck.user_interrupts == user_interrupts &&
3095 !test_and_set_bit(engine->id, &i915->gpu_error.missed_irq_rings)) {
3096 if (!(i915->gpu_error.test_irq_rings & intel_engine_flag(engine)))
3097 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
3098 engine->name);
3099 else
3100 DRM_INFO("Fake missed irq on %s\n",
3101 engine->name);
3102 wake_up_all(&engine->irq_queue);
3103 }
3104
3105 return user_interrupts;
3106}
Chris Wilson737b1502015-01-26 18:03:03 +02003107/*
Ben Gamarif65d9422009-09-14 17:48:44 -04003108 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003109 * batchbuffers in a long time. We keep track per ring seqno progress and
3110 * if there are no progress, hangcheck score for that ring is increased.
3111 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3112 * we kick the ring. If we see no progress on three subsequent calls
3113 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003114 */
Chris Wilson737b1502015-01-26 18:03:03 +02003115static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04003116{
Chris Wilson737b1502015-01-26 18:03:03 +02003117 struct drm_i915_private *dev_priv =
3118 container_of(work, typeof(*dev_priv),
3119 gpu_error.hangcheck_work.work);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003120 struct intel_engine_cs *engine;
Dave Gordonc3232b12016-03-23 18:19:53 +00003121 enum intel_engine_id id;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003122 int busy_count = 0, rings_hung = 0;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00003123 bool stuck[I915_NUM_ENGINES] = { 0 };
Chris Wilson9107e9d2013-06-10 11:20:20 +01003124#define BUSY 1
3125#define KICK 5
3126#define HUNG 20
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003127#define ACTIVE_DECAY 15
Chris Wilson893eead2010-10-27 14:44:35 +01003128
Jani Nikulad330a952014-01-21 11:24:25 +02003129 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003130 return;
3131
Imre Deak1f814da2015-12-16 02:52:19 +02003132 /*
3133 * The hangcheck work is synced during runtime suspend, we don't
3134 * require a wakeref. TODO: instead of disabling the asserts make
3135 * sure that we hold a reference when this work is running.
3136 */
3137 DISABLE_RPM_WAKEREF_ASSERTS(dev_priv);
3138
Mika Kuoppala75714942015-12-16 09:26:48 +02003139 /* As enabling the GPU requires fairly extensive mmio access,
3140 * periodically arm the mmio checker to see if we are triggering
3141 * any invalid access.
3142 */
3143 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
3144
Dave Gordonc3232b12016-03-23 18:19:53 +00003145 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson50877442014-03-21 12:41:53 +00003146 u64 acthd;
3147 u32 seqno;
Chris Wilson12471ba2016-04-09 10:57:55 +01003148 unsigned user_interrupts;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003149 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01003150
Chris Wilson6274f212013-06-10 11:20:21 +01003151 semaphore_clear_deadlocks(dev_priv);
3152
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003153 /* We don't strictly need an irq-barrier here, as we are not
3154 * serving an interrupt request, be paranoid in case the
3155 * barrier has side-effects (such as preventing a broken
3156 * cacheline snoop) and so be sure that we can see the seqno
3157 * advance. If the seqno should stick, due to a stale
3158 * cacheline, we would erroneously declare the GPU hung.
3159 */
3160 if (engine->irq_seqno_barrier)
3161 engine->irq_seqno_barrier(engine);
3162
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003163 acthd = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003164 seqno = engine->get_seqno(engine);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003165
Chris Wilson12471ba2016-04-09 10:57:55 +01003166 /* Reset stuck interrupts between batch advances */
3167 user_interrupts = 0;
3168
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003169 if (engine->hangcheck.seqno == seqno) {
3170 if (ring_idle(engine, seqno)) {
3171 engine->hangcheck.action = HANGCHECK_IDLE;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003172 if (waitqueue_active(&engine->irq_queue)) {
Chris Wilson094f9a52013-09-25 17:34:55 +01003173 /* Safeguard against driver failure */
Chris Wilson12471ba2016-04-09 10:57:55 +01003174 user_interrupts = kick_waiters(engine);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003175 engine->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003176 } else
3177 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003178 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003179 /* We always increment the hangcheck score
3180 * if the ring is busy and still processing
3181 * the same request, so that no single request
3182 * can run indefinitely (such as a chain of
3183 * batches). The only time we do not increment
3184 * the hangcheck score on this ring, if this
3185 * ring is in a legitimate wait for another
3186 * ring. In that case the waiting ring is a
3187 * victim and we want to be sure we catch the
3188 * right culprit. Then every time we do kick
3189 * the ring, add a small increment to the
3190 * score so that we can catch a batch that is
3191 * being repeatedly kicked and so responsible
3192 * for stalling the machine.
3193 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003194 engine->hangcheck.action = ring_stuck(engine,
3195 acthd);
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003196
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003197 switch (engine->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003198 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003199 case HANGCHECK_WAIT:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003200 break;
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003201 case HANGCHECK_ACTIVE:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003202 engine->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003203 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003204 case HANGCHECK_KICK:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003205 engine->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003206 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003207 case HANGCHECK_HUNG:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003208 engine->hangcheck.score += HUNG;
Dave Gordonc3232b12016-03-23 18:19:53 +00003209 stuck[id] = true;
Chris Wilson6274f212013-06-10 11:20:21 +01003210 break;
3211 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003212 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003213 } else {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003214 engine->hangcheck.action = HANGCHECK_ACTIVE;
Mika Kuoppalada661462013-09-06 16:03:28 +03003215
Chris Wilson9107e9d2013-06-10 11:20:20 +01003216 /* Gradually reduce the count so that we catch DoS
3217 * attempts across multiple batches.
3218 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003219 if (engine->hangcheck.score > 0)
3220 engine->hangcheck.score -= ACTIVE_DECAY;
3221 if (engine->hangcheck.score < 0)
3222 engine->hangcheck.score = 0;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003223
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003224 /* Clear head and subunit states on seqno movement */
Chris Wilson12471ba2016-04-09 10:57:55 +01003225 acthd = 0;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003226
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003227 memset(engine->hangcheck.instdone, 0,
3228 sizeof(engine->hangcheck.instdone));
Chris Wilsond1e61e72012-04-10 17:00:41 +01003229 }
3230
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003231 engine->hangcheck.seqno = seqno;
3232 engine->hangcheck.acthd = acthd;
Chris Wilson12471ba2016-04-09 10:57:55 +01003233 engine->hangcheck.user_interrupts = user_interrupts;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003234 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003235 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003236
Dave Gordonc3232b12016-03-23 18:19:53 +00003237 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003238 if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003239 DRM_INFO("%s on %s\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003240 stuck[id] ? "stuck" : "no progress",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003241 engine->name);
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00003242 rings_hung |= intel_engine_flag(engine);
Mika Kuoppala92cab732013-05-24 17:16:07 +03003243 }
3244 }
3245
Imre Deak1f814da2015-12-16 02:52:19 +02003246 if (rings_hung) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003247 i915_handle_error(dev_priv, rings_hung, "Engine(s) hung");
Imre Deak1f814da2015-12-16 02:52:19 +02003248 goto out;
3249 }
Ben Gamarif65d9422009-09-14 17:48:44 -04003250
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003251 if (busy_count)
3252 /* Reset timer case chip hangs without another request
3253 * being added */
Chris Wilsonc0336662016-05-06 15:40:21 +01003254 i915_queue_hangcheck(dev_priv);
Imre Deak1f814da2015-12-16 02:52:19 +02003255
3256out:
3257 ENABLE_RPM_WAKEREF_ASSERTS(dev_priv);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003258}
3259
Chris Wilsonc0336662016-05-06 15:40:21 +01003260void i915_queue_hangcheck(struct drm_i915_private *dev_priv)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003261{
Chris Wilsonc0336662016-05-06 15:40:21 +01003262 struct i915_gpu_error *e = &dev_priv->gpu_error;
Chris Wilson672e7b72014-11-19 09:47:19 +00003263
Jani Nikulad330a952014-01-21 11:24:25 +02003264 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003265 return;
3266
Chris Wilson737b1502015-01-26 18:03:03 +02003267 /* Don't continually defer the hangcheck so that it is always run at
3268 * least once after work has been scheduled on any ring. Otherwise,
3269 * we will ignore a hung ring if a second ring is kept busy.
3270 */
3271
3272 queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
3273 round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003274}
3275
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003276static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003277{
3278 struct drm_i915_private *dev_priv = dev->dev_private;
3279
3280 if (HAS_PCH_NOP(dev))
3281 return;
3282
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003283 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003284
3285 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3286 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003287}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003288
Paulo Zanoni622364b2014-04-01 15:37:22 -03003289/*
3290 * SDEIER is also touched by the interrupt handler to work around missed PCH
3291 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3292 * instead we unconditionally enable all PCH interrupt sources here, but then
3293 * only unmask them as needed with SDEIMR.
3294 *
3295 * This function needs to be called before interrupts are enabled.
3296 */
3297static void ibx_irq_pre_postinstall(struct drm_device *dev)
3298{
3299 struct drm_i915_private *dev_priv = dev->dev_private;
3300
3301 if (HAS_PCH_NOP(dev))
3302 return;
3303
3304 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003305 I915_WRITE(SDEIER, 0xffffffff);
3306 POSTING_READ(SDEIER);
3307}
3308
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003309static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003310{
3311 struct drm_i915_private *dev_priv = dev->dev_private;
3312
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003313 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003314 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003315 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003316}
3317
Ville Syrjälä70591a42014-10-30 19:42:58 +02003318static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3319{
3320 enum pipe pipe;
3321
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003322 if (IS_CHERRYVIEW(dev_priv))
3323 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3324 else
3325 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3326
Ville Syrjäläad22d102016-04-12 18:56:14 +03003327 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003328 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3329
Ville Syrjäläad22d102016-04-12 18:56:14 +03003330 for_each_pipe(dev_priv, pipe) {
3331 I915_WRITE(PIPESTAT(pipe),
3332 PIPE_FIFO_UNDERRUN_STATUS |
3333 PIPESTAT_INT_STATUS_MASK);
3334 dev_priv->pipestat_irq_mask[pipe] = 0;
3335 }
Ville Syrjälä70591a42014-10-30 19:42:58 +02003336
3337 GEN5_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003338 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003339}
3340
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003341static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3342{
3343 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003344 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003345 enum pipe pipe;
3346
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003347 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3348 PIPE_CRC_DONE_INTERRUPT_STATUS;
3349
3350 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3351 for_each_pipe(dev_priv, pipe)
3352 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3353
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003354 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3355 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3356 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003357 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003358 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003359
3360 WARN_ON(dev_priv->irq_mask != ~0);
3361
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003362 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003363
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003364 GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003365}
3366
3367/* drm_dma.h hooks
3368*/
3369static void ironlake_irq_reset(struct drm_device *dev)
3370{
3371 struct drm_i915_private *dev_priv = dev->dev_private;
3372
3373 I915_WRITE(HWSTAM, 0xffffffff);
3374
3375 GEN5_IRQ_RESET(DE);
3376 if (IS_GEN7(dev))
3377 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3378
3379 gen5_gt_irq_reset(dev);
3380
3381 ibx_irq_reset(dev);
3382}
3383
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003384static void valleyview_irq_preinstall(struct drm_device *dev)
3385{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003386 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003387
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003388 I915_WRITE(VLV_MASTER_IER, 0);
3389 POSTING_READ(VLV_MASTER_IER);
3390
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003391 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003392
Ville Syrjäläad22d102016-04-12 18:56:14 +03003393 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003394 if (dev_priv->display_irqs_enabled)
3395 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003396 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003397}
3398
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003399static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3400{
3401 GEN8_IRQ_RESET_NDX(GT, 0);
3402 GEN8_IRQ_RESET_NDX(GT, 1);
3403 GEN8_IRQ_RESET_NDX(GT, 2);
3404 GEN8_IRQ_RESET_NDX(GT, 3);
3405}
3406
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003407static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003408{
3409 struct drm_i915_private *dev_priv = dev->dev_private;
3410 int pipe;
3411
Ben Widawskyabd58f02013-11-02 21:07:09 -07003412 I915_WRITE(GEN8_MASTER_IRQ, 0);
3413 POSTING_READ(GEN8_MASTER_IRQ);
3414
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003415 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003416
Damien Lespiau055e3932014-08-18 13:49:10 +01003417 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003418 if (intel_display_power_is_enabled(dev_priv,
3419 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003420 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003421
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003422 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3423 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3424 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003425
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303426 if (HAS_PCH_SPLIT(dev))
3427 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003428}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003429
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003430void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3431 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003432{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003433 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003434 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003435
Daniel Vetter13321782014-09-15 14:55:29 +02003436 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003437 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3438 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3439 dev_priv->de_irq_mask[pipe],
3440 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003441 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003442}
3443
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003444void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3445 unsigned int pipe_mask)
3446{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003447 enum pipe pipe;
3448
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003449 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003450 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3451 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003452 spin_unlock_irq(&dev_priv->irq_lock);
3453
3454 /* make sure we're done processing display irqs */
3455 synchronize_irq(dev_priv->dev->irq);
3456}
3457
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003458static void cherryview_irq_preinstall(struct drm_device *dev)
3459{
3460 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003461
3462 I915_WRITE(GEN8_MASTER_IRQ, 0);
3463 POSTING_READ(GEN8_MASTER_IRQ);
3464
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003465 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003466
3467 GEN5_IRQ_RESET(GEN8_PCU_);
3468
Ville Syrjäläad22d102016-04-12 18:56:14 +03003469 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003470 if (dev_priv->display_irqs_enabled)
3471 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003472 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003473}
3474
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003475static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003476 const u32 hpd[HPD_NUM_PINS])
3477{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003478 struct intel_encoder *encoder;
3479 u32 enabled_irqs = 0;
3480
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003481 for_each_intel_encoder(dev_priv->dev, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003482 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3483 enabled_irqs |= hpd[encoder->hpd_pin];
3484
3485 return enabled_irqs;
3486}
3487
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003488static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003489{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003490 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003491
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003492 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003493 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003494 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003495 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003496 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003497 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003498 }
3499
Daniel Vetterfee884e2013-07-04 23:35:21 +02003500 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003501
3502 /*
3503 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003504 * duration to 2ms (which is the minimum in the Display Port spec).
3505 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003506 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003507 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3508 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3509 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3510 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3511 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003512 /*
3513 * When CPU and PCH are on the same package, port A
3514 * HPD must be enabled in both north and south.
3515 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003516 if (HAS_PCH_LPT_LP(dev_priv))
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003517 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003518 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003519}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003520
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003521static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003522{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003523 u32 hotplug_irqs, hotplug, enabled_irqs;
3524
3525 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003526 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003527
3528 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3529
3530 /* Enable digital hotplug on the PCH */
3531 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3532 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003533 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003534 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3535
3536 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3537 hotplug |= PORTE_HOTPLUG_ENABLE;
3538 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003539}
3540
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003541static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003542{
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003543 u32 hotplug_irqs, hotplug, enabled_irqs;
3544
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003545 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003546 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003547 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003548
3549 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003550 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003551 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003552 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003553
3554 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003555 } else {
3556 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003557 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003558
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003559 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3560 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003561
3562 /*
3563 * Enable digital hotplug on the CPU, and configure the DP short pulse
3564 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003565 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003566 */
3567 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3568 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3569 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3570 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3571
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003572 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003573}
3574
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003575static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003576{
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003577 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003578
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003579 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003580 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003581
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003582 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003583
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003584 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3585 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3586 PORTA_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303587
3588 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3589 hotplug, enabled_irqs);
3590 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3591
3592 /*
3593 * For BXT invert bit has to be set based on AOB design
3594 * for HPD detection logic, update it based on VBT fields.
3595 */
3596
3597 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3598 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3599 hotplug |= BXT_DDIA_HPD_INVERT;
3600 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3601 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3602 hotplug |= BXT_DDIB_HPD_INVERT;
3603 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3604 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3605 hotplug |= BXT_DDIC_HPD_INVERT;
3606
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003607 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003608}
3609
Paulo Zanonid46da432013-02-08 17:35:15 -02003610static void ibx_irq_postinstall(struct drm_device *dev)
3611{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003612 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003613 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003614
Daniel Vetter692a04c2013-05-29 21:43:05 +02003615 if (HAS_PCH_NOP(dev))
3616 return;
3617
Paulo Zanoni105b1222014-04-01 15:37:17 -03003618 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003619 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003620 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003621 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003622
Ville Syrjäläb51a2842015-09-18 20:03:41 +03003623 gen5_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003624 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003625}
3626
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003627static void gen5_gt_irq_postinstall(struct drm_device *dev)
3628{
3629 struct drm_i915_private *dev_priv = dev->dev_private;
3630 u32 pm_irqs, gt_irqs;
3631
3632 pm_irqs = gt_irqs = 0;
3633
3634 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003635 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003636 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003637 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3638 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003639 }
3640
3641 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3642 if (IS_GEN5(dev)) {
3643 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3644 ILK_BSD_USER_INTERRUPT;
3645 } else {
3646 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3647 }
3648
Paulo Zanoni35079892014-04-01 15:37:15 -03003649 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003650
3651 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003652 /*
3653 * RPS interrupts will get enabled/disabled on demand when RPS
3654 * itself is enabled/disabled.
3655 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003656 if (HAS_VEBOX(dev))
3657 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3658
Paulo Zanoni605cd252013-08-06 18:57:15 -03003659 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003660 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003661 }
3662}
3663
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003664static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003665{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003666 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003667 u32 display_mask, extra_mask;
3668
3669 if (INTEL_INFO(dev)->gen >= 7) {
3670 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3671 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3672 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003673 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003674 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003675 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3676 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003677 } else {
3678 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3679 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003680 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003681 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3682 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003683 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3684 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3685 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003686 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003687
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003688 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003689
Paulo Zanoni0c841212014-04-01 15:37:27 -03003690 I915_WRITE(HWSTAM, 0xeffe);
3691
Paulo Zanoni622364b2014-04-01 15:37:22 -03003692 ibx_irq_pre_postinstall(dev);
3693
Paulo Zanoni35079892014-04-01 15:37:15 -03003694 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003695
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003696 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003697
Paulo Zanonid46da432013-02-08 17:35:15 -02003698 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003699
Jesse Barnesf97108d2010-01-29 11:27:07 -08003700 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003701 /* Enable PCU event interrupts
3702 *
3703 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003704 * setup is guaranteed to run in single-threaded context. But we
3705 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003706 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003707 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003708 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003709 }
3710
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003711 return 0;
3712}
3713
Imre Deakf8b79e52014-03-04 19:23:07 +02003714void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3715{
3716 assert_spin_locked(&dev_priv->irq_lock);
3717
3718 if (dev_priv->display_irqs_enabled)
3719 return;
3720
3721 dev_priv->display_irqs_enabled = true;
3722
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003723 if (intel_irqs_enabled(dev_priv)) {
3724 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003725 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003726 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003727}
3728
3729void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3730{
3731 assert_spin_locked(&dev_priv->irq_lock);
3732
3733 if (!dev_priv->display_irqs_enabled)
3734 return;
3735
3736 dev_priv->display_irqs_enabled = false;
3737
Imre Deak950eaba2014-09-08 15:21:09 +03003738 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003739 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003740}
3741
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003742
3743static int valleyview_irq_postinstall(struct drm_device *dev)
3744{
3745 struct drm_i915_private *dev_priv = dev->dev_private;
3746
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003747 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003748
Ville Syrjäläad22d102016-04-12 18:56:14 +03003749 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003750 if (dev_priv->display_irqs_enabled)
3751 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003752 spin_unlock_irq(&dev_priv->irq_lock);
3753
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003754 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003755 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003756
3757 return 0;
3758}
3759
Ben Widawskyabd58f02013-11-02 21:07:09 -07003760static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3761{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003762 /* These are interrupts we'll toggle with the ring mask register */
3763 uint32_t gt_interrupts[] = {
3764 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003765 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003766 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3767 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003768 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003769 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3770 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3771 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003772 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003773 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3774 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003775 };
3776
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003777 if (HAS_L3_DPF(dev_priv))
3778 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3779
Ben Widawsky09610212014-05-15 20:58:08 +03003780 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303781 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3782 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003783 /*
3784 * RPS interrupts will get enabled/disabled on demand when RPS itself
3785 * is enabled/disabled.
3786 */
3787 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303788 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003789}
3790
3791static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3792{
Damien Lespiau770de832014-03-20 20:45:01 +00003793 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3794 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003795 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3796 u32 de_port_enables;
3797 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003798
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003799 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003800 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3801 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003802 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3803 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303804 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003805 de_port_masked |= BXT_DE_PORT_GMBUS;
3806 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003807 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3808 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003809 }
Damien Lespiau770de832014-03-20 20:45:01 +00003810
3811 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3812 GEN8_PIPE_FIFO_UNDERRUN;
3813
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003814 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003815 if (IS_BROXTON(dev_priv))
3816 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3817 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003818 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3819
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003820 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3821 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3822 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003823
Damien Lespiau055e3932014-08-18 13:49:10 +01003824 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003825 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003826 POWER_DOMAIN_PIPE(pipe)))
3827 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3828 dev_priv->de_irq_mask[pipe],
3829 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003830
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003831 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003832}
3833
3834static int gen8_irq_postinstall(struct drm_device *dev)
3835{
3836 struct drm_i915_private *dev_priv = dev->dev_private;
3837
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303838 if (HAS_PCH_SPLIT(dev))
3839 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003840
Ben Widawskyabd58f02013-11-02 21:07:09 -07003841 gen8_gt_irq_postinstall(dev_priv);
3842 gen8_de_irq_postinstall(dev_priv);
3843
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303844 if (HAS_PCH_SPLIT(dev))
3845 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003846
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003847 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003848 POSTING_READ(GEN8_MASTER_IRQ);
3849
3850 return 0;
3851}
3852
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003853static int cherryview_irq_postinstall(struct drm_device *dev)
3854{
3855 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003856
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003857 gen8_gt_irq_postinstall(dev_priv);
3858
Ville Syrjäläad22d102016-04-12 18:56:14 +03003859 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003860 if (dev_priv->display_irqs_enabled)
3861 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003862 spin_unlock_irq(&dev_priv->irq_lock);
3863
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003864 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003865 POSTING_READ(GEN8_MASTER_IRQ);
3866
3867 return 0;
3868}
3869
Ben Widawskyabd58f02013-11-02 21:07:09 -07003870static void gen8_irq_uninstall(struct drm_device *dev)
3871{
3872 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003873
3874 if (!dev_priv)
3875 return;
3876
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003877 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003878}
3879
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003880static void valleyview_irq_uninstall(struct drm_device *dev)
3881{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003882 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003883
3884 if (!dev_priv)
3885 return;
3886
Imre Deak843d0e72014-04-14 20:24:23 +03003887 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003888 POSTING_READ(VLV_MASTER_IER);
Imre Deak843d0e72014-04-14 20:24:23 +03003889
Ville Syrjälä893fce82014-10-30 19:42:56 +02003890 gen5_gt_irq_reset(dev);
3891
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003892 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003893
Ville Syrjäläad22d102016-04-12 18:56:14 +03003894 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003895 if (dev_priv->display_irqs_enabled)
3896 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003897 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003898}
3899
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003900static void cherryview_irq_uninstall(struct drm_device *dev)
3901{
3902 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003903
3904 if (!dev_priv)
3905 return;
3906
3907 I915_WRITE(GEN8_MASTER_IRQ, 0);
3908 POSTING_READ(GEN8_MASTER_IRQ);
3909
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003910 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003911
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003912 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003913
Ville Syrjäläad22d102016-04-12 18:56:14 +03003914 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003915 if (dev_priv->display_irqs_enabled)
3916 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003917 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003918}
3919
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003920static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003921{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003922 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003923
3924 if (!dev_priv)
3925 return;
3926
Paulo Zanonibe30b292014-04-01 15:37:25 -03003927 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003928}
3929
Chris Wilsonc2798b12012-04-22 21:13:57 +01003930static void i8xx_irq_preinstall(struct drm_device * dev)
3931{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003932 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003933 int pipe;
3934
Damien Lespiau055e3932014-08-18 13:49:10 +01003935 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003936 I915_WRITE(PIPESTAT(pipe), 0);
3937 I915_WRITE16(IMR, 0xffff);
3938 I915_WRITE16(IER, 0x0);
3939 POSTING_READ16(IER);
3940}
3941
3942static int i8xx_irq_postinstall(struct drm_device *dev)
3943{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003944 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003945
Chris Wilsonc2798b12012-04-22 21:13:57 +01003946 I915_WRITE16(EMR,
3947 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3948
3949 /* Unmask the interrupts that we always want on. */
3950 dev_priv->irq_mask =
3951 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3952 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3953 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003954 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003955 I915_WRITE16(IMR, dev_priv->irq_mask);
3956
3957 I915_WRITE16(IER,
3958 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3959 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003960 I915_USER_INTERRUPT);
3961 POSTING_READ16(IER);
3962
Daniel Vetter379ef822013-10-16 22:55:56 +02003963 /* Interrupt setup is already guaranteed to be single-threaded, this is
3964 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003965 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003966 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3967 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003968 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003969
Chris Wilsonc2798b12012-04-22 21:13:57 +01003970 return 0;
3971}
3972
Daniel Vetterff1f5252012-10-02 15:10:55 +02003973static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003974{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003975 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003976 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003977 u16 iir, new_iir;
3978 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003979 int pipe;
3980 u16 flip_mask =
3981 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3982 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Imre Deak1f814da2015-12-16 02:52:19 +02003983 irqreturn_t ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003984
Imre Deak2dd2a882015-02-24 11:14:30 +02003985 if (!intel_irqs_enabled(dev_priv))
3986 return IRQ_NONE;
3987
Imre Deak1f814da2015-12-16 02:52:19 +02003988 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3989 disable_rpm_wakeref_asserts(dev_priv);
3990
3991 ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003992 iir = I915_READ16(IIR);
3993 if (iir == 0)
Imre Deak1f814da2015-12-16 02:52:19 +02003994 goto out;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003995
3996 while (iir & ~flip_mask) {
3997 /* Can't rely on pipestat interrupt bit in iir as it might
3998 * have been cleared after the pipestat interrupt was received.
3999 * It doesn't set the bit in iir again, but it still produces
4000 * interrupts (for non-MSI).
4001 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004002 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004003 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004004 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004005
Damien Lespiau055e3932014-08-18 13:49:10 +01004006 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004007 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004008 pipe_stats[pipe] = I915_READ(reg);
4009
4010 /*
4011 * Clear the PIPE*STAT regs before the IIR
4012 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004013 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004014 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004015 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004016 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004017
4018 I915_WRITE16(IIR, iir & ~flip_mask);
4019 new_iir = I915_READ16(IIR); /* Flush posted writes */
4020
Chris Wilsonc2798b12012-04-22 21:13:57 +01004021 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004022 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004023
Damien Lespiau055e3932014-08-18 13:49:10 +01004024 for_each_pipe(dev_priv, pipe) {
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02004025 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
4026 intel_pipe_handle_vblank(dev_priv, pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004027
Daniel Vetter4356d582013-10-16 22:55:55 +02004028 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004029 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004030
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004031 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4032 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4033 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02004034 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004035
4036 iir = new_iir;
4037 }
Imre Deak1f814da2015-12-16 02:52:19 +02004038 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004039
Imre Deak1f814da2015-12-16 02:52:19 +02004040out:
4041 enable_rpm_wakeref_asserts(dev_priv);
4042
4043 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004044}
4045
4046static void i8xx_irq_uninstall(struct drm_device * dev)
4047{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004048 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004049 int pipe;
4050
Damien Lespiau055e3932014-08-18 13:49:10 +01004051 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004052 /* Clear enable bits; then clear status bits */
4053 I915_WRITE(PIPESTAT(pipe), 0);
4054 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4055 }
4056 I915_WRITE16(IMR, 0xffff);
4057 I915_WRITE16(IER, 0x0);
4058 I915_WRITE16(IIR, I915_READ16(IIR));
4059}
4060
Chris Wilsona266c7d2012-04-24 22:59:44 +01004061static void i915_irq_preinstall(struct drm_device * dev)
4062{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004063 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004064 int pipe;
4065
Chris Wilsona266c7d2012-04-24 22:59:44 +01004066 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004067 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004068 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4069 }
4070
Chris Wilson00d98eb2012-04-24 22:59:48 +01004071 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004072 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004073 I915_WRITE(PIPESTAT(pipe), 0);
4074 I915_WRITE(IMR, 0xffffffff);
4075 I915_WRITE(IER, 0x0);
4076 POSTING_READ(IER);
4077}
4078
4079static int i915_irq_postinstall(struct drm_device *dev)
4080{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004081 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01004082 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004083
Chris Wilson38bde182012-04-24 22:59:50 +01004084 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4085
4086 /* Unmask the interrupts that we always want on. */
4087 dev_priv->irq_mask =
4088 ~(I915_ASLE_INTERRUPT |
4089 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4090 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4091 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02004092 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004093
4094 enable_mask =
4095 I915_ASLE_INTERRUPT |
4096 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4097 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004098 I915_USER_INTERRUPT;
4099
Chris Wilsona266c7d2012-04-24 22:59:44 +01004100 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004101 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004102 POSTING_READ(PORT_HOTPLUG_EN);
4103
Chris Wilsona266c7d2012-04-24 22:59:44 +01004104 /* Enable in IER... */
4105 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4106 /* and unmask in IMR */
4107 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4108 }
4109
Chris Wilsona266c7d2012-04-24 22:59:44 +01004110 I915_WRITE(IMR, dev_priv->irq_mask);
4111 I915_WRITE(IER, enable_mask);
4112 POSTING_READ(IER);
4113
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004114 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004115
Daniel Vetter379ef822013-10-16 22:55:56 +02004116 /* Interrupt setup is already guaranteed to be single-threaded, this is
4117 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004118 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004119 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4120 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004121 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004122
Daniel Vetter20afbda2012-12-11 14:05:07 +01004123 return 0;
4124}
4125
Daniel Vetterff1f5252012-10-02 15:10:55 +02004126static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004127{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004128 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004129 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01004130 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004131 u32 flip_mask =
4132 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4133 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004134 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004135
Imre Deak2dd2a882015-02-24 11:14:30 +02004136 if (!intel_irqs_enabled(dev_priv))
4137 return IRQ_NONE;
4138
Imre Deak1f814da2015-12-16 02:52:19 +02004139 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4140 disable_rpm_wakeref_asserts(dev_priv);
4141
Chris Wilsona266c7d2012-04-24 22:59:44 +01004142 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004143 do {
4144 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004145 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004146
4147 /* Can't rely on pipestat interrupt bit in iir as it might
4148 * have been cleared after the pipestat interrupt was received.
4149 * It doesn't set the bit in iir again, but it still produces
4150 * interrupts (for non-MSI).
4151 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004152 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004153 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004154 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004155
Damien Lespiau055e3932014-08-18 13:49:10 +01004156 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004157 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004158 pipe_stats[pipe] = I915_READ(reg);
4159
Chris Wilson38bde182012-04-24 22:59:50 +01004160 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004161 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004162 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004163 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004164 }
4165 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004166 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004167
4168 if (!irq_received)
4169 break;
4170
Chris Wilsona266c7d2012-04-24 22:59:44 +01004171 /* Consume port. Then clear IIR or we'll miss events */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004172 if (I915_HAS_HOTPLUG(dev_priv) &&
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004173 iir & I915_DISPLAY_PORT_INTERRUPT) {
4174 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4175 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004176 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004177 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004178
Chris Wilson38bde182012-04-24 22:59:50 +01004179 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180 new_iir = I915_READ(IIR); /* Flush posted writes */
4181
Chris Wilsona266c7d2012-04-24 22:59:44 +01004182 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004183 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004184
Damien Lespiau055e3932014-08-18 13:49:10 +01004185 for_each_pipe(dev_priv, pipe) {
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02004186 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
4187 intel_pipe_handle_vblank(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004188
4189 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4190 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004191
4192 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004193 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004194
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004195 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4196 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4197 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004198 }
4199
Chris Wilsona266c7d2012-04-24 22:59:44 +01004200 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004201 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004202
4203 /* With MSI, interrupts are only generated when iir
4204 * transitions from zero to nonzero. If another bit got
4205 * set while we were handling the existing iir bits, then
4206 * we would never get another interrupt.
4207 *
4208 * This is fine on non-MSI as well, as if we hit this path
4209 * we avoid exiting the interrupt handler only to generate
4210 * another one.
4211 *
4212 * Note that for MSI this could cause a stray interrupt report
4213 * if an interrupt landed in the time between writing IIR and
4214 * the posting read. This should be rare enough to never
4215 * trigger the 99% of 100,000 interrupts test for disabling
4216 * stray interrupts.
4217 */
Chris Wilson38bde182012-04-24 22:59:50 +01004218 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004219 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004220 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004221
Imre Deak1f814da2015-12-16 02:52:19 +02004222 enable_rpm_wakeref_asserts(dev_priv);
4223
Chris Wilsona266c7d2012-04-24 22:59:44 +01004224 return ret;
4225}
4226
4227static void i915_irq_uninstall(struct drm_device * dev)
4228{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004229 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004230 int pipe;
4231
Chris Wilsona266c7d2012-04-24 22:59:44 +01004232 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004233 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004234 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4235 }
4236
Chris Wilson00d98eb2012-04-24 22:59:48 +01004237 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004238 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004239 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004240 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004241 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4242 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004243 I915_WRITE(IMR, 0xffffffff);
4244 I915_WRITE(IER, 0x0);
4245
Chris Wilsona266c7d2012-04-24 22:59:44 +01004246 I915_WRITE(IIR, I915_READ(IIR));
4247}
4248
4249static void i965_irq_preinstall(struct drm_device * dev)
4250{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004251 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004252 int pipe;
4253
Egbert Eich0706f172015-09-23 16:15:27 +02004254 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004255 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004256
4257 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004258 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004259 I915_WRITE(PIPESTAT(pipe), 0);
4260 I915_WRITE(IMR, 0xffffffff);
4261 I915_WRITE(IER, 0x0);
4262 POSTING_READ(IER);
4263}
4264
4265static int i965_irq_postinstall(struct drm_device *dev)
4266{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004267 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004268 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004269 u32 error_mask;
4270
Chris Wilsona266c7d2012-04-24 22:59:44 +01004271 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004272 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004273 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004274 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4275 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4276 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4277 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4278 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4279
4280 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004281 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4282 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004283 enable_mask |= I915_USER_INTERRUPT;
4284
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004285 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004286 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004287
Daniel Vetterb79480b2013-06-27 17:52:10 +02004288 /* Interrupt setup is already guaranteed to be single-threaded, this is
4289 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004290 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004291 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4292 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4293 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004294 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004295
Chris Wilsona266c7d2012-04-24 22:59:44 +01004296 /*
4297 * Enable some error detection, note the instruction error mask
4298 * bit is reserved, so we leave it masked.
4299 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004300 if (IS_G4X(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004301 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4302 GM45_ERROR_MEM_PRIV |
4303 GM45_ERROR_CP_PRIV |
4304 I915_ERROR_MEMORY_REFRESH);
4305 } else {
4306 error_mask = ~(I915_ERROR_PAGE_TABLE |
4307 I915_ERROR_MEMORY_REFRESH);
4308 }
4309 I915_WRITE(EMR, error_mask);
4310
4311 I915_WRITE(IMR, dev_priv->irq_mask);
4312 I915_WRITE(IER, enable_mask);
4313 POSTING_READ(IER);
4314
Egbert Eich0706f172015-09-23 16:15:27 +02004315 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004316 POSTING_READ(PORT_HOTPLUG_EN);
4317
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004318 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004319
4320 return 0;
4321}
4322
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004323static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004324{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004325 u32 hotplug_en;
4326
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004327 assert_spin_locked(&dev_priv->irq_lock);
4328
Ville Syrjälä778eb332015-01-09 14:21:13 +02004329 /* Note HDMI and DP share hotplug bits */
4330 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004331 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004332 /* Programming the CRT detection parameters tends
4333 to generate a spurious hotplug event about three
4334 seconds later. So just do it once.
4335 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004336 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004337 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004338 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004339
Ville Syrjälä778eb332015-01-09 14:21:13 +02004340 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004341 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004342 HOTPLUG_INT_EN_MASK |
4343 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4344 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4345 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004346}
4347
Daniel Vetterff1f5252012-10-02 15:10:55 +02004348static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004349{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004350 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004351 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004352 u32 iir, new_iir;
4353 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004354 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004355 u32 flip_mask =
4356 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4357 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004358
Imre Deak2dd2a882015-02-24 11:14:30 +02004359 if (!intel_irqs_enabled(dev_priv))
4360 return IRQ_NONE;
4361
Imre Deak1f814da2015-12-16 02:52:19 +02004362 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4363 disable_rpm_wakeref_asserts(dev_priv);
4364
Chris Wilsona266c7d2012-04-24 22:59:44 +01004365 iir = I915_READ(IIR);
4366
Chris Wilsona266c7d2012-04-24 22:59:44 +01004367 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004368 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004369 bool blc_event = false;
4370
Chris Wilsona266c7d2012-04-24 22:59:44 +01004371 /* Can't rely on pipestat interrupt bit in iir as it might
4372 * have been cleared after the pipestat interrupt was received.
4373 * It doesn't set the bit in iir again, but it still produces
4374 * interrupts (for non-MSI).
4375 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004376 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004377 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004378 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004379
Damien Lespiau055e3932014-08-18 13:49:10 +01004380 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004381 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004382 pipe_stats[pipe] = I915_READ(reg);
4383
4384 /*
4385 * Clear the PIPE*STAT regs before the IIR
4386 */
4387 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004388 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004389 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004390 }
4391 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004392 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004393
4394 if (!irq_received)
4395 break;
4396
4397 ret = IRQ_HANDLED;
4398
4399 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004400 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
4401 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4402 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004403 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004404 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004405
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004406 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004407 new_iir = I915_READ(IIR); /* Flush posted writes */
4408
Chris Wilsona266c7d2012-04-24 22:59:44 +01004409 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004410 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004411 if (iir & I915_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004412 notify_ring(&dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004413
Damien Lespiau055e3932014-08-18 13:49:10 +01004414 for_each_pipe(dev_priv, pipe) {
Maarten Lankhorst8dd634d2016-05-17 15:07:55 +02004415 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
4416 intel_pipe_handle_vblank(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004417
4418 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4419 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004420
4421 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004422 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004423
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004424 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4425 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004426 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004427
4428 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004429 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004430
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004431 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004432 gmbus_irq_handler(dev_priv);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004433
Chris Wilsona266c7d2012-04-24 22:59:44 +01004434 /* With MSI, interrupts are only generated when iir
4435 * transitions from zero to nonzero. If another bit got
4436 * set while we were handling the existing iir bits, then
4437 * we would never get another interrupt.
4438 *
4439 * This is fine on non-MSI as well, as if we hit this path
4440 * we avoid exiting the interrupt handler only to generate
4441 * another one.
4442 *
4443 * Note that for MSI this could cause a stray interrupt report
4444 * if an interrupt landed in the time between writing IIR and
4445 * the posting read. This should be rare enough to never
4446 * trigger the 99% of 100,000 interrupts test for disabling
4447 * stray interrupts.
4448 */
4449 iir = new_iir;
4450 }
4451
Imre Deak1f814da2015-12-16 02:52:19 +02004452 enable_rpm_wakeref_asserts(dev_priv);
4453
Chris Wilsona266c7d2012-04-24 22:59:44 +01004454 return ret;
4455}
4456
4457static void i965_irq_uninstall(struct drm_device * dev)
4458{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004459 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004460 int pipe;
4461
4462 if (!dev_priv)
4463 return;
4464
Egbert Eich0706f172015-09-23 16:15:27 +02004465 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004466 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004467
4468 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004469 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004470 I915_WRITE(PIPESTAT(pipe), 0);
4471 I915_WRITE(IMR, 0xffffffff);
4472 I915_WRITE(IER, 0x0);
4473
Damien Lespiau055e3932014-08-18 13:49:10 +01004474 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004475 I915_WRITE(PIPESTAT(pipe),
4476 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4477 I915_WRITE(IIR, I915_READ(IIR));
4478}
4479
Daniel Vetterfca52a52014-09-30 10:56:45 +02004480/**
4481 * intel_irq_init - initializes irq support
4482 * @dev_priv: i915 device instance
4483 *
4484 * This function initializes all the irq support including work items, timers
4485 * and all the vtables. It does not setup the interrupt itself though.
4486 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004487void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004488{
Daniel Vetterb9632912014-09-30 10:56:44 +02004489 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004490
Jani Nikula77913b32015-06-18 13:06:16 +03004491 intel_hpd_init_work(dev_priv);
4492
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004493 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004494 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004495
Deepak Sa6706b42014-03-15 20:23:22 +05304496 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004497 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004498 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004499 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004500 else
4501 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304502
Chris Wilson737b1502015-01-26 18:03:03 +02004503 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4504 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004505
Daniel Vetterb9632912014-09-30 10:56:44 +02004506 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004507 dev->max_vblank_count = 0;
4508 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004509 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004510 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004511 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004512 } else {
4513 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4514 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004515 }
4516
Ville Syrjälä21da2702014-08-06 14:49:55 +03004517 /*
4518 * Opt out of the vblank disable timer on everything except gen2.
4519 * Gen2 doesn't have a hardware frame counter and so depends on
4520 * vblank interrupts to produce sane vblank seuquence numbers.
4521 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004522 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004523 dev->vblank_disable_immediate = true;
4524
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004525 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4526 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004527
Daniel Vetterb9632912014-09-30 10:56:44 +02004528 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004529 dev->driver->irq_handler = cherryview_irq_handler;
4530 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4531 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4532 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4533 dev->driver->enable_vblank = valleyview_enable_vblank;
4534 dev->driver->disable_vblank = valleyview_disable_vblank;
4535 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004536 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004537 dev->driver->irq_handler = valleyview_irq_handler;
4538 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4539 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4540 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4541 dev->driver->enable_vblank = valleyview_enable_vblank;
4542 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004543 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004544 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004545 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004546 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004547 dev->driver->irq_postinstall = gen8_irq_postinstall;
4548 dev->driver->irq_uninstall = gen8_irq_uninstall;
4549 dev->driver->enable_vblank = gen8_enable_vblank;
4550 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004551 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004552 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004553 else if (HAS_PCH_SPT(dev))
4554 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4555 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004556 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004557 } else if (HAS_PCH_SPLIT(dev)) {
4558 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004559 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004560 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4561 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4562 dev->driver->enable_vblank = ironlake_enable_vblank;
4563 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004564 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004565 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004566 if (IS_GEN2(dev_priv)) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004567 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4568 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4569 dev->driver->irq_handler = i8xx_irq_handler;
4570 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004571 } else if (IS_GEN3(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004572 dev->driver->irq_preinstall = i915_irq_preinstall;
4573 dev->driver->irq_postinstall = i915_irq_postinstall;
4574 dev->driver->irq_uninstall = i915_irq_uninstall;
4575 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004576 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004577 dev->driver->irq_preinstall = i965_irq_preinstall;
4578 dev->driver->irq_postinstall = i965_irq_postinstall;
4579 dev->driver->irq_uninstall = i965_irq_uninstall;
4580 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004581 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004582 if (I915_HAS_HOTPLUG(dev_priv))
4583 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004584 dev->driver->enable_vblank = i915_enable_vblank;
4585 dev->driver->disable_vblank = i915_disable_vblank;
4586 }
4587}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004588
Daniel Vetterfca52a52014-09-30 10:56:45 +02004589/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004590 * intel_irq_install - enables the hardware interrupt
4591 * @dev_priv: i915 device instance
4592 *
4593 * This function enables the hardware interrupt handling, but leaves the hotplug
4594 * handling still disabled. It is called after intel_irq_init().
4595 *
4596 * In the driver load and resume code we need working interrupts in a few places
4597 * but don't want to deal with the hassle of concurrent probe and hotplug
4598 * workers. Hence the split into this two-stage approach.
4599 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004600int intel_irq_install(struct drm_i915_private *dev_priv)
4601{
4602 /*
4603 * We enable some interrupt sources in our postinstall hooks, so mark
4604 * interrupts as enabled _before_ actually enabling them to avoid
4605 * special cases in our ordering checks.
4606 */
4607 dev_priv->pm.irqs_enabled = true;
4608
4609 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4610}
4611
Daniel Vetterfca52a52014-09-30 10:56:45 +02004612/**
4613 * intel_irq_uninstall - finilizes all irq handling
4614 * @dev_priv: i915 device instance
4615 *
4616 * This stops interrupt and hotplug handling and unregisters and frees all
4617 * resources acquired in the init functions.
4618 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004619void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4620{
4621 drm_irq_uninstall(dev_priv->dev);
4622 intel_hpd_cancel_work(dev_priv);
4623 dev_priv->pm.irqs_enabled = false;
4624}
4625
Daniel Vetterfca52a52014-09-30 10:56:45 +02004626/**
4627 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4628 * @dev_priv: i915 device instance
4629 *
4630 * This function is used to disable interrupts at runtime, both in the runtime
4631 * pm and the system suspend/resume code.
4632 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004633void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004634{
Daniel Vetterb9632912014-09-30 10:56:44 +02004635 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004636 dev_priv->pm.irqs_enabled = false;
Imre Deak2dd2a882015-02-24 11:14:30 +02004637 synchronize_irq(dev_priv->dev->irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004638}
4639
Daniel Vetterfca52a52014-09-30 10:56:45 +02004640/**
4641 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4642 * @dev_priv: i915 device instance
4643 *
4644 * This function is used to enable interrupts at runtime, both in the runtime
4645 * pm and the system suspend/resume code.
4646 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004647void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004648{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004649 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004650 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4651 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004652}