blob: bd6c8b0eeaefd5f7beabd70abdbd18aa6ab5f693 [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
Paulo Zanoni337ba012014-04-01 15:37:16 -0300139/*
140 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
141 */
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200142static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv,
143 i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300144{
145 u32 val = I915_READ(reg);
146
147 if (val == 0)
148 return;
149
150 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200151 i915_mmio_reg_offset(reg), val);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300152 I915_WRITE(reg, 0xffffffff);
153 POSTING_READ(reg);
154 I915_WRITE(reg, 0xffffffff);
155 POSTING_READ(reg);
156}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300157
Paulo Zanoni35079892014-04-01 15:37:15 -0300158#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300159 gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300160 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200161 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
162 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300163} while (0)
164
165#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300166 gen5_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300167 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200168 I915_WRITE(type##IMR, (imr_val)); \
169 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300170} while (0)
171
Imre Deakc9a9a262014-11-05 20:48:37 +0200172static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
173
Egbert Eich0706f172015-09-23 16:15:27 +0200174/* For display hotplug interrupt */
175static inline void
176i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
177 uint32_t mask,
178 uint32_t bits)
179{
180 uint32_t val;
181
182 assert_spin_locked(&dev_priv->irq_lock);
183 WARN_ON(bits & ~mask);
184
185 val = I915_READ(PORT_HOTPLUG_EN);
186 val &= ~mask;
187 val |= bits;
188 I915_WRITE(PORT_HOTPLUG_EN, val);
189}
190
191/**
192 * i915_hotplug_interrupt_update - update hotplug interrupt enable
193 * @dev_priv: driver private
194 * @mask: bits to update
195 * @bits: bits to enable
196 * NOTE: the HPD enable bits are modified both inside and outside
197 * of an interrupt context. To avoid that read-modify-write cycles
198 * interfer, these bits are protected by a spinlock. Since this
199 * function is usually not called from a context where the lock is
200 * held already, this function acquires the lock itself. A non-locking
201 * version is also available.
202 */
203void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
204 uint32_t mask,
205 uint32_t bits)
206{
207 spin_lock_irq(&dev_priv->irq_lock);
208 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
209 spin_unlock_irq(&dev_priv->irq_lock);
210}
211
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300212/**
213 * ilk_update_display_irq - update DEIMR
214 * @dev_priv: driver private
215 * @interrupt_mask: mask of interrupt bits to update
216 * @enabled_irq_mask: mask of interrupt bits to enable
217 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200218void ilk_update_display_irq(struct drm_i915_private *dev_priv,
219 uint32_t interrupt_mask,
220 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800221{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300222 uint32_t new_val;
223
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200224 assert_spin_locked(&dev_priv->irq_lock);
225
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300226 WARN_ON(enabled_irq_mask & ~interrupt_mask);
227
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700228 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300229 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300230
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300231 new_val = dev_priv->irq_mask;
232 new_val &= ~interrupt_mask;
233 new_val |= (~enabled_irq_mask & interrupt_mask);
234
235 if (new_val != dev_priv->irq_mask) {
236 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000237 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000238 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800239 }
240}
241
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300242/**
243 * ilk_update_gt_irq - update GTIMR
244 * @dev_priv: driver private
245 * @interrupt_mask: mask of interrupt bits to update
246 * @enabled_irq_mask: mask of interrupt bits to enable
247 */
248static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
249 uint32_t interrupt_mask,
250 uint32_t enabled_irq_mask)
251{
252 assert_spin_locked(&dev_priv->irq_lock);
253
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100254 WARN_ON(enabled_irq_mask & ~interrupt_mask);
255
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700256 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300257 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300258
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300259 dev_priv->gt_irq_mask &= ~interrupt_mask;
260 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
261 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300262}
263
Daniel Vetter480c8032014-07-16 09:49:40 +0200264void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300265{
266 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100267 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300268}
269
Daniel Vetter480c8032014-07-16 09:49:40 +0200270void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300271{
272 ilk_update_gt_irq(dev_priv, mask, 0);
273}
274
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200275static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200276{
277 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
278}
279
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200280static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200281{
282 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
283}
284
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200285static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200286{
287 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
288}
289
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300290/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200291 * snb_update_pm_irq - update GEN6_PMIMR
292 * @dev_priv: driver private
293 * @interrupt_mask: mask of interrupt bits to update
294 * @enabled_irq_mask: mask of interrupt bits to enable
295 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300296static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
297 uint32_t interrupt_mask,
298 uint32_t enabled_irq_mask)
299{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300300 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300301
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100302 WARN_ON(enabled_irq_mask & ~interrupt_mask);
303
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300304 assert_spin_locked(&dev_priv->irq_lock);
305
Paulo Zanoni605cd252013-08-06 18:57:15 -0300306 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300307 new_val &= ~interrupt_mask;
308 new_val |= (~enabled_irq_mask & interrupt_mask);
309
Paulo Zanoni605cd252013-08-06 18:57:15 -0300310 if (new_val != dev_priv->pm_irq_mask) {
311 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200312 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
313 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300314 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300315}
316
Daniel Vetter480c8032014-07-16 09:49:40 +0200317void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300318{
Imre Deak9939fba2014-11-20 23:01:47 +0200319 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
320 return;
321
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300322 snb_update_pm_irq(dev_priv, mask, mask);
323}
324
Imre Deak9939fba2014-11-20 23:01:47 +0200325static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
326 uint32_t mask)
327{
328 snb_update_pm_irq(dev_priv, mask, 0);
329}
330
Daniel Vetter480c8032014-07-16 09:49:40 +0200331void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300332{
Imre Deak9939fba2014-11-20 23:01:47 +0200333 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
334 return;
335
336 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300337}
338
Chris Wilsondc979972016-05-10 14:10:04 +0100339void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200340{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200341 i915_reg_t reg = gen6_pm_iir(dev_priv);
Imre Deak3cc134e2014-11-19 15:30:03 +0200342
343 spin_lock_irq(&dev_priv->irq_lock);
344 I915_WRITE(reg, dev_priv->pm_rps_events);
345 I915_WRITE(reg, dev_priv->pm_rps_events);
346 POSTING_READ(reg);
Imre Deak096fad92015-03-23 19:11:35 +0200347 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200348 spin_unlock_irq(&dev_priv->irq_lock);
349}
350
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100351void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200352{
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100353 if (READ_ONCE(dev_priv->rps.interrupts_enabled))
354 return;
355
Imre Deakb900b942014-11-05 20:48:48 +0200356 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100357 WARN_ON_ONCE(dev_priv->rps.pm_iir);
358 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200359 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200360 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
361 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200362 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200363
Imre Deakb900b942014-11-05 20:48:48 +0200364 spin_unlock_irq(&dev_priv->irq_lock);
365}
366
Imre Deak59d02a12014-12-19 19:33:26 +0200367u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
368{
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530369 return (mask & ~dev_priv->rps.pm_intr_keep);
Imre Deak59d02a12014-12-19 19:33:26 +0200370}
371
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100372void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200373{
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100374 if (!READ_ONCE(dev_priv->rps.interrupts_enabled))
375 return;
376
Imre Deakd4d70aa2014-11-19 15:30:04 +0200377 spin_lock_irq(&dev_priv->irq_lock);
378 dev_priv->rps.interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200379
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100380 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200381
382 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200383 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
384 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200385
386 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100387 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100388
389 /* Now that we will not be generating any more work, flush any
390 * outsanding tasks. As we are called on the RPS idle path,
391 * we will reset the GPU to minimum frequencies, so the current
392 * state of the worker can be discarded.
393 */
394 cancel_work_sync(&dev_priv->rps.work);
395 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200396}
397
Ben Widawsky09610212014-05-15 20:58:08 +0300398/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200399 * bdw_update_port_irq - update DE port interrupt
400 * @dev_priv: driver private
401 * @interrupt_mask: mask of interrupt bits to update
402 * @enabled_irq_mask: mask of interrupt bits to enable
403 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300404static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
405 uint32_t interrupt_mask,
406 uint32_t enabled_irq_mask)
407{
408 uint32_t new_val;
409 uint32_t old_val;
410
411 assert_spin_locked(&dev_priv->irq_lock);
412
413 WARN_ON(enabled_irq_mask & ~interrupt_mask);
414
415 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
416 return;
417
418 old_val = I915_READ(GEN8_DE_PORT_IMR);
419
420 new_val = old_val;
421 new_val &= ~interrupt_mask;
422 new_val |= (~enabled_irq_mask & interrupt_mask);
423
424 if (new_val != old_val) {
425 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
426 POSTING_READ(GEN8_DE_PORT_IMR);
427 }
428}
429
430/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200431 * bdw_update_pipe_irq - update DE pipe interrupt
432 * @dev_priv: driver private
433 * @pipe: pipe whose interrupt to update
434 * @interrupt_mask: mask of interrupt bits to update
435 * @enabled_irq_mask: mask of interrupt bits to enable
436 */
437void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
438 enum pipe pipe,
439 uint32_t interrupt_mask,
440 uint32_t enabled_irq_mask)
441{
442 uint32_t new_val;
443
444 assert_spin_locked(&dev_priv->irq_lock);
445
446 WARN_ON(enabled_irq_mask & ~interrupt_mask);
447
448 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
449 return;
450
451 new_val = dev_priv->de_irq_mask[pipe];
452 new_val &= ~interrupt_mask;
453 new_val |= (~enabled_irq_mask & interrupt_mask);
454
455 if (new_val != dev_priv->de_irq_mask[pipe]) {
456 dev_priv->de_irq_mask[pipe] = new_val;
457 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
458 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
459 }
460}
461
462/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200463 * ibx_display_interrupt_update - update SDEIMR
464 * @dev_priv: driver private
465 * @interrupt_mask: mask of interrupt bits to update
466 * @enabled_irq_mask: mask of interrupt bits to enable
467 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200468void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
469 uint32_t interrupt_mask,
470 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200471{
472 uint32_t sdeimr = I915_READ(SDEIMR);
473 sdeimr &= ~interrupt_mask;
474 sdeimr |= (~enabled_irq_mask & interrupt_mask);
475
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100476 WARN_ON(enabled_irq_mask & ~interrupt_mask);
477
Daniel Vetterfee884e2013-07-04 23:35:21 +0200478 assert_spin_locked(&dev_priv->irq_lock);
479
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700480 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300481 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300482
Daniel Vetterfee884e2013-07-04 23:35:21 +0200483 I915_WRITE(SDEIMR, sdeimr);
484 POSTING_READ(SDEIMR);
485}
Paulo Zanoni86642812013-04-12 17:57:57 -0300486
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100487static void
Imre Deak755e9012014-02-10 18:42:47 +0200488__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
489 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800490{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200491 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200492 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800493
Daniel Vetterb79480b2013-06-27 17:52:10 +0200494 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200495 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200496
Ville Syrjälä04feced2014-04-03 13:28:33 +0300497 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
498 status_mask & ~PIPESTAT_INT_STATUS_MASK,
499 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
500 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200501 return;
502
503 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200504 return;
505
Imre Deak91d181d2014-02-10 18:42:49 +0200506 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
507
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200508 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200509 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200510 I915_WRITE(reg, pipestat);
511 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800512}
513
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100514static void
Imre Deak755e9012014-02-10 18:42:47 +0200515__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
516 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800517{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200518 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200519 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800520
Daniel Vetterb79480b2013-06-27 17:52:10 +0200521 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200522 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200523
Ville Syrjälä04feced2014-04-03 13:28:33 +0300524 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
525 status_mask & ~PIPESTAT_INT_STATUS_MASK,
526 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
527 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200528 return;
529
Imre Deak755e9012014-02-10 18:42:47 +0200530 if ((pipestat & enable_mask) == 0)
531 return;
532
Imre Deak91d181d2014-02-10 18:42:49 +0200533 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
534
Imre Deak755e9012014-02-10 18:42:47 +0200535 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200536 I915_WRITE(reg, pipestat);
537 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800538}
539
Imre Deak10c59c52014-02-10 18:42:48 +0200540static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
541{
542 u32 enable_mask = status_mask << 16;
543
544 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300545 * On pipe A we don't support the PSR interrupt yet,
546 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200547 */
548 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
549 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300550 /*
551 * On pipe B and C we don't support the PSR interrupt yet, on pipe
552 * A the same bit is for perf counters which we don't use either.
553 */
554 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
555 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200556
557 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
558 SPRITE0_FLIP_DONE_INT_EN_VLV |
559 SPRITE1_FLIP_DONE_INT_EN_VLV);
560 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
561 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
562 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
563 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
564
565 return enable_mask;
566}
567
Imre Deak755e9012014-02-10 18:42:47 +0200568void
569i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
570 u32 status_mask)
571{
572 u32 enable_mask;
573
Wayne Boyer666a4532015-12-09 12:29:35 -0800574 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100575 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200576 status_mask);
577 else
578 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200579 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
580}
581
582void
583i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
584 u32 status_mask)
585{
586 u32 enable_mask;
587
Wayne Boyer666a4532015-12-09 12:29:35 -0800588 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100589 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200590 status_mask);
591 else
592 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200593 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
594}
595
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000596/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300597 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100598 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000599 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100600static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000601{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100602 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300603 return;
604
Daniel Vetter13321782014-09-15 14:55:29 +0200605 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000606
Imre Deak755e9012014-02-10 18:42:47 +0200607 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100608 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200609 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200610 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000611
Daniel Vetter13321782014-09-15 14:55:29 +0200612 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000613}
614
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300615/*
616 * This timing diagram depicts the video signal in and
617 * around the vertical blanking period.
618 *
619 * Assumptions about the fictitious mode used in this example:
620 * vblank_start >= 3
621 * vsync_start = vblank_start + 1
622 * vsync_end = vblank_start + 2
623 * vtotal = vblank_start + 3
624 *
625 * start of vblank:
626 * latch double buffered registers
627 * increment frame counter (ctg+)
628 * generate start of vblank interrupt (gen4+)
629 * |
630 * | frame start:
631 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
632 * | may be shifted forward 1-3 extra lines via PIPECONF
633 * | |
634 * | | start of vsync:
635 * | | generate vsync interrupt
636 * | | |
637 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
638 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
639 * ----va---> <-----------------vb--------------------> <--------va-------------
640 * | | <----vs-----> |
641 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
642 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
643 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
644 * | | |
645 * last visible pixel first visible pixel
646 * | increment frame counter (gen3/4)
647 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
648 *
649 * x = horizontal active
650 * _ = horizontal blanking
651 * hs = horizontal sync
652 * va = vertical active
653 * vb = vertical blanking
654 * vs = vertical sync
655 * vbs = vblank_start (number)
656 *
657 * Summary:
658 * - most events happen at the start of horizontal sync
659 * - frame start happens at the start of horizontal blank, 1-4 lines
660 * (depending on PIPECONF settings) after the start of vblank
661 * - gen3/4 pixel and frame counter are synchronized with the start
662 * of horizontal active on the first line of vertical active
663 */
664
Keith Packard42f52ef2008-10-18 19:39:29 -0700665/* Called from drm generic code, passed a 'crtc', which
666 * we use as a pipe index
667 */
Thierry Reding88e72712015-09-24 18:35:31 +0200668static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700669{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100670 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200671 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300672 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100673 struct intel_crtc *intel_crtc =
674 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200675 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700676
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100677 htotal = mode->crtc_htotal;
678 hsync_start = mode->crtc_hsync_start;
679 vbl_start = mode->crtc_vblank_start;
680 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
681 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300682
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300683 /* Convert to pixel count */
684 vbl_start *= htotal;
685
686 /* Start of vblank event occurs at start of hsync */
687 vbl_start -= htotal - hsync_start;
688
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800689 high_frame = PIPEFRAME(pipe);
690 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100691
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700692 /*
693 * High & low register fields aren't synchronized, so make sure
694 * we get a low value that's stable across two reads of the high
695 * register.
696 */
697 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100698 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300699 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100700 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700701 } while (high1 != high2);
702
Chris Wilson5eddb702010-09-11 13:48:45 +0100703 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300704 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100705 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300706
707 /*
708 * The frame counter increments at beginning of active.
709 * Cook up a vblank counter by also checking the pixel
710 * counter against vblank start.
711 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200712 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700713}
714
Dave Airlie974e59b2015-10-30 09:45:33 +1000715static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800716{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100717 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800718
Ville Syrjälä649636e2015-09-22 19:50:01 +0300719 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800720}
721
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300722/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300723static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
724{
725 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100726 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200727 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300728 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300729 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300730
Ville Syrjälä80715b22014-05-15 20:23:23 +0300731 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300732 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
733 vtotal /= 2;
734
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100735 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300736 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300737 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300738 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300739
740 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700741 * On HSW, the DSL reg (0x70000) appears to return 0 if we
742 * read it just before the start of vblank. So try it again
743 * so we don't accidentally end up spanning a vblank frame
744 * increment, causing the pipe_update_end() code to squak at us.
745 *
746 * The nature of this problem means we can't simply check the ISR
747 * bit and return the vblank start value; nor can we use the scanline
748 * debug register in the transcoder as it appears to have the same
749 * problem. We may need to extend this to include other platforms,
750 * but so far testing only shows the problem on HSW.
751 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100752 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700753 int i, temp;
754
755 for (i = 0; i < 100; i++) {
756 udelay(1);
757 temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) &
758 DSL_LINEMASK_GEN3;
759 if (temp != position) {
760 position = temp;
761 break;
762 }
763 }
764 }
765
766 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300767 * See update_scanline_offset() for the details on the
768 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300769 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300770 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300771}
772
Thierry Reding88e72712015-09-24 18:35:31 +0200773static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200774 unsigned int flags, int *vpos, int *hpos,
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300775 ktime_t *stime, ktime_t *etime,
776 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100777{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100778 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300779 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
780 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300781 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300782 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100783 bool in_vbl = true;
784 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100785 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100786
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200787 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100788 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800789 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100790 return 0;
791 }
792
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300793 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300794 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300795 vtotal = mode->crtc_vtotal;
796 vbl_start = mode->crtc_vblank_start;
797 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100798
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200799 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
800 vbl_start = DIV_ROUND_UP(vbl_start, 2);
801 vbl_end /= 2;
802 vtotal /= 2;
803 }
804
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300805 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
806
Mario Kleinerad3543e2013-10-30 05:13:08 +0100807 /*
808 * Lock uncore.lock, as we will do multiple timing critical raw
809 * register reads, potentially with preemption disabled, so the
810 * following code must not block on uncore.lock.
811 */
812 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300813
Mario Kleinerad3543e2013-10-30 05:13:08 +0100814 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
815
816 /* Get optional system timestamp before query. */
817 if (stime)
818 *stime = ktime_get();
819
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100820 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100821 /* No obvious pixelcount register. Only query vertical
822 * scanout position from Display scan line register.
823 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300824 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100825 } else {
826 /* Have access to pixelcount since start of frame.
827 * We can split this into vertical and horizontal
828 * scanout position.
829 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300830 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100831
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300832 /* convert to pixel counts */
833 vbl_start *= htotal;
834 vbl_end *= htotal;
835 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300836
837 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300838 * In interlaced modes, the pixel counter counts all pixels,
839 * so one field will have htotal more pixels. In order to avoid
840 * the reported position from jumping backwards when the pixel
841 * counter is beyond the length of the shorter field, just
842 * clamp the position the length of the shorter field. This
843 * matches how the scanline counter based position works since
844 * the scanline counter doesn't count the two half lines.
845 */
846 if (position >= vtotal)
847 position = vtotal - 1;
848
849 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300850 * Start of vblank interrupt is triggered at start of hsync,
851 * just prior to the first active line of vblank. However we
852 * consider lines to start at the leading edge of horizontal
853 * active. So, should we get here before we've crossed into
854 * the horizontal active of the first line in vblank, we would
855 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
856 * always add htotal-hsync_start to the current pixel position.
857 */
858 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300859 }
860
Mario Kleinerad3543e2013-10-30 05:13:08 +0100861 /* Get optional system timestamp after query. */
862 if (etime)
863 *etime = ktime_get();
864
865 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
866
867 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
868
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300869 in_vbl = position >= vbl_start && position < vbl_end;
870
871 /*
872 * While in vblank, position will be negative
873 * counting up towards 0 at vbl_end. And outside
874 * vblank, position will be positive counting
875 * up since vbl_end.
876 */
877 if (position >= vbl_start)
878 position -= vbl_end;
879 else
880 position += vtotal - vbl_end;
881
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100882 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300883 *vpos = position;
884 *hpos = 0;
885 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100886 *vpos = position / htotal;
887 *hpos = position - (*vpos * htotal);
888 }
889
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100890 /* In vblank? */
891 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200892 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100893
894 return ret;
895}
896
Ville Syrjäläa225f072014-04-29 13:35:45 +0300897int intel_get_crtc_scanline(struct intel_crtc *crtc)
898{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100899 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +0300900 unsigned long irqflags;
901 int position;
902
903 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
904 position = __intel_get_crtc_scanline(crtc);
905 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
906
907 return position;
908}
909
Thierry Reding88e72712015-09-24 18:35:31 +0200910static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100911 int *max_error,
912 struct timeval *vblank_time,
913 unsigned flags)
914{
Chris Wilson4041b852011-01-22 10:07:56 +0000915 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100916
Thierry Reding88e72712015-09-24 18:35:31 +0200917 if (pipe >= INTEL_INFO(dev)->num_pipes) {
918 DRM_ERROR("Invalid crtc %u\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100919 return -EINVAL;
920 }
921
922 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000923 crtc = intel_get_crtc_for_pipe(dev, pipe);
924 if (crtc == NULL) {
Thierry Reding88e72712015-09-24 18:35:31 +0200925 DRM_ERROR("Invalid crtc %u\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000926 return -EINVAL;
927 }
928
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200929 if (!crtc->hwmode.crtc_clock) {
Thierry Reding88e72712015-09-24 18:35:31 +0200930 DRM_DEBUG_KMS("crtc %u is disabled\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000931 return -EBUSY;
932 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100933
934 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000935 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
936 vblank_time, flags,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200937 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100938}
939
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100940static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800941{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000942 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200943 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200944
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200945 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800946
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200947 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
948
Daniel Vetter20e4d402012-08-08 23:35:39 +0200949 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200950
Jesse Barnes7648fa92010-05-20 14:28:11 -0700951 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000952 busy_up = I915_READ(RCPREVBSYTUPAVG);
953 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800954 max_avg = I915_READ(RCBMAXAVG);
955 min_avg = I915_READ(RCBMINAVG);
956
957 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000958 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200959 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
960 new_delay = dev_priv->ips.cur_delay - 1;
961 if (new_delay < dev_priv->ips.max_delay)
962 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000963 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200964 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
965 new_delay = dev_priv->ips.cur_delay + 1;
966 if (new_delay > dev_priv->ips.min_delay)
967 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800968 }
969
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100970 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200971 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800972
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200973 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200974
Jesse Barnesf97108d2010-01-29 11:27:07 -0800975 return;
976}
977
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000978static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +0100979{
Chris Wilsonaca34b62016-07-06 12:39:02 +0100980 smp_store_mb(engine->breadcrumbs.irq_posted, true);
Chris Wilson83348ba2016-08-09 17:47:51 +0100981 if (intel_engine_wakeup(engine))
Chris Wilson688e6c72016-07-01 17:23:15 +0100982 trace_i915_gem_request_notify(engine);
Chris Wilson549f7362010-10-19 11:19:32 +0100983}
984
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000985static void vlv_c0_read(struct drm_i915_private *dev_priv,
986 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400987{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000988 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
989 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
990 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400991}
992
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000993static bool vlv_c0_above(struct drm_i915_private *dev_priv,
994 const struct intel_rps_ei *old,
995 const struct intel_rps_ei *now,
996 int threshold)
Deepak S31685c22014-07-03 17:33:01 -0400997{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000998 u64 time, c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +0300999 unsigned int mul = 100;
Deepak S31685c22014-07-03 17:33:01 -04001000
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001001 if (old->cz_clock == 0)
1002 return false;
Deepak S31685c22014-07-03 17:33:01 -04001003
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001004 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
1005 mul <<= 8;
1006
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001007 time = now->cz_clock - old->cz_clock;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001008 time *= threshold * dev_priv->czclk_freq;
Deepak S31685c22014-07-03 17:33:01 -04001009
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001010 /* Workload can be split between render + media, e.g. SwapBuffers
1011 * being blitted in X after being rendered in mesa. To account for
1012 * this we need to combine both engines into our activity counter.
1013 */
1014 c0 = now->render_c0 - old->render_c0;
1015 c0 += now->media_c0 - old->media_c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001016 c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC;
Deepak S31685c22014-07-03 17:33:01 -04001017
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001018 return c0 >= time;
1019}
Deepak S31685c22014-07-03 17:33:01 -04001020
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001021void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1022{
1023 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
1024 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001025}
1026
1027static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1028{
1029 struct intel_rps_ei now;
1030 u32 events = 0;
1031
Chris Wilson6f4b12f82015-03-18 09:48:23 +00001032 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001033 return 0;
1034
1035 vlv_c0_read(dev_priv, &now);
1036 if (now.cz_clock == 0)
1037 return 0;
Deepak S31685c22014-07-03 17:33:01 -04001038
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001039 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1040 if (!vlv_c0_above(dev_priv,
1041 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001042 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001043 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1044 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -04001045 }
1046
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001047 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1048 if (vlv_c0_above(dev_priv,
1049 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001050 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001051 events |= GEN6_PM_RP_UP_THRESHOLD;
1052 dev_priv->rps.up_ei = now;
1053 }
1054
1055 return events;
Deepak S31685c22014-07-03 17:33:01 -04001056}
1057
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001058static bool any_waiters(struct drm_i915_private *dev_priv)
1059{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001060 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001061
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001062 for_each_engine(engine, dev_priv)
Chris Wilson688e6c72016-07-01 17:23:15 +01001063 if (intel_engine_has_waiter(engine))
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001064 return true;
1065
1066 return false;
1067}
1068
Ben Widawsky4912d042011-04-25 11:25:20 -07001069static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001070{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001071 struct drm_i915_private *dev_priv =
1072 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001073 bool client_boost;
1074 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001075 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001076
Daniel Vetter59cdb632013-07-04 23:35:28 +02001077 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001078 /* Speed up work cancelation during disabling rps interrupts. */
1079 if (!dev_priv->rps.interrupts_enabled) {
1080 spin_unlock_irq(&dev_priv->irq_lock);
1081 return;
1082 }
Imre Deak1f814da2015-12-16 02:52:19 +02001083
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001084 pm_iir = dev_priv->rps.pm_iir;
1085 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001086 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1087 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001088 client_boost = dev_priv->rps.client_boost;
1089 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001090 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001091
Paulo Zanoni60611c12013-08-15 11:50:01 -03001092 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301093 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001094
Chris Wilson8d3afd72015-05-21 21:01:47 +01001095 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilsonc33d2472016-07-04 08:08:36 +01001096 return;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001097
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001098 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001099
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001100 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1101
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001102 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001103 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001104 min = dev_priv->rps.min_freq_softlimit;
1105 max = dev_priv->rps.max_freq_softlimit;
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001106 if (client_boost || any_waiters(dev_priv))
1107 max = dev_priv->rps.max_freq;
1108 if (client_boost && new_delay < dev_priv->rps.boost_freq) {
1109 new_delay = dev_priv->rps.boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001110 adj = 0;
1111 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001112 if (adj > 0)
1113 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001114 else /* CHV needs even encode values */
1115 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001116 /*
1117 * For better performance, jump directly
1118 * to RPe if we're below it.
1119 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001120 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001121 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001122 adj = 0;
1123 }
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001124 } else if (client_boost || any_waiters(dev_priv)) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001125 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001126 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001127 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1128 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001129 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001130 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001131 adj = 0;
1132 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1133 if (adj < 0)
1134 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001135 else /* CHV needs even encode values */
1136 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001137 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001138 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001139 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001140
Chris Wilsonedcf2842015-04-07 16:20:29 +01001141 dev_priv->rps.last_adj = adj;
1142
Ben Widawsky79249632012-09-07 19:43:42 -07001143 /* sysfs frequency interfaces may have snuck in while servicing the
1144 * interrupt
1145 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001146 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001147 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301148
Chris Wilsondc979972016-05-10 14:10:04 +01001149 intel_set_rps(dev_priv, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001150
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001151 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001152}
1153
Ben Widawskye3689192012-05-25 16:56:22 -07001154
1155/**
1156 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1157 * occurred.
1158 * @work: workqueue struct
1159 *
1160 * Doesn't actually do anything except notify userspace. As a consequence of
1161 * this event, userspace should try to remap the bad rows since statistically
1162 * it is likely the same row is more likely to go bad again.
1163 */
1164static void ivybridge_parity_work(struct work_struct *work)
1165{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001166 struct drm_i915_private *dev_priv =
1167 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001168 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001169 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001170 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001171 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001172
1173 /* We must turn off DOP level clock gating to access the L3 registers.
1174 * In order to prevent a get/put style interface, acquire struct mutex
1175 * any time we access those registers.
1176 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001177 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001178
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001179 /* If we've screwed up tracking, just let the interrupt fire again */
1180 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1181 goto out;
1182
Ben Widawskye3689192012-05-25 16:56:22 -07001183 misccpctl = I915_READ(GEN7_MISCCPCTL);
1184 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1185 POSTING_READ(GEN7_MISCCPCTL);
1186
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001187 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001188 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001189
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001190 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001191 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001192 break;
1193
1194 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1195
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001196 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001197
1198 error_status = I915_READ(reg);
1199 row = GEN7_PARITY_ERROR_ROW(error_status);
1200 bank = GEN7_PARITY_ERROR_BANK(error_status);
1201 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1202
1203 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1204 POSTING_READ(reg);
1205
1206 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1207 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1208 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1209 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1210 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1211 parity_event[5] = NULL;
1212
Chris Wilson91c8a322016-07-05 10:40:23 +01001213 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001214 KOBJ_CHANGE, parity_event);
1215
1216 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1217 slice, row, bank, subbank);
1218
1219 kfree(parity_event[4]);
1220 kfree(parity_event[3]);
1221 kfree(parity_event[2]);
1222 kfree(parity_event[1]);
1223 }
Ben Widawskye3689192012-05-25 16:56:22 -07001224
1225 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1226
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001227out:
1228 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001229 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001230 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001231 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001232
Chris Wilson91c8a322016-07-05 10:40:23 +01001233 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001234}
1235
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001236static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1237 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001238{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001239 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001240 return;
1241
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001242 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001243 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001244 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001245
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001246 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001247 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1248 dev_priv->l3_parity.which_slice |= 1 << 1;
1249
1250 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1251 dev_priv->l3_parity.which_slice |= 1 << 0;
1252
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001253 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001254}
1255
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001256static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001257 u32 gt_iir)
1258{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001259 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001260 notify_ring(&dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001261 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001262 notify_ring(&dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001263}
1264
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001265static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001266 u32 gt_iir)
1267{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001268 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001269 notify_ring(&dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001270 if (gt_iir & GT_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001271 notify_ring(&dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001272 if (gt_iir & GT_BLT_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001273 notify_ring(&dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001274
Ben Widawskycc609d52013-05-28 19:22:29 -07001275 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1276 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001277 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1278 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001279
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001280 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1281 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001282}
1283
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001284static __always_inline void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001285gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001286{
1287 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift))
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001288 notify_ring(engine);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001289 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift))
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01001290 tasklet_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001291}
1292
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001293static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1294 u32 master_ctl,
1295 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001296{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001297 irqreturn_t ret = IRQ_NONE;
1298
1299 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001300 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1301 if (gt_iir[0]) {
1302 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001303 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001304 } else
1305 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1306 }
1307
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001308 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001309 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1310 if (gt_iir[1]) {
1311 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001312 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001313 } else
1314 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1315 }
1316
Chris Wilson74cdb332015-04-07 16:21:05 +01001317 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001318 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1319 if (gt_iir[3]) {
1320 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001321 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001322 } else
1323 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1324 }
1325
Ben Widawsky09610212014-05-15 20:58:08 +03001326 if (master_ctl & GEN8_GT_PM_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001327 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
1328 if (gt_iir[2] & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001329 I915_WRITE_FW(GEN8_GT_IIR(2),
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001330 gt_iir[2] & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001331 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001332 } else
1333 DRM_ERROR("The master control interrupt lied (PM)!\n");
1334 }
1335
Ben Widawskyabd58f02013-11-02 21:07:09 -07001336 return ret;
1337}
1338
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001339static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1340 u32 gt_iir[4])
1341{
1342 if (gt_iir[0]) {
1343 gen8_cs_irq_handler(&dev_priv->engine[RCS],
1344 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
1345 gen8_cs_irq_handler(&dev_priv->engine[BCS],
1346 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1347 }
1348
1349 if (gt_iir[1]) {
1350 gen8_cs_irq_handler(&dev_priv->engine[VCS],
1351 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
1352 gen8_cs_irq_handler(&dev_priv->engine[VCS2],
1353 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1354 }
1355
1356 if (gt_iir[3])
1357 gen8_cs_irq_handler(&dev_priv->engine[VECS],
1358 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1359
1360 if (gt_iir[2] & dev_priv->pm_rps_events)
1361 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
1362}
1363
Imre Deak63c88d22015-07-20 14:43:39 -07001364static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1365{
1366 switch (port) {
1367 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001368 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001369 case PORT_B:
1370 return val & PORTB_HOTPLUG_LONG_DETECT;
1371 case PORT_C:
1372 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001373 default:
1374 return false;
1375 }
1376}
1377
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001378static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1379{
1380 switch (port) {
1381 case PORT_E:
1382 return val & PORTE_HOTPLUG_LONG_DETECT;
1383 default:
1384 return false;
1385 }
1386}
1387
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001388static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1389{
1390 switch (port) {
1391 case PORT_A:
1392 return val & PORTA_HOTPLUG_LONG_DETECT;
1393 case PORT_B:
1394 return val & PORTB_HOTPLUG_LONG_DETECT;
1395 case PORT_C:
1396 return val & PORTC_HOTPLUG_LONG_DETECT;
1397 case PORT_D:
1398 return val & PORTD_HOTPLUG_LONG_DETECT;
1399 default:
1400 return false;
1401 }
1402}
1403
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001404static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1405{
1406 switch (port) {
1407 case PORT_A:
1408 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1409 default:
1410 return false;
1411 }
1412}
1413
Jani Nikula676574d2015-05-28 15:43:53 +03001414static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001415{
1416 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001417 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001418 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001419 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001420 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001421 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001422 return val & PORTD_HOTPLUG_LONG_DETECT;
1423 default:
1424 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001425 }
1426}
1427
Jani Nikula676574d2015-05-28 15:43:53 +03001428static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001429{
1430 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001431 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001432 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001433 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001434 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001435 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001436 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1437 default:
1438 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001439 }
1440}
1441
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001442/*
1443 * Get a bit mask of pins that have triggered, and which ones may be long.
1444 * This can be called multiple times with the same masks to accumulate
1445 * hotplug detection results from several registers.
1446 *
1447 * Note that the caller is expected to zero out the masks initially.
1448 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001449static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001450 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001451 const u32 hpd[HPD_NUM_PINS],
1452 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001453{
Jani Nikula8c841e52015-06-18 13:06:17 +03001454 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001455 int i;
1456
Jani Nikula676574d2015-05-28 15:43:53 +03001457 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001458 if ((hpd[i] & hotplug_trigger) == 0)
1459 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001460
Jani Nikula8c841e52015-06-18 13:06:17 +03001461 *pin_mask |= BIT(i);
1462
Imre Deakcc24fcd2015-07-21 15:32:45 -07001463 if (!intel_hpd_pin_to_port(i, &port))
1464 continue;
1465
Imre Deakfd63e2a2015-07-21 15:32:44 -07001466 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001467 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001468 }
1469
1470 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1471 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1472
1473}
1474
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001475static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001476{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001477 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001478}
1479
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001480static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001481{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001482 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001483}
1484
Shuang He8bf1e9f2013-10-15 18:55:27 +01001485#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001486static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1487 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001488 uint32_t crc0, uint32_t crc1,
1489 uint32_t crc2, uint32_t crc3,
1490 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001491{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001492 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1493 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001494 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001495
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001496 spin_lock(&pipe_crc->lock);
1497
Damien Lespiau0c912c72013-10-15 18:55:37 +01001498 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001499 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001500 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001501 return;
1502 }
1503
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001504 head = pipe_crc->head;
1505 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001506
1507 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001508 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001509 DRM_ERROR("CRC buffer overflowing\n");
1510 return;
1511 }
1512
1513 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001514
Chris Wilson91c8a322016-07-05 10:40:23 +01001515 entry->frame = dev_priv->drm.driver->get_vblank_counter(&dev_priv->drm,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001516 pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001517 entry->crc[0] = crc0;
1518 entry->crc[1] = crc1;
1519 entry->crc[2] = crc2;
1520 entry->crc[3] = crc3;
1521 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001522
1523 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001524 pipe_crc->head = head;
1525
1526 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001527
1528 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001529}
Daniel Vetter277de952013-10-18 16:37:07 +02001530#else
1531static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001532display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1533 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001534 uint32_t crc0, uint32_t crc1,
1535 uint32_t crc2, uint32_t crc3,
1536 uint32_t crc4) {}
1537#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001538
Daniel Vetter277de952013-10-18 16:37:07 +02001539
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001540static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1541 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001542{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001543 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001544 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1545 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001546}
1547
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001548static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1549 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001550{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001551 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001552 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1553 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1554 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1555 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1556 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001557}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001558
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001559static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1560 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001561{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001562 uint32_t res1, res2;
1563
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001564 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001565 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1566 else
1567 res1 = 0;
1568
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001569 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001570 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1571 else
1572 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001573
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001574 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001575 I915_READ(PIPE_CRC_RES_RED(pipe)),
1576 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1577 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1578 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001579}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001580
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001581/* The RPS events need forcewake, so we add them to a work queue and mask their
1582 * IMR bits until the work is done. Other interrupts can be processed without
1583 * the work queue. */
1584static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001585{
Deepak Sa6706b42014-03-15 20:23:22 +05301586 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001587 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001588 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001589 if (dev_priv->rps.interrupts_enabled) {
1590 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001591 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001592 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001593 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001594 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001595
Imre Deakc9a9a262014-11-05 20:48:37 +02001596 if (INTEL_INFO(dev_priv)->gen >= 8)
1597 return;
1598
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001599 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001600 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001601 notify_ring(&dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001602
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001603 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1604 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001605 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001606}
1607
Daniel Vetter5a21b662016-05-24 17:13:53 +02001608static bool intel_pipe_handle_vblank(struct drm_i915_private *dev_priv,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001609 enum pipe pipe)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001610{
Daniel Vetter5a21b662016-05-24 17:13:53 +02001611 bool ret;
1612
Chris Wilson91c8a322016-07-05 10:40:23 +01001613 ret = drm_handle_vblank(&dev_priv->drm, pipe);
Daniel Vetter5a21b662016-05-24 17:13:53 +02001614 if (ret)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001615 intel_finish_page_flip_mmio(dev_priv, pipe);
Daniel Vetter5a21b662016-05-24 17:13:53 +02001616
1617 return ret;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001618}
1619
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001620static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1621 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001622{
Imre Deakc1874ed2014-02-04 21:35:46 +02001623 int pipe;
1624
Imre Deak58ead0d2014-02-04 21:35:47 +02001625 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001626
1627 if (!dev_priv->display_irqs_enabled) {
1628 spin_unlock(&dev_priv->irq_lock);
1629 return;
1630 }
1631
Damien Lespiau055e3932014-08-18 13:49:10 +01001632 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001633 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001634 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001635
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001636 /*
1637 * PIPESTAT bits get signalled even when the interrupt is
1638 * disabled with the mask bits, and some of the status bits do
1639 * not generate interrupts at all (like the underrun bit). Hence
1640 * we need to be careful that we only handle what we want to
1641 * handle.
1642 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001643
1644 /* fifo underruns are filterered in the underrun handler. */
1645 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001646
1647 switch (pipe) {
1648 case PIPE_A:
1649 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1650 break;
1651 case PIPE_B:
1652 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1653 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001654 case PIPE_C:
1655 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1656 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001657 }
1658 if (iir & iir_bit)
1659 mask |= dev_priv->pipestat_irq_mask[pipe];
1660
1661 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001662 continue;
1663
1664 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001665 mask |= PIPESTAT_INT_ENABLE_MASK;
1666 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001667
1668 /*
1669 * Clear the PIPE*STAT regs before the IIR
1670 */
Imre Deak91d181d2014-02-10 18:42:49 +02001671 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1672 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001673 I915_WRITE(reg, pipe_stats[pipe]);
1674 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001675 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001676}
1677
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001678static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001679 u32 pipe_stats[I915_MAX_PIPES])
1680{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001681 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001682
Damien Lespiau055e3932014-08-18 13:49:10 +01001683 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02001684 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1685 intel_pipe_handle_vblank(dev_priv, pipe))
1686 intel_check_page_flip(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001687
Maarten Lankhorst5251f042016-05-17 15:07:47 +02001688 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001689 intel_finish_page_flip_cs(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001690
1691 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001692 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001693
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001694 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1695 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001696 }
1697
1698 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001699 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001700}
1701
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001702static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001703{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001704 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001705
1706 if (hotplug_status)
1707 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1708
1709 return hotplug_status;
1710}
1711
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001712static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001713 u32 hotplug_status)
1714{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001715 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001716
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001717 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1718 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001719 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001720
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001721 if (hotplug_trigger) {
1722 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1723 hotplug_trigger, hpd_status_g4x,
1724 i9xx_port_hotplug_long_detect);
1725
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001726 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001727 }
Jani Nikula369712e2015-05-27 15:03:40 +03001728
1729 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001730 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001731 } else {
1732 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001733
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001734 if (hotplug_trigger) {
1735 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001736 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001737 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001738 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001739 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001740 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001741}
1742
Daniel Vetterff1f5252012-10-02 15:10:55 +02001743static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001744{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001745 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001746 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001747 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001748
Imre Deak2dd2a882015-02-24 11:14:30 +02001749 if (!intel_irqs_enabled(dev_priv))
1750 return IRQ_NONE;
1751
Imre Deak1f814da2015-12-16 02:52:19 +02001752 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1753 disable_rpm_wakeref_asserts(dev_priv);
1754
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001755 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001756 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001757 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001758 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001759 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001760
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001761 gt_iir = I915_READ(GTIIR);
1762 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001763 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001764
1765 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001766 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001767
1768 ret = IRQ_HANDLED;
1769
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001770 /*
1771 * Theory on interrupt generation, based on empirical evidence:
1772 *
1773 * x = ((VLV_IIR & VLV_IER) ||
1774 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1775 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1776 *
1777 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1778 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1779 * guarantee the CPU interrupt will be raised again even if we
1780 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1781 * bits this time around.
1782 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001783 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001784 ier = I915_READ(VLV_IER);
1785 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001786
1787 if (gt_iir)
1788 I915_WRITE(GTIIR, gt_iir);
1789 if (pm_iir)
1790 I915_WRITE(GEN6_PMIIR, pm_iir);
1791
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001792 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001793 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001794
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001795 /* Call regardless, as some status bits might not be
1796 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001797 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001798
1799 /*
1800 * VLV_IIR is single buffered, and reflects the level
1801 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1802 */
1803 if (iir)
1804 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001805
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001806 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001807 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1808 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001809
Ville Syrjälä52894872016-04-13 21:19:56 +03001810 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001811 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03001812 if (pm_iir)
1813 gen6_rps_irq_handler(dev_priv, pm_iir);
1814
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001815 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001816 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001817
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001818 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001819 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001820
Imre Deak1f814da2015-12-16 02:52:19 +02001821 enable_rpm_wakeref_asserts(dev_priv);
1822
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001823 return ret;
1824}
1825
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001826static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1827{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001828 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001829 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001830 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001831
Imre Deak2dd2a882015-02-24 11:14:30 +02001832 if (!intel_irqs_enabled(dev_priv))
1833 return IRQ_NONE;
1834
Imre Deak1f814da2015-12-16 02:52:19 +02001835 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1836 disable_rpm_wakeref_asserts(dev_priv);
1837
Chris Wilson579de732016-03-14 09:01:57 +00001838 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001839 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001840 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001841 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001842 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001843 u32 ier = 0;
1844
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001845 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1846 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001847
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001848 if (master_ctl == 0 && iir == 0)
1849 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001850
Oscar Mateo27b6c122014-06-16 16:11:00 +01001851 ret = IRQ_HANDLED;
1852
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001853 /*
1854 * Theory on interrupt generation, based on empirical evidence:
1855 *
1856 * x = ((VLV_IIR & VLV_IER) ||
1857 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1858 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1859 *
1860 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1861 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1862 * guarantee the CPU interrupt will be raised again even if we
1863 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1864 * bits this time around.
1865 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001866 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001867 ier = I915_READ(VLV_IER);
1868 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001869
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001870 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001871
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001872 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001873 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001874
Oscar Mateo27b6c122014-06-16 16:11:00 +01001875 /* Call regardless, as some status bits might not be
1876 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001877 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001878
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001879 /*
1880 * VLV_IIR is single buffered, and reflects the level
1881 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1882 */
1883 if (iir)
1884 I915_WRITE(VLV_IIR, iir);
1885
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001886 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03001887 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001888 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001889
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001890 gen8_gt_irq_handler(dev_priv, gt_iir);
1891
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001892 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001893 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001894
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001895 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00001896 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001897
Imre Deak1f814da2015-12-16 02:52:19 +02001898 enable_rpm_wakeref_asserts(dev_priv);
1899
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001900 return ret;
1901}
1902
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001903static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1904 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03001905 const u32 hpd[HPD_NUM_PINS])
1906{
Ville Syrjälä40e56412015-08-27 23:56:10 +03001907 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1908
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001909 /*
1910 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1911 * unless we touch the hotplug register, even if hotplug_trigger is
1912 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1913 * errors.
1914 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03001915 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001916 if (!hotplug_trigger) {
1917 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1918 PORTD_HOTPLUG_STATUS_MASK |
1919 PORTC_HOTPLUG_STATUS_MASK |
1920 PORTB_HOTPLUG_STATUS_MASK;
1921 dig_hotplug_reg &= ~mask;
1922 }
1923
Ville Syrjälä40e56412015-08-27 23:56:10 +03001924 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001925 if (!hotplug_trigger)
1926 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03001927
1928 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1929 dig_hotplug_reg, hpd,
1930 pch_port_hotplug_long_detect);
1931
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001932 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03001933}
1934
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001935static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001936{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001937 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001938 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001939
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001940 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001941
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001942 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1943 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1944 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001945 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001946 port_name(port));
1947 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001948
Daniel Vetterce99c252012-12-01 13:53:47 +01001949 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001950 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01001951
Jesse Barnes776ad802011-01-04 15:09:39 -08001952 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001953 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08001954
1955 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1956 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1957
1958 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1959 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1960
1961 if (pch_iir & SDE_POISON)
1962 DRM_ERROR("PCH poison interrupt\n");
1963
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001964 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001965 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001966 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1967 pipe_name(pipe),
1968 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001969
1970 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1971 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1972
1973 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1974 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1975
Jesse Barnes776ad802011-01-04 15:09:39 -08001976 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001977 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001978
1979 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001980 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001981}
1982
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001983static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03001984{
Paulo Zanoni86642812013-04-12 17:57:57 -03001985 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001986 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001987
Paulo Zanonide032bf2013-04-12 17:57:58 -03001988 if (err_int & ERR_INT_POISON)
1989 DRM_ERROR("Poison interrupt\n");
1990
Damien Lespiau055e3932014-08-18 13:49:10 +01001991 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001992 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1993 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03001994
Daniel Vetter5a69b892013-10-16 22:55:52 +02001995 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001996 if (IS_IVYBRIDGE(dev_priv))
1997 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001998 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001999 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002000 }
2001 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002002
Paulo Zanoni86642812013-04-12 17:57:57 -03002003 I915_WRITE(GEN7_ERR_INT, err_int);
2004}
2005
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002006static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002007{
Paulo Zanoni86642812013-04-12 17:57:57 -03002008 u32 serr_int = I915_READ(SERR_INT);
2009
Paulo Zanonide032bf2013-04-12 17:57:58 -03002010 if (serr_int & SERR_INT_POISON)
2011 DRM_ERROR("PCH poison interrupt\n");
2012
Paulo Zanoni86642812013-04-12 17:57:57 -03002013 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002014 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002015
2016 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002017 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002018
2019 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002020 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002021
2022 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002023}
2024
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002025static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002026{
Adam Jackson23e81d62012-06-06 15:45:44 -04002027 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002028 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002029
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002030 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002031
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002032 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2033 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2034 SDE_AUDIO_POWER_SHIFT_CPT);
2035 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2036 port_name(port));
2037 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002038
2039 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002040 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002041
2042 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002043 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002044
2045 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2046 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2047
2048 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2049 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2050
2051 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002052 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002053 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2054 pipe_name(pipe),
2055 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002056
2057 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002058 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002059}
2060
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002061static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002062{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002063 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2064 ~SDE_PORTE_HOTPLUG_SPT;
2065 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2066 u32 pin_mask = 0, long_mask = 0;
2067
2068 if (hotplug_trigger) {
2069 u32 dig_hotplug_reg;
2070
2071 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2072 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2073
2074 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2075 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002076 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002077 }
2078
2079 if (hotplug2_trigger) {
2080 u32 dig_hotplug_reg;
2081
2082 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2083 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2084
2085 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2086 dig_hotplug_reg, hpd_spt,
2087 spt_port_hotplug2_long_detect);
2088 }
2089
2090 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002091 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002092
2093 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002094 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002095}
2096
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002097static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2098 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002099 const u32 hpd[HPD_NUM_PINS])
2100{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002101 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2102
2103 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2104 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2105
2106 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2107 dig_hotplug_reg, hpd,
2108 ilk_port_hotplug_long_detect);
2109
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002110 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002111}
2112
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002113static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2114 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002115{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002116 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002117 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2118
Ville Syrjälä40e56412015-08-27 23:56:10 +03002119 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002120 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002121
2122 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002123 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002124
2125 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002126 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002127
Paulo Zanonic008bc62013-07-12 16:35:10 -03002128 if (de_iir & DE_POISON)
2129 DRM_ERROR("Poison interrupt\n");
2130
Damien Lespiau055e3932014-08-18 13:49:10 +01002131 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002132 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2133 intel_pipe_handle_vblank(dev_priv, pipe))
2134 intel_check_page_flip(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002135
Daniel Vetter40da17c22013-10-21 18:04:36 +02002136 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002137 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002138
Daniel Vetter40da17c22013-10-21 18:04:36 +02002139 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002140 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002141
Daniel Vetter40da17c22013-10-21 18:04:36 +02002142 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002143 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002144 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002145 }
2146
2147 /* check event from PCH */
2148 if (de_iir & DE_PCH_EVENT) {
2149 u32 pch_iir = I915_READ(SDEIIR);
2150
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002151 if (HAS_PCH_CPT(dev_priv))
2152 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002153 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002154 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002155
2156 /* should clear PCH hotplug event before clear CPU irq */
2157 I915_WRITE(SDEIIR, pch_iir);
2158 }
2159
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002160 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2161 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002162}
2163
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002164static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2165 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002166{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002167 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002168 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2169
Ville Syrjälä40e56412015-08-27 23:56:10 +03002170 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002171 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002172
2173 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002174 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002175
2176 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002177 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002178
2179 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002180 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002181
Damien Lespiau055e3932014-08-18 13:49:10 +01002182 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002183 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2184 intel_pipe_handle_vblank(dev_priv, pipe))
2185 intel_check_page_flip(dev_priv, pipe);
Daniel Vetter40da17c22013-10-21 18:04:36 +02002186
2187 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002188 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002189 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002190 }
2191
2192 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002193 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002194 u32 pch_iir = I915_READ(SDEIIR);
2195
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002196 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002197
2198 /* clear PCH hotplug event before clear CPU irq */
2199 I915_WRITE(SDEIIR, pch_iir);
2200 }
2201}
2202
Oscar Mateo72c90f62014-06-16 16:10:57 +01002203/*
2204 * To handle irqs with the minimum potential races with fresh interrupts, we:
2205 * 1 - Disable Master Interrupt Control.
2206 * 2 - Find the source(s) of the interrupt.
2207 * 3 - Clear the Interrupt Identity bits (IIR).
2208 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2209 * 5 - Re-enable Master Interrupt Control.
2210 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002211static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002212{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002213 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002214 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002215 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002216 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002217
Imre Deak2dd2a882015-02-24 11:14:30 +02002218 if (!intel_irqs_enabled(dev_priv))
2219 return IRQ_NONE;
2220
Imre Deak1f814da2015-12-16 02:52:19 +02002221 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2222 disable_rpm_wakeref_asserts(dev_priv);
2223
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002224 /* disable master interrupt before clearing iir */
2225 de_ier = I915_READ(DEIER);
2226 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002227 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002228
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002229 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2230 * interrupts will will be stored on its back queue, and then we'll be
2231 * able to process them after we restore SDEIER (as soon as we restore
2232 * it, we'll get an interrupt if SDEIIR still has something to process
2233 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002234 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002235 sde_ier = I915_READ(SDEIER);
2236 I915_WRITE(SDEIER, 0);
2237 POSTING_READ(SDEIER);
2238 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002239
Oscar Mateo72c90f62014-06-16 16:10:57 +01002240 /* Find, clear, then process each source of interrupt */
2241
Chris Wilson0e434062012-05-09 21:45:44 +01002242 gt_iir = I915_READ(GTIIR);
2243 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002244 I915_WRITE(GTIIR, gt_iir);
2245 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002246 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002247 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002248 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002249 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002250 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002251
2252 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002253 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002254 I915_WRITE(DEIIR, de_iir);
2255 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002256 if (INTEL_GEN(dev_priv) >= 7)
2257 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002258 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002259 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002260 }
2261
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002262 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002263 u32 pm_iir = I915_READ(GEN6_PMIIR);
2264 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002265 I915_WRITE(GEN6_PMIIR, pm_iir);
2266 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002267 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002268 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002269 }
2270
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002271 I915_WRITE(DEIER, de_ier);
2272 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002273 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002274 I915_WRITE(SDEIER, sde_ier);
2275 POSTING_READ(SDEIER);
2276 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002277
Imre Deak1f814da2015-12-16 02:52:19 +02002278 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2279 enable_rpm_wakeref_asserts(dev_priv);
2280
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002281 return ret;
2282}
2283
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002284static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2285 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002286 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302287{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002288 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302289
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002290 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2291 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302292
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002293 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002294 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002295 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002296
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002297 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302298}
2299
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002300static irqreturn_t
2301gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002302{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002303 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002304 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002305 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002306
Ben Widawskyabd58f02013-11-02 21:07:09 -07002307 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002308 iir = I915_READ(GEN8_DE_MISC_IIR);
2309 if (iir) {
2310 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002311 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002312 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002313 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002314 else
2315 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002316 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002317 else
2318 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002319 }
2320
Daniel Vetter6d766f02013-11-07 14:49:55 +01002321 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002322 iir = I915_READ(GEN8_DE_PORT_IIR);
2323 if (iir) {
2324 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302325 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002326
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002327 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002328 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002329
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002330 tmp_mask = GEN8_AUX_CHANNEL_A;
2331 if (INTEL_INFO(dev_priv)->gen >= 9)
2332 tmp_mask |= GEN9_AUX_CHANNEL_B |
2333 GEN9_AUX_CHANNEL_C |
2334 GEN9_AUX_CHANNEL_D;
2335
2336 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002337 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302338 found = true;
2339 }
2340
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002341 if (IS_BROXTON(dev_priv)) {
2342 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2343 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002344 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2345 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002346 found = true;
2347 }
2348 } else if (IS_BROADWELL(dev_priv)) {
2349 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2350 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002351 ilk_hpd_irq_handler(dev_priv,
2352 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002353 found = true;
2354 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302355 }
2356
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002357 if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
2358 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302359 found = true;
2360 }
2361
Shashank Sharmad04a4922014-08-22 17:40:41 +05302362 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002363 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002364 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002365 else
2366 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002367 }
2368
Damien Lespiau055e3932014-08-18 13:49:10 +01002369 for_each_pipe(dev_priv, pipe) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002370 u32 flip_done, fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002371
Daniel Vetterc42664c2013-11-07 11:05:40 +01002372 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2373 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002374
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002375 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2376 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002377 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002378 continue;
2379 }
2380
2381 ret = IRQ_HANDLED;
2382 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2383
Daniel Vetter5a21b662016-05-24 17:13:53 +02002384 if (iir & GEN8_PIPE_VBLANK &&
2385 intel_pipe_handle_vblank(dev_priv, pipe))
2386 intel_check_page_flip(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002387
2388 flip_done = iir;
2389 if (INTEL_INFO(dev_priv)->gen >= 9)
2390 flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE;
2391 else
2392 flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE;
2393
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002394 if (flip_done)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002395 intel_finish_page_flip_cs(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002396
2397 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002398 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002399
2400 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2401 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2402
2403 fault_errors = iir;
2404 if (INTEL_INFO(dev_priv)->gen >= 9)
2405 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2406 else
2407 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2408
2409 if (fault_errors)
2410 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2411 pipe_name(pipe),
2412 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002413 }
2414
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002415 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302416 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002417 /*
2418 * FIXME(BDW): Assume for now that the new interrupt handling
2419 * scheme also closed the SDE interrupt handling race we've seen
2420 * on older pch-split platforms. But this needs testing.
2421 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002422 iir = I915_READ(SDEIIR);
2423 if (iir) {
2424 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002425 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002426
Rodrigo Vivi22dea0b2016-07-01 17:07:12 -07002427 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002428 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002429 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002430 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002431 } else {
2432 /*
2433 * Like on previous PCH there seems to be something
2434 * fishy going on with forwarding PCH interrupts.
2435 */
2436 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2437 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002438 }
2439
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002440 return ret;
2441}
2442
2443static irqreturn_t gen8_irq_handler(int irq, void *arg)
2444{
2445 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002446 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002447 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002448 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002449 irqreturn_t ret;
2450
2451 if (!intel_irqs_enabled(dev_priv))
2452 return IRQ_NONE;
2453
2454 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2455 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2456 if (!master_ctl)
2457 return IRQ_NONE;
2458
2459 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2460
2461 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2462 disable_rpm_wakeref_asserts(dev_priv);
2463
2464 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002465 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2466 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002467 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2468
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002469 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2470 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002471
Imre Deak1f814da2015-12-16 02:52:19 +02002472 enable_rpm_wakeref_asserts(dev_priv);
2473
Ben Widawskyabd58f02013-11-02 21:07:09 -07002474 return ret;
2475}
2476
Chris Wilson1f15b762016-07-01 17:23:14 +01002477static void i915_error_wake_up(struct drm_i915_private *dev_priv)
Daniel Vetter17e1df02013-09-08 21:57:13 +02002478{
Daniel Vetter17e1df02013-09-08 21:57:13 +02002479 /*
2480 * Notify all waiters for GPU completion events that reset state has
2481 * been changed, and that they need to restart their wait after
2482 * checking for potential errors (and bail out to drop locks if there is
2483 * a gpu reset pending so that i915_error_work_func can acquire them).
2484 */
2485
2486 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
Chris Wilson1f15b762016-07-01 17:23:14 +01002487 wake_up_all(&dev_priv->gpu_error.wait_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002488
2489 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2490 wake_up_all(&dev_priv->pending_flip_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002491}
2492
Jesse Barnes8a905232009-07-11 16:48:03 -04002493/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002494 * i915_reset_and_wakeup - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002495 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002496 *
2497 * Fire an error uevent so userspace can see that a hang or error
2498 * was detected.
2499 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002500static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002501{
Chris Wilson91c8a322016-07-05 10:40:23 +01002502 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002503 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2504 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2505 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Jesse Barnes8a905232009-07-11 16:48:03 -04002506
Chris Wilsonc0336662016-05-06 15:40:21 +01002507 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002508
Chris Wilson8af29b02016-09-09 14:11:47 +01002509 DRM_DEBUG_DRIVER("resetting chip\n");
2510 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2511
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002512 /*
Chris Wilson8af29b02016-09-09 14:11:47 +01002513 * In most cases it's guaranteed that we get here with an RPM
2514 * reference held, for example because there is a pending GPU
2515 * request that won't finish until the reset is done. This
2516 * isn't the case at least when we get here by doing a
2517 * simulated reset via debugs, so get an RPM reference.
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002518 */
Chris Wilson8af29b02016-09-09 14:11:47 +01002519 intel_runtime_pm_get(dev_priv);
Chris Wilson8af29b02016-09-09 14:11:47 +01002520 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002521
Chris Wilson780f2622016-09-09 14:11:52 +01002522 do {
2523 /*
2524 * All state reset _must_ be completed before we update the
2525 * reset counter, for otherwise waiters might miss the reset
2526 * pending state and not properly drop locks, resulting in
2527 * deadlocks with the reset work.
2528 */
2529 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
2530 i915_reset(dev_priv);
2531 mutex_unlock(&dev_priv->drm.struct_mutex);
2532 }
2533
2534 /* We need to wait for anyone holding the lock to wakeup */
2535 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2536 I915_RESET_IN_PROGRESS,
2537 TASK_UNINTERRUPTIBLE,
2538 HZ));
Ville Syrjälä75147472014-11-24 18:28:11 +02002539
Chris Wilson8af29b02016-09-09 14:11:47 +01002540 intel_finish_reset(dev_priv);
Chris Wilson8af29b02016-09-09 14:11:47 +01002541 intel_runtime_pm_put(dev_priv);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002542
Chris Wilson780f2622016-09-09 14:11:52 +01002543 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002544 kobject_uevent_env(kobj,
2545 KOBJ_CHANGE, reset_done_event);
Imre Deakf454c692014-04-23 01:09:04 +03002546
Chris Wilson8af29b02016-09-09 14:11:47 +01002547 /*
2548 * Note: The wake_up also serves as a memory barrier so that
2549 * waiters see the updated value of the dev_priv->gpu_error.
2550 */
2551 wake_up_all(&dev_priv->gpu_error.reset_queue);
Jesse Barnes8a905232009-07-11 16:48:03 -04002552}
2553
Ben Widawskyd6369512016-09-20 16:54:32 +03002554static inline void
2555i915_err_print_instdone(struct drm_i915_private *dev_priv,
2556 struct intel_instdone *instdone)
2557{
Ben Widawskyf9e61372016-09-20 16:54:33 +03002558 int slice;
2559 int subslice;
2560
Ben Widawskyd6369512016-09-20 16:54:32 +03002561 pr_err(" INSTDONE: 0x%08x\n", instdone->instdone);
2562
2563 if (INTEL_GEN(dev_priv) <= 3)
2564 return;
2565
2566 pr_err(" SC_INSTDONE: 0x%08x\n", instdone->slice_common);
2567
2568 if (INTEL_GEN(dev_priv) <= 6)
2569 return;
2570
Ben Widawskyf9e61372016-09-20 16:54:33 +03002571 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
2572 pr_err(" SAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
2573 slice, subslice, instdone->sampler[slice][subslice]);
2574
2575 for_each_instdone_slice_subslice(dev_priv, slice, subslice)
2576 pr_err(" ROW_INSTDONE[%d][%d]: 0x%08x\n",
2577 slice, subslice, instdone->row[slice][subslice]);
Ben Widawskyd6369512016-09-20 16:54:32 +03002578}
2579
Chris Wilsonc0336662016-05-06 15:40:21 +01002580static void i915_report_and_clear_eir(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002581{
Ben Widawskyd6369512016-09-20 16:54:32 +03002582 struct intel_instdone instdone;
Jesse Barnes8a905232009-07-11 16:48:03 -04002583 u32 eir = I915_READ(EIR);
Ben Widawskyd6369512016-09-20 16:54:32 +03002584 int pipe;
Jesse Barnes8a905232009-07-11 16:48:03 -04002585
Chris Wilson35aed2e2010-05-27 13:18:12 +01002586 if (!eir)
2587 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002588
Joe Perchesa70491c2012-03-18 13:00:11 -07002589 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002590
Ben Widawskyd6369512016-09-20 16:54:32 +03002591 i915_get_engine_instdone(dev_priv, RCS, &instdone);
Ben Widawskybd9854f2012-08-23 15:18:09 -07002592
Chris Wilsonc0336662016-05-06 15:40:21 +01002593 if (IS_G4X(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002594 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2595 u32 ipeir = I915_READ(IPEIR_I965);
2596
Joe Perchesa70491c2012-03-18 13:00:11 -07002597 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2598 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawskyd6369512016-09-20 16:54:32 +03002599 i915_err_print_instdone(dev_priv, &instdone);
Joe Perchesa70491c2012-03-18 13:00:11 -07002600 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002601 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002602 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002603 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002604 }
2605 if (eir & GM45_ERROR_PAGE_TABLE) {
2606 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002607 pr_err("page table error\n");
2608 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002609 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002610 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002611 }
2612 }
2613
Chris Wilsonc0336662016-05-06 15:40:21 +01002614 if (!IS_GEN2(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002615 if (eir & I915_ERROR_PAGE_TABLE) {
2616 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002617 pr_err("page table error\n");
2618 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002619 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002620 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002621 }
2622 }
2623
2624 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002625 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002626 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002627 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002628 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002629 /* pipestat has already been acked */
2630 }
2631 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002632 pr_err("instruction error\n");
2633 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawskyd6369512016-09-20 16:54:32 +03002634 i915_err_print_instdone(dev_priv, &instdone);
Chris Wilsonc0336662016-05-06 15:40:21 +01002635 if (INTEL_GEN(dev_priv) < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002636 u32 ipeir = I915_READ(IPEIR);
2637
Joe Perchesa70491c2012-03-18 13:00:11 -07002638 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2639 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002640 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002641 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002642 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002643 } else {
2644 u32 ipeir = I915_READ(IPEIR_I965);
2645
Joe Perchesa70491c2012-03-18 13:00:11 -07002646 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2647 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002648 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002649 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002650 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002651 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002652 }
2653 }
2654
2655 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002656 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002657 eir = I915_READ(EIR);
2658 if (eir) {
2659 /*
2660 * some errors might have become stuck,
2661 * mask them.
2662 */
2663 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2664 I915_WRITE(EMR, I915_READ(EMR) | eir);
2665 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2666 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002667}
2668
2669/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002670 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002671 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002672 * @engine_mask: mask representing engines that are hung
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002673 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002674 * dump it to the syslog. Also call i915_capture_error_state() to make
2675 * sure we get a record and make it available in debugfs. Fire a uevent
2676 * so userspace knows something bad happened (should trigger collection
2677 * of a ring dump etc.).
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002678 * @fmt: Error message format string
Chris Wilson35aed2e2010-05-27 13:18:12 +01002679 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002680void i915_handle_error(struct drm_i915_private *dev_priv,
2681 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002682 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002683{
Mika Kuoppala58174462014-02-25 17:11:26 +02002684 va_list args;
2685 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002686
Mika Kuoppala58174462014-02-25 17:11:26 +02002687 va_start(args, fmt);
2688 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2689 va_end(args);
2690
Chris Wilsonc0336662016-05-06 15:40:21 +01002691 i915_capture_error_state(dev_priv, engine_mask, error_msg);
2692 i915_report_and_clear_eir(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002693
Chris Wilson8af29b02016-09-09 14:11:47 +01002694 if (!engine_mask)
2695 return;
Ben Gamariba1234d2009-09-14 17:48:47 -04002696
Chris Wilson8af29b02016-09-09 14:11:47 +01002697 if (test_and_set_bit(I915_RESET_IN_PROGRESS,
2698 &dev_priv->gpu_error.flags))
2699 return;
2700
2701 /*
2702 * Wakeup waiting processes so that the reset function
2703 * i915_reset_and_wakeup doesn't deadlock trying to grab
2704 * various locks. By bumping the reset counter first, the woken
2705 * processes will see a reset in progress and back off,
2706 * releasing their locks and then wait for the reset completion.
2707 * We must do this for _all_ gpu waiters that might hold locks
2708 * that the reset work needs to acquire.
2709 *
2710 * Note: The wake_up also provides a memory barrier to ensure that the
2711 * waiters see the updated value of the reset flags.
2712 */
2713 i915_error_wake_up(dev_priv);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002714
Chris Wilsonc0336662016-05-06 15:40:21 +01002715 i915_reset_and_wakeup(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002716}
2717
Keith Packard42f52ef2008-10-18 19:39:29 -07002718/* Called from drm generic code, passed 'crtc' which
2719 * we use as a pipe index
2720 */
Thierry Reding88e72712015-09-24 18:35:31 +02002721static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002722{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002723 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002724 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002725
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002726 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002727 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002728 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002729 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002730 else
Keith Packard7c463582008-11-04 02:03:27 -08002731 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002732 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002733 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002734
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002735 return 0;
2736}
2737
Thierry Reding88e72712015-09-24 18:35:31 +02002738static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002739{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002740 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002741 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002742 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002743 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002744
Jesse Barnesf796cf82011-04-07 13:58:17 -07002745 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002746 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002747 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2748
2749 return 0;
2750}
2751
Thierry Reding88e72712015-09-24 18:35:31 +02002752static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002753{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002754 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002755 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002756
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002757 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002758 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002759 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39: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 gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002766{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002767 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002768 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002769
Ben Widawskyabd58f02013-11-02 21:07:09 -07002770 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002771 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002772 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002773
Ben Widawskyabd58f02013-11-02 21:07:09 -07002774 return 0;
2775}
2776
Keith Packard42f52ef2008-10-18 19:39:29 -07002777/* Called from drm generic code, passed 'crtc' which
2778 * we use as a pipe index
2779 */
Thierry Reding88e72712015-09-24 18:35:31 +02002780static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002781{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002782 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002783 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002784
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002785 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002786 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002787 PIPE_VBLANK_INTERRUPT_STATUS |
2788 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002789 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2790}
2791
Thierry Reding88e72712015-09-24 18:35:31 +02002792static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002793{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002794 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002795 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002796 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002797 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002798
2799 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002800 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002801 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2802}
2803
Thierry Reding88e72712015-09-24 18:35:31 +02002804static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002805{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002806 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002807 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002808
2809 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002810 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002811 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002812 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2813}
2814
Thierry Reding88e72712015-09-24 18:35:31 +02002815static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002816{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002817 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002818 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002819
Ben Widawskyabd58f02013-11-02 21:07:09 -07002820 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002821 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002822 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2823}
2824
Chris Wilson9107e9d2013-06-10 11:20:20 +01002825static bool
Chris Wilson31bb59c2016-07-01 17:23:27 +01002826ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr)
Daniel Vettera028c4b2014-03-15 00:08:56 +01002827{
Chris Wilson31bb59c2016-07-01 17:23:27 +01002828 if (INTEL_GEN(engine->i915) >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002829 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002830 } else {
2831 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2832 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2833 MI_SEMAPHORE_REGISTER);
2834 }
2835}
2836
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002837static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002838semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr,
2839 u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002840{
Chris Wilsonc0336662016-05-06 15:40:21 +01002841 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002842 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002843
Chris Wilsonc0336662016-05-06 15:40:21 +01002844 if (INTEL_GEN(dev_priv) >= 8) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002845 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002846 if (engine == signaller)
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002847 continue;
2848
Chris Wilson348b9b12016-10-03 13:45:16 +01002849 if (offset == signaller->semaphore.signal_ggtt[engine->hw_id])
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002850 return signaller;
2851 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002852 } else {
2853 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2854
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002855 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002856 if(engine == signaller)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002857 continue;
2858
Chris Wilson348b9b12016-10-03 13:45:16 +01002859 if (sync_bits == signaller->semaphore.mbox.wait[engine->hw_id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002860 return signaller;
2861 }
2862 }
2863
Chris Wilson348b9b12016-10-03 13:45:16 +01002864 DRM_DEBUG_DRIVER("No signaller ring found for %s, ipehr 0x%08x, offset 0x%016llx\n",
2865 engine->name, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002866
Chris Wilson80b5bdb2016-09-09 14:11:58 +01002867 return ERR_PTR(-ENODEV);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002868}
2869
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002870static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002871semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002872{
Chris Wilsonc0336662016-05-06 15:40:21 +01002873 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson406ea8d2016-07-20 13:31:55 +01002874 void __iomem *vaddr;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002875 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002876 u64 offset = 0;
2877 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002878
Tomas Elf381e8ae2015-10-08 19:31:33 +01002879 /*
2880 * This function does not support execlist mode - any attempt to
2881 * proceed further into this function will result in a kernel panic
2882 * when dereferencing ring->buffer, which is not set up in execlist
2883 * mode.
2884 *
2885 * The correct way of doing it would be to derive the currently
2886 * executing ring buffer from the current context, which is derived
2887 * from the currently running request. Unfortunately, to get the
2888 * current request we would have to grab the struct_mutex before doing
2889 * anything else, which would be ill-advised since some other thread
2890 * might have grabbed it already and managed to hang itself, causing
2891 * the hang checker to deadlock.
2892 *
2893 * Therefore, this function does not support execlist mode in its
2894 * current form. Just return NULL and move on.
2895 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002896 if (engine->buffer == NULL)
Tomas Elf381e8ae2015-10-08 19:31:33 +01002897 return NULL;
2898
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002899 ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
Chris Wilson31bb59c2016-07-01 17:23:27 +01002900 if (!ipehr_is_semaphore_wait(engine, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002901 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002902
Daniel Vetter88fe4292014-03-15 00:08:55 +01002903 /*
2904 * HEAD is likely pointing to the dword after the actual command,
2905 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002906 * or 4 dwords depending on the semaphore wait command size.
2907 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002908 * point at at batch, and semaphores are always emitted into the
2909 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002910 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002911 head = I915_READ_HEAD(engine) & HEAD_ADDR;
Chris Wilsonc0336662016-05-06 15:40:21 +01002912 backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4;
Chris Wilsonf2f0ed72016-07-20 13:31:56 +01002913 vaddr = (void __iomem *)engine->buffer->vaddr;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002914
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002915 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002916 /*
2917 * Be paranoid and presume the hw has gone off into the wild -
2918 * our ring is smaller than what the hardware (and hence
2919 * HEAD_ADDR) allows. Also handles wrap-around.
2920 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002921 head &= engine->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002922
2923 /* This here seems to blow up */
Chris Wilson406ea8d2016-07-20 13:31:55 +01002924 cmd = ioread32(vaddr + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002925 if (cmd == ipehr)
2926 break;
2927
Daniel Vetter88fe4292014-03-15 00:08:55 +01002928 head -= 4;
2929 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002930
Daniel Vetter88fe4292014-03-15 00:08:55 +01002931 if (!i)
2932 return NULL;
2933
Chris Wilson406ea8d2016-07-20 13:31:55 +01002934 *seqno = ioread32(vaddr + head + 4) + 1;
Chris Wilsonc0336662016-05-06 15:40:21 +01002935 if (INTEL_GEN(dev_priv) >= 8) {
Chris Wilson406ea8d2016-07-20 13:31:55 +01002936 offset = ioread32(vaddr + head + 12);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002937 offset <<= 32;
Chris Wilson406ea8d2016-07-20 13:31:55 +01002938 offset |= ioread32(vaddr + head + 8);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002939 }
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002940 return semaphore_wait_to_signaller_ring(engine, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002941}
2942
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002943static int semaphore_passed(struct intel_engine_cs *engine)
Chris Wilson6274f212013-06-10 11:20:21 +01002944{
Chris Wilsonc0336662016-05-06 15:40:21 +01002945 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002946 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002947 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002948
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002949 engine->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002950
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002951 signaller = semaphore_waits_for(engine, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002952 if (signaller == NULL)
2953 return -1;
2954
Chris Wilson80b5bdb2016-09-09 14:11:58 +01002955 if (IS_ERR(signaller))
2956 return 0;
2957
Chris Wilson4be17382014-06-06 10:22:29 +01002958 /* Prevent pathological recursion due to driver bugs */
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00002959 if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES)
Chris Wilson6274f212013-06-10 11:20:21 +01002960 return -1;
2961
Chris Wilson1b7744e2016-07-01 17:23:17 +01002962 if (i915_seqno_passed(intel_engine_get_seqno(signaller), seqno))
Chris Wilson4be17382014-06-06 10:22:29 +01002963 return 1;
2964
Chris Wilsona0d036b2014-07-19 12:40:42 +01002965 /* cursory check for an unkickable deadlock */
2966 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2967 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002968 return -1;
2969
2970 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002971}
2972
2973static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2974{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002975 struct intel_engine_cs *engine;
Chris Wilson6274f212013-06-10 11:20:21 +01002976
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002977 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002978 engine->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002979}
2980
Ben Widawskyd6369512016-09-20 16:54:32 +03002981static bool instdone_unchanged(u32 current_instdone, u32 *old_instdone)
2982{
2983 u32 tmp = current_instdone | *old_instdone;
2984 bool unchanged;
2985
2986 unchanged = tmp == *old_instdone;
2987 *old_instdone |= tmp;
2988
2989 return unchanged;
2990}
2991
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002992static bool subunits_stuck(struct intel_engine_cs *engine)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002993{
Ben Widawskyd6369512016-09-20 16:54:32 +03002994 struct drm_i915_private *dev_priv = engine->i915;
2995 struct intel_instdone instdone;
2996 struct intel_instdone *accu_instdone = &engine->hangcheck.instdone;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002997 bool stuck;
Ben Widawskyf9e61372016-09-20 16:54:33 +03002998 int slice;
2999 int subslice;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003000
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003001 if (engine->id != RCS)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003002 return true;
3003
Ben Widawskyd6369512016-09-20 16:54:32 +03003004 i915_get_engine_instdone(dev_priv, RCS, &instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003005
3006 /* There might be unstable subunit states even when
3007 * actual head is not moving. Filter out the unstable ones by
3008 * accumulating the undone -> done transitions and only
3009 * consider those as progress.
3010 */
Ben Widawskyd6369512016-09-20 16:54:32 +03003011 stuck = instdone_unchanged(instdone.instdone,
3012 &accu_instdone->instdone);
3013 stuck &= instdone_unchanged(instdone.slice_common,
3014 &accu_instdone->slice_common);
Ben Widawskyf9e61372016-09-20 16:54:33 +03003015
3016 for_each_instdone_slice_subslice(dev_priv, slice, subslice) {
3017 stuck &= instdone_unchanged(instdone.sampler[slice][subslice],
3018 &accu_instdone->sampler[slice][subslice]);
3019 stuck &= instdone_unchanged(instdone.row[slice][subslice],
3020 &accu_instdone->row[slice][subslice]);
3021 }
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003022
3023 return stuck;
3024}
3025
Chris Wilson7e37f882016-08-02 22:50:21 +01003026static enum intel_engine_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003027head_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003028{
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003029 if (acthd != engine->hangcheck.acthd) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003030
3031 /* Clear subunit states on head movement */
Ben Widawskyd6369512016-09-20 16:54:32 +03003032 memset(&engine->hangcheck.instdone, 0,
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003033 sizeof(engine->hangcheck.instdone));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003034
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003035 return HANGCHECK_ACTIVE;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003036 }
Chris Wilson6274f212013-06-10 11:20:21 +01003037
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003038 if (!subunits_stuck(engine))
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003039 return HANGCHECK_ACTIVE;
3040
3041 return HANGCHECK_HUNG;
3042}
3043
Chris Wilson7e37f882016-08-02 22:50:21 +01003044static enum intel_engine_hangcheck_action
3045engine_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003046{
Chris Wilsonc0336662016-05-06 15:40:21 +01003047 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson7e37f882016-08-02 22:50:21 +01003048 enum intel_engine_hangcheck_action ha;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003049 u32 tmp;
3050
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003051 ha = head_stuck(engine, acthd);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003052 if (ha != HANGCHECK_HUNG)
3053 return ha;
3054
Chris Wilsonc0336662016-05-06 15:40:21 +01003055 if (IS_GEN2(dev_priv))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003056 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003057
3058 /* Is the chip hanging on a WAIT_FOR_EVENT?
3059 * If so we can simply poke the RB_WAIT bit
3060 * and break the hang. This should work on
3061 * all but the second generation chipsets.
3062 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003063 tmp = I915_READ_CTL(engine);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003064 if (tmp & RING_WAIT) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003065 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003066 "Kicking stuck wait on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003067 engine->name);
3068 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003069 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003070 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003071
Chris Wilsonc0336662016-05-06 15:40:21 +01003072 if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003073 switch (semaphore_passed(engine)) {
Chris Wilson6274f212013-06-10 11:20:21 +01003074 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003075 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003076 case 1:
Chris Wilsonc0336662016-05-06 15:40:21 +01003077 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003078 "Kicking stuck semaphore on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003079 engine->name);
3080 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003081 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003082 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003083 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003084 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003085 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003086
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003087 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003088}
3089
Chris Wilson737b1502015-01-26 18:03:03 +02003090/*
Ben Gamarif65d9422009-09-14 17:48:44 -04003091 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003092 * batchbuffers in a long time. We keep track per ring seqno progress and
3093 * if there are no progress, hangcheck score for that ring is increased.
3094 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3095 * we kick the ring. If we see no progress on three subsequent calls
3096 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003097 */
Chris Wilson737b1502015-01-26 18:03:03 +02003098static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04003099{
Chris Wilson737b1502015-01-26 18:03:03 +02003100 struct drm_i915_private *dev_priv =
3101 container_of(work, typeof(*dev_priv),
3102 gpu_error.hangcheck_work.work);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003103 struct intel_engine_cs *engine;
Chris Wilson2b284282016-07-04 08:48:32 +01003104 unsigned int hung = 0, stuck = 0;
3105 int busy_count = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003106#define BUSY 1
3107#define KICK 5
3108#define HUNG 20
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003109#define ACTIVE_DECAY 15
Chris Wilson893eead2010-10-27 14:44:35 +01003110
Jani Nikulad330a952014-01-21 11:24:25 +02003111 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003112 return;
3113
Chris Wilsonb1379d42016-07-05 08:54:36 +01003114 if (!READ_ONCE(dev_priv->gt.awake))
Chris Wilson67d97da2016-07-04 08:08:31 +01003115 return;
Imre Deak1f814da2015-12-16 02:52:19 +02003116
Mika Kuoppala75714942015-12-16 09:26:48 +02003117 /* As enabling the GPU requires fairly extensive mmio access,
3118 * periodically arm the mmio checker to see if we are triggering
3119 * any invalid access.
3120 */
3121 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
3122
Chris Wilson2b284282016-07-04 08:48:32 +01003123 for_each_engine(engine, dev_priv) {
Chris Wilson688e6c72016-07-01 17:23:15 +01003124 bool busy = intel_engine_has_waiter(engine);
Chris Wilson50877442014-03-21 12:41:53 +00003125 u64 acthd;
3126 u32 seqno;
Chris Wilson34730fe2016-08-20 15:54:08 +01003127 u32 submit;
Chris Wilsonb4519512012-05-11 14:29:30 +01003128
Chris Wilson6274f212013-06-10 11:20:21 +01003129 semaphore_clear_deadlocks(dev_priv);
3130
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003131 /* We don't strictly need an irq-barrier here, as we are not
3132 * serving an interrupt request, be paranoid in case the
3133 * barrier has side-effects (such as preventing a broken
3134 * cacheline snoop) and so be sure that we can see the seqno
3135 * advance. If the seqno should stick, due to a stale
3136 * cacheline, we would erroneously declare the GPU hung.
3137 */
3138 if (engine->irq_seqno_barrier)
3139 engine->irq_seqno_barrier(engine);
3140
Chris Wilson7e37f882016-08-02 22:50:21 +01003141 acthd = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01003142 seqno = intel_engine_get_seqno(engine);
Chris Wilson34730fe2016-08-20 15:54:08 +01003143 submit = READ_ONCE(engine->last_submitted_seqno);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003144
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003145 if (engine->hangcheck.seqno == seqno) {
Chris Wilson34730fe2016-08-20 15:54:08 +01003146 if (i915_seqno_passed(seqno, submit)) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003147 engine->hangcheck.action = HANGCHECK_IDLE;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003148 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003149 /* We always increment the hangcheck score
Chris Wilson9930ca12016-07-27 09:07:30 +01003150 * if the engine is busy and still processing
Chris Wilson6274f212013-06-10 11:20:21 +01003151 * the same request, so that no single request
3152 * can run indefinitely (such as a chain of
3153 * batches). The only time we do not increment
3154 * the hangcheck score on this ring, if this
Chris Wilson9930ca12016-07-27 09:07:30 +01003155 * engine is in a legitimate wait for another
3156 * engine. In that case the waiting engine is a
Chris Wilson6274f212013-06-10 11:20:21 +01003157 * victim and we want to be sure we catch the
3158 * right culprit. Then every time we do kick
3159 * the ring, add a small increment to the
3160 * score so that we can catch a batch that is
3161 * being repeatedly kicked and so responsible
3162 * for stalling the machine.
3163 */
Chris Wilson7e37f882016-08-02 22:50:21 +01003164 engine->hangcheck.action =
3165 engine_stuck(engine, acthd);
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003166
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003167 switch (engine->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003168 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003169 case HANGCHECK_WAIT:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003170 break;
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003171 case HANGCHECK_ACTIVE:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003172 engine->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003173 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003174 case HANGCHECK_KICK:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003175 engine->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003176 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003177 case HANGCHECK_HUNG:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003178 engine->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003179 break;
3180 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003181 }
Chris Wilson2b284282016-07-04 08:48:32 +01003182
3183 if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
3184 hung |= intel_engine_flag(engine);
3185 if (engine->hangcheck.action != HANGCHECK_HUNG)
3186 stuck |= intel_engine_flag(engine);
3187 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003188 } else {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003189 engine->hangcheck.action = HANGCHECK_ACTIVE;
Mika Kuoppalada661462013-09-06 16:03:28 +03003190
Chris Wilson9107e9d2013-06-10 11:20:20 +01003191 /* Gradually reduce the count so that we catch DoS
3192 * attempts across multiple batches.
3193 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003194 if (engine->hangcheck.score > 0)
3195 engine->hangcheck.score -= ACTIVE_DECAY;
3196 if (engine->hangcheck.score < 0)
3197 engine->hangcheck.score = 0;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003198
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003199 /* Clear head and subunit states on seqno movement */
Chris Wilson12471ba2016-04-09 10:57:55 +01003200 acthd = 0;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003201
Ben Widawskyd6369512016-09-20 16:54:32 +03003202 memset(&engine->hangcheck.instdone, 0,
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003203 sizeof(engine->hangcheck.instdone));
Chris Wilsond1e61e72012-04-10 17:00:41 +01003204 }
3205
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003206 engine->hangcheck.seqno = seqno;
3207 engine->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003208 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003209 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003210
Chris Wilson2b284282016-07-04 08:48:32 +01003211 if (hung) {
3212 char msg[80];
Chris Wilsonbafb0fc2016-08-27 08:54:01 +01003213 unsigned int tmp;
Chris Wilson2b284282016-07-04 08:48:32 +01003214 int len;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003215
Chris Wilson2b284282016-07-04 08:48:32 +01003216 /* If some rings hung but others were still busy, only
3217 * blame the hanging rings in the synopsis.
3218 */
3219 if (stuck != hung)
3220 hung &= ~stuck;
3221 len = scnprintf(msg, sizeof(msg),
3222 "%s on ", stuck == hung ? "No progress" : "Hang");
Chris Wilsonbafb0fc2016-08-27 08:54:01 +01003223 for_each_engine_masked(engine, dev_priv, hung, tmp)
Chris Wilson2b284282016-07-04 08:48:32 +01003224 len += scnprintf(msg + len, sizeof(msg) - len,
3225 "%s, ", engine->name);
3226 msg[len-2] = '\0';
3227
3228 return i915_handle_error(dev_priv, hung, msg);
3229 }
Ben Gamarif65d9422009-09-14 17:48:44 -04003230
Chris Wilson05535722016-07-01 17:23:11 +01003231 /* Reset timer in case GPU hangs without another request being added */
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003232 if (busy_count)
Chris Wilsonc0336662016-05-06 15:40:21 +01003233 i915_queue_hangcheck(dev_priv);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003234}
3235
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003236static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003237{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003238 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003239
3240 if (HAS_PCH_NOP(dev))
3241 return;
3242
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003243 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003244
3245 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3246 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003247}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003248
Paulo Zanoni622364b2014-04-01 15:37:22 -03003249/*
3250 * SDEIER is also touched by the interrupt handler to work around missed PCH
3251 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3252 * instead we unconditionally enable all PCH interrupt sources here, but then
3253 * only unmask them as needed with SDEIMR.
3254 *
3255 * This function needs to be called before interrupts are enabled.
3256 */
3257static void ibx_irq_pre_postinstall(struct drm_device *dev)
3258{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003259 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003260
3261 if (HAS_PCH_NOP(dev))
3262 return;
3263
3264 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003265 I915_WRITE(SDEIER, 0xffffffff);
3266 POSTING_READ(SDEIER);
3267}
3268
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003269static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003270{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003271 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003272
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003273 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003274 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003275 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003276}
3277
Ville Syrjälä70591a42014-10-30 19:42:58 +02003278static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3279{
3280 enum pipe pipe;
3281
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003282 if (IS_CHERRYVIEW(dev_priv))
3283 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3284 else
3285 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3286
Ville Syrjäläad22d102016-04-12 18:56:14 +03003287 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003288 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3289
Ville Syrjäläad22d102016-04-12 18:56:14 +03003290 for_each_pipe(dev_priv, pipe) {
3291 I915_WRITE(PIPESTAT(pipe),
3292 PIPE_FIFO_UNDERRUN_STATUS |
3293 PIPESTAT_INT_STATUS_MASK);
3294 dev_priv->pipestat_irq_mask[pipe] = 0;
3295 }
Ville Syrjälä70591a42014-10-30 19:42:58 +02003296
3297 GEN5_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003298 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003299}
3300
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003301static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3302{
3303 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003304 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003305 enum pipe pipe;
3306
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003307 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3308 PIPE_CRC_DONE_INTERRUPT_STATUS;
3309
3310 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3311 for_each_pipe(dev_priv, pipe)
3312 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3313
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003314 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3315 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3316 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003317 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003318 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003319
3320 WARN_ON(dev_priv->irq_mask != ~0);
3321
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003322 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003323
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003324 GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003325}
3326
3327/* drm_dma.h hooks
3328*/
3329static void ironlake_irq_reset(struct drm_device *dev)
3330{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003331 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003332
3333 I915_WRITE(HWSTAM, 0xffffffff);
3334
3335 GEN5_IRQ_RESET(DE);
3336 if (IS_GEN7(dev))
3337 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3338
3339 gen5_gt_irq_reset(dev);
3340
3341 ibx_irq_reset(dev);
3342}
3343
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003344static void valleyview_irq_preinstall(struct drm_device *dev)
3345{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003346 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003347
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003348 I915_WRITE(VLV_MASTER_IER, 0);
3349 POSTING_READ(VLV_MASTER_IER);
3350
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003351 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003352
Ville Syrjäläad22d102016-04-12 18:56:14 +03003353 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003354 if (dev_priv->display_irqs_enabled)
3355 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003356 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003357}
3358
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003359static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3360{
3361 GEN8_IRQ_RESET_NDX(GT, 0);
3362 GEN8_IRQ_RESET_NDX(GT, 1);
3363 GEN8_IRQ_RESET_NDX(GT, 2);
3364 GEN8_IRQ_RESET_NDX(GT, 3);
3365}
3366
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003367static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003368{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003369 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003370 int pipe;
3371
Ben Widawskyabd58f02013-11-02 21:07:09 -07003372 I915_WRITE(GEN8_MASTER_IRQ, 0);
3373 POSTING_READ(GEN8_MASTER_IRQ);
3374
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003375 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003376
Damien Lespiau055e3932014-08-18 13:49:10 +01003377 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003378 if (intel_display_power_is_enabled(dev_priv,
3379 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003380 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003381
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003382 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3383 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3384 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003385
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303386 if (HAS_PCH_SPLIT(dev))
3387 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003388}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003389
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003390void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3391 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003392{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003393 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003394 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003395
Daniel Vetter13321782014-09-15 14:55:29 +02003396 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003397 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3398 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3399 dev_priv->de_irq_mask[pipe],
3400 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003401 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003402}
3403
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003404void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3405 unsigned int pipe_mask)
3406{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003407 enum pipe pipe;
3408
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003409 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003410 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3411 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003412 spin_unlock_irq(&dev_priv->irq_lock);
3413
3414 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003415 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003416}
3417
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003418static void cherryview_irq_preinstall(struct drm_device *dev)
3419{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003420 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003421
3422 I915_WRITE(GEN8_MASTER_IRQ, 0);
3423 POSTING_READ(GEN8_MASTER_IRQ);
3424
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003425 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003426
3427 GEN5_IRQ_RESET(GEN8_PCU_);
3428
Ville Syrjäläad22d102016-04-12 18:56:14 +03003429 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003430 if (dev_priv->display_irqs_enabled)
3431 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003432 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003433}
3434
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003435static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003436 const u32 hpd[HPD_NUM_PINS])
3437{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003438 struct intel_encoder *encoder;
3439 u32 enabled_irqs = 0;
3440
Chris Wilson91c8a322016-07-05 10:40:23 +01003441 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003442 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3443 enabled_irqs |= hpd[encoder->hpd_pin];
3444
3445 return enabled_irqs;
3446}
3447
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003448static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003449{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003450 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003451
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003452 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003453 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003454 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003455 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003456 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003457 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003458 }
3459
Daniel Vetterfee884e2013-07-04 23:35:21 +02003460 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003461
3462 /*
3463 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003464 * duration to 2ms (which is the minimum in the Display Port spec).
3465 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003466 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003467 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3468 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3469 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3470 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3471 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003472 /*
3473 * When CPU and PCH are on the same package, port A
3474 * HPD must be enabled in both north and south.
3475 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003476 if (HAS_PCH_LPT_LP(dev_priv))
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003477 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003478 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003479}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003480
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003481static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003482{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003483 u32 hotplug_irqs, hotplug, enabled_irqs;
3484
3485 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003486 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003487
3488 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3489
3490 /* Enable digital hotplug on the PCH */
3491 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3492 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003493 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003494 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3495
3496 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3497 hotplug |= PORTE_HOTPLUG_ENABLE;
3498 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003499}
3500
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003501static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003502{
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003503 u32 hotplug_irqs, hotplug, enabled_irqs;
3504
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003505 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003506 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003507 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003508
3509 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003510 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003511 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003512 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003513
3514 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003515 } else {
3516 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003517 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003518
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003519 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3520 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003521
3522 /*
3523 * Enable digital hotplug on the CPU, and configure the DP short pulse
3524 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003525 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003526 */
3527 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3528 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3529 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3530 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3531
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003532 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003533}
3534
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003535static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003536{
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003537 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003538
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003539 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003540 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003541
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003542 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003543
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003544 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3545 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3546 PORTA_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303547
3548 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3549 hotplug, enabled_irqs);
3550 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3551
3552 /*
3553 * For BXT invert bit has to be set based on AOB design
3554 * for HPD detection logic, update it based on VBT fields.
3555 */
3556
3557 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3558 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3559 hotplug |= BXT_DDIA_HPD_INVERT;
3560 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3561 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3562 hotplug |= BXT_DDIB_HPD_INVERT;
3563 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3564 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3565 hotplug |= BXT_DDIC_HPD_INVERT;
3566
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003567 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003568}
3569
Paulo Zanonid46da432013-02-08 17:35:15 -02003570static void ibx_irq_postinstall(struct drm_device *dev)
3571{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003572 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003573 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003574
Daniel Vetter692a04c2013-05-29 21:43:05 +02003575 if (HAS_PCH_NOP(dev))
3576 return;
3577
Paulo Zanoni105b1222014-04-01 15:37:17 -03003578 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003579 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003580 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003581 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003582
Ville Syrjäläb51a2842015-09-18 20:03:41 +03003583 gen5_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003584 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003585}
3586
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003587static void gen5_gt_irq_postinstall(struct drm_device *dev)
3588{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003589 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003590 u32 pm_irqs, gt_irqs;
3591
3592 pm_irqs = gt_irqs = 0;
3593
3594 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003595 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003596 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003597 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3598 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003599 }
3600
3601 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3602 if (IS_GEN5(dev)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003603 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003604 } else {
3605 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3606 }
3607
Paulo Zanoni35079892014-04-01 15:37:15 -03003608 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003609
3610 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003611 /*
3612 * RPS interrupts will get enabled/disabled on demand when RPS
3613 * itself is enabled/disabled.
3614 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003615 if (HAS_VEBOX(dev))
3616 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3617
Paulo Zanoni605cd252013-08-06 18:57:15 -03003618 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003619 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003620 }
3621}
3622
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003623static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003624{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003625 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003626 u32 display_mask, extra_mask;
3627
3628 if (INTEL_INFO(dev)->gen >= 7) {
3629 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3630 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3631 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003632 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003633 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003634 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3635 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003636 } else {
3637 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3638 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003639 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003640 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3641 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003642 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3643 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3644 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003645 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003646
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003647 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003648
Paulo Zanoni0c841212014-04-01 15:37:27 -03003649 I915_WRITE(HWSTAM, 0xeffe);
3650
Paulo Zanoni622364b2014-04-01 15:37:22 -03003651 ibx_irq_pre_postinstall(dev);
3652
Paulo Zanoni35079892014-04-01 15:37:15 -03003653 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003654
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003655 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003656
Paulo Zanonid46da432013-02-08 17:35:15 -02003657 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003658
Jesse Barnesf97108d2010-01-29 11:27:07 -08003659 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003660 /* Enable PCU event interrupts
3661 *
3662 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003663 * setup is guaranteed to run in single-threaded context. But we
3664 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003665 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003666 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003667 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003668 }
3669
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003670 return 0;
3671}
3672
Imre Deakf8b79e52014-03-04 19:23:07 +02003673void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3674{
3675 assert_spin_locked(&dev_priv->irq_lock);
3676
3677 if (dev_priv->display_irqs_enabled)
3678 return;
3679
3680 dev_priv->display_irqs_enabled = true;
3681
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003682 if (intel_irqs_enabled(dev_priv)) {
3683 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003684 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003685 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003686}
3687
3688void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3689{
3690 assert_spin_locked(&dev_priv->irq_lock);
3691
3692 if (!dev_priv->display_irqs_enabled)
3693 return;
3694
3695 dev_priv->display_irqs_enabled = false;
3696
Imre Deak950eaba2014-09-08 15:21:09 +03003697 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003698 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003699}
3700
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003701
3702static int valleyview_irq_postinstall(struct drm_device *dev)
3703{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003704 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003705
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003706 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003707
Ville Syrjäläad22d102016-04-12 18:56:14 +03003708 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003709 if (dev_priv->display_irqs_enabled)
3710 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003711 spin_unlock_irq(&dev_priv->irq_lock);
3712
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003713 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003714 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003715
3716 return 0;
3717}
3718
Ben Widawskyabd58f02013-11-02 21:07:09 -07003719static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3720{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003721 /* These are interrupts we'll toggle with the ring mask register */
3722 uint32_t gt_interrupts[] = {
3723 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003724 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003725 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3726 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003727 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003728 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3729 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3730 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003731 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003732 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3733 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003734 };
3735
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003736 if (HAS_L3_DPF(dev_priv))
3737 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3738
Ben Widawsky09610212014-05-15 20:58:08 +03003739 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303740 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3741 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003742 /*
3743 * RPS interrupts will get enabled/disabled on demand when RPS itself
3744 * is enabled/disabled.
3745 */
3746 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303747 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003748}
3749
3750static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3751{
Damien Lespiau770de832014-03-20 20:45:01 +00003752 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3753 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003754 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3755 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003756 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003757 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003758
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003759 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003760 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3761 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003762 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3763 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303764 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003765 de_port_masked |= BXT_DE_PORT_GMBUS;
3766 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003767 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3768 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003769 }
Damien Lespiau770de832014-03-20 20:45:01 +00003770
3771 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3772 GEN8_PIPE_FIFO_UNDERRUN;
3773
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003774 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003775 if (IS_BROXTON(dev_priv))
3776 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3777 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003778 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3779
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003780 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3781 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3782 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003783
Damien Lespiau055e3932014-08-18 13:49:10 +01003784 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003785 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003786 POWER_DOMAIN_PIPE(pipe)))
3787 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3788 dev_priv->de_irq_mask[pipe],
3789 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003790
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003791 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ville Syrjälä11825b02016-05-19 12:14:43 +03003792 GEN5_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003793}
3794
3795static int gen8_irq_postinstall(struct drm_device *dev)
3796{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003797 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003798
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303799 if (HAS_PCH_SPLIT(dev))
3800 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003801
Ben Widawskyabd58f02013-11-02 21:07:09 -07003802 gen8_gt_irq_postinstall(dev_priv);
3803 gen8_de_irq_postinstall(dev_priv);
3804
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303805 if (HAS_PCH_SPLIT(dev))
3806 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003807
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003808 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003809 POSTING_READ(GEN8_MASTER_IRQ);
3810
3811 return 0;
3812}
3813
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003814static int cherryview_irq_postinstall(struct drm_device *dev)
3815{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003816 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003817
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003818 gen8_gt_irq_postinstall(dev_priv);
3819
Ville Syrjäläad22d102016-04-12 18:56:14 +03003820 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003821 if (dev_priv->display_irqs_enabled)
3822 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003823 spin_unlock_irq(&dev_priv->irq_lock);
3824
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003825 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003826 POSTING_READ(GEN8_MASTER_IRQ);
3827
3828 return 0;
3829}
3830
Ben Widawskyabd58f02013-11-02 21:07:09 -07003831static void gen8_irq_uninstall(struct drm_device *dev)
3832{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003833 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003834
3835 if (!dev_priv)
3836 return;
3837
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003838 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003839}
3840
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003841static void valleyview_irq_uninstall(struct drm_device *dev)
3842{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003843 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003844
3845 if (!dev_priv)
3846 return;
3847
Imre Deak843d0e72014-04-14 20:24:23 +03003848 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003849 POSTING_READ(VLV_MASTER_IER);
Imre Deak843d0e72014-04-14 20:24:23 +03003850
Ville Syrjälä893fce82014-10-30 19:42:56 +02003851 gen5_gt_irq_reset(dev);
3852
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003853 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003854
Ville Syrjäläad22d102016-04-12 18:56:14 +03003855 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003856 if (dev_priv->display_irqs_enabled)
3857 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003858 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003859}
3860
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003861static void cherryview_irq_uninstall(struct drm_device *dev)
3862{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003863 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003864
3865 if (!dev_priv)
3866 return;
3867
3868 I915_WRITE(GEN8_MASTER_IRQ, 0);
3869 POSTING_READ(GEN8_MASTER_IRQ);
3870
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003871 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003872
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003873 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003874
Ville Syrjäläad22d102016-04-12 18:56:14 +03003875 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003876 if (dev_priv->display_irqs_enabled)
3877 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003878 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003879}
3880
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003881static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003882{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003883 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46979952011-04-07 13:53:55 -07003884
3885 if (!dev_priv)
3886 return;
3887
Paulo Zanonibe30b292014-04-01 15:37:25 -03003888 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003889}
3890
Chris Wilsonc2798b12012-04-22 21:13:57 +01003891static void i8xx_irq_preinstall(struct drm_device * dev)
3892{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003893 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003894 int pipe;
3895
Damien Lespiau055e3932014-08-18 13:49:10 +01003896 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003897 I915_WRITE(PIPESTAT(pipe), 0);
3898 I915_WRITE16(IMR, 0xffff);
3899 I915_WRITE16(IER, 0x0);
3900 POSTING_READ16(IER);
3901}
3902
3903static int i8xx_irq_postinstall(struct drm_device *dev)
3904{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003905 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003906
Chris Wilsonc2798b12012-04-22 21:13:57 +01003907 I915_WRITE16(EMR,
3908 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3909
3910 /* Unmask the interrupts that we always want on. */
3911 dev_priv->irq_mask =
3912 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3913 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3914 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003915 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003916 I915_WRITE16(IMR, dev_priv->irq_mask);
3917
3918 I915_WRITE16(IER,
3919 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3920 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003921 I915_USER_INTERRUPT);
3922 POSTING_READ16(IER);
3923
Daniel Vetter379ef822013-10-16 22:55:56 +02003924 /* Interrupt setup is already guaranteed to be single-threaded, this is
3925 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003926 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003927 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3928 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003929 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003930
Chris Wilsonc2798b12012-04-22 21:13:57 +01003931 return 0;
3932}
3933
Daniel Vetter5a21b662016-05-24 17:13:53 +02003934/*
3935 * Returns true when a page flip has completed.
3936 */
3937static bool i8xx_handle_vblank(struct drm_i915_private *dev_priv,
3938 int plane, int pipe, u32 iir)
3939{
3940 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3941
3942 if (!intel_pipe_handle_vblank(dev_priv, pipe))
3943 return false;
3944
3945 if ((iir & flip_pending) == 0)
3946 goto check_page_flip;
3947
3948 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3949 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3950 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3951 * the flip is completed (no longer pending). Since this doesn't raise
3952 * an interrupt per se, we watch for the change at vblank.
3953 */
3954 if (I915_READ16(ISR) & flip_pending)
3955 goto check_page_flip;
3956
3957 intel_finish_page_flip_cs(dev_priv, pipe);
3958 return true;
3959
3960check_page_flip:
3961 intel_check_page_flip(dev_priv, pipe);
3962 return false;
3963}
3964
Daniel Vetterff1f5252012-10-02 15:10:55 +02003965static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003966{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003967 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003968 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003969 u16 iir, new_iir;
3970 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003971 int pipe;
3972 u16 flip_mask =
3973 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3974 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Imre Deak1f814da2015-12-16 02:52:19 +02003975 irqreturn_t ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003976
Imre Deak2dd2a882015-02-24 11:14:30 +02003977 if (!intel_irqs_enabled(dev_priv))
3978 return IRQ_NONE;
3979
Imre Deak1f814da2015-12-16 02:52:19 +02003980 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3981 disable_rpm_wakeref_asserts(dev_priv);
3982
3983 ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003984 iir = I915_READ16(IIR);
3985 if (iir == 0)
Imre Deak1f814da2015-12-16 02:52:19 +02003986 goto out;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003987
3988 while (iir & ~flip_mask) {
3989 /* Can't rely on pipestat interrupt bit in iir as it might
3990 * have been cleared after the pipestat interrupt was received.
3991 * It doesn't set the bit in iir again, but it still produces
3992 * interrupts (for non-MSI).
3993 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003994 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003995 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003996 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003997
Damien Lespiau055e3932014-08-18 13:49:10 +01003998 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003999 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004000 pipe_stats[pipe] = I915_READ(reg);
4001
4002 /*
4003 * Clear the PIPE*STAT regs before the IIR
4004 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004005 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004006 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004007 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004008 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004009
4010 I915_WRITE16(IIR, iir & ~flip_mask);
4011 new_iir = I915_READ16(IIR); /* Flush posted writes */
4012
Chris Wilsonc2798b12012-04-22 21:13:57 +01004013 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004014 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004015
Damien Lespiau055e3932014-08-18 13:49:10 +01004016 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004017 int plane = pipe;
4018 if (HAS_FBC(dev_priv))
4019 plane = !plane;
4020
4021 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4022 i8xx_handle_vblank(dev_priv, plane, pipe, iir))
4023 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004024
Daniel Vetter4356d582013-10-16 22:55:55 +02004025 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004026 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004027
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004028 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4029 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4030 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02004031 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004032
4033 iir = new_iir;
4034 }
Imre Deak1f814da2015-12-16 02:52:19 +02004035 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004036
Imre Deak1f814da2015-12-16 02:52:19 +02004037out:
4038 enable_rpm_wakeref_asserts(dev_priv);
4039
4040 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004041}
4042
4043static void i8xx_irq_uninstall(struct drm_device * dev)
4044{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004045 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004046 int pipe;
4047
Damien Lespiau055e3932014-08-18 13:49:10 +01004048 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004049 /* Clear enable bits; then clear status bits */
4050 I915_WRITE(PIPESTAT(pipe), 0);
4051 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4052 }
4053 I915_WRITE16(IMR, 0xffff);
4054 I915_WRITE16(IER, 0x0);
4055 I915_WRITE16(IIR, I915_READ16(IIR));
4056}
4057
Chris Wilsona266c7d2012-04-24 22:59:44 +01004058static void i915_irq_preinstall(struct drm_device * dev)
4059{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004060 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004061 int pipe;
4062
Chris Wilsona266c7d2012-04-24 22:59:44 +01004063 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004064 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004065 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4066 }
4067
Chris Wilson00d98eb2012-04-24 22:59:48 +01004068 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004069 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004070 I915_WRITE(PIPESTAT(pipe), 0);
4071 I915_WRITE(IMR, 0xffffffff);
4072 I915_WRITE(IER, 0x0);
4073 POSTING_READ(IER);
4074}
4075
4076static int i915_irq_postinstall(struct drm_device *dev)
4077{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004078 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004079 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004080
Chris Wilson38bde182012-04-24 22:59:50 +01004081 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4082
4083 /* Unmask the interrupts that we always want on. */
4084 dev_priv->irq_mask =
4085 ~(I915_ASLE_INTERRUPT |
4086 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4087 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4088 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02004089 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004090
4091 enable_mask =
4092 I915_ASLE_INTERRUPT |
4093 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4094 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004095 I915_USER_INTERRUPT;
4096
Chris Wilsona266c7d2012-04-24 22:59:44 +01004097 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004098 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004099 POSTING_READ(PORT_HOTPLUG_EN);
4100
Chris Wilsona266c7d2012-04-24 22:59:44 +01004101 /* Enable in IER... */
4102 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4103 /* and unmask in IMR */
4104 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4105 }
4106
Chris Wilsona266c7d2012-04-24 22:59:44 +01004107 I915_WRITE(IMR, dev_priv->irq_mask);
4108 I915_WRITE(IER, enable_mask);
4109 POSTING_READ(IER);
4110
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004111 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004112
Daniel Vetter379ef822013-10-16 22:55:56 +02004113 /* Interrupt setup is already guaranteed to be single-threaded, this is
4114 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004115 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004116 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4117 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004118 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004119
Daniel Vetter20afbda2012-12-11 14:05:07 +01004120 return 0;
4121}
4122
Daniel Vetter5a21b662016-05-24 17:13:53 +02004123/*
4124 * Returns true when a page flip has completed.
4125 */
4126static bool i915_handle_vblank(struct drm_i915_private *dev_priv,
4127 int plane, int pipe, u32 iir)
4128{
4129 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4130
4131 if (!intel_pipe_handle_vblank(dev_priv, pipe))
4132 return false;
4133
4134 if ((iir & flip_pending) == 0)
4135 goto check_page_flip;
4136
4137 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4138 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4139 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4140 * the flip is completed (no longer pending). Since this doesn't raise
4141 * an interrupt per se, we watch for the change at vblank.
4142 */
4143 if (I915_READ(ISR) & flip_pending)
4144 goto check_page_flip;
4145
4146 intel_finish_page_flip_cs(dev_priv, pipe);
4147 return true;
4148
4149check_page_flip:
4150 intel_check_page_flip(dev_priv, pipe);
4151 return false;
4152}
4153
Daniel Vetterff1f5252012-10-02 15:10:55 +02004154static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004155{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004156 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004157 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004158 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004159 u32 flip_mask =
4160 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4161 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004162 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004163
Imre Deak2dd2a882015-02-24 11:14:30 +02004164 if (!intel_irqs_enabled(dev_priv))
4165 return IRQ_NONE;
4166
Imre Deak1f814da2015-12-16 02:52:19 +02004167 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4168 disable_rpm_wakeref_asserts(dev_priv);
4169
Chris Wilsona266c7d2012-04-24 22:59:44 +01004170 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004171 do {
4172 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004173 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004174
4175 /* Can't rely on pipestat interrupt bit in iir as it might
4176 * have been cleared after the pipestat interrupt was received.
4177 * It doesn't set the bit in iir again, but it still produces
4178 * interrupts (for non-MSI).
4179 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004180 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004181 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004182 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004183
Damien Lespiau055e3932014-08-18 13:49:10 +01004184 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004185 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004186 pipe_stats[pipe] = I915_READ(reg);
4187
Chris Wilson38bde182012-04-24 22:59:50 +01004188 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004189 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004190 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004191 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004192 }
4193 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004194 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004195
4196 if (!irq_received)
4197 break;
4198
Chris Wilsona266c7d2012-04-24 22:59:44 +01004199 /* Consume port. Then clear IIR or we'll miss events */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004200 if (I915_HAS_HOTPLUG(dev_priv) &&
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004201 iir & I915_DISPLAY_PORT_INTERRUPT) {
4202 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4203 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004204 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004205 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004206
Chris Wilson38bde182012-04-24 22:59:50 +01004207 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004208 new_iir = I915_READ(IIR); /* Flush posted writes */
4209
Chris Wilsona266c7d2012-04-24 22:59:44 +01004210 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004211 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004212
Damien Lespiau055e3932014-08-18 13:49:10 +01004213 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004214 int plane = pipe;
4215 if (HAS_FBC(dev_priv))
4216 plane = !plane;
4217
4218 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4219 i915_handle_vblank(dev_priv, plane, pipe, iir))
4220 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004221
4222 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4223 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004224
4225 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004226 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004227
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004228 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4229 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4230 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004231 }
4232
Chris Wilsona266c7d2012-04-24 22:59:44 +01004233 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004234 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004235
4236 /* With MSI, interrupts are only generated when iir
4237 * transitions from zero to nonzero. If another bit got
4238 * set while we were handling the existing iir bits, then
4239 * we would never get another interrupt.
4240 *
4241 * This is fine on non-MSI as well, as if we hit this path
4242 * we avoid exiting the interrupt handler only to generate
4243 * another one.
4244 *
4245 * Note that for MSI this could cause a stray interrupt report
4246 * if an interrupt landed in the time between writing IIR and
4247 * the posting read. This should be rare enough to never
4248 * trigger the 99% of 100,000 interrupts test for disabling
4249 * stray interrupts.
4250 */
Chris Wilson38bde182012-04-24 22:59:50 +01004251 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004252 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004253 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004254
Imre Deak1f814da2015-12-16 02:52:19 +02004255 enable_rpm_wakeref_asserts(dev_priv);
4256
Chris Wilsona266c7d2012-04-24 22:59:44 +01004257 return ret;
4258}
4259
4260static void i915_irq_uninstall(struct drm_device * dev)
4261{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004262 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004263 int pipe;
4264
Chris Wilsona266c7d2012-04-24 22:59:44 +01004265 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004266 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004267 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4268 }
4269
Chris Wilson00d98eb2012-04-24 22:59:48 +01004270 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004271 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004272 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004273 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004274 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4275 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004276 I915_WRITE(IMR, 0xffffffff);
4277 I915_WRITE(IER, 0x0);
4278
Chris Wilsona266c7d2012-04-24 22:59:44 +01004279 I915_WRITE(IIR, I915_READ(IIR));
4280}
4281
4282static void i965_irq_preinstall(struct drm_device * dev)
4283{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004284 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004285 int pipe;
4286
Egbert Eich0706f172015-09-23 16:15:27 +02004287 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004288 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004289
4290 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004291 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004292 I915_WRITE(PIPESTAT(pipe), 0);
4293 I915_WRITE(IMR, 0xffffffff);
4294 I915_WRITE(IER, 0x0);
4295 POSTING_READ(IER);
4296}
4297
4298static int i965_irq_postinstall(struct drm_device *dev)
4299{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004300 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004301 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004302 u32 error_mask;
4303
Chris Wilsona266c7d2012-04-24 22:59:44 +01004304 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004305 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004306 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004307 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4308 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4309 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4310 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4311 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4312
4313 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004314 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4315 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004316 enable_mask |= I915_USER_INTERRUPT;
4317
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004318 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004319 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004320
Daniel Vetterb79480b2013-06-27 17:52:10 +02004321 /* Interrupt setup is already guaranteed to be single-threaded, this is
4322 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004323 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004324 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4325 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4326 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004327 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004328
Chris Wilsona266c7d2012-04-24 22:59:44 +01004329 /*
4330 * Enable some error detection, note the instruction error mask
4331 * bit is reserved, so we leave it masked.
4332 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004333 if (IS_G4X(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004334 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4335 GM45_ERROR_MEM_PRIV |
4336 GM45_ERROR_CP_PRIV |
4337 I915_ERROR_MEMORY_REFRESH);
4338 } else {
4339 error_mask = ~(I915_ERROR_PAGE_TABLE |
4340 I915_ERROR_MEMORY_REFRESH);
4341 }
4342 I915_WRITE(EMR, error_mask);
4343
4344 I915_WRITE(IMR, dev_priv->irq_mask);
4345 I915_WRITE(IER, enable_mask);
4346 POSTING_READ(IER);
4347
Egbert Eich0706f172015-09-23 16:15:27 +02004348 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004349 POSTING_READ(PORT_HOTPLUG_EN);
4350
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004351 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004352
4353 return 0;
4354}
4355
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004356static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004357{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004358 u32 hotplug_en;
4359
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004360 assert_spin_locked(&dev_priv->irq_lock);
4361
Ville Syrjälä778eb332015-01-09 14:21:13 +02004362 /* Note HDMI and DP share hotplug bits */
4363 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004364 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004365 /* Programming the CRT detection parameters tends
4366 to generate a spurious hotplug event about three
4367 seconds later. So just do it once.
4368 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004369 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004370 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004371 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004372
Ville Syrjälä778eb332015-01-09 14:21:13 +02004373 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004374 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004375 HOTPLUG_INT_EN_MASK |
4376 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4377 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4378 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004379}
4380
Daniel Vetterff1f5252012-10-02 15:10:55 +02004381static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004382{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004383 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004384 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004385 u32 iir, new_iir;
4386 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004387 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004388 u32 flip_mask =
4389 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4390 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004391
Imre Deak2dd2a882015-02-24 11:14:30 +02004392 if (!intel_irqs_enabled(dev_priv))
4393 return IRQ_NONE;
4394
Imre Deak1f814da2015-12-16 02:52:19 +02004395 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4396 disable_rpm_wakeref_asserts(dev_priv);
4397
Chris Wilsona266c7d2012-04-24 22:59:44 +01004398 iir = I915_READ(IIR);
4399
Chris Wilsona266c7d2012-04-24 22:59:44 +01004400 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004401 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004402 bool blc_event = false;
4403
Chris Wilsona266c7d2012-04-24 22:59:44 +01004404 /* Can't rely on pipestat interrupt bit in iir as it might
4405 * have been cleared after the pipestat interrupt was received.
4406 * It doesn't set the bit in iir again, but it still produces
4407 * interrupts (for non-MSI).
4408 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004409 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004410 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004411 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004412
Damien Lespiau055e3932014-08-18 13:49:10 +01004413 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004414 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004415 pipe_stats[pipe] = I915_READ(reg);
4416
4417 /*
4418 * Clear the PIPE*STAT regs before the IIR
4419 */
4420 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004421 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004422 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004423 }
4424 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004425 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004426
4427 if (!irq_received)
4428 break;
4429
4430 ret = IRQ_HANDLED;
4431
4432 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004433 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
4434 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4435 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004436 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004437 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004438
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004439 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004440 new_iir = I915_READ(IIR); /* Flush posted writes */
4441
Chris Wilsona266c7d2012-04-24 22:59:44 +01004442 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004443 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004444 if (iir & I915_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004445 notify_ring(&dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004446
Damien Lespiau055e3932014-08-18 13:49:10 +01004447 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004448 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
4449 i915_handle_vblank(dev_priv, pipe, pipe, iir))
4450 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004451
4452 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4453 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004454
4455 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004456 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004457
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004458 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4459 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004460 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004461
4462 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004463 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004464
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004465 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004466 gmbus_irq_handler(dev_priv);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004467
Chris Wilsona266c7d2012-04-24 22:59:44 +01004468 /* With MSI, interrupts are only generated when iir
4469 * transitions from zero to nonzero. If another bit got
4470 * set while we were handling the existing iir bits, then
4471 * we would never get another interrupt.
4472 *
4473 * This is fine on non-MSI as well, as if we hit this path
4474 * we avoid exiting the interrupt handler only to generate
4475 * another one.
4476 *
4477 * Note that for MSI this could cause a stray interrupt report
4478 * if an interrupt landed in the time between writing IIR and
4479 * the posting read. This should be rare enough to never
4480 * trigger the 99% of 100,000 interrupts test for disabling
4481 * stray interrupts.
4482 */
4483 iir = new_iir;
4484 }
4485
Imre Deak1f814da2015-12-16 02:52:19 +02004486 enable_rpm_wakeref_asserts(dev_priv);
4487
Chris Wilsona266c7d2012-04-24 22:59:44 +01004488 return ret;
4489}
4490
4491static void i965_irq_uninstall(struct drm_device * dev)
4492{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004493 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004494 int pipe;
4495
4496 if (!dev_priv)
4497 return;
4498
Egbert Eich0706f172015-09-23 16:15:27 +02004499 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004500 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004501
4502 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004503 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004504 I915_WRITE(PIPESTAT(pipe), 0);
4505 I915_WRITE(IMR, 0xffffffff);
4506 I915_WRITE(IER, 0x0);
4507
Damien Lespiau055e3932014-08-18 13:49:10 +01004508 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004509 I915_WRITE(PIPESTAT(pipe),
4510 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4511 I915_WRITE(IIR, I915_READ(IIR));
4512}
4513
Daniel Vetterfca52a52014-09-30 10:56:45 +02004514/**
4515 * intel_irq_init - initializes irq support
4516 * @dev_priv: i915 device instance
4517 *
4518 * This function initializes all the irq support including work items, timers
4519 * and all the vtables. It does not setup the interrupt itself though.
4520 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004521void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004522{
Chris Wilson91c8a322016-07-05 10:40:23 +01004523 struct drm_device *dev = &dev_priv->drm;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004524
Jani Nikula77913b32015-06-18 13:06:16 +03004525 intel_hpd_init_work(dev_priv);
4526
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004527 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004528 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004529
Deepak Sa6706b42014-03-15 20:23:22 +05304530 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004531 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004532 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004533 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004534 else
4535 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304536
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304537 dev_priv->rps.pm_intr_keep = 0;
4538
4539 /*
4540 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
4541 * if GEN6_PM_UP_EI_EXPIRED is masked.
4542 *
4543 * TODO: verify if this can be reproduced on VLV,CHV.
4544 */
4545 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
4546 dev_priv->rps.pm_intr_keep |= GEN6_PM_RP_UP_EI_EXPIRED;
4547
4548 if (INTEL_INFO(dev_priv)->gen >= 8)
Dave Gordonb20e3cf2016-09-12 21:19:35 +01004549 dev_priv->rps.pm_intr_keep |= GEN8_PMINTR_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304550
Chris Wilson737b1502015-01-26 18:03:03 +02004551 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4552 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004553
Daniel Vetterb9632912014-09-30 10:56:44 +02004554 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004555 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004556 dev->max_vblank_count = 0;
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004557 dev->driver->get_vblank_counter = drm_vblank_no_hw_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004558 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004559 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004560 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004561 } else {
4562 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4563 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004564 }
4565
Ville Syrjälä21da2702014-08-06 14:49:55 +03004566 /*
4567 * Opt out of the vblank disable timer on everything except gen2.
4568 * Gen2 doesn't have a hardware frame counter and so depends on
4569 * vblank interrupts to produce sane vblank seuquence numbers.
4570 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004571 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004572 dev->vblank_disable_immediate = true;
4573
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004574 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4575 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004576
Daniel Vetterb9632912014-09-30 10:56:44 +02004577 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004578 dev->driver->irq_handler = cherryview_irq_handler;
4579 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4580 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4581 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4582 dev->driver->enable_vblank = valleyview_enable_vblank;
4583 dev->driver->disable_vblank = valleyview_disable_vblank;
4584 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004585 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004586 dev->driver->irq_handler = valleyview_irq_handler;
4587 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4588 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4589 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4590 dev->driver->enable_vblank = valleyview_enable_vblank;
4591 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004592 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004593 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004594 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004595 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004596 dev->driver->irq_postinstall = gen8_irq_postinstall;
4597 dev->driver->irq_uninstall = gen8_irq_uninstall;
4598 dev->driver->enable_vblank = gen8_enable_vblank;
4599 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004600 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004601 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi22dea0b2016-07-01 17:07:12 -07004602 else if (HAS_PCH_SPT(dev) || HAS_PCH_KBP(dev))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004603 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4604 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004605 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004606 } else if (HAS_PCH_SPLIT(dev)) {
4607 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004608 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004609 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4610 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4611 dev->driver->enable_vblank = ironlake_enable_vblank;
4612 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004613 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004614 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004615 if (IS_GEN2(dev_priv)) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004616 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4617 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4618 dev->driver->irq_handler = i8xx_irq_handler;
4619 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004620 } else if (IS_GEN3(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004621 dev->driver->irq_preinstall = i915_irq_preinstall;
4622 dev->driver->irq_postinstall = i915_irq_postinstall;
4623 dev->driver->irq_uninstall = i915_irq_uninstall;
4624 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004625 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004626 dev->driver->irq_preinstall = i965_irq_preinstall;
4627 dev->driver->irq_postinstall = i965_irq_postinstall;
4628 dev->driver->irq_uninstall = i965_irq_uninstall;
4629 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004630 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004631 if (I915_HAS_HOTPLUG(dev_priv))
4632 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004633 dev->driver->enable_vblank = i915_enable_vblank;
4634 dev->driver->disable_vblank = i915_disable_vblank;
4635 }
4636}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004637
Daniel Vetterfca52a52014-09-30 10:56:45 +02004638/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004639 * intel_irq_install - enables the hardware interrupt
4640 * @dev_priv: i915 device instance
4641 *
4642 * This function enables the hardware interrupt handling, but leaves the hotplug
4643 * handling still disabled. It is called after intel_irq_init().
4644 *
4645 * In the driver load and resume code we need working interrupts in a few places
4646 * but don't want to deal with the hassle of concurrent probe and hotplug
4647 * workers. Hence the split into this two-stage approach.
4648 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004649int intel_irq_install(struct drm_i915_private *dev_priv)
4650{
4651 /*
4652 * We enable some interrupt sources in our postinstall hooks, so mark
4653 * interrupts as enabled _before_ actually enabling them to avoid
4654 * special cases in our ordering checks.
4655 */
4656 dev_priv->pm.irqs_enabled = true;
4657
Chris Wilson91c8a322016-07-05 10:40:23 +01004658 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004659}
4660
Daniel Vetterfca52a52014-09-30 10:56:45 +02004661/**
4662 * intel_irq_uninstall - finilizes all irq handling
4663 * @dev_priv: i915 device instance
4664 *
4665 * This stops interrupt and hotplug handling and unregisters and frees all
4666 * resources acquired in the init functions.
4667 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004668void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4669{
Chris Wilson91c8a322016-07-05 10:40:23 +01004670 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004671 intel_hpd_cancel_work(dev_priv);
4672 dev_priv->pm.irqs_enabled = false;
4673}
4674
Daniel Vetterfca52a52014-09-30 10:56:45 +02004675/**
4676 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4677 * @dev_priv: i915 device instance
4678 *
4679 * This function is used to disable interrupts at runtime, both in the runtime
4680 * pm and the system suspend/resume code.
4681 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004682void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004683{
Chris Wilson91c8a322016-07-05 10:40:23 +01004684 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004685 dev_priv->pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004686 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004687}
4688
Daniel Vetterfca52a52014-09-30 10:56:45 +02004689/**
4690 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4691 * @dev_priv: i915 device instance
4692 *
4693 * This function is used to enable interrupts at runtime, both in the runtime
4694 * pm and the system suspend/resume code.
4695 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004696void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004697{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004698 dev_priv->pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004699 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4700 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004701}