blob: 2f01b0b959a1aed5468a67691e910af9119d0558 [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{
Imre Deakb900b942014-11-05 20:48:48 +0200353 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100354 WARN_ON_ONCE(dev_priv->rps.pm_iir);
355 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200356 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200357 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
358 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200359 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200360
Imre Deakb900b942014-11-05 20:48:48 +0200361 spin_unlock_irq(&dev_priv->irq_lock);
362}
363
Imre Deak59d02a12014-12-19 19:33:26 +0200364u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
365{
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530366 return (mask & ~dev_priv->rps.pm_intr_keep);
Imre Deak59d02a12014-12-19 19:33:26 +0200367}
368
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100369void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200370{
Imre Deakd4d70aa2014-11-19 15:30:04 +0200371 spin_lock_irq(&dev_priv->irq_lock);
372 dev_priv->rps.interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200373
Imre Deak59d02a12014-12-19 19:33:26 +0200374 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200375
376 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200377 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
378 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200379
380 spin_unlock_irq(&dev_priv->irq_lock);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100381 synchronize_irq(dev_priv->dev->irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100382
383 /* Now that we will not be generating any more work, flush any
384 * outsanding tasks. As we are called on the RPS idle path,
385 * we will reset the GPU to minimum frequencies, so the current
386 * state of the worker can be discarded.
387 */
388 cancel_work_sync(&dev_priv->rps.work);
389 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200390}
391
Ben Widawsky09610212014-05-15 20:58:08 +0300392/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200393 * bdw_update_port_irq - update DE port interrupt
394 * @dev_priv: driver private
395 * @interrupt_mask: mask of interrupt bits to update
396 * @enabled_irq_mask: mask of interrupt bits to enable
397 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300398static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
399 uint32_t interrupt_mask,
400 uint32_t enabled_irq_mask)
401{
402 uint32_t new_val;
403 uint32_t old_val;
404
405 assert_spin_locked(&dev_priv->irq_lock);
406
407 WARN_ON(enabled_irq_mask & ~interrupt_mask);
408
409 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
410 return;
411
412 old_val = I915_READ(GEN8_DE_PORT_IMR);
413
414 new_val = old_val;
415 new_val &= ~interrupt_mask;
416 new_val |= (~enabled_irq_mask & interrupt_mask);
417
418 if (new_val != old_val) {
419 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
420 POSTING_READ(GEN8_DE_PORT_IMR);
421 }
422}
423
424/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200425 * bdw_update_pipe_irq - update DE pipe interrupt
426 * @dev_priv: driver private
427 * @pipe: pipe whose interrupt to update
428 * @interrupt_mask: mask of interrupt bits to update
429 * @enabled_irq_mask: mask of interrupt bits to enable
430 */
431void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
432 enum pipe pipe,
433 uint32_t interrupt_mask,
434 uint32_t enabled_irq_mask)
435{
436 uint32_t new_val;
437
438 assert_spin_locked(&dev_priv->irq_lock);
439
440 WARN_ON(enabled_irq_mask & ~interrupt_mask);
441
442 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
443 return;
444
445 new_val = dev_priv->de_irq_mask[pipe];
446 new_val &= ~interrupt_mask;
447 new_val |= (~enabled_irq_mask & interrupt_mask);
448
449 if (new_val != dev_priv->de_irq_mask[pipe]) {
450 dev_priv->de_irq_mask[pipe] = new_val;
451 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
452 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
453 }
454}
455
456/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200457 * ibx_display_interrupt_update - update SDEIMR
458 * @dev_priv: driver private
459 * @interrupt_mask: mask of interrupt bits to update
460 * @enabled_irq_mask: mask of interrupt bits to enable
461 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200462void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
463 uint32_t interrupt_mask,
464 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200465{
466 uint32_t sdeimr = I915_READ(SDEIMR);
467 sdeimr &= ~interrupt_mask;
468 sdeimr |= (~enabled_irq_mask & interrupt_mask);
469
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100470 WARN_ON(enabled_irq_mask & ~interrupt_mask);
471
Daniel Vetterfee884e2013-07-04 23:35:21 +0200472 assert_spin_locked(&dev_priv->irq_lock);
473
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700474 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300475 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300476
Daniel Vetterfee884e2013-07-04 23:35:21 +0200477 I915_WRITE(SDEIMR, sdeimr);
478 POSTING_READ(SDEIMR);
479}
Paulo Zanoni86642812013-04-12 17:57:57 -0300480
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100481static void
Imre Deak755e9012014-02-10 18:42:47 +0200482__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
483 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800484{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200485 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200486 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800487
Daniel Vetterb79480b2013-06-27 17:52:10 +0200488 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200489 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200490
Ville Syrjälä04feced2014-04-03 13:28:33 +0300491 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
492 status_mask & ~PIPESTAT_INT_STATUS_MASK,
493 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
494 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200495 return;
496
497 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200498 return;
499
Imre Deak91d181d2014-02-10 18:42:49 +0200500 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
501
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200502 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200503 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200504 I915_WRITE(reg, pipestat);
505 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800506}
507
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100508static void
Imre Deak755e9012014-02-10 18:42:47 +0200509__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
510 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800511{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200512 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200513 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800514
Daniel Vetterb79480b2013-06-27 17:52:10 +0200515 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200516 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200517
Ville Syrjälä04feced2014-04-03 13:28:33 +0300518 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
519 status_mask & ~PIPESTAT_INT_STATUS_MASK,
520 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
521 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200522 return;
523
Imre Deak755e9012014-02-10 18:42:47 +0200524 if ((pipestat & enable_mask) == 0)
525 return;
526
Imre Deak91d181d2014-02-10 18:42:49 +0200527 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
528
Imre Deak755e9012014-02-10 18:42:47 +0200529 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200530 I915_WRITE(reg, pipestat);
531 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800532}
533
Imre Deak10c59c52014-02-10 18:42:48 +0200534static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
535{
536 u32 enable_mask = status_mask << 16;
537
538 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300539 * On pipe A we don't support the PSR interrupt yet,
540 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200541 */
542 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
543 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300544 /*
545 * On pipe B and C we don't support the PSR interrupt yet, on pipe
546 * A the same bit is for perf counters which we don't use either.
547 */
548 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
549 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200550
551 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
552 SPRITE0_FLIP_DONE_INT_EN_VLV |
553 SPRITE1_FLIP_DONE_INT_EN_VLV);
554 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
555 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
556 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
557 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
558
559 return enable_mask;
560}
561
Imre Deak755e9012014-02-10 18:42:47 +0200562void
563i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
564 u32 status_mask)
565{
566 u32 enable_mask;
567
Wayne Boyer666a4532015-12-09 12:29:35 -0800568 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Imre Deak10c59c52014-02-10 18:42:48 +0200569 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
570 status_mask);
571 else
572 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200573 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
574}
575
576void
577i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
578 u32 status_mask)
579{
580 u32 enable_mask;
581
Wayne Boyer666a4532015-12-09 12:29:35 -0800582 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Imre Deak10c59c52014-02-10 18:42:48 +0200583 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
584 status_mask);
585 else
586 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200587 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
588}
589
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000590/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300591 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100592 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000593 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100594static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000595{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100596 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300597 return;
598
Daniel Vetter13321782014-09-15 14:55:29 +0200599 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000600
Imre Deak755e9012014-02-10 18:42:47 +0200601 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100602 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200603 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200604 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000605
Daniel Vetter13321782014-09-15 14:55:29 +0200606 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000607}
608
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300609/*
610 * This timing diagram depicts the video signal in and
611 * around the vertical blanking period.
612 *
613 * Assumptions about the fictitious mode used in this example:
614 * vblank_start >= 3
615 * vsync_start = vblank_start + 1
616 * vsync_end = vblank_start + 2
617 * vtotal = vblank_start + 3
618 *
619 * start of vblank:
620 * latch double buffered registers
621 * increment frame counter (ctg+)
622 * generate start of vblank interrupt (gen4+)
623 * |
624 * | frame start:
625 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
626 * | may be shifted forward 1-3 extra lines via PIPECONF
627 * | |
628 * | | start of vsync:
629 * | | generate vsync interrupt
630 * | | |
631 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
632 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
633 * ----va---> <-----------------vb--------------------> <--------va-------------
634 * | | <----vs-----> |
635 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
636 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
637 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
638 * | | |
639 * last visible pixel first visible pixel
640 * | increment frame counter (gen3/4)
641 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
642 *
643 * x = horizontal active
644 * _ = horizontal blanking
645 * hs = horizontal sync
646 * va = vertical active
647 * vb = vertical blanking
648 * vs = vertical sync
649 * vbs = vblank_start (number)
650 *
651 * Summary:
652 * - most events happen at the start of horizontal sync
653 * - frame start happens at the start of horizontal blank, 1-4 lines
654 * (depending on PIPECONF settings) after the start of vblank
655 * - gen3/4 pixel and frame counter are synchronized with the start
656 * of horizontal active on the first line of vertical active
657 */
658
Thierry Reding88e72712015-09-24 18:35:31 +0200659static u32 i8xx_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300660{
661 /* Gen2 doesn't have a hardware frame counter */
662 return 0;
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 Wilson3d5564e2016-07-01 17:23:23 +0100980 smp_store_mb(engine->irq_posted, true);
Chris Wilson688e6c72016-07-01 17:23:15 +0100981 if (intel_engine_wakeup(engine)) {
982 trace_i915_gem_request_notify(engine);
983 engine->user_interrupts++;
984 }
Chris Wilson549f7362010-10-19 11:19:32 +0100985}
986
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000987static void vlv_c0_read(struct drm_i915_private *dev_priv,
988 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400989{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000990 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
991 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
992 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400993}
994
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000995static bool vlv_c0_above(struct drm_i915_private *dev_priv,
996 const struct intel_rps_ei *old,
997 const struct intel_rps_ei *now,
998 int threshold)
Deepak S31685c22014-07-03 17:33:01 -0400999{
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001000 u64 time, c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001001 unsigned int mul = 100;
Deepak S31685c22014-07-03 17:33:01 -04001002
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001003 if (old->cz_clock == 0)
1004 return false;
Deepak S31685c22014-07-03 17:33:01 -04001005
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001006 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
1007 mul <<= 8;
1008
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001009 time = now->cz_clock - old->cz_clock;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001010 time *= threshold * dev_priv->czclk_freq;
Deepak S31685c22014-07-03 17:33:01 -04001011
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001012 /* Workload can be split between render + media, e.g. SwapBuffers
1013 * being blitted in X after being rendered in mesa. To account for
1014 * this we need to combine both engines into our activity counter.
1015 */
1016 c0 = now->render_c0 - old->render_c0;
1017 c0 += now->media_c0 - old->media_c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001018 c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC;
Deepak S31685c22014-07-03 17:33:01 -04001019
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001020 return c0 >= time;
1021}
Deepak S31685c22014-07-03 17:33:01 -04001022
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001023void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1024{
1025 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
1026 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001027}
1028
1029static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1030{
1031 struct intel_rps_ei now;
1032 u32 events = 0;
1033
Chris Wilson6f4b12f82015-03-18 09:48:23 +00001034 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001035 return 0;
1036
1037 vlv_c0_read(dev_priv, &now);
1038 if (now.cz_clock == 0)
1039 return 0;
Deepak S31685c22014-07-03 17:33:01 -04001040
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001041 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1042 if (!vlv_c0_above(dev_priv,
1043 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001044 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001045 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1046 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -04001047 }
1048
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001049 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1050 if (vlv_c0_above(dev_priv,
1051 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001052 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001053 events |= GEN6_PM_RP_UP_THRESHOLD;
1054 dev_priv->rps.up_ei = now;
1055 }
1056
1057 return events;
Deepak S31685c22014-07-03 17:33:01 -04001058}
1059
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001060static bool any_waiters(struct drm_i915_private *dev_priv)
1061{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001062 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001063
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001064 for_each_engine(engine, dev_priv)
Chris Wilson688e6c72016-07-01 17:23:15 +01001065 if (intel_engine_has_waiter(engine))
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001066 return true;
1067
1068 return false;
1069}
1070
Ben Widawsky4912d042011-04-25 11:25:20 -07001071static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001072{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001073 struct drm_i915_private *dev_priv =
1074 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001075 bool client_boost;
1076 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001077 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001078
Daniel Vetter59cdb632013-07-04 23:35:28 +02001079 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001080 /* Speed up work cancelation during disabling rps interrupts. */
1081 if (!dev_priv->rps.interrupts_enabled) {
1082 spin_unlock_irq(&dev_priv->irq_lock);
1083 return;
1084 }
Imre Deak1f814da2015-12-16 02:52:19 +02001085
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001086 pm_iir = dev_priv->rps.pm_iir;
1087 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001088 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1089 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001090 client_boost = dev_priv->rps.client_boost;
1091 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001092 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001093
Paulo Zanoni60611c12013-08-15 11:50:01 -03001094 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301095 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001096
Chris Wilson8d3afd72015-05-21 21:01:47 +01001097 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilsonc33d2472016-07-04 08:08:36 +01001098 return;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001099
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001100 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001101
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001102 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1103
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001104 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001105 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001106 min = dev_priv->rps.min_freq_softlimit;
1107 max = dev_priv->rps.max_freq_softlimit;
1108
1109 if (client_boost) {
1110 new_delay = dev_priv->rps.max_freq_softlimit;
1111 adj = 0;
1112 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001113 if (adj > 0)
1114 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001115 else /* CHV needs even encode values */
1116 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001117 /*
1118 * For better performance, jump directly
1119 * to RPe if we're below it.
1120 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001121 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001122 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001123 adj = 0;
1124 }
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001125 } else if (any_waiters(dev_priv)) {
1126 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001127 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001128 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1129 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001130 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001131 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001132 adj = 0;
1133 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1134 if (adj < 0)
1135 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001136 else /* CHV needs even encode values */
1137 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001138 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001139 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001140 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001141
Chris Wilsonedcf2842015-04-07 16:20:29 +01001142 dev_priv->rps.last_adj = adj;
1143
Ben Widawsky79249632012-09-07 19:43:42 -07001144 /* sysfs frequency interfaces may have snuck in while servicing the
1145 * interrupt
1146 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001147 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001148 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301149
Chris Wilsondc979972016-05-10 14:10:04 +01001150 intel_set_rps(dev_priv, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001152 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001153}
1154
Ben Widawskye3689192012-05-25 16:56:22 -07001155
1156/**
1157 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1158 * occurred.
1159 * @work: workqueue struct
1160 *
1161 * Doesn't actually do anything except notify userspace. As a consequence of
1162 * this event, userspace should try to remap the bad rows since statistically
1163 * it is likely the same row is more likely to go bad again.
1164 */
1165static void ivybridge_parity_work(struct work_struct *work)
1166{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001167 struct drm_i915_private *dev_priv =
1168 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001169 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001170 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001171 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001172 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001173
1174 /* We must turn off DOP level clock gating to access the L3 registers.
1175 * In order to prevent a get/put style interface, acquire struct mutex
1176 * any time we access those registers.
1177 */
1178 mutex_lock(&dev_priv->dev->struct_mutex);
1179
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001180 /* If we've screwed up tracking, just let the interrupt fire again */
1181 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1182 goto out;
1183
Ben Widawskye3689192012-05-25 16:56:22 -07001184 misccpctl = I915_READ(GEN7_MISCCPCTL);
1185 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1186 POSTING_READ(GEN7_MISCCPCTL);
1187
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001188 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001189 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001190
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001191 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001192 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001193 break;
1194
1195 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1196
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001197 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001198
1199 error_status = I915_READ(reg);
1200 row = GEN7_PARITY_ERROR_ROW(error_status);
1201 bank = GEN7_PARITY_ERROR_BANK(error_status);
1202 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1203
1204 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1205 POSTING_READ(reg);
1206
1207 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1208 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1209 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1210 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1211 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1212 parity_event[5] = NULL;
1213
Dave Airlie5bdebb12013-10-11 14:07:25 +10001214 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001215 KOBJ_CHANGE, parity_event);
1216
1217 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1218 slice, row, bank, subbank);
1219
1220 kfree(parity_event[4]);
1221 kfree(parity_event[3]);
1222 kfree(parity_event[2]);
1223 kfree(parity_event[1]);
1224 }
Ben Widawskye3689192012-05-25 16:56:22 -07001225
1226 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1227
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001228out:
1229 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001230 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001231 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001232 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001233
1234 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001235}
1236
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001237static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1238 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001239{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001240 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001241 return;
1242
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001243 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001244 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001245 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001246
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001247 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001248 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1249 dev_priv->l3_parity.which_slice |= 1 << 1;
1250
1251 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1252 dev_priv->l3_parity.which_slice |= 1 << 0;
1253
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001254 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001255}
1256
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001257static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001258 u32 gt_iir)
1259{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001260 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001261 notify_ring(&dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001262 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001263 notify_ring(&dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001264}
1265
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001266static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001267 u32 gt_iir)
1268{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001269 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001270 notify_ring(&dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001271 if (gt_iir & GT_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001272 notify_ring(&dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001273 if (gt_iir & GT_BLT_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001274 notify_ring(&dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001275
Ben Widawskycc609d52013-05-28 19:22:29 -07001276 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1277 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001278 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1279 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001280
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001281 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1282 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001283}
1284
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001285static __always_inline void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001286gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001287{
1288 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift))
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001289 notify_ring(engine);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001290 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift))
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01001291 tasklet_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001292}
1293
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001294static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1295 u32 master_ctl,
1296 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001297{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001298 irqreturn_t ret = IRQ_NONE;
1299
1300 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001301 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1302 if (gt_iir[0]) {
1303 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001304 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001305 } else
1306 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1307 }
1308
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001309 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001310 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1311 if (gt_iir[1]) {
1312 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001313 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001314 } else
1315 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1316 }
1317
Chris Wilson74cdb332015-04-07 16:21:05 +01001318 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001319 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1320 if (gt_iir[3]) {
1321 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001322 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001323 } else
1324 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1325 }
1326
Ben Widawsky09610212014-05-15 20:58:08 +03001327 if (master_ctl & GEN8_GT_PM_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001328 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
1329 if (gt_iir[2] & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001330 I915_WRITE_FW(GEN8_GT_IIR(2),
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001331 gt_iir[2] & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001332 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001333 } else
1334 DRM_ERROR("The master control interrupt lied (PM)!\n");
1335 }
1336
Ben Widawskyabd58f02013-11-02 21:07:09 -07001337 return ret;
1338}
1339
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001340static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1341 u32 gt_iir[4])
1342{
1343 if (gt_iir[0]) {
1344 gen8_cs_irq_handler(&dev_priv->engine[RCS],
1345 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
1346 gen8_cs_irq_handler(&dev_priv->engine[BCS],
1347 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1348 }
1349
1350 if (gt_iir[1]) {
1351 gen8_cs_irq_handler(&dev_priv->engine[VCS],
1352 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
1353 gen8_cs_irq_handler(&dev_priv->engine[VCS2],
1354 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1355 }
1356
1357 if (gt_iir[3])
1358 gen8_cs_irq_handler(&dev_priv->engine[VECS],
1359 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1360
1361 if (gt_iir[2] & dev_priv->pm_rps_events)
1362 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
1363}
1364
Imre Deak63c88d22015-07-20 14:43:39 -07001365static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1366{
1367 switch (port) {
1368 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001369 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001370 case PORT_B:
1371 return val & PORTB_HOTPLUG_LONG_DETECT;
1372 case PORT_C:
1373 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001374 default:
1375 return false;
1376 }
1377}
1378
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001379static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1380{
1381 switch (port) {
1382 case PORT_E:
1383 return val & PORTE_HOTPLUG_LONG_DETECT;
1384 default:
1385 return false;
1386 }
1387}
1388
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001389static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1390{
1391 switch (port) {
1392 case PORT_A:
1393 return val & PORTA_HOTPLUG_LONG_DETECT;
1394 case PORT_B:
1395 return val & PORTB_HOTPLUG_LONG_DETECT;
1396 case PORT_C:
1397 return val & PORTC_HOTPLUG_LONG_DETECT;
1398 case PORT_D:
1399 return val & PORTD_HOTPLUG_LONG_DETECT;
1400 default:
1401 return false;
1402 }
1403}
1404
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001405static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1406{
1407 switch (port) {
1408 case PORT_A:
1409 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1410 default:
1411 return false;
1412 }
1413}
1414
Jani Nikula676574d2015-05-28 15:43:53 +03001415static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001416{
1417 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001418 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001419 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001420 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001421 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001422 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001423 return val & PORTD_HOTPLUG_LONG_DETECT;
1424 default:
1425 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001426 }
1427}
1428
Jani Nikula676574d2015-05-28 15:43:53 +03001429static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001430{
1431 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001432 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001433 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001434 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001435 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001436 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001437 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1438 default:
1439 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001440 }
1441}
1442
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001443/*
1444 * Get a bit mask of pins that have triggered, and which ones may be long.
1445 * This can be called multiple times with the same masks to accumulate
1446 * hotplug detection results from several registers.
1447 *
1448 * Note that the caller is expected to zero out the masks initially.
1449 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001450static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001451 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001452 const u32 hpd[HPD_NUM_PINS],
1453 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001454{
Jani Nikula8c841e52015-06-18 13:06:17 +03001455 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001456 int i;
1457
Jani Nikula676574d2015-05-28 15:43:53 +03001458 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001459 if ((hpd[i] & hotplug_trigger) == 0)
1460 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001461
Jani Nikula8c841e52015-06-18 13:06:17 +03001462 *pin_mask |= BIT(i);
1463
Imre Deakcc24fcd2015-07-21 15:32:45 -07001464 if (!intel_hpd_pin_to_port(i, &port))
1465 continue;
1466
Imre Deakfd63e2a2015-07-21 15:32:44 -07001467 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001468 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001469 }
1470
1471 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1472 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1473
1474}
1475
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001476static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001477{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001478 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001479}
1480
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001481static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001482{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001483 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001484}
1485
Shuang He8bf1e9f2013-10-15 18:55:27 +01001486#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001487static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1488 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001489 uint32_t crc0, uint32_t crc1,
1490 uint32_t crc2, uint32_t crc3,
1491 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001492{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001493 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1494 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001495 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001496
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001497 spin_lock(&pipe_crc->lock);
1498
Damien Lespiau0c912c72013-10-15 18:55:37 +01001499 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001500 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001501 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001502 return;
1503 }
1504
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001505 head = pipe_crc->head;
1506 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001507
1508 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001509 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001510 DRM_ERROR("CRC buffer overflowing\n");
1511 return;
1512 }
1513
1514 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001515
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001516 entry->frame = dev_priv->dev->driver->get_vblank_counter(dev_priv->dev,
1517 pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001518 entry->crc[0] = crc0;
1519 entry->crc[1] = crc1;
1520 entry->crc[2] = crc2;
1521 entry->crc[3] = crc3;
1522 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001523
1524 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001525 pipe_crc->head = head;
1526
1527 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001528
1529 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001530}
Daniel Vetter277de952013-10-18 16:37:07 +02001531#else
1532static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001533display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1534 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001535 uint32_t crc0, uint32_t crc1,
1536 uint32_t crc2, uint32_t crc3,
1537 uint32_t crc4) {}
1538#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001539
Daniel Vetter277de952013-10-18 16:37:07 +02001540
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001541static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1542 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001543{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001544 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001545 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1546 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001547}
1548
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001549static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1550 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001551{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001552 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001553 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1554 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1555 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1556 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1557 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001558}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001559
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001560static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1561 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001562{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001563 uint32_t res1, res2;
1564
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001565 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001566 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1567 else
1568 res1 = 0;
1569
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001570 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001571 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1572 else
1573 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001574
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001575 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001576 I915_READ(PIPE_CRC_RES_RED(pipe)),
1577 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1578 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1579 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001580}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001581
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001582/* The RPS events need forcewake, so we add them to a work queue and mask their
1583 * IMR bits until the work is done. Other interrupts can be processed without
1584 * the work queue. */
1585static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001586{
Deepak Sa6706b42014-03-15 20:23:22 +05301587 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001588 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001589 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001590 if (dev_priv->rps.interrupts_enabled) {
1591 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001592 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001593 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001594 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001595 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001596
Imre Deakc9a9a262014-11-05 20:48:37 +02001597 if (INTEL_INFO(dev_priv)->gen >= 8)
1598 return;
1599
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001600 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001601 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001602 notify_ring(&dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001603
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001604 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1605 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001606 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001607}
1608
Daniel Vetter5a21b662016-05-24 17:13:53 +02001609static bool intel_pipe_handle_vblank(struct drm_i915_private *dev_priv,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001610 enum pipe pipe)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001611{
Daniel Vetter5a21b662016-05-24 17:13:53 +02001612 bool ret;
1613
1614 ret = drm_handle_vblank(dev_priv->dev, pipe);
1615 if (ret)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001616 intel_finish_page_flip_mmio(dev_priv, pipe);
Daniel Vetter5a21b662016-05-24 17:13:53 +02001617
1618 return ret;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001619}
1620
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001621static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1622 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001623{
Imre Deakc1874ed2014-02-04 21:35:46 +02001624 int pipe;
1625
Imre Deak58ead0d2014-02-04 21:35:47 +02001626 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001627
1628 if (!dev_priv->display_irqs_enabled) {
1629 spin_unlock(&dev_priv->irq_lock);
1630 return;
1631 }
1632
Damien Lespiau055e3932014-08-18 13:49:10 +01001633 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001634 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001635 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001636
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001637 /*
1638 * PIPESTAT bits get signalled even when the interrupt is
1639 * disabled with the mask bits, and some of the status bits do
1640 * not generate interrupts at all (like the underrun bit). Hence
1641 * we need to be careful that we only handle what we want to
1642 * handle.
1643 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001644
1645 /* fifo underruns are filterered in the underrun handler. */
1646 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001647
1648 switch (pipe) {
1649 case PIPE_A:
1650 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1651 break;
1652 case PIPE_B:
1653 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1654 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001655 case PIPE_C:
1656 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1657 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001658 }
1659 if (iir & iir_bit)
1660 mask |= dev_priv->pipestat_irq_mask[pipe];
1661
1662 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001663 continue;
1664
1665 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001666 mask |= PIPESTAT_INT_ENABLE_MASK;
1667 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001668
1669 /*
1670 * Clear the PIPE*STAT regs before the IIR
1671 */
Imre Deak91d181d2014-02-10 18:42:49 +02001672 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1673 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001674 I915_WRITE(reg, pipe_stats[pipe]);
1675 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001676 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001677}
1678
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001679static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001680 u32 pipe_stats[I915_MAX_PIPES])
1681{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001682 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001683
Damien Lespiau055e3932014-08-18 13:49:10 +01001684 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02001685 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1686 intel_pipe_handle_vblank(dev_priv, pipe))
1687 intel_check_page_flip(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001688
Maarten Lankhorst5251f042016-05-17 15:07:47 +02001689 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001690 intel_finish_page_flip_cs(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001691
1692 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001693 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001694
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001695 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1696 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001697 }
1698
1699 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001700 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001701}
1702
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001703static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001704{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001705 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001706
1707 if (hotplug_status)
1708 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1709
1710 return hotplug_status;
1711}
1712
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001713static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001714 u32 hotplug_status)
1715{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001716 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001717
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001718 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1719 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001720 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001721
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001722 if (hotplug_trigger) {
1723 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1724 hotplug_trigger, hpd_status_g4x,
1725 i9xx_port_hotplug_long_detect);
1726
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001727 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001728 }
Jani Nikula369712e2015-05-27 15:03:40 +03001729
1730 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001731 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001732 } else {
1733 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001734
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001735 if (hotplug_trigger) {
1736 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001737 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001738 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001739 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001740 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001741 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001742}
1743
Daniel Vetterff1f5252012-10-02 15:10:55 +02001744static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001745{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001746 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001747 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001748 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001749
Imre Deak2dd2a882015-02-24 11:14:30 +02001750 if (!intel_irqs_enabled(dev_priv))
1751 return IRQ_NONE;
1752
Imre Deak1f814da2015-12-16 02:52:19 +02001753 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1754 disable_rpm_wakeref_asserts(dev_priv);
1755
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001756 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001757 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001758 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001759 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001760 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001761
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001762 gt_iir = I915_READ(GTIIR);
1763 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001764 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001765
1766 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001767 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001768
1769 ret = IRQ_HANDLED;
1770
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001771 /*
1772 * Theory on interrupt generation, based on empirical evidence:
1773 *
1774 * x = ((VLV_IIR & VLV_IER) ||
1775 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1776 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1777 *
1778 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1779 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1780 * guarantee the CPU interrupt will be raised again even if we
1781 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1782 * bits this time around.
1783 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001784 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001785 ier = I915_READ(VLV_IER);
1786 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001787
1788 if (gt_iir)
1789 I915_WRITE(GTIIR, gt_iir);
1790 if (pm_iir)
1791 I915_WRITE(GEN6_PMIIR, pm_iir);
1792
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001793 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001794 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001795
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001796 /* Call regardless, as some status bits might not be
1797 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001798 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001799
1800 /*
1801 * VLV_IIR is single buffered, and reflects the level
1802 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1803 */
1804 if (iir)
1805 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001806
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001807 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001808 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1809 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001810
Ville Syrjälä52894872016-04-13 21:19:56 +03001811 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001812 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03001813 if (pm_iir)
1814 gen6_rps_irq_handler(dev_priv, pm_iir);
1815
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001816 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001817 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001818
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001819 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001820 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001821
Imre Deak1f814da2015-12-16 02:52:19 +02001822 enable_rpm_wakeref_asserts(dev_priv);
1823
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001824 return ret;
1825}
1826
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001827static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1828{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001829 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001830 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001831 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001832
Imre Deak2dd2a882015-02-24 11:14:30 +02001833 if (!intel_irqs_enabled(dev_priv))
1834 return IRQ_NONE;
1835
Imre Deak1f814da2015-12-16 02:52:19 +02001836 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1837 disable_rpm_wakeref_asserts(dev_priv);
1838
Chris Wilson579de732016-03-14 09:01:57 +00001839 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001840 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001841 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001842 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001843 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001844 u32 ier = 0;
1845
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001846 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1847 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001848
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001849 if (master_ctl == 0 && iir == 0)
1850 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001851
Oscar Mateo27b6c122014-06-16 16:11:00 +01001852 ret = IRQ_HANDLED;
1853
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001854 /*
1855 * Theory on interrupt generation, based on empirical evidence:
1856 *
1857 * x = ((VLV_IIR & VLV_IER) ||
1858 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1859 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1860 *
1861 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1862 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1863 * guarantee the CPU interrupt will be raised again even if we
1864 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1865 * bits this time around.
1866 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001867 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001868 ier = I915_READ(VLV_IER);
1869 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001870
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001871 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001872
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001873 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001874 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001875
Oscar Mateo27b6c122014-06-16 16:11:00 +01001876 /* Call regardless, as some status bits might not be
1877 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001878 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001879
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001880 /*
1881 * VLV_IIR is single buffered, and reflects the level
1882 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1883 */
1884 if (iir)
1885 I915_WRITE(VLV_IIR, iir);
1886
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001887 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03001888 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001889 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001890
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001891 gen8_gt_irq_handler(dev_priv, gt_iir);
1892
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001893 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001894 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001895
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001896 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00001897 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001898
Imre Deak1f814da2015-12-16 02:52:19 +02001899 enable_rpm_wakeref_asserts(dev_priv);
1900
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001901 return ret;
1902}
1903
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001904static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1905 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03001906 const u32 hpd[HPD_NUM_PINS])
1907{
Ville Syrjälä40e56412015-08-27 23:56:10 +03001908 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1909
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001910 /*
1911 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1912 * unless we touch the hotplug register, even if hotplug_trigger is
1913 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1914 * errors.
1915 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03001916 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001917 if (!hotplug_trigger) {
1918 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1919 PORTD_HOTPLUG_STATUS_MASK |
1920 PORTC_HOTPLUG_STATUS_MASK |
1921 PORTB_HOTPLUG_STATUS_MASK;
1922 dig_hotplug_reg &= ~mask;
1923 }
1924
Ville Syrjälä40e56412015-08-27 23:56:10 +03001925 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001926 if (!hotplug_trigger)
1927 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03001928
1929 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1930 dig_hotplug_reg, hpd,
1931 pch_port_hotplug_long_detect);
1932
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001933 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03001934}
1935
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001936static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001937{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001938 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001939 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001940
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001941 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001942
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001943 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1944 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1945 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001946 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001947 port_name(port));
1948 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001949
Daniel Vetterce99c252012-12-01 13:53:47 +01001950 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001951 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01001952
Jesse Barnes776ad802011-01-04 15:09:39 -08001953 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001954 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08001955
1956 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1957 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1958
1959 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1960 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1961
1962 if (pch_iir & SDE_POISON)
1963 DRM_ERROR("PCH poison interrupt\n");
1964
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001965 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001966 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001967 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1968 pipe_name(pipe),
1969 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001970
1971 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1972 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1973
1974 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1975 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1976
Jesse Barnes776ad802011-01-04 15:09:39 -08001977 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001978 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001979
1980 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001981 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001982}
1983
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001984static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03001985{
Paulo Zanoni86642812013-04-12 17:57:57 -03001986 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001987 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001988
Paulo Zanonide032bf2013-04-12 17:57:58 -03001989 if (err_int & ERR_INT_POISON)
1990 DRM_ERROR("Poison interrupt\n");
1991
Damien Lespiau055e3932014-08-18 13:49:10 +01001992 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001993 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1994 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03001995
Daniel Vetter5a69b892013-10-16 22:55:52 +02001996 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001997 if (IS_IVYBRIDGE(dev_priv))
1998 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001999 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002000 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002001 }
2002 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002003
Paulo Zanoni86642812013-04-12 17:57:57 -03002004 I915_WRITE(GEN7_ERR_INT, err_int);
2005}
2006
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002007static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002008{
Paulo Zanoni86642812013-04-12 17:57:57 -03002009 u32 serr_int = I915_READ(SERR_INT);
2010
Paulo Zanonide032bf2013-04-12 17:57:58 -03002011 if (serr_int & SERR_INT_POISON)
2012 DRM_ERROR("PCH poison interrupt\n");
2013
Paulo Zanoni86642812013-04-12 17:57:57 -03002014 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002015 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002016
2017 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002018 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002019
2020 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002021 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002022
2023 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002024}
2025
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002026static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002027{
Adam Jackson23e81d62012-06-06 15:45:44 -04002028 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002029 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002030
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002031 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002032
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002033 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2034 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2035 SDE_AUDIO_POWER_SHIFT_CPT);
2036 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2037 port_name(port));
2038 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002039
2040 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002041 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002042
2043 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002044 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002045
2046 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2047 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2048
2049 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2050 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2051
2052 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002053 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002054 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2055 pipe_name(pipe),
2056 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002057
2058 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002059 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002060}
2061
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002062static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002063{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002064 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2065 ~SDE_PORTE_HOTPLUG_SPT;
2066 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2067 u32 pin_mask = 0, long_mask = 0;
2068
2069 if (hotplug_trigger) {
2070 u32 dig_hotplug_reg;
2071
2072 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2073 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2074
2075 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2076 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002077 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002078 }
2079
2080 if (hotplug2_trigger) {
2081 u32 dig_hotplug_reg;
2082
2083 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2084 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2085
2086 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2087 dig_hotplug_reg, hpd_spt,
2088 spt_port_hotplug2_long_detect);
2089 }
2090
2091 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002092 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002093
2094 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002095 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002096}
2097
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002098static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2099 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002100 const u32 hpd[HPD_NUM_PINS])
2101{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002102 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2103
2104 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2105 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2106
2107 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2108 dig_hotplug_reg, hpd,
2109 ilk_port_hotplug_long_detect);
2110
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002111 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002112}
2113
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002114static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2115 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002116{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002117 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002118 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2119
Ville Syrjälä40e56412015-08-27 23:56:10 +03002120 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002121 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002122
2123 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002124 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002125
2126 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002127 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002128
Paulo Zanonic008bc62013-07-12 16:35:10 -03002129 if (de_iir & DE_POISON)
2130 DRM_ERROR("Poison interrupt\n");
2131
Damien Lespiau055e3932014-08-18 13:49:10 +01002132 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002133 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2134 intel_pipe_handle_vblank(dev_priv, pipe))
2135 intel_check_page_flip(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002136
Daniel Vetter40da17c22013-10-21 18:04:36 +02002137 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002138 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002139
Daniel Vetter40da17c22013-10-21 18:04:36 +02002140 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002141 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002142
Daniel Vetter40da17c22013-10-21 18:04:36 +02002143 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002144 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002145 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002146 }
2147
2148 /* check event from PCH */
2149 if (de_iir & DE_PCH_EVENT) {
2150 u32 pch_iir = I915_READ(SDEIIR);
2151
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002152 if (HAS_PCH_CPT(dev_priv))
2153 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002154 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002155 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002156
2157 /* should clear PCH hotplug event before clear CPU irq */
2158 I915_WRITE(SDEIIR, pch_iir);
2159 }
2160
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002161 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2162 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002163}
2164
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002165static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2166 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002167{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002168 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002169 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2170
Ville Syrjälä40e56412015-08-27 23:56:10 +03002171 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002172 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002173
2174 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002175 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002176
2177 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002178 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002179
2180 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002181 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002182
Damien Lespiau055e3932014-08-18 13:49:10 +01002183 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002184 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2185 intel_pipe_handle_vblank(dev_priv, pipe))
2186 intel_check_page_flip(dev_priv, pipe);
Daniel Vetter40da17c22013-10-21 18:04:36 +02002187
2188 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002189 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002190 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002191 }
2192
2193 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002194 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002195 u32 pch_iir = I915_READ(SDEIIR);
2196
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002197 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002198
2199 /* clear PCH hotplug event before clear CPU irq */
2200 I915_WRITE(SDEIIR, pch_iir);
2201 }
2202}
2203
Oscar Mateo72c90f62014-06-16 16:10:57 +01002204/*
2205 * To handle irqs with the minimum potential races with fresh interrupts, we:
2206 * 1 - Disable Master Interrupt Control.
2207 * 2 - Find the source(s) of the interrupt.
2208 * 3 - Clear the Interrupt Identity bits (IIR).
2209 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2210 * 5 - Re-enable Master Interrupt Control.
2211 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002212static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002213{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002214 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002215 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002216 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002217 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002218
Imre Deak2dd2a882015-02-24 11:14:30 +02002219 if (!intel_irqs_enabled(dev_priv))
2220 return IRQ_NONE;
2221
Imre Deak1f814da2015-12-16 02:52:19 +02002222 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2223 disable_rpm_wakeref_asserts(dev_priv);
2224
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002225 /* disable master interrupt before clearing iir */
2226 de_ier = I915_READ(DEIER);
2227 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002228 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002229
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002230 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2231 * interrupts will will be stored on its back queue, and then we'll be
2232 * able to process them after we restore SDEIER (as soon as we restore
2233 * it, we'll get an interrupt if SDEIIR still has something to process
2234 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002235 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002236 sde_ier = I915_READ(SDEIER);
2237 I915_WRITE(SDEIER, 0);
2238 POSTING_READ(SDEIER);
2239 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002240
Oscar Mateo72c90f62014-06-16 16:10:57 +01002241 /* Find, clear, then process each source of interrupt */
2242
Chris Wilson0e434062012-05-09 21:45:44 +01002243 gt_iir = I915_READ(GTIIR);
2244 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002245 I915_WRITE(GTIIR, gt_iir);
2246 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002247 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002248 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002249 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002250 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002251 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002252
2253 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002254 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002255 I915_WRITE(DEIIR, de_iir);
2256 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002257 if (INTEL_GEN(dev_priv) >= 7)
2258 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002259 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002260 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002261 }
2262
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002263 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002264 u32 pm_iir = I915_READ(GEN6_PMIIR);
2265 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002266 I915_WRITE(GEN6_PMIIR, pm_iir);
2267 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002268 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002269 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002270 }
2271
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002272 I915_WRITE(DEIER, de_ier);
2273 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002274 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002275 I915_WRITE(SDEIER, sde_ier);
2276 POSTING_READ(SDEIER);
2277 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002278
Imre Deak1f814da2015-12-16 02:52:19 +02002279 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2280 enable_rpm_wakeref_asserts(dev_priv);
2281
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002282 return ret;
2283}
2284
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002285static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2286 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002287 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302288{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002289 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302290
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002291 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2292 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302293
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002294 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002295 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002296 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002297
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002298 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302299}
2300
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002301static irqreturn_t
2302gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002303{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002304 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002305 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002306 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002307
Ben Widawskyabd58f02013-11-02 21:07:09 -07002308 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002309 iir = I915_READ(GEN8_DE_MISC_IIR);
2310 if (iir) {
2311 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002312 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002313 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002314 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002315 else
2316 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002317 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002318 else
2319 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002320 }
2321
Daniel Vetter6d766f02013-11-07 14:49:55 +01002322 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002323 iir = I915_READ(GEN8_DE_PORT_IIR);
2324 if (iir) {
2325 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302326 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002327
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002328 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002329 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002330
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002331 tmp_mask = GEN8_AUX_CHANNEL_A;
2332 if (INTEL_INFO(dev_priv)->gen >= 9)
2333 tmp_mask |= GEN9_AUX_CHANNEL_B |
2334 GEN9_AUX_CHANNEL_C |
2335 GEN9_AUX_CHANNEL_D;
2336
2337 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002338 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302339 found = true;
2340 }
2341
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002342 if (IS_BROXTON(dev_priv)) {
2343 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2344 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002345 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2346 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002347 found = true;
2348 }
2349 } else if (IS_BROADWELL(dev_priv)) {
2350 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2351 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002352 ilk_hpd_irq_handler(dev_priv,
2353 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002354 found = true;
2355 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302356 }
2357
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002358 if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
2359 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302360 found = true;
2361 }
2362
Shashank Sharmad04a4922014-08-22 17:40:41 +05302363 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002364 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002365 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002366 else
2367 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002368 }
2369
Damien Lespiau055e3932014-08-18 13:49:10 +01002370 for_each_pipe(dev_priv, pipe) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002371 u32 flip_done, fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002372
Daniel Vetterc42664c2013-11-07 11:05:40 +01002373 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2374 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002375
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002376 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2377 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002378 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002379 continue;
2380 }
2381
2382 ret = IRQ_HANDLED;
2383 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2384
Daniel Vetter5a21b662016-05-24 17:13:53 +02002385 if (iir & GEN8_PIPE_VBLANK &&
2386 intel_pipe_handle_vblank(dev_priv, pipe))
2387 intel_check_page_flip(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002388
2389 flip_done = iir;
2390 if (INTEL_INFO(dev_priv)->gen >= 9)
2391 flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE;
2392 else
2393 flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE;
2394
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002395 if (flip_done)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002396 intel_finish_page_flip_cs(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002397
2398 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002399 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002400
2401 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2402 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2403
2404 fault_errors = iir;
2405 if (INTEL_INFO(dev_priv)->gen >= 9)
2406 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2407 else
2408 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2409
2410 if (fault_errors)
2411 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2412 pipe_name(pipe),
2413 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002414 }
2415
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002416 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302417 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002418 /*
2419 * FIXME(BDW): Assume for now that the new interrupt handling
2420 * scheme also closed the SDE interrupt handling race we've seen
2421 * on older pch-split platforms. But this needs testing.
2422 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002423 iir = I915_READ(SDEIIR);
2424 if (iir) {
2425 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002426 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002427
2428 if (HAS_PCH_SPT(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002429 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002430 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002431 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002432 } else {
2433 /*
2434 * Like on previous PCH there seems to be something
2435 * fishy going on with forwarding PCH interrupts.
2436 */
2437 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2438 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002439 }
2440
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002441 return ret;
2442}
2443
2444static irqreturn_t gen8_irq_handler(int irq, void *arg)
2445{
2446 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002447 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002448 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002449 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002450 irqreturn_t ret;
2451
2452 if (!intel_irqs_enabled(dev_priv))
2453 return IRQ_NONE;
2454
2455 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2456 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2457 if (!master_ctl)
2458 return IRQ_NONE;
2459
2460 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2461
2462 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2463 disable_rpm_wakeref_asserts(dev_priv);
2464
2465 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002466 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2467 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002468 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2469
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002470 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2471 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002472
Imre Deak1f814da2015-12-16 02:52:19 +02002473 enable_rpm_wakeref_asserts(dev_priv);
2474
Ben Widawskyabd58f02013-11-02 21:07:09 -07002475 return ret;
2476}
2477
Chris Wilson1f15b762016-07-01 17:23:14 +01002478static void i915_error_wake_up(struct drm_i915_private *dev_priv)
Daniel Vetter17e1df02013-09-08 21:57:13 +02002479{
Daniel Vetter17e1df02013-09-08 21:57:13 +02002480 /*
2481 * Notify all waiters for GPU completion events that reset state has
2482 * been changed, and that they need to restart their wait after
2483 * checking for potential errors (and bail out to drop locks if there is
2484 * a gpu reset pending so that i915_error_work_func can acquire them).
2485 */
2486
2487 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
Chris Wilson1f15b762016-07-01 17:23:14 +01002488 wake_up_all(&dev_priv->gpu_error.wait_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002489
2490 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2491 wake_up_all(&dev_priv->pending_flip_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002492}
2493
Jesse Barnes8a905232009-07-11 16:48:03 -04002494/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002495 * i915_reset_and_wakeup - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002496 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002497 *
2498 * Fire an error uevent so userspace can see that a hang or error
2499 * was detected.
2500 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002501static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002502{
Chris Wilsonc0336662016-05-06 15:40:21 +01002503 struct kobject *kobj = &dev_priv->dev->primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002504 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2505 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2506 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002507 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002508
Chris Wilsonc0336662016-05-06 15:40:21 +01002509 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002510
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002511 /*
2512 * Note that there's only one work item which does gpu resets, so we
2513 * need not worry about concurrent gpu resets potentially incrementing
2514 * error->reset_counter twice. We only need to take care of another
2515 * racing irq/hangcheck declaring the gpu dead for a second time. A
2516 * quick check for that is good enough: schedule_work ensures the
2517 * correct ordering between hang detection and this work item, and since
2518 * the reset in-progress bit is only ever set by code outside of this
2519 * work we don't need to worry about any other races.
2520 */
Chris Wilsond98c52c2016-04-13 17:35:05 +01002521 if (i915_reset_in_progress(&dev_priv->gpu_error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002522 DRM_DEBUG_DRIVER("resetting chip\n");
Chris Wilsonc0336662016-05-06 15:40:21 +01002523 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002524
Daniel Vetter17e1df02013-09-08 21:57:13 +02002525 /*
Imre Deakf454c692014-04-23 01:09:04 +03002526 * In most cases it's guaranteed that we get here with an RPM
2527 * reference held, for example because there is a pending GPU
2528 * request that won't finish until the reset is done. This
2529 * isn't the case at least when we get here by doing a
2530 * simulated reset via debugs, so get an RPM reference.
2531 */
2532 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002533
Chris Wilsonc0336662016-05-06 15:40:21 +01002534 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002535
Imre Deakf454c692014-04-23 01:09:04 +03002536 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002537 * All state reset _must_ be completed before we update the
2538 * reset counter, for otherwise waiters might miss the reset
2539 * pending state and not properly drop locks, resulting in
2540 * deadlocks with the reset work.
2541 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002542 ret = i915_reset(dev_priv);
Daniel Vetterf69061b2012-12-06 09:01:42 +01002543
Chris Wilsonc0336662016-05-06 15:40:21 +01002544 intel_finish_reset(dev_priv);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002545
Imre Deakf454c692014-04-23 01:09:04 +03002546 intel_runtime_pm_put(dev_priv);
2547
Chris Wilsond98c52c2016-04-13 17:35:05 +01002548 if (ret == 0)
Chris Wilsonc0336662016-05-06 15:40:21 +01002549 kobject_uevent_env(kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002550 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002551
Daniel Vetter17e1df02013-09-08 21:57:13 +02002552 /*
2553 * Note: The wake_up also serves as a memory barrier so that
2554 * waiters see the update value of the reset counter atomic_t.
2555 */
Chris Wilson1f15b762016-07-01 17:23:14 +01002556 wake_up_all(&dev_priv->gpu_error.reset_queue);
Ben Gamarif316a422009-09-14 17:48:46 -04002557 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002558}
2559
Chris Wilsonc0336662016-05-06 15:40:21 +01002560static void i915_report_and_clear_eir(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002561{
Ben Widawskybd9854f2012-08-23 15:18:09 -07002562 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002563 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002564 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002565
Chris Wilson35aed2e2010-05-27 13:18:12 +01002566 if (!eir)
2567 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002568
Joe Perchesa70491c2012-03-18 13:00:11 -07002569 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002570
Chris Wilsonc0336662016-05-06 15:40:21 +01002571 i915_get_extra_instdone(dev_priv, instdone);
Ben Widawskybd9854f2012-08-23 15:18:09 -07002572
Chris Wilsonc0336662016-05-06 15:40:21 +01002573 if (IS_G4X(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002574 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2575 u32 ipeir = I915_READ(IPEIR_I965);
2576
Joe Perchesa70491c2012-03-18 13:00:11 -07002577 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2578 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002579 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2580 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002581 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002582 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002583 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002584 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002585 }
2586 if (eir & GM45_ERROR_PAGE_TABLE) {
2587 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002588 pr_err("page table error\n");
2589 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002590 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002591 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002592 }
2593 }
2594
Chris Wilsonc0336662016-05-06 15:40:21 +01002595 if (!IS_GEN2(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002596 if (eir & I915_ERROR_PAGE_TABLE) {
2597 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002598 pr_err("page table error\n");
2599 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002600 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002601 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002602 }
2603 }
2604
2605 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002606 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002607 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002608 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002609 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002610 /* pipestat has already been acked */
2611 }
2612 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002613 pr_err("instruction error\n");
2614 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002615 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2616 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsonc0336662016-05-06 15:40:21 +01002617 if (INTEL_GEN(dev_priv) < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002618 u32 ipeir = I915_READ(IPEIR);
2619
Joe Perchesa70491c2012-03-18 13:00:11 -07002620 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2621 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002622 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002623 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002624 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002625 } else {
2626 u32 ipeir = I915_READ(IPEIR_I965);
2627
Joe Perchesa70491c2012-03-18 13:00:11 -07002628 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2629 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002630 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002631 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002632 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002633 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002634 }
2635 }
2636
2637 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002638 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002639 eir = I915_READ(EIR);
2640 if (eir) {
2641 /*
2642 * some errors might have become stuck,
2643 * mask them.
2644 */
2645 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2646 I915_WRITE(EMR, I915_READ(EMR) | eir);
2647 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2648 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002649}
2650
2651/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002652 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002653 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002654 * @engine_mask: mask representing engines that are hung
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002655 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002656 * dump it to the syslog. Also call i915_capture_error_state() to make
2657 * sure we get a record and make it available in debugfs. Fire a uevent
2658 * so userspace knows something bad happened (should trigger collection
2659 * of a ring dump etc.).
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002660 * @fmt: Error message format string
Chris Wilson35aed2e2010-05-27 13:18:12 +01002661 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002662void i915_handle_error(struct drm_i915_private *dev_priv,
2663 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002664 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002665{
Mika Kuoppala58174462014-02-25 17:11:26 +02002666 va_list args;
2667 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002668
Mika Kuoppala58174462014-02-25 17:11:26 +02002669 va_start(args, fmt);
2670 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2671 va_end(args);
2672
Chris Wilsonc0336662016-05-06 15:40:21 +01002673 i915_capture_error_state(dev_priv, engine_mask, error_msg);
2674 i915_report_and_clear_eir(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002675
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002676 if (engine_mask) {
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002677 atomic_or(I915_RESET_IN_PROGRESS_FLAG,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002678 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002679
Ben Gamari11ed50e2009-09-14 17:48:45 -04002680 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002681 * Wakeup waiting processes so that the reset function
2682 * i915_reset_and_wakeup doesn't deadlock trying to grab
2683 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002684 * processes will see a reset in progress and back off,
2685 * releasing their locks and then wait for the reset completion.
2686 * We must do this for _all_ gpu waiters that might hold locks
2687 * that the reset work needs to acquire.
2688 *
2689 * Note: The wake_up serves as the required memory barrier to
2690 * ensure that the waiters see the updated value of the reset
2691 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002692 */
Chris Wilson1f15b762016-07-01 17:23:14 +01002693 i915_error_wake_up(dev_priv);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002694 }
2695
Chris Wilsonc0336662016-05-06 15:40:21 +01002696 i915_reset_and_wakeup(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002697}
2698
Keith Packard42f52ef2008-10-18 19:39:29 -07002699/* Called from drm generic code, passed 'crtc' which
2700 * we use as a pipe index
2701 */
Thierry Reding88e72712015-09-24 18:35:31 +02002702static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002703{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002704 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002705 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002706
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002707 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002708 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002709 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002710 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002711 else
Keith Packard7c463582008-11-04 02:03:27 -08002712 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002713 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002714 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002715
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002716 return 0;
2717}
2718
Thierry Reding88e72712015-09-24 18:35:31 +02002719static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002720{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002721 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002722 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002723 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002724 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002725
Jesse Barnesf796cf82011-04-07 13:58:17 -07002726 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002727 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002728 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2729
2730 return 0;
2731}
2732
Thierry Reding88e72712015-09-24 18:35:31 +02002733static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002734{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002735 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002736 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002737
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002738 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002739 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002740 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002741 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2742
2743 return 0;
2744}
2745
Thierry Reding88e72712015-09-24 18:35:31 +02002746static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002747{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002748 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002749 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002750
Ben Widawskyabd58f02013-11-02 21:07:09 -07002751 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002752 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002753 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002754
Ben Widawskyabd58f02013-11-02 21:07:09 -07002755 return 0;
2756}
2757
Keith Packard42f52ef2008-10-18 19:39:29 -07002758/* Called from drm generic code, passed 'crtc' which
2759 * we use as a pipe index
2760 */
Thierry Reding88e72712015-09-24 18:35:31 +02002761static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002762{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002763 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002764 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002765
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002766 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002767 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002768 PIPE_VBLANK_INTERRUPT_STATUS |
2769 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002770 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2771}
2772
Thierry Reding88e72712015-09-24 18:35:31 +02002773static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002774{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002775 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002776 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002777 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002778 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002779
2780 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002781 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002782 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2783}
2784
Thierry Reding88e72712015-09-24 18:35:31 +02002785static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002786{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002787 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002788 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002789
2790 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002791 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002792 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002793 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2794}
2795
Thierry Reding88e72712015-09-24 18:35:31 +02002796static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002797{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002798 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002799 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002800
Ben Widawskyabd58f02013-11-02 21:07:09 -07002801 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002802 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002803 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2804}
2805
Chris Wilson9107e9d2013-06-10 11:20:20 +01002806static bool
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002807ring_idle(struct intel_engine_cs *engine, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002808{
Chris Wilsoncffa7812016-04-07 07:29:18 +01002809 return i915_seqno_passed(seqno,
2810 READ_ONCE(engine->last_submitted_seqno));
Ben Gamarif65d9422009-09-14 17:48:44 -04002811}
2812
Daniel Vettera028c4b2014-03-15 00:08:56 +01002813static bool
Chris Wilson31bb59c2016-07-01 17:23:27 +01002814ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr)
Daniel Vettera028c4b2014-03-15 00:08:56 +01002815{
Chris Wilson31bb59c2016-07-01 17:23:27 +01002816 if (INTEL_GEN(engine->i915) >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002817 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002818 } else {
2819 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2820 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2821 MI_SEMAPHORE_REGISTER);
2822 }
2823}
2824
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002825static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002826semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr,
2827 u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002828{
Chris Wilsonc0336662016-05-06 15:40:21 +01002829 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002830 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002831
Chris Wilsonc0336662016-05-06 15:40:21 +01002832 if (INTEL_GEN(dev_priv) >= 8) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002833 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002834 if (engine == signaller)
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002835 continue;
2836
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002837 if (offset == signaller->semaphore.signal_ggtt[engine->id])
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002838 return signaller;
2839 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002840 } else {
2841 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2842
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002843 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002844 if(engine == signaller)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002845 continue;
2846
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002847 if (sync_bits == signaller->semaphore.mbox.wait[engine->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002848 return signaller;
2849 }
2850 }
2851
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002852 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002853 engine->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002854
2855 return NULL;
2856}
2857
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002858static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002859semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002860{
Chris Wilsonc0336662016-05-06 15:40:21 +01002861 struct drm_i915_private *dev_priv = engine->i915;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002862 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002863 u64 offset = 0;
2864 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002865
Tomas Elf381e8ae2015-10-08 19:31:33 +01002866 /*
2867 * This function does not support execlist mode - any attempt to
2868 * proceed further into this function will result in a kernel panic
2869 * when dereferencing ring->buffer, which is not set up in execlist
2870 * mode.
2871 *
2872 * The correct way of doing it would be to derive the currently
2873 * executing ring buffer from the current context, which is derived
2874 * from the currently running request. Unfortunately, to get the
2875 * current request we would have to grab the struct_mutex before doing
2876 * anything else, which would be ill-advised since some other thread
2877 * might have grabbed it already and managed to hang itself, causing
2878 * the hang checker to deadlock.
2879 *
2880 * Therefore, this function does not support execlist mode in its
2881 * current form. Just return NULL and move on.
2882 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002883 if (engine->buffer == NULL)
Tomas Elf381e8ae2015-10-08 19:31:33 +01002884 return NULL;
2885
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002886 ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
Chris Wilson31bb59c2016-07-01 17:23:27 +01002887 if (!ipehr_is_semaphore_wait(engine, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002888 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002889
Daniel Vetter88fe4292014-03-15 00:08:55 +01002890 /*
2891 * HEAD is likely pointing to the dword after the actual command,
2892 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002893 * or 4 dwords depending on the semaphore wait command size.
2894 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002895 * point at at batch, and semaphores are always emitted into the
2896 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002897 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002898 head = I915_READ_HEAD(engine) & HEAD_ADDR;
Chris Wilsonc0336662016-05-06 15:40:21 +01002899 backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002900
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002901 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002902 /*
2903 * Be paranoid and presume the hw has gone off into the wild -
2904 * our ring is smaller than what the hardware (and hence
2905 * HEAD_ADDR) allows. Also handles wrap-around.
2906 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002907 head &= engine->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002908
2909 /* This here seems to blow up */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002910 cmd = ioread32(engine->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002911 if (cmd == ipehr)
2912 break;
2913
Daniel Vetter88fe4292014-03-15 00:08:55 +01002914 head -= 4;
2915 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002916
Daniel Vetter88fe4292014-03-15 00:08:55 +01002917 if (!i)
2918 return NULL;
2919
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002920 *seqno = ioread32(engine->buffer->virtual_start + head + 4) + 1;
Chris Wilsonc0336662016-05-06 15:40:21 +01002921 if (INTEL_GEN(dev_priv) >= 8) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002922 offset = ioread32(engine->buffer->virtual_start + head + 12);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002923 offset <<= 32;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002924 offset = ioread32(engine->buffer->virtual_start + head + 8);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002925 }
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002926 return semaphore_wait_to_signaller_ring(engine, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002927}
2928
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002929static int semaphore_passed(struct intel_engine_cs *engine)
Chris Wilson6274f212013-06-10 11:20:21 +01002930{
Chris Wilsonc0336662016-05-06 15:40:21 +01002931 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002932 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002933 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002934
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002935 engine->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002936
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002937 signaller = semaphore_waits_for(engine, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002938 if (signaller == NULL)
2939 return -1;
2940
2941 /* Prevent pathological recursion due to driver bugs */
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00002942 if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES)
Chris Wilson6274f212013-06-10 11:20:21 +01002943 return -1;
2944
Chris Wilson1b7744e2016-07-01 17:23:17 +01002945 if (i915_seqno_passed(intel_engine_get_seqno(signaller), seqno))
Chris Wilson4be17382014-06-06 10:22:29 +01002946 return 1;
2947
Chris Wilsona0d036b2014-07-19 12:40:42 +01002948 /* cursory check for an unkickable deadlock */
2949 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2950 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002951 return -1;
2952
2953 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002954}
2955
2956static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2957{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002958 struct intel_engine_cs *engine;
Chris Wilson6274f212013-06-10 11:20:21 +01002959
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002960 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002961 engine->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002962}
2963
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002964static bool subunits_stuck(struct intel_engine_cs *engine)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002965{
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002966 u32 instdone[I915_NUM_INSTDONE_REG];
2967 bool stuck;
2968 int i;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002969
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002970 if (engine->id != RCS)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002971 return true;
2972
Chris Wilsonc0336662016-05-06 15:40:21 +01002973 i915_get_extra_instdone(engine->i915, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002974
2975 /* There might be unstable subunit states even when
2976 * actual head is not moving. Filter out the unstable ones by
2977 * accumulating the undone -> done transitions and only
2978 * consider those as progress.
2979 */
2980 stuck = true;
2981 for (i = 0; i < I915_NUM_INSTDONE_REG; i++) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002982 const u32 tmp = instdone[i] | engine->hangcheck.instdone[i];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002983
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002984 if (tmp != engine->hangcheck.instdone[i])
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002985 stuck = false;
2986
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002987 engine->hangcheck.instdone[i] |= tmp;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002988 }
2989
2990 return stuck;
2991}
2992
2993static enum intel_ring_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002994head_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002995{
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002996 if (acthd != engine->hangcheck.acthd) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002997
2998 /* Clear subunit states on head movement */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002999 memset(engine->hangcheck.instdone, 0,
3000 sizeof(engine->hangcheck.instdone));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003001
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003002 return HANGCHECK_ACTIVE;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003003 }
Chris Wilson6274f212013-06-10 11:20:21 +01003004
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003005 if (!subunits_stuck(engine))
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003006 return HANGCHECK_ACTIVE;
3007
3008 return HANGCHECK_HUNG;
3009}
3010
3011static enum intel_ring_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003012ring_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003013{
Chris Wilsonc0336662016-05-06 15:40:21 +01003014 struct drm_i915_private *dev_priv = engine->i915;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003015 enum intel_ring_hangcheck_action ha;
3016 u32 tmp;
3017
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003018 ha = head_stuck(engine, acthd);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003019 if (ha != HANGCHECK_HUNG)
3020 return ha;
3021
Chris Wilsonc0336662016-05-06 15:40:21 +01003022 if (IS_GEN2(dev_priv))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003023 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003024
3025 /* Is the chip hanging on a WAIT_FOR_EVENT?
3026 * If so we can simply poke the RB_WAIT bit
3027 * and break the hang. This should work on
3028 * all but the second generation chipsets.
3029 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003030 tmp = I915_READ_CTL(engine);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003031 if (tmp & RING_WAIT) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003032 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003033 "Kicking stuck wait on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003034 engine->name);
3035 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003036 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003037 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003038
Chris Wilsonc0336662016-05-06 15:40:21 +01003039 if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003040 switch (semaphore_passed(engine)) {
Chris Wilson6274f212013-06-10 11:20:21 +01003041 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003042 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003043 case 1:
Chris Wilsonc0336662016-05-06 15:40:21 +01003044 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003045 "Kicking stuck semaphore on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003046 engine->name);
3047 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003048 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003049 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003050 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003051 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003052 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003053
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003054 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003055}
3056
Chris Wilson12471ba2016-04-09 10:57:55 +01003057static unsigned kick_waiters(struct intel_engine_cs *engine)
3058{
Chris Wilsonc0336662016-05-06 15:40:21 +01003059 struct drm_i915_private *i915 = engine->i915;
Chris Wilson12471ba2016-04-09 10:57:55 +01003060 unsigned user_interrupts = READ_ONCE(engine->user_interrupts);
3061
3062 if (engine->hangcheck.user_interrupts == user_interrupts &&
3063 !test_and_set_bit(engine->id, &i915->gpu_error.missed_irq_rings)) {
Chris Wilson688e6c72016-07-01 17:23:15 +01003064 if (!test_bit(engine->id, &i915->gpu_error.test_irq_rings))
Chris Wilson12471ba2016-04-09 10:57:55 +01003065 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
3066 engine->name);
Chris Wilson688e6c72016-07-01 17:23:15 +01003067
3068 intel_engine_enable_fake_irq(engine);
Chris Wilson12471ba2016-04-09 10:57:55 +01003069 }
3070
3071 return user_interrupts;
3072}
Chris Wilson737b1502015-01-26 18:03:03 +02003073/*
Ben Gamarif65d9422009-09-14 17:48:44 -04003074 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003075 * batchbuffers in a long time. We keep track per ring seqno progress and
3076 * if there are no progress, hangcheck score for that ring is increased.
3077 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3078 * we kick the ring. If we see no progress on three subsequent calls
3079 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003080 */
Chris Wilson737b1502015-01-26 18:03:03 +02003081static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04003082{
Chris Wilson737b1502015-01-26 18:03:03 +02003083 struct drm_i915_private *dev_priv =
3084 container_of(work, typeof(*dev_priv),
3085 gpu_error.hangcheck_work.work);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003086 struct intel_engine_cs *engine;
Dave Gordonc3232b12016-03-23 18:19:53 +00003087 enum intel_engine_id id;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003088 int busy_count = 0, rings_hung = 0;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00003089 bool stuck[I915_NUM_ENGINES] = { 0 };
Chris Wilson9107e9d2013-06-10 11:20:20 +01003090#define BUSY 1
3091#define KICK 5
3092#define HUNG 20
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003093#define ACTIVE_DECAY 15
Chris Wilson893eead2010-10-27 14:44:35 +01003094
Jani Nikulad330a952014-01-21 11:24:25 +02003095 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003096 return;
3097
Chris Wilsonb1379d42016-07-05 08:54:36 +01003098 if (!READ_ONCE(dev_priv->gt.awake))
Chris Wilson67d97da2016-07-04 08:08:31 +01003099 return;
Imre Deak1f814da2015-12-16 02:52:19 +02003100
Mika Kuoppala75714942015-12-16 09:26:48 +02003101 /* As enabling the GPU requires fairly extensive mmio access,
3102 * periodically arm the mmio checker to see if we are triggering
3103 * any invalid access.
3104 */
3105 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
3106
Dave Gordonc3232b12016-03-23 18:19:53 +00003107 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson688e6c72016-07-01 17:23:15 +01003108 bool busy = intel_engine_has_waiter(engine);
Chris Wilson50877442014-03-21 12:41:53 +00003109 u64 acthd;
3110 u32 seqno;
Chris Wilson12471ba2016-04-09 10:57:55 +01003111 unsigned user_interrupts;
Chris Wilsonb4519512012-05-11 14:29:30 +01003112
Chris Wilson6274f212013-06-10 11:20:21 +01003113 semaphore_clear_deadlocks(dev_priv);
3114
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003115 /* We don't strictly need an irq-barrier here, as we are not
3116 * serving an interrupt request, be paranoid in case the
3117 * barrier has side-effects (such as preventing a broken
3118 * cacheline snoop) and so be sure that we can see the seqno
3119 * advance. If the seqno should stick, due to a stale
3120 * cacheline, we would erroneously declare the GPU hung.
3121 */
3122 if (engine->irq_seqno_barrier)
3123 engine->irq_seqno_barrier(engine);
3124
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003125 acthd = intel_ring_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01003126 seqno = intel_engine_get_seqno(engine);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003127
Chris Wilson12471ba2016-04-09 10:57:55 +01003128 /* Reset stuck interrupts between batch advances */
3129 user_interrupts = 0;
3130
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003131 if (engine->hangcheck.seqno == seqno) {
3132 if (ring_idle(engine, seqno)) {
3133 engine->hangcheck.action = HANGCHECK_IDLE;
Chris Wilson05535722016-07-01 17:23:11 +01003134 if (busy) {
Chris Wilson094f9a52013-09-25 17:34:55 +01003135 /* Safeguard against driver failure */
Chris Wilson12471ba2016-04-09 10:57:55 +01003136 user_interrupts = kick_waiters(engine);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003137 engine->hangcheck.score += BUSY;
Chris Wilson05535722016-07-01 17:23:11 +01003138 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003139 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003140 /* We always increment the hangcheck score
3141 * if the ring is busy and still processing
3142 * the same request, so that no single request
3143 * can run indefinitely (such as a chain of
3144 * batches). The only time we do not increment
3145 * the hangcheck score on this ring, if this
3146 * ring is in a legitimate wait for another
3147 * ring. In that case the waiting ring is a
3148 * victim and we want to be sure we catch the
3149 * right culprit. Then every time we do kick
3150 * the ring, add a small increment to the
3151 * score so that we can catch a batch that is
3152 * being repeatedly kicked and so responsible
3153 * for stalling the machine.
3154 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003155 engine->hangcheck.action = ring_stuck(engine,
3156 acthd);
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003157
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003158 switch (engine->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003159 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003160 case HANGCHECK_WAIT:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003161 break;
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003162 case HANGCHECK_ACTIVE:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003163 engine->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003164 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003165 case HANGCHECK_KICK:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003166 engine->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003167 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003168 case HANGCHECK_HUNG:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003169 engine->hangcheck.score += HUNG;
Dave Gordonc3232b12016-03-23 18:19:53 +00003170 stuck[id] = true;
Chris Wilson6274f212013-06-10 11:20:21 +01003171 break;
3172 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003173 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003174 } else {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003175 engine->hangcheck.action = HANGCHECK_ACTIVE;
Mika Kuoppalada661462013-09-06 16:03:28 +03003176
Chris Wilson9107e9d2013-06-10 11:20:20 +01003177 /* Gradually reduce the count so that we catch DoS
3178 * attempts across multiple batches.
3179 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003180 if (engine->hangcheck.score > 0)
3181 engine->hangcheck.score -= ACTIVE_DECAY;
3182 if (engine->hangcheck.score < 0)
3183 engine->hangcheck.score = 0;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003184
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003185 /* Clear head and subunit states on seqno movement */
Chris Wilson12471ba2016-04-09 10:57:55 +01003186 acthd = 0;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003187
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003188 memset(engine->hangcheck.instdone, 0,
3189 sizeof(engine->hangcheck.instdone));
Chris Wilsond1e61e72012-04-10 17:00:41 +01003190 }
3191
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003192 engine->hangcheck.seqno = seqno;
3193 engine->hangcheck.acthd = acthd;
Chris Wilson12471ba2016-04-09 10:57:55 +01003194 engine->hangcheck.user_interrupts = user_interrupts;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003195 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003196 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003197
Dave Gordonc3232b12016-03-23 18:19:53 +00003198 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003199 if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003200 DRM_INFO("%s on %s\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003201 stuck[id] ? "stuck" : "no progress",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003202 engine->name);
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00003203 rings_hung |= intel_engine_flag(engine);
Mika Kuoppala92cab732013-05-24 17:16:07 +03003204 }
3205 }
3206
Chris Wilson67d97da2016-07-04 08:08:31 +01003207 if (rings_hung)
Chris Wilsonc0336662016-05-06 15:40:21 +01003208 i915_handle_error(dev_priv, rings_hung, "Engine(s) hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003209
Chris Wilson05535722016-07-01 17:23:11 +01003210 /* Reset timer in case GPU hangs without another request being added */
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003211 if (busy_count)
Chris Wilsonc0336662016-05-06 15:40:21 +01003212 i915_queue_hangcheck(dev_priv);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003213}
3214
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003215static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003216{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003217 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003218
3219 if (HAS_PCH_NOP(dev))
3220 return;
3221
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003222 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003223
3224 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3225 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003226}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003227
Paulo Zanoni622364b2014-04-01 15:37:22 -03003228/*
3229 * SDEIER is also touched by the interrupt handler to work around missed PCH
3230 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3231 * instead we unconditionally enable all PCH interrupt sources here, but then
3232 * only unmask them as needed with SDEIMR.
3233 *
3234 * This function needs to be called before interrupts are enabled.
3235 */
3236static void ibx_irq_pre_postinstall(struct drm_device *dev)
3237{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003238 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003239
3240 if (HAS_PCH_NOP(dev))
3241 return;
3242
3243 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003244 I915_WRITE(SDEIER, 0xffffffff);
3245 POSTING_READ(SDEIER);
3246}
3247
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003248static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003249{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003250 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003251
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003252 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003253 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003254 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003255}
3256
Ville Syrjälä70591a42014-10-30 19:42:58 +02003257static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3258{
3259 enum pipe pipe;
3260
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003261 if (IS_CHERRYVIEW(dev_priv))
3262 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3263 else
3264 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3265
Ville Syrjäläad22d102016-04-12 18:56:14 +03003266 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003267 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3268
Ville Syrjäläad22d102016-04-12 18:56:14 +03003269 for_each_pipe(dev_priv, pipe) {
3270 I915_WRITE(PIPESTAT(pipe),
3271 PIPE_FIFO_UNDERRUN_STATUS |
3272 PIPESTAT_INT_STATUS_MASK);
3273 dev_priv->pipestat_irq_mask[pipe] = 0;
3274 }
Ville Syrjälä70591a42014-10-30 19:42:58 +02003275
3276 GEN5_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003277 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003278}
3279
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003280static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3281{
3282 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003283 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003284 enum pipe pipe;
3285
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003286 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3287 PIPE_CRC_DONE_INTERRUPT_STATUS;
3288
3289 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3290 for_each_pipe(dev_priv, pipe)
3291 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3292
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003293 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3294 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3295 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003296 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003297 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003298
3299 WARN_ON(dev_priv->irq_mask != ~0);
3300
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003301 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003302
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003303 GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003304}
3305
3306/* drm_dma.h hooks
3307*/
3308static void ironlake_irq_reset(struct drm_device *dev)
3309{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003310 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003311
3312 I915_WRITE(HWSTAM, 0xffffffff);
3313
3314 GEN5_IRQ_RESET(DE);
3315 if (IS_GEN7(dev))
3316 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3317
3318 gen5_gt_irq_reset(dev);
3319
3320 ibx_irq_reset(dev);
3321}
3322
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003323static void valleyview_irq_preinstall(struct drm_device *dev)
3324{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003325 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003326
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003327 I915_WRITE(VLV_MASTER_IER, 0);
3328 POSTING_READ(VLV_MASTER_IER);
3329
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003330 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003331
Ville Syrjäläad22d102016-04-12 18:56:14 +03003332 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003333 if (dev_priv->display_irqs_enabled)
3334 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003335 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003336}
3337
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003338static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3339{
3340 GEN8_IRQ_RESET_NDX(GT, 0);
3341 GEN8_IRQ_RESET_NDX(GT, 1);
3342 GEN8_IRQ_RESET_NDX(GT, 2);
3343 GEN8_IRQ_RESET_NDX(GT, 3);
3344}
3345
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003346static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003347{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003348 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003349 int pipe;
3350
Ben Widawskyabd58f02013-11-02 21:07:09 -07003351 I915_WRITE(GEN8_MASTER_IRQ, 0);
3352 POSTING_READ(GEN8_MASTER_IRQ);
3353
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003354 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003355
Damien Lespiau055e3932014-08-18 13:49:10 +01003356 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003357 if (intel_display_power_is_enabled(dev_priv,
3358 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003359 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003360
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003361 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3362 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3363 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003364
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303365 if (HAS_PCH_SPLIT(dev))
3366 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003367}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003368
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003369void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3370 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003371{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003372 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003373 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003374
Daniel Vetter13321782014-09-15 14:55:29 +02003375 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003376 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3377 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3378 dev_priv->de_irq_mask[pipe],
3379 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003380 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003381}
3382
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003383void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3384 unsigned int pipe_mask)
3385{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003386 enum pipe pipe;
3387
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003388 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003389 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3390 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003391 spin_unlock_irq(&dev_priv->irq_lock);
3392
3393 /* make sure we're done processing display irqs */
3394 synchronize_irq(dev_priv->dev->irq);
3395}
3396
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003397static void cherryview_irq_preinstall(struct drm_device *dev)
3398{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003399 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003400
3401 I915_WRITE(GEN8_MASTER_IRQ, 0);
3402 POSTING_READ(GEN8_MASTER_IRQ);
3403
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003404 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003405
3406 GEN5_IRQ_RESET(GEN8_PCU_);
3407
Ville Syrjäläad22d102016-04-12 18:56:14 +03003408 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003409 if (dev_priv->display_irqs_enabled)
3410 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003411 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003412}
3413
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003414static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003415 const u32 hpd[HPD_NUM_PINS])
3416{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003417 struct intel_encoder *encoder;
3418 u32 enabled_irqs = 0;
3419
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003420 for_each_intel_encoder(dev_priv->dev, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003421 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3422 enabled_irqs |= hpd[encoder->hpd_pin];
3423
3424 return enabled_irqs;
3425}
3426
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003427static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003428{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003429 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003430
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003431 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003432 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003433 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003434 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003435 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003436 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003437 }
3438
Daniel Vetterfee884e2013-07-04 23:35:21 +02003439 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003440
3441 /*
3442 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003443 * duration to 2ms (which is the minimum in the Display Port spec).
3444 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003445 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003446 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3447 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3448 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3449 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3450 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003451 /*
3452 * When CPU and PCH are on the same package, port A
3453 * HPD must be enabled in both north and south.
3454 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003455 if (HAS_PCH_LPT_LP(dev_priv))
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003456 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003457 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003458}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003459
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003460static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003461{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003462 u32 hotplug_irqs, hotplug, enabled_irqs;
3463
3464 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003465 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003466
3467 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3468
3469 /* Enable digital hotplug on the PCH */
3470 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3471 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003472 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003473 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3474
3475 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3476 hotplug |= PORTE_HOTPLUG_ENABLE;
3477 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003478}
3479
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003480static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003481{
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003482 u32 hotplug_irqs, hotplug, enabled_irqs;
3483
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003484 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003485 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003486 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003487
3488 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003489 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003490 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003491 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003492
3493 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003494 } else {
3495 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003496 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003497
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003498 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3499 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003500
3501 /*
3502 * Enable digital hotplug on the CPU, and configure the DP short pulse
3503 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003504 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003505 */
3506 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3507 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3508 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3509 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3510
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003511 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003512}
3513
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003514static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003515{
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003516 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003517
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003518 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003519 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003520
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003521 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003522
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003523 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3524 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3525 PORTA_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303526
3527 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3528 hotplug, enabled_irqs);
3529 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3530
3531 /*
3532 * For BXT invert bit has to be set based on AOB design
3533 * for HPD detection logic, update it based on VBT fields.
3534 */
3535
3536 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3537 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3538 hotplug |= BXT_DDIA_HPD_INVERT;
3539 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3540 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3541 hotplug |= BXT_DDIB_HPD_INVERT;
3542 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3543 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3544 hotplug |= BXT_DDIC_HPD_INVERT;
3545
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003546 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003547}
3548
Paulo Zanonid46da432013-02-08 17:35:15 -02003549static void ibx_irq_postinstall(struct drm_device *dev)
3550{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003551 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003552 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003553
Daniel Vetter692a04c2013-05-29 21:43:05 +02003554 if (HAS_PCH_NOP(dev))
3555 return;
3556
Paulo Zanoni105b1222014-04-01 15:37:17 -03003557 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003558 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003559 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003560 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003561
Ville Syrjäläb51a2842015-09-18 20:03:41 +03003562 gen5_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003563 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003564}
3565
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003566static void gen5_gt_irq_postinstall(struct drm_device *dev)
3567{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003568 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003569 u32 pm_irqs, gt_irqs;
3570
3571 pm_irqs = gt_irqs = 0;
3572
3573 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003574 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003575 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003576 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3577 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003578 }
3579
3580 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3581 if (IS_GEN5(dev)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003582 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003583 } else {
3584 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3585 }
3586
Paulo Zanoni35079892014-04-01 15:37:15 -03003587 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003588
3589 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003590 /*
3591 * RPS interrupts will get enabled/disabled on demand when RPS
3592 * itself is enabled/disabled.
3593 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003594 if (HAS_VEBOX(dev))
3595 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3596
Paulo Zanoni605cd252013-08-06 18:57:15 -03003597 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003598 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003599 }
3600}
3601
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003602static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003603{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003604 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003605 u32 display_mask, extra_mask;
3606
3607 if (INTEL_INFO(dev)->gen >= 7) {
3608 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3609 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3610 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003611 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003612 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003613 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3614 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003615 } else {
3616 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3617 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003618 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003619 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3620 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003621 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3622 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3623 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003624 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003625
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003626 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003627
Paulo Zanoni0c841212014-04-01 15:37:27 -03003628 I915_WRITE(HWSTAM, 0xeffe);
3629
Paulo Zanoni622364b2014-04-01 15:37:22 -03003630 ibx_irq_pre_postinstall(dev);
3631
Paulo Zanoni35079892014-04-01 15:37:15 -03003632 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003633
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003634 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003635
Paulo Zanonid46da432013-02-08 17:35:15 -02003636 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003637
Jesse Barnesf97108d2010-01-29 11:27:07 -08003638 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003639 /* Enable PCU event interrupts
3640 *
3641 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003642 * setup is guaranteed to run in single-threaded context. But we
3643 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003644 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003645 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003646 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003647 }
3648
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003649 return 0;
3650}
3651
Imre Deakf8b79e52014-03-04 19:23:07 +02003652void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3653{
3654 assert_spin_locked(&dev_priv->irq_lock);
3655
3656 if (dev_priv->display_irqs_enabled)
3657 return;
3658
3659 dev_priv->display_irqs_enabled = true;
3660
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003661 if (intel_irqs_enabled(dev_priv)) {
3662 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003663 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003664 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003665}
3666
3667void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3668{
3669 assert_spin_locked(&dev_priv->irq_lock);
3670
3671 if (!dev_priv->display_irqs_enabled)
3672 return;
3673
3674 dev_priv->display_irqs_enabled = false;
3675
Imre Deak950eaba2014-09-08 15:21:09 +03003676 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003677 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003678}
3679
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003680
3681static int valleyview_irq_postinstall(struct drm_device *dev)
3682{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003683 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003684
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003685 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003686
Ville Syrjäläad22d102016-04-12 18:56:14 +03003687 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003688 if (dev_priv->display_irqs_enabled)
3689 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003690 spin_unlock_irq(&dev_priv->irq_lock);
3691
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003692 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003693 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003694
3695 return 0;
3696}
3697
Ben Widawskyabd58f02013-11-02 21:07:09 -07003698static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3699{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003700 /* These are interrupts we'll toggle with the ring mask register */
3701 uint32_t gt_interrupts[] = {
3702 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003703 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003704 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3705 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003706 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003707 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3708 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3709 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003710 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003711 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3712 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003713 };
3714
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003715 if (HAS_L3_DPF(dev_priv))
3716 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3717
Ben Widawsky09610212014-05-15 20:58:08 +03003718 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303719 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3720 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003721 /*
3722 * RPS interrupts will get enabled/disabled on demand when RPS itself
3723 * is enabled/disabled.
3724 */
3725 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303726 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003727}
3728
3729static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3730{
Damien Lespiau770de832014-03-20 20:45:01 +00003731 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3732 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003733 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3734 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003735 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003736 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003737
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003738 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003739 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3740 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003741 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3742 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303743 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003744 de_port_masked |= BXT_DE_PORT_GMBUS;
3745 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003746 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3747 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003748 }
Damien Lespiau770de832014-03-20 20:45:01 +00003749
3750 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3751 GEN8_PIPE_FIFO_UNDERRUN;
3752
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003753 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003754 if (IS_BROXTON(dev_priv))
3755 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3756 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003757 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3758
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003759 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3760 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3761 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003762
Damien Lespiau055e3932014-08-18 13:49:10 +01003763 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003764 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003765 POWER_DOMAIN_PIPE(pipe)))
3766 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3767 dev_priv->de_irq_mask[pipe],
3768 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003769
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003770 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ville Syrjälä11825b02016-05-19 12:14:43 +03003771 GEN5_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003772}
3773
3774static int gen8_irq_postinstall(struct drm_device *dev)
3775{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003776 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003777
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303778 if (HAS_PCH_SPLIT(dev))
3779 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003780
Ben Widawskyabd58f02013-11-02 21:07:09 -07003781 gen8_gt_irq_postinstall(dev_priv);
3782 gen8_de_irq_postinstall(dev_priv);
3783
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303784 if (HAS_PCH_SPLIT(dev))
3785 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003786
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003787 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003788 POSTING_READ(GEN8_MASTER_IRQ);
3789
3790 return 0;
3791}
3792
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003793static int cherryview_irq_postinstall(struct drm_device *dev)
3794{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003795 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003796
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003797 gen8_gt_irq_postinstall(dev_priv);
3798
Ville Syrjäläad22d102016-04-12 18:56:14 +03003799 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003800 if (dev_priv->display_irqs_enabled)
3801 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003802 spin_unlock_irq(&dev_priv->irq_lock);
3803
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003804 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003805 POSTING_READ(GEN8_MASTER_IRQ);
3806
3807 return 0;
3808}
3809
Ben Widawskyabd58f02013-11-02 21:07:09 -07003810static void gen8_irq_uninstall(struct drm_device *dev)
3811{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003812 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003813
3814 if (!dev_priv)
3815 return;
3816
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003817 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003818}
3819
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003820static void valleyview_irq_uninstall(struct drm_device *dev)
3821{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003822 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003823
3824 if (!dev_priv)
3825 return;
3826
Imre Deak843d0e72014-04-14 20:24:23 +03003827 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003828 POSTING_READ(VLV_MASTER_IER);
Imre Deak843d0e72014-04-14 20:24:23 +03003829
Ville Syrjälä893fce82014-10-30 19:42:56 +02003830 gen5_gt_irq_reset(dev);
3831
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003832 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003833
Ville Syrjäläad22d102016-04-12 18:56:14 +03003834 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003835 if (dev_priv->display_irqs_enabled)
3836 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003837 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003838}
3839
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003840static void cherryview_irq_uninstall(struct drm_device *dev)
3841{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003842 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003843
3844 if (!dev_priv)
3845 return;
3846
3847 I915_WRITE(GEN8_MASTER_IRQ, 0);
3848 POSTING_READ(GEN8_MASTER_IRQ);
3849
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003850 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003851
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003852 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003853
Ville Syrjäläad22d102016-04-12 18:56:14 +03003854 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003855 if (dev_priv->display_irqs_enabled)
3856 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003857 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003858}
3859
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003860static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003861{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003862 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46979952011-04-07 13:53:55 -07003863
3864 if (!dev_priv)
3865 return;
3866
Paulo Zanonibe30b292014-04-01 15:37:25 -03003867 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003868}
3869
Chris Wilsonc2798b12012-04-22 21:13:57 +01003870static void i8xx_irq_preinstall(struct drm_device * dev)
3871{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003872 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003873 int pipe;
3874
Damien Lespiau055e3932014-08-18 13:49:10 +01003875 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003876 I915_WRITE(PIPESTAT(pipe), 0);
3877 I915_WRITE16(IMR, 0xffff);
3878 I915_WRITE16(IER, 0x0);
3879 POSTING_READ16(IER);
3880}
3881
3882static int i8xx_irq_postinstall(struct drm_device *dev)
3883{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003884 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003885
Chris Wilsonc2798b12012-04-22 21:13:57 +01003886 I915_WRITE16(EMR,
3887 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3888
3889 /* Unmask the interrupts that we always want on. */
3890 dev_priv->irq_mask =
3891 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3892 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3893 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003894 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003895 I915_WRITE16(IMR, dev_priv->irq_mask);
3896
3897 I915_WRITE16(IER,
3898 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3899 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003900 I915_USER_INTERRUPT);
3901 POSTING_READ16(IER);
3902
Daniel Vetter379ef822013-10-16 22:55:56 +02003903 /* Interrupt setup is already guaranteed to be single-threaded, this is
3904 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003905 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003906 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3907 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003908 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003909
Chris Wilsonc2798b12012-04-22 21:13:57 +01003910 return 0;
3911}
3912
Daniel Vetter5a21b662016-05-24 17:13:53 +02003913/*
3914 * Returns true when a page flip has completed.
3915 */
3916static bool i8xx_handle_vblank(struct drm_i915_private *dev_priv,
3917 int plane, int pipe, u32 iir)
3918{
3919 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3920
3921 if (!intel_pipe_handle_vblank(dev_priv, pipe))
3922 return false;
3923
3924 if ((iir & flip_pending) == 0)
3925 goto check_page_flip;
3926
3927 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3928 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3929 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3930 * the flip is completed (no longer pending). Since this doesn't raise
3931 * an interrupt per se, we watch for the change at vblank.
3932 */
3933 if (I915_READ16(ISR) & flip_pending)
3934 goto check_page_flip;
3935
3936 intel_finish_page_flip_cs(dev_priv, pipe);
3937 return true;
3938
3939check_page_flip:
3940 intel_check_page_flip(dev_priv, pipe);
3941 return false;
3942}
3943
Daniel Vetterff1f5252012-10-02 15:10:55 +02003944static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003945{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003946 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003947 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003948 u16 iir, new_iir;
3949 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003950 int pipe;
3951 u16 flip_mask =
3952 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3953 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Imre Deak1f814da2015-12-16 02:52:19 +02003954 irqreturn_t ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003955
Imre Deak2dd2a882015-02-24 11:14:30 +02003956 if (!intel_irqs_enabled(dev_priv))
3957 return IRQ_NONE;
3958
Imre Deak1f814da2015-12-16 02:52:19 +02003959 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3960 disable_rpm_wakeref_asserts(dev_priv);
3961
3962 ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003963 iir = I915_READ16(IIR);
3964 if (iir == 0)
Imre Deak1f814da2015-12-16 02:52:19 +02003965 goto out;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003966
3967 while (iir & ~flip_mask) {
3968 /* Can't rely on pipestat interrupt bit in iir as it might
3969 * have been cleared after the pipestat interrupt was received.
3970 * It doesn't set the bit in iir again, but it still produces
3971 * interrupts (for non-MSI).
3972 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003973 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003974 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003975 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003976
Damien Lespiau055e3932014-08-18 13:49:10 +01003977 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003978 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003979 pipe_stats[pipe] = I915_READ(reg);
3980
3981 /*
3982 * Clear the PIPE*STAT regs before the IIR
3983 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003984 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003985 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003986 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003987 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003988
3989 I915_WRITE16(IIR, iir & ~flip_mask);
3990 new_iir = I915_READ16(IIR); /* Flush posted writes */
3991
Chris Wilsonc2798b12012-04-22 21:13:57 +01003992 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00003993 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003994
Damien Lespiau055e3932014-08-18 13:49:10 +01003995 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02003996 int plane = pipe;
3997 if (HAS_FBC(dev_priv))
3998 plane = !plane;
3999
4000 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4001 i8xx_handle_vblank(dev_priv, plane, pipe, iir))
4002 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004003
Daniel Vetter4356d582013-10-16 22:55:55 +02004004 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004005 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004006
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004007 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4008 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4009 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02004010 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004011
4012 iir = new_iir;
4013 }
Imre Deak1f814da2015-12-16 02:52:19 +02004014 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004015
Imre Deak1f814da2015-12-16 02:52:19 +02004016out:
4017 enable_rpm_wakeref_asserts(dev_priv);
4018
4019 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004020}
4021
4022static void i8xx_irq_uninstall(struct drm_device * dev)
4023{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004024 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004025 int pipe;
4026
Damien Lespiau055e3932014-08-18 13:49:10 +01004027 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004028 /* Clear enable bits; then clear status bits */
4029 I915_WRITE(PIPESTAT(pipe), 0);
4030 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4031 }
4032 I915_WRITE16(IMR, 0xffff);
4033 I915_WRITE16(IER, 0x0);
4034 I915_WRITE16(IIR, I915_READ16(IIR));
4035}
4036
Chris Wilsona266c7d2012-04-24 22:59:44 +01004037static void i915_irq_preinstall(struct drm_device * dev)
4038{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004039 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004040 int pipe;
4041
Chris Wilsona266c7d2012-04-24 22:59:44 +01004042 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004043 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004044 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4045 }
4046
Chris Wilson00d98eb2012-04-24 22:59:48 +01004047 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004048 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004049 I915_WRITE(PIPESTAT(pipe), 0);
4050 I915_WRITE(IMR, 0xffffffff);
4051 I915_WRITE(IER, 0x0);
4052 POSTING_READ(IER);
4053}
4054
4055static int i915_irq_postinstall(struct drm_device *dev)
4056{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004057 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004058 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004059
Chris Wilson38bde182012-04-24 22:59:50 +01004060 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4061
4062 /* Unmask the interrupts that we always want on. */
4063 dev_priv->irq_mask =
4064 ~(I915_ASLE_INTERRUPT |
4065 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4066 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4067 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02004068 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004069
4070 enable_mask =
4071 I915_ASLE_INTERRUPT |
4072 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4073 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004074 I915_USER_INTERRUPT;
4075
Chris Wilsona266c7d2012-04-24 22:59:44 +01004076 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004077 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004078 POSTING_READ(PORT_HOTPLUG_EN);
4079
Chris Wilsona266c7d2012-04-24 22:59:44 +01004080 /* Enable in IER... */
4081 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4082 /* and unmask in IMR */
4083 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4084 }
4085
Chris Wilsona266c7d2012-04-24 22:59:44 +01004086 I915_WRITE(IMR, dev_priv->irq_mask);
4087 I915_WRITE(IER, enable_mask);
4088 POSTING_READ(IER);
4089
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004090 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004091
Daniel Vetter379ef822013-10-16 22:55:56 +02004092 /* Interrupt setup is already guaranteed to be single-threaded, this is
4093 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004094 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004095 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4096 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004097 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004098
Daniel Vetter20afbda2012-12-11 14:05:07 +01004099 return 0;
4100}
4101
Daniel Vetter5a21b662016-05-24 17:13:53 +02004102/*
4103 * Returns true when a page flip has completed.
4104 */
4105static bool i915_handle_vblank(struct drm_i915_private *dev_priv,
4106 int plane, int pipe, u32 iir)
4107{
4108 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4109
4110 if (!intel_pipe_handle_vblank(dev_priv, pipe))
4111 return false;
4112
4113 if ((iir & flip_pending) == 0)
4114 goto check_page_flip;
4115
4116 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4117 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4118 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4119 * the flip is completed (no longer pending). Since this doesn't raise
4120 * an interrupt per se, we watch for the change at vblank.
4121 */
4122 if (I915_READ(ISR) & flip_pending)
4123 goto check_page_flip;
4124
4125 intel_finish_page_flip_cs(dev_priv, pipe);
4126 return true;
4127
4128check_page_flip:
4129 intel_check_page_flip(dev_priv, pipe);
4130 return false;
4131}
4132
Daniel Vetterff1f5252012-10-02 15:10:55 +02004133static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004134{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004135 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004136 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004137 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004138 u32 flip_mask =
4139 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4140 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004141 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004142
Imre Deak2dd2a882015-02-24 11:14:30 +02004143 if (!intel_irqs_enabled(dev_priv))
4144 return IRQ_NONE;
4145
Imre Deak1f814da2015-12-16 02:52:19 +02004146 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4147 disable_rpm_wakeref_asserts(dev_priv);
4148
Chris Wilsona266c7d2012-04-24 22:59:44 +01004149 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004150 do {
4151 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004152 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004153
4154 /* Can't rely on pipestat interrupt bit in iir as it might
4155 * have been cleared after the pipestat interrupt was received.
4156 * It doesn't set the bit in iir again, but it still produces
4157 * interrupts (for non-MSI).
4158 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004159 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004160 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004161 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004162
Damien Lespiau055e3932014-08-18 13:49:10 +01004163 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004164 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004165 pipe_stats[pipe] = I915_READ(reg);
4166
Chris Wilson38bde182012-04-24 22:59:50 +01004167 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004168 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004169 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004170 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004171 }
4172 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004173 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004174
4175 if (!irq_received)
4176 break;
4177
Chris Wilsona266c7d2012-04-24 22:59:44 +01004178 /* Consume port. Then clear IIR or we'll miss events */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004179 if (I915_HAS_HOTPLUG(dev_priv) &&
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004180 iir & I915_DISPLAY_PORT_INTERRUPT) {
4181 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4182 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004183 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004184 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004185
Chris Wilson38bde182012-04-24 22:59:50 +01004186 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004187 new_iir = I915_READ(IIR); /* Flush posted writes */
4188
Chris Wilsona266c7d2012-04-24 22:59:44 +01004189 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004190 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004191
Damien Lespiau055e3932014-08-18 13:49:10 +01004192 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004193 int plane = pipe;
4194 if (HAS_FBC(dev_priv))
4195 plane = !plane;
4196
4197 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4198 i915_handle_vblank(dev_priv, plane, pipe, iir))
4199 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004200
4201 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4202 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004203
4204 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004205 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004206
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004207 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4208 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4209 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004210 }
4211
Chris Wilsona266c7d2012-04-24 22:59:44 +01004212 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004213 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004214
4215 /* With MSI, interrupts are only generated when iir
4216 * transitions from zero to nonzero. If another bit got
4217 * set while we were handling the existing iir bits, then
4218 * we would never get another interrupt.
4219 *
4220 * This is fine on non-MSI as well, as if we hit this path
4221 * we avoid exiting the interrupt handler only to generate
4222 * another one.
4223 *
4224 * Note that for MSI this could cause a stray interrupt report
4225 * if an interrupt landed in the time between writing IIR and
4226 * the posting read. This should be rare enough to never
4227 * trigger the 99% of 100,000 interrupts test for disabling
4228 * stray interrupts.
4229 */
Chris Wilson38bde182012-04-24 22:59:50 +01004230 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004231 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004232 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004233
Imre Deak1f814da2015-12-16 02:52:19 +02004234 enable_rpm_wakeref_asserts(dev_priv);
4235
Chris Wilsona266c7d2012-04-24 22:59:44 +01004236 return ret;
4237}
4238
4239static void i915_irq_uninstall(struct drm_device * dev)
4240{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004241 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004242 int pipe;
4243
Chris Wilsona266c7d2012-04-24 22:59:44 +01004244 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004245 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004246 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4247 }
4248
Chris Wilson00d98eb2012-04-24 22:59:48 +01004249 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004250 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004251 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004252 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004253 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4254 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004255 I915_WRITE(IMR, 0xffffffff);
4256 I915_WRITE(IER, 0x0);
4257
Chris Wilsona266c7d2012-04-24 22:59:44 +01004258 I915_WRITE(IIR, I915_READ(IIR));
4259}
4260
4261static void i965_irq_preinstall(struct drm_device * dev)
4262{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004263 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004264 int pipe;
4265
Egbert Eich0706f172015-09-23 16:15:27 +02004266 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004267 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004268
4269 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004270 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004271 I915_WRITE(PIPESTAT(pipe), 0);
4272 I915_WRITE(IMR, 0xffffffff);
4273 I915_WRITE(IER, 0x0);
4274 POSTING_READ(IER);
4275}
4276
4277static int i965_irq_postinstall(struct drm_device *dev)
4278{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004279 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004280 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004281 u32 error_mask;
4282
Chris Wilsona266c7d2012-04-24 22:59:44 +01004283 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004284 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004285 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004286 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4287 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4288 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4289 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4290 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4291
4292 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004293 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4294 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004295 enable_mask |= I915_USER_INTERRUPT;
4296
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004297 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004298 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004299
Daniel Vetterb79480b2013-06-27 17:52:10 +02004300 /* Interrupt setup is already guaranteed to be single-threaded, this is
4301 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004302 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004303 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4304 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4305 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004306 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004307
Chris Wilsona266c7d2012-04-24 22:59:44 +01004308 /*
4309 * Enable some error detection, note the instruction error mask
4310 * bit is reserved, so we leave it masked.
4311 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004312 if (IS_G4X(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004313 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4314 GM45_ERROR_MEM_PRIV |
4315 GM45_ERROR_CP_PRIV |
4316 I915_ERROR_MEMORY_REFRESH);
4317 } else {
4318 error_mask = ~(I915_ERROR_PAGE_TABLE |
4319 I915_ERROR_MEMORY_REFRESH);
4320 }
4321 I915_WRITE(EMR, error_mask);
4322
4323 I915_WRITE(IMR, dev_priv->irq_mask);
4324 I915_WRITE(IER, enable_mask);
4325 POSTING_READ(IER);
4326
Egbert Eich0706f172015-09-23 16:15:27 +02004327 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004328 POSTING_READ(PORT_HOTPLUG_EN);
4329
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004330 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004331
4332 return 0;
4333}
4334
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004335static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004336{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004337 u32 hotplug_en;
4338
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004339 assert_spin_locked(&dev_priv->irq_lock);
4340
Ville Syrjälä778eb332015-01-09 14:21:13 +02004341 /* Note HDMI and DP share hotplug bits */
4342 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004343 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004344 /* Programming the CRT detection parameters tends
4345 to generate a spurious hotplug event about three
4346 seconds later. So just do it once.
4347 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004348 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004349 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004350 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004351
Ville Syrjälä778eb332015-01-09 14:21:13 +02004352 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004353 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004354 HOTPLUG_INT_EN_MASK |
4355 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4356 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4357 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004358}
4359
Daniel Vetterff1f5252012-10-02 15:10:55 +02004360static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004361{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004362 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004363 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004364 u32 iir, new_iir;
4365 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004366 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004367 u32 flip_mask =
4368 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4369 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004370
Imre Deak2dd2a882015-02-24 11:14:30 +02004371 if (!intel_irqs_enabled(dev_priv))
4372 return IRQ_NONE;
4373
Imre Deak1f814da2015-12-16 02:52:19 +02004374 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4375 disable_rpm_wakeref_asserts(dev_priv);
4376
Chris Wilsona266c7d2012-04-24 22:59:44 +01004377 iir = I915_READ(IIR);
4378
Chris Wilsona266c7d2012-04-24 22:59:44 +01004379 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004380 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004381 bool blc_event = false;
4382
Chris Wilsona266c7d2012-04-24 22:59:44 +01004383 /* Can't rely on pipestat interrupt bit in iir as it might
4384 * have been cleared after the pipestat interrupt was received.
4385 * It doesn't set the bit in iir again, but it still produces
4386 * interrupts (for non-MSI).
4387 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004388 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004389 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004390 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004391
Damien Lespiau055e3932014-08-18 13:49:10 +01004392 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004393 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004394 pipe_stats[pipe] = I915_READ(reg);
4395
4396 /*
4397 * Clear the PIPE*STAT regs before the IIR
4398 */
4399 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004400 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004401 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004402 }
4403 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004404 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004405
4406 if (!irq_received)
4407 break;
4408
4409 ret = IRQ_HANDLED;
4410
4411 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004412 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
4413 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4414 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004415 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004416 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004417
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004418 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004419 new_iir = I915_READ(IIR); /* Flush posted writes */
4420
Chris Wilsona266c7d2012-04-24 22:59:44 +01004421 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004422 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004423 if (iir & I915_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004424 notify_ring(&dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004425
Damien Lespiau055e3932014-08-18 13:49:10 +01004426 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004427 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
4428 i915_handle_vblank(dev_priv, pipe, pipe, iir))
4429 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004430
4431 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4432 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004433
4434 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004435 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004436
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004437 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4438 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004439 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004440
4441 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004442 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004443
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004444 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004445 gmbus_irq_handler(dev_priv);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004446
Chris Wilsona266c7d2012-04-24 22:59:44 +01004447 /* With MSI, interrupts are only generated when iir
4448 * transitions from zero to nonzero. If another bit got
4449 * set while we were handling the existing iir bits, then
4450 * we would never get another interrupt.
4451 *
4452 * This is fine on non-MSI as well, as if we hit this path
4453 * we avoid exiting the interrupt handler only to generate
4454 * another one.
4455 *
4456 * Note that for MSI this could cause a stray interrupt report
4457 * if an interrupt landed in the time between writing IIR and
4458 * the posting read. This should be rare enough to never
4459 * trigger the 99% of 100,000 interrupts test for disabling
4460 * stray interrupts.
4461 */
4462 iir = new_iir;
4463 }
4464
Imre Deak1f814da2015-12-16 02:52:19 +02004465 enable_rpm_wakeref_asserts(dev_priv);
4466
Chris Wilsona266c7d2012-04-24 22:59:44 +01004467 return ret;
4468}
4469
4470static void i965_irq_uninstall(struct drm_device * dev)
4471{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004472 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004473 int pipe;
4474
4475 if (!dev_priv)
4476 return;
4477
Egbert Eich0706f172015-09-23 16:15:27 +02004478 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004479 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004480
4481 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004482 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004483 I915_WRITE(PIPESTAT(pipe), 0);
4484 I915_WRITE(IMR, 0xffffffff);
4485 I915_WRITE(IER, 0x0);
4486
Damien Lespiau055e3932014-08-18 13:49:10 +01004487 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004488 I915_WRITE(PIPESTAT(pipe),
4489 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4490 I915_WRITE(IIR, I915_READ(IIR));
4491}
4492
Daniel Vetterfca52a52014-09-30 10:56:45 +02004493/**
4494 * intel_irq_init - initializes irq support
4495 * @dev_priv: i915 device instance
4496 *
4497 * This function initializes all the irq support including work items, timers
4498 * and all the vtables. It does not setup the interrupt itself though.
4499 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004500void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004501{
Daniel Vetterb9632912014-09-30 10:56:44 +02004502 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004503
Jani Nikula77913b32015-06-18 13:06:16 +03004504 intel_hpd_init_work(dev_priv);
4505
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004506 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004507 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004508
Deepak Sa6706b42014-03-15 20:23:22 +05304509 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004510 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004511 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004512 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004513 else
4514 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304515
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304516 dev_priv->rps.pm_intr_keep = 0;
4517
4518 /*
4519 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
4520 * if GEN6_PM_UP_EI_EXPIRED is masked.
4521 *
4522 * TODO: verify if this can be reproduced on VLV,CHV.
4523 */
4524 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
4525 dev_priv->rps.pm_intr_keep |= GEN6_PM_RP_UP_EI_EXPIRED;
4526
4527 if (INTEL_INFO(dev_priv)->gen >= 8)
4528 dev_priv->rps.pm_intr_keep |= GEN8_PMINTR_REDIRECT_TO_NON_DISP;
4529
Chris Wilson737b1502015-01-26 18:03:03 +02004530 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4531 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004532
Daniel Vetterb9632912014-09-30 10:56:44 +02004533 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004534 dev->max_vblank_count = 0;
4535 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004536 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004537 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004538 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004539 } else {
4540 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4541 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004542 }
4543
Ville Syrjälä21da2702014-08-06 14:49:55 +03004544 /*
4545 * Opt out of the vblank disable timer on everything except gen2.
4546 * Gen2 doesn't have a hardware frame counter and so depends on
4547 * vblank interrupts to produce sane vblank seuquence numbers.
4548 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004549 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004550 dev->vblank_disable_immediate = true;
4551
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004552 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4553 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004554
Daniel Vetterb9632912014-09-30 10:56:44 +02004555 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004556 dev->driver->irq_handler = cherryview_irq_handler;
4557 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4558 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4559 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4560 dev->driver->enable_vblank = valleyview_enable_vblank;
4561 dev->driver->disable_vblank = valleyview_disable_vblank;
4562 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004563 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004564 dev->driver->irq_handler = valleyview_irq_handler;
4565 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4566 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4567 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4568 dev->driver->enable_vblank = valleyview_enable_vblank;
4569 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004570 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004571 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004572 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004573 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004574 dev->driver->irq_postinstall = gen8_irq_postinstall;
4575 dev->driver->irq_uninstall = gen8_irq_uninstall;
4576 dev->driver->enable_vblank = gen8_enable_vblank;
4577 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004578 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004579 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004580 else if (HAS_PCH_SPT(dev))
4581 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4582 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004583 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004584 } else if (HAS_PCH_SPLIT(dev)) {
4585 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004586 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004587 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4588 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4589 dev->driver->enable_vblank = ironlake_enable_vblank;
4590 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004591 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004592 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004593 if (IS_GEN2(dev_priv)) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004594 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4595 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4596 dev->driver->irq_handler = i8xx_irq_handler;
4597 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004598 } else if (IS_GEN3(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004599 dev->driver->irq_preinstall = i915_irq_preinstall;
4600 dev->driver->irq_postinstall = i915_irq_postinstall;
4601 dev->driver->irq_uninstall = i915_irq_uninstall;
4602 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004603 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004604 dev->driver->irq_preinstall = i965_irq_preinstall;
4605 dev->driver->irq_postinstall = i965_irq_postinstall;
4606 dev->driver->irq_uninstall = i965_irq_uninstall;
4607 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004608 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004609 if (I915_HAS_HOTPLUG(dev_priv))
4610 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004611 dev->driver->enable_vblank = i915_enable_vblank;
4612 dev->driver->disable_vblank = i915_disable_vblank;
4613 }
4614}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004615
Daniel Vetterfca52a52014-09-30 10:56:45 +02004616/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004617 * intel_irq_install - enables the hardware interrupt
4618 * @dev_priv: i915 device instance
4619 *
4620 * This function enables the hardware interrupt handling, but leaves the hotplug
4621 * handling still disabled. It is called after intel_irq_init().
4622 *
4623 * In the driver load and resume code we need working interrupts in a few places
4624 * but don't want to deal with the hassle of concurrent probe and hotplug
4625 * workers. Hence the split into this two-stage approach.
4626 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004627int intel_irq_install(struct drm_i915_private *dev_priv)
4628{
4629 /*
4630 * We enable some interrupt sources in our postinstall hooks, so mark
4631 * interrupts as enabled _before_ actually enabling them to avoid
4632 * special cases in our ordering checks.
4633 */
4634 dev_priv->pm.irqs_enabled = true;
4635
4636 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4637}
4638
Daniel Vetterfca52a52014-09-30 10:56:45 +02004639/**
4640 * intel_irq_uninstall - finilizes all irq handling
4641 * @dev_priv: i915 device instance
4642 *
4643 * This stops interrupt and hotplug handling and unregisters and frees all
4644 * resources acquired in the init functions.
4645 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004646void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4647{
4648 drm_irq_uninstall(dev_priv->dev);
4649 intel_hpd_cancel_work(dev_priv);
4650 dev_priv->pm.irqs_enabled = false;
4651}
4652
Daniel Vetterfca52a52014-09-30 10:56:45 +02004653/**
4654 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4655 * @dev_priv: i915 device instance
4656 *
4657 * This function is used to disable interrupts at runtime, both in the runtime
4658 * pm and the system suspend/resume code.
4659 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004660void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004661{
Daniel Vetterb9632912014-09-30 10:56:44 +02004662 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004663 dev_priv->pm.irqs_enabled = false;
Imre Deak2dd2a882015-02-24 11:14:30 +02004664 synchronize_irq(dev_priv->dev->irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004665}
4666
Daniel Vetterfca52a52014-09-30 10:56:45 +02004667/**
4668 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4669 * @dev_priv: i915 device instance
4670 *
4671 * This function is used to enable interrupts at runtime, both in the runtime
4672 * pm and the system suspend/resume code.
4673 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004674void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004675{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004676 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004677 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4678 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004679}