blob: 4378a659d962d96d31b0f5a503dbb6318c764855 [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);
262 POSTING_READ(GTIMR);
263}
264
Daniel Vetter480c8032014-07-16 09:49:40 +0200265void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300266{
267 ilk_update_gt_irq(dev_priv, mask, mask);
268}
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);
Imre Deak78e68d32014-12-15 18:59:27 +0200354
Imre Deakb900b942014-11-05 20:48:48 +0200355 WARN_ON(dev_priv->rps.pm_iir);
Imre Deak3cc134e2014-11-19 15:30:03 +0200356 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200357 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200358 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
359 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200360 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200361
Imre Deakb900b942014-11-05 20:48:48 +0200362 spin_unlock_irq(&dev_priv->irq_lock);
363}
364
Imre Deak59d02a12014-12-19 19:33:26 +0200365u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
366{
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530367 return (mask & ~dev_priv->rps.pm_intr_keep);
Imre Deak59d02a12014-12-19 19:33:26 +0200368}
369
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100370void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200371{
Imre Deakd4d70aa2014-11-19 15:30:04 +0200372 spin_lock_irq(&dev_priv->irq_lock);
373 dev_priv->rps.interrupts_enabled = false;
374 spin_unlock_irq(&dev_priv->irq_lock);
375
376 cancel_work_sync(&dev_priv->rps.work);
377
Imre Deak9939fba2014-11-20 23:01:47 +0200378 spin_lock_irq(&dev_priv->irq_lock);
379
Imre Deak59d02a12014-12-19 19:33:26 +0200380 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200381
382 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200383 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
384 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200385
386 spin_unlock_irq(&dev_priv->irq_lock);
387
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100388 synchronize_irq(dev_priv->dev->irq);
Imre Deakb900b942014-11-05 20:48:48 +0200389}
390
Ben Widawsky09610212014-05-15 20:58:08 +0300391/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200392 * bdw_update_port_irq - update DE port interrupt
393 * @dev_priv: driver private
394 * @interrupt_mask: mask of interrupt bits to update
395 * @enabled_irq_mask: mask of interrupt bits to enable
396 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300397static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
398 uint32_t interrupt_mask,
399 uint32_t enabled_irq_mask)
400{
401 uint32_t new_val;
402 uint32_t old_val;
403
404 assert_spin_locked(&dev_priv->irq_lock);
405
406 WARN_ON(enabled_irq_mask & ~interrupt_mask);
407
408 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
409 return;
410
411 old_val = I915_READ(GEN8_DE_PORT_IMR);
412
413 new_val = old_val;
414 new_val &= ~interrupt_mask;
415 new_val |= (~enabled_irq_mask & interrupt_mask);
416
417 if (new_val != old_val) {
418 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
419 POSTING_READ(GEN8_DE_PORT_IMR);
420 }
421}
422
423/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200424 * bdw_update_pipe_irq - update DE pipe interrupt
425 * @dev_priv: driver private
426 * @pipe: pipe whose interrupt to update
427 * @interrupt_mask: mask of interrupt bits to update
428 * @enabled_irq_mask: mask of interrupt bits to enable
429 */
430void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
431 enum pipe pipe,
432 uint32_t interrupt_mask,
433 uint32_t enabled_irq_mask)
434{
435 uint32_t new_val;
436
437 assert_spin_locked(&dev_priv->irq_lock);
438
439 WARN_ON(enabled_irq_mask & ~interrupt_mask);
440
441 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
442 return;
443
444 new_val = dev_priv->de_irq_mask[pipe];
445 new_val &= ~interrupt_mask;
446 new_val |= (~enabled_irq_mask & interrupt_mask);
447
448 if (new_val != dev_priv->de_irq_mask[pipe]) {
449 dev_priv->de_irq_mask[pipe] = new_val;
450 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
451 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
452 }
453}
454
455/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200456 * ibx_display_interrupt_update - update SDEIMR
457 * @dev_priv: driver private
458 * @interrupt_mask: mask of interrupt bits to update
459 * @enabled_irq_mask: mask of interrupt bits to enable
460 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200461void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
462 uint32_t interrupt_mask,
463 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200464{
465 uint32_t sdeimr = I915_READ(SDEIMR);
466 sdeimr &= ~interrupt_mask;
467 sdeimr |= (~enabled_irq_mask & interrupt_mask);
468
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100469 WARN_ON(enabled_irq_mask & ~interrupt_mask);
470
Daniel Vetterfee884e2013-07-04 23:35:21 +0200471 assert_spin_locked(&dev_priv->irq_lock);
472
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700473 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300474 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300475
Daniel Vetterfee884e2013-07-04 23:35:21 +0200476 I915_WRITE(SDEIMR, sdeimr);
477 POSTING_READ(SDEIMR);
478}
Paulo Zanoni86642812013-04-12 17:57:57 -0300479
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100480static void
Imre Deak755e9012014-02-10 18:42:47 +0200481__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
482 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800483{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200484 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200485 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800486
Daniel Vetterb79480b2013-06-27 17:52:10 +0200487 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200488 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200489
Ville Syrjälä04feced2014-04-03 13:28:33 +0300490 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
491 status_mask & ~PIPESTAT_INT_STATUS_MASK,
492 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
493 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200494 return;
495
496 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200497 return;
498
Imre Deak91d181d2014-02-10 18:42:49 +0200499 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
500
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200501 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200502 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200503 I915_WRITE(reg, pipestat);
504 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800505}
506
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100507static void
Imre Deak755e9012014-02-10 18:42:47 +0200508__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
509 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800510{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200511 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200512 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800513
Daniel Vetterb79480b2013-06-27 17:52:10 +0200514 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200515 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200516
Ville Syrjälä04feced2014-04-03 13:28:33 +0300517 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
518 status_mask & ~PIPESTAT_INT_STATUS_MASK,
519 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
520 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200521 return;
522
Imre Deak755e9012014-02-10 18:42:47 +0200523 if ((pipestat & enable_mask) == 0)
524 return;
525
Imre Deak91d181d2014-02-10 18:42:49 +0200526 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
527
Imre Deak755e9012014-02-10 18:42:47 +0200528 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200529 I915_WRITE(reg, pipestat);
530 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800531}
532
Imre Deak10c59c52014-02-10 18:42:48 +0200533static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
534{
535 u32 enable_mask = status_mask << 16;
536
537 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300538 * On pipe A we don't support the PSR interrupt yet,
539 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200540 */
541 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
542 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300543 /*
544 * On pipe B and C we don't support the PSR interrupt yet, on pipe
545 * A the same bit is for perf counters which we don't use either.
546 */
547 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
548 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200549
550 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
551 SPRITE0_FLIP_DONE_INT_EN_VLV |
552 SPRITE1_FLIP_DONE_INT_EN_VLV);
553 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
554 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
555 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
556 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
557
558 return enable_mask;
559}
560
Imre Deak755e9012014-02-10 18:42:47 +0200561void
562i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
563 u32 status_mask)
564{
565 u32 enable_mask;
566
Wayne Boyer666a4532015-12-09 12:29:35 -0800567 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Imre Deak10c59c52014-02-10 18:42:48 +0200568 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
569 status_mask);
570 else
571 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200572 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
573}
574
575void
576i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
577 u32 status_mask)
578{
579 u32 enable_mask;
580
Wayne Boyer666a4532015-12-09 12:29:35 -0800581 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Imre Deak10c59c52014-02-10 18:42:48 +0200582 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
583 status_mask);
584 else
585 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200586 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
587}
588
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000589/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300590 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100591 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000592 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100593static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000594{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100595 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300596 return;
597
Daniel Vetter13321782014-09-15 14:55:29 +0200598 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000599
Imre Deak755e9012014-02-10 18:42:47 +0200600 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100601 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200602 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200603 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000604
Daniel Vetter13321782014-09-15 14:55:29 +0200605 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000606}
607
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300608/*
609 * This timing diagram depicts the video signal in and
610 * around the vertical blanking period.
611 *
612 * Assumptions about the fictitious mode used in this example:
613 * vblank_start >= 3
614 * vsync_start = vblank_start + 1
615 * vsync_end = vblank_start + 2
616 * vtotal = vblank_start + 3
617 *
618 * start of vblank:
619 * latch double buffered registers
620 * increment frame counter (ctg+)
621 * generate start of vblank interrupt (gen4+)
622 * |
623 * | frame start:
624 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
625 * | may be shifted forward 1-3 extra lines via PIPECONF
626 * | |
627 * | | start of vsync:
628 * | | generate vsync interrupt
629 * | | |
630 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
631 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
632 * ----va---> <-----------------vb--------------------> <--------va-------------
633 * | | <----vs-----> |
634 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
635 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
636 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
637 * | | |
638 * last visible pixel first visible pixel
639 * | increment frame counter (gen3/4)
640 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
641 *
642 * x = horizontal active
643 * _ = horizontal blanking
644 * hs = horizontal sync
645 * va = vertical active
646 * vb = vertical blanking
647 * vs = vertical sync
648 * vbs = vblank_start (number)
649 *
650 * Summary:
651 * - most events happen at the start of horizontal sync
652 * - frame start happens at the start of horizontal blank, 1-4 lines
653 * (depending on PIPECONF settings) after the start of vblank
654 * - gen3/4 pixel and frame counter are synchronized with the start
655 * of horizontal active on the first line of vertical active
656 */
657
Thierry Reding88e72712015-09-24 18:35:31 +0200658static u32 i8xx_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300659{
660 /* Gen2 doesn't have a hardware frame counter */
661 return 0;
662}
663
Keith Packard42f52ef2008-10-18 19:39:29 -0700664/* Called from drm generic code, passed a 'crtc', which
665 * we use as a pipe index
666 */
Thierry Reding88e72712015-09-24 18:35:31 +0200667static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700668{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300669 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200670 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300671 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100672 struct intel_crtc *intel_crtc =
673 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200674 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700675
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100676 htotal = mode->crtc_htotal;
677 hsync_start = mode->crtc_hsync_start;
678 vbl_start = mode->crtc_vblank_start;
679 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
680 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300681
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300682 /* Convert to pixel count */
683 vbl_start *= htotal;
684
685 /* Start of vblank event occurs at start of hsync */
686 vbl_start -= htotal - hsync_start;
687
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800688 high_frame = PIPEFRAME(pipe);
689 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100690
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700691 /*
692 * High & low register fields aren't synchronized, so make sure
693 * we get a low value that's stable across two reads of the high
694 * register.
695 */
696 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100697 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300698 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100699 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700700 } while (high1 != high2);
701
Chris Wilson5eddb702010-09-11 13:48:45 +0100702 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300703 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100704 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300705
706 /*
707 * The frame counter increments at beginning of active.
708 * Cook up a vblank counter by also checking the pixel
709 * counter against vblank start.
710 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200711 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700712}
713
Dave Airlie974e59b2015-10-30 09:45:33 +1000714static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800715{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300716 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800717
Ville Syrjälä649636e2015-09-22 19:50:01 +0300718 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800719}
720
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300721/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300722static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
723{
724 struct drm_device *dev = crtc->base.dev;
725 struct drm_i915_private *dev_priv = dev->dev_private;
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200726 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300727 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300728 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300729
Ville Syrjälä80715b22014-05-15 20:23:23 +0300730 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300731 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
732 vtotal /= 2;
733
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100734 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300735 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300736 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300737 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300738
739 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700740 * On HSW, the DSL reg (0x70000) appears to return 0 if we
741 * read it just before the start of vblank. So try it again
742 * so we don't accidentally end up spanning a vblank frame
743 * increment, causing the pipe_update_end() code to squak at us.
744 *
745 * The nature of this problem means we can't simply check the ISR
746 * bit and return the vblank start value; nor can we use the scanline
747 * debug register in the transcoder as it appears to have the same
748 * problem. We may need to extend this to include other platforms,
749 * but so far testing only shows the problem on HSW.
750 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100751 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700752 int i, temp;
753
754 for (i = 0; i < 100; i++) {
755 udelay(1);
756 temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) &
757 DSL_LINEMASK_GEN3;
758 if (temp != position) {
759 position = temp;
760 break;
761 }
762 }
763 }
764
765 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300766 * See update_scanline_offset() for the details on the
767 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300768 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300769 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300770}
771
Thierry Reding88e72712015-09-24 18:35:31 +0200772static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200773 unsigned int flags, int *vpos, int *hpos,
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300774 ktime_t *stime, ktime_t *etime,
775 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100776{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300777 struct drm_i915_private *dev_priv = dev->dev_private;
778 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
779 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300780 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300781 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100782 bool in_vbl = true;
783 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100784 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100785
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200786 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100787 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800788 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100789 return 0;
790 }
791
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300792 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300793 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300794 vtotal = mode->crtc_vtotal;
795 vbl_start = mode->crtc_vblank_start;
796 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100797
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200798 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
799 vbl_start = DIV_ROUND_UP(vbl_start, 2);
800 vbl_end /= 2;
801 vtotal /= 2;
802 }
803
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300804 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
805
Mario Kleinerad3543e2013-10-30 05:13:08 +0100806 /*
807 * Lock uncore.lock, as we will do multiple timing critical raw
808 * register reads, potentially with preemption disabled, so the
809 * following code must not block on uncore.lock.
810 */
811 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300812
Mario Kleinerad3543e2013-10-30 05:13:08 +0100813 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
814
815 /* Get optional system timestamp before query. */
816 if (stime)
817 *stime = ktime_get();
818
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100819 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100820 /* No obvious pixelcount register. Only query vertical
821 * scanout position from Display scan line register.
822 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300823 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100824 } else {
825 /* Have access to pixelcount since start of frame.
826 * We can split this into vertical and horizontal
827 * scanout position.
828 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300829 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100830
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300831 /* convert to pixel counts */
832 vbl_start *= htotal;
833 vbl_end *= htotal;
834 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300835
836 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300837 * In interlaced modes, the pixel counter counts all pixels,
838 * so one field will have htotal more pixels. In order to avoid
839 * the reported position from jumping backwards when the pixel
840 * counter is beyond the length of the shorter field, just
841 * clamp the position the length of the shorter field. This
842 * matches how the scanline counter based position works since
843 * the scanline counter doesn't count the two half lines.
844 */
845 if (position >= vtotal)
846 position = vtotal - 1;
847
848 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300849 * Start of vblank interrupt is triggered at start of hsync,
850 * just prior to the first active line of vblank. However we
851 * consider lines to start at the leading edge of horizontal
852 * active. So, should we get here before we've crossed into
853 * the horizontal active of the first line in vblank, we would
854 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
855 * always add htotal-hsync_start to the current pixel position.
856 */
857 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300858 }
859
Mario Kleinerad3543e2013-10-30 05:13:08 +0100860 /* Get optional system timestamp after query. */
861 if (etime)
862 *etime = ktime_get();
863
864 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
865
866 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
867
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300868 in_vbl = position >= vbl_start && position < vbl_end;
869
870 /*
871 * While in vblank, position will be negative
872 * counting up towards 0 at vbl_end. And outside
873 * vblank, position will be positive counting
874 * up since vbl_end.
875 */
876 if (position >= vbl_start)
877 position -= vbl_end;
878 else
879 position += vtotal - vbl_end;
880
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100881 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300882 *vpos = position;
883 *hpos = 0;
884 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100885 *vpos = position / htotal;
886 *hpos = position - (*vpos * htotal);
887 }
888
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100889 /* In vblank? */
890 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200891 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100892
893 return ret;
894}
895
Ville Syrjäläa225f072014-04-29 13:35:45 +0300896int intel_get_crtc_scanline(struct intel_crtc *crtc)
897{
898 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
899 unsigned long irqflags;
900 int position;
901
902 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
903 position = __intel_get_crtc_scanline(crtc);
904 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
905
906 return position;
907}
908
Thierry Reding88e72712015-09-24 18:35:31 +0200909static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100910 int *max_error,
911 struct timeval *vblank_time,
912 unsigned flags)
913{
Chris Wilson4041b852011-01-22 10:07:56 +0000914 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100915
Thierry Reding88e72712015-09-24 18:35:31 +0200916 if (pipe >= INTEL_INFO(dev)->num_pipes) {
917 DRM_ERROR("Invalid crtc %u\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100918 return -EINVAL;
919 }
920
921 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000922 crtc = intel_get_crtc_for_pipe(dev, pipe);
923 if (crtc == NULL) {
Thierry Reding88e72712015-09-24 18:35:31 +0200924 DRM_ERROR("Invalid crtc %u\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000925 return -EINVAL;
926 }
927
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200928 if (!crtc->hwmode.crtc_clock) {
Thierry Reding88e72712015-09-24 18:35:31 +0200929 DRM_DEBUG_KMS("crtc %u is disabled\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000930 return -EBUSY;
931 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100932
933 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000934 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
935 vblank_time, flags,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200936 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100937}
938
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100939static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800940{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000941 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200942 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200943
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200944 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800945
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200946 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
947
Daniel Vetter20e4d402012-08-08 23:35:39 +0200948 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200949
Jesse Barnes7648fa92010-05-20 14:28:11 -0700950 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000951 busy_up = I915_READ(RCPREVBSYTUPAVG);
952 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800953 max_avg = I915_READ(RCBMAXAVG);
954 min_avg = I915_READ(RCBMINAVG);
955
956 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000957 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200958 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
959 new_delay = dev_priv->ips.cur_delay - 1;
960 if (new_delay < dev_priv->ips.max_delay)
961 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000962 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200963 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
964 new_delay = dev_priv->ips.cur_delay + 1;
965 if (new_delay > dev_priv->ips.min_delay)
966 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800967 }
968
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100969 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200970 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800971
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200972 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200973
Jesse Barnesf97108d2010-01-29 11:27:07 -0800974 return;
975}
976
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000977static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +0100978{
Tvrtko Ursulin117897f2016-03-16 11:00:40 +0000979 if (!intel_engine_initialized(engine))
Chris Wilson475553d2011-01-20 09:52:56 +0000980 return;
981
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000982 trace_i915_gem_request_notify(engine);
Chris Wilson12471ba2016-04-09 10:57:55 +0100983 engine->user_interrupts++;
Chris Wilson9862e602011-01-04 22:22:17 +0000984
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000985 wake_up_all(&engine->irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +0100986}
987
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000988static void vlv_c0_read(struct drm_i915_private *dev_priv,
989 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400990{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000991 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
992 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
993 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400994}
995
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000996static bool vlv_c0_above(struct drm_i915_private *dev_priv,
997 const struct intel_rps_ei *old,
998 const struct intel_rps_ei *now,
999 int threshold)
Deepak S31685c22014-07-03 17:33:01 -04001000{
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001001 u64 time, c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001002 unsigned int mul = 100;
Deepak S31685c22014-07-03 17:33:01 -04001003
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001004 if (old->cz_clock == 0)
1005 return false;
Deepak S31685c22014-07-03 17:33:01 -04001006
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001007 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
1008 mul <<= 8;
1009
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001010 time = now->cz_clock - old->cz_clock;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001011 time *= threshold * dev_priv->czclk_freq;
Deepak S31685c22014-07-03 17:33:01 -04001012
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001013 /* Workload can be split between render + media, e.g. SwapBuffers
1014 * being blitted in X after being rendered in mesa. To account for
1015 * this we need to combine both engines into our activity counter.
1016 */
1017 c0 = now->render_c0 - old->render_c0;
1018 c0 += now->media_c0 - old->media_c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001019 c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC;
Deepak S31685c22014-07-03 17:33:01 -04001020
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001021 return c0 >= time;
1022}
Deepak S31685c22014-07-03 17:33:01 -04001023
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001024void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1025{
1026 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
1027 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001028}
1029
1030static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1031{
1032 struct intel_rps_ei now;
1033 u32 events = 0;
1034
Chris Wilson6f4b12f82015-03-18 09:48:23 +00001035 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001036 return 0;
1037
1038 vlv_c0_read(dev_priv, &now);
1039 if (now.cz_clock == 0)
1040 return 0;
Deepak S31685c22014-07-03 17:33:01 -04001041
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001042 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1043 if (!vlv_c0_above(dev_priv,
1044 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001045 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001046 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1047 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -04001048 }
1049
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001050 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1051 if (vlv_c0_above(dev_priv,
1052 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001053 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001054 events |= GEN6_PM_RP_UP_THRESHOLD;
1055 dev_priv->rps.up_ei = now;
1056 }
1057
1058 return events;
Deepak S31685c22014-07-03 17:33:01 -04001059}
1060
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001061static bool any_waiters(struct drm_i915_private *dev_priv)
1062{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001063 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001064
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001065 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001066 if (engine->irq_refcount)
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001067 return true;
1068
1069 return false;
1070}
1071
Ben Widawsky4912d042011-04-25 11:25:20 -07001072static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001073{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001074 struct drm_i915_private *dev_priv =
1075 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001076 bool client_boost;
1077 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001078 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001079
Daniel Vetter59cdb632013-07-04 23:35:28 +02001080 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001081 /* Speed up work cancelation during disabling rps interrupts. */
1082 if (!dev_priv->rps.interrupts_enabled) {
1083 spin_unlock_irq(&dev_priv->irq_lock);
1084 return;
1085 }
Imre Deak1f814da2015-12-16 02:52:19 +02001086
1087 /*
1088 * The RPS work is synced during runtime suspend, we don't require a
1089 * wakeref. TODO: instead of disabling the asserts make sure that we
1090 * always hold an RPM reference while the work is running.
1091 */
1092 DISABLE_RPM_WAKEREF_ASSERTS(dev_priv);
1093
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001094 pm_iir = dev_priv->rps.pm_iir;
1095 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001096 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1097 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001098 client_boost = dev_priv->rps.client_boost;
1099 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001100 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001101
Paulo Zanoni60611c12013-08-15 11:50:01 -03001102 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301103 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001104
Chris Wilson8d3afd72015-05-21 21:01:47 +01001105 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Imre Deak1f814da2015-12-16 02:52:19 +02001106 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001107
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001108 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001109
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001110 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1111
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001112 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001113 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001114 min = dev_priv->rps.min_freq_softlimit;
1115 max = dev_priv->rps.max_freq_softlimit;
1116
1117 if (client_boost) {
1118 new_delay = dev_priv->rps.max_freq_softlimit;
1119 adj = 0;
1120 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001121 if (adj > 0)
1122 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001123 else /* CHV needs even encode values */
1124 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001125 /*
1126 * For better performance, jump directly
1127 * to RPe if we're below it.
1128 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001129 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001130 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001131 adj = 0;
1132 }
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001133 } else if (any_waiters(dev_priv)) {
1134 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001135 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001136 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1137 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001138 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001139 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001140 adj = 0;
1141 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1142 if (adj < 0)
1143 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001144 else /* CHV needs even encode values */
1145 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001146 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001147 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001148 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001149
Chris Wilsonedcf2842015-04-07 16:20:29 +01001150 dev_priv->rps.last_adj = adj;
1151
Ben Widawsky79249632012-09-07 19:43:42 -07001152 /* sysfs frequency interfaces may have snuck in while servicing the
1153 * interrupt
1154 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001155 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001156 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301157
Chris Wilsondc979972016-05-10 14:10:04 +01001158 intel_set_rps(dev_priv, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001159
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001160 mutex_unlock(&dev_priv->rps.hw_lock);
Imre Deak1f814da2015-12-16 02:52:19 +02001161out:
1162 ENABLE_RPM_WAKEREF_ASSERTS(dev_priv);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001163}
1164
Ben Widawskye3689192012-05-25 16:56:22 -07001165
1166/**
1167 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1168 * occurred.
1169 * @work: workqueue struct
1170 *
1171 * Doesn't actually do anything except notify userspace. As a consequence of
1172 * this event, userspace should try to remap the bad rows since statistically
1173 * it is likely the same row is more likely to go bad again.
1174 */
1175static void ivybridge_parity_work(struct work_struct *work)
1176{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001177 struct drm_i915_private *dev_priv =
1178 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001179 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001180 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001181 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001182 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001183
1184 /* We must turn off DOP level clock gating to access the L3 registers.
1185 * In order to prevent a get/put style interface, acquire struct mutex
1186 * any time we access those registers.
1187 */
1188 mutex_lock(&dev_priv->dev->struct_mutex);
1189
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001190 /* If we've screwed up tracking, just let the interrupt fire again */
1191 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1192 goto out;
1193
Ben Widawskye3689192012-05-25 16:56:22 -07001194 misccpctl = I915_READ(GEN7_MISCCPCTL);
1195 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1196 POSTING_READ(GEN7_MISCCPCTL);
1197
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001198 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001199 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001200
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001201 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001202 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001203 break;
1204
1205 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1206
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001207 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001208
1209 error_status = I915_READ(reg);
1210 row = GEN7_PARITY_ERROR_ROW(error_status);
1211 bank = GEN7_PARITY_ERROR_BANK(error_status);
1212 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1213
1214 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1215 POSTING_READ(reg);
1216
1217 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1218 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1219 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1220 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1221 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1222 parity_event[5] = NULL;
1223
Dave Airlie5bdebb12013-10-11 14:07:25 +10001224 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001225 KOBJ_CHANGE, parity_event);
1226
1227 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1228 slice, row, bank, subbank);
1229
1230 kfree(parity_event[4]);
1231 kfree(parity_event[3]);
1232 kfree(parity_event[2]);
1233 kfree(parity_event[1]);
1234 }
Ben Widawskye3689192012-05-25 16:56:22 -07001235
1236 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1237
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001238out:
1239 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001240 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001241 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001242 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001243
1244 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001245}
1246
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001247static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1248 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001249{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001250 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001251 return;
1252
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001253 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001254 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001255 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001256
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001257 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001258 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1259 dev_priv->l3_parity.which_slice |= 1 << 1;
1260
1261 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1262 dev_priv->l3_parity.which_slice |= 1 << 0;
1263
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001264 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001265}
1266
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001267static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001268 u32 gt_iir)
1269{
1270 if (gt_iir &
1271 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001272 notify_ring(&dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001273 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001274 notify_ring(&dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001275}
1276
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001277static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001278 u32 gt_iir)
1279{
1280
Ben Widawskycc609d52013-05-28 19:22:29 -07001281 if (gt_iir &
1282 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001283 notify_ring(&dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001284 if (gt_iir & GT_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001285 notify_ring(&dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001286 if (gt_iir & GT_BLT_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001287 notify_ring(&dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001288
Ben Widawskycc609d52013-05-28 19:22:29 -07001289 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1290 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001291 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1292 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001293
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001294 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1295 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001296}
1297
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001298static __always_inline void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001299gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001300{
1301 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift))
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001302 notify_ring(engine);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001303 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift))
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01001304 tasklet_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001305}
1306
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001307static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1308 u32 master_ctl,
1309 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001310{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001311 irqreturn_t ret = IRQ_NONE;
1312
1313 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001314 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1315 if (gt_iir[0]) {
1316 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001317 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001318 } else
1319 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1320 }
1321
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001322 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001323 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1324 if (gt_iir[1]) {
1325 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001326 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001327 } else
1328 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1329 }
1330
Chris Wilson74cdb332015-04-07 16:21:05 +01001331 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001332 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1333 if (gt_iir[3]) {
1334 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001335 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001336 } else
1337 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1338 }
1339
Ben Widawsky09610212014-05-15 20:58:08 +03001340 if (master_ctl & GEN8_GT_PM_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001341 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
1342 if (gt_iir[2] & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001343 I915_WRITE_FW(GEN8_GT_IIR(2),
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001344 gt_iir[2] & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001345 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001346 } else
1347 DRM_ERROR("The master control interrupt lied (PM)!\n");
1348 }
1349
Ben Widawskyabd58f02013-11-02 21:07:09 -07001350 return ret;
1351}
1352
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001353static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1354 u32 gt_iir[4])
1355{
1356 if (gt_iir[0]) {
1357 gen8_cs_irq_handler(&dev_priv->engine[RCS],
1358 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
1359 gen8_cs_irq_handler(&dev_priv->engine[BCS],
1360 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1361 }
1362
1363 if (gt_iir[1]) {
1364 gen8_cs_irq_handler(&dev_priv->engine[VCS],
1365 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
1366 gen8_cs_irq_handler(&dev_priv->engine[VCS2],
1367 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1368 }
1369
1370 if (gt_iir[3])
1371 gen8_cs_irq_handler(&dev_priv->engine[VECS],
1372 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1373
1374 if (gt_iir[2] & dev_priv->pm_rps_events)
1375 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
1376}
1377
Imre Deak63c88d22015-07-20 14:43:39 -07001378static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1379{
1380 switch (port) {
1381 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001382 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001383 case PORT_B:
1384 return val & PORTB_HOTPLUG_LONG_DETECT;
1385 case PORT_C:
1386 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001387 default:
1388 return false;
1389 }
1390}
1391
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001392static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1393{
1394 switch (port) {
1395 case PORT_E:
1396 return val & PORTE_HOTPLUG_LONG_DETECT;
1397 default:
1398 return false;
1399 }
1400}
1401
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001402static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1403{
1404 switch (port) {
1405 case PORT_A:
1406 return val & PORTA_HOTPLUG_LONG_DETECT;
1407 case PORT_B:
1408 return val & PORTB_HOTPLUG_LONG_DETECT;
1409 case PORT_C:
1410 return val & PORTC_HOTPLUG_LONG_DETECT;
1411 case PORT_D:
1412 return val & PORTD_HOTPLUG_LONG_DETECT;
1413 default:
1414 return false;
1415 }
1416}
1417
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001418static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1419{
1420 switch (port) {
1421 case PORT_A:
1422 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1423 default:
1424 return false;
1425 }
1426}
1427
Jani Nikula676574d2015-05-28 15:43:53 +03001428static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001429{
1430 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001431 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001432 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001433 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001434 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001435 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001436 return val & PORTD_HOTPLUG_LONG_DETECT;
1437 default:
1438 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001439 }
1440}
1441
Jani Nikula676574d2015-05-28 15:43:53 +03001442static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001443{
1444 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001445 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001446 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001447 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001448 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001449 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001450 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1451 default:
1452 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001453 }
1454}
1455
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001456/*
1457 * Get a bit mask of pins that have triggered, and which ones may be long.
1458 * This can be called multiple times with the same masks to accumulate
1459 * hotplug detection results from several registers.
1460 *
1461 * Note that the caller is expected to zero out the masks initially.
1462 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001463static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001464 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001465 const u32 hpd[HPD_NUM_PINS],
1466 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001467{
Jani Nikula8c841e52015-06-18 13:06:17 +03001468 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001469 int i;
1470
Jani Nikula676574d2015-05-28 15:43:53 +03001471 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001472 if ((hpd[i] & hotplug_trigger) == 0)
1473 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001474
Jani Nikula8c841e52015-06-18 13:06:17 +03001475 *pin_mask |= BIT(i);
1476
Imre Deakcc24fcd2015-07-21 15:32:45 -07001477 if (!intel_hpd_pin_to_port(i, &port))
1478 continue;
1479
Imre Deakfd63e2a2015-07-21 15:32:44 -07001480 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001481 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001482 }
1483
1484 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1485 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1486
1487}
1488
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001489static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001490{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001491 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001492}
1493
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001494static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001495{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001496 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001497}
1498
Shuang He8bf1e9f2013-10-15 18:55:27 +01001499#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001500static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1501 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001502 uint32_t crc0, uint32_t crc1,
1503 uint32_t crc2, uint32_t crc3,
1504 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001505{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001506 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1507 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001508 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001509
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001510 spin_lock(&pipe_crc->lock);
1511
Damien Lespiau0c912c72013-10-15 18:55:37 +01001512 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001513 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001514 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001515 return;
1516 }
1517
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001518 head = pipe_crc->head;
1519 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001520
1521 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001522 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001523 DRM_ERROR("CRC buffer overflowing\n");
1524 return;
1525 }
1526
1527 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001528
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001529 entry->frame = dev_priv->dev->driver->get_vblank_counter(dev_priv->dev,
1530 pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001531 entry->crc[0] = crc0;
1532 entry->crc[1] = crc1;
1533 entry->crc[2] = crc2;
1534 entry->crc[3] = crc3;
1535 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001536
1537 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001538 pipe_crc->head = head;
1539
1540 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001541
1542 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001543}
Daniel Vetter277de952013-10-18 16:37:07 +02001544#else
1545static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001546display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1547 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001548 uint32_t crc0, uint32_t crc1,
1549 uint32_t crc2, uint32_t crc3,
1550 uint32_t crc4) {}
1551#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001552
Daniel Vetter277de952013-10-18 16:37:07 +02001553
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001554static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1555 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001556{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001557 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001558 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1559 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001560}
1561
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001562static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1563 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001564{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001565 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001566 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1567 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1568 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1569 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1570 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001571}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001572
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001573static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1574 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001575{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001576 uint32_t res1, res2;
1577
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001578 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001579 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1580 else
1581 res1 = 0;
1582
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001583 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001584 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1585 else
1586 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001587
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001588 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001589 I915_READ(PIPE_CRC_RES_RED(pipe)),
1590 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1591 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1592 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001593}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001594
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001595/* The RPS events need forcewake, so we add them to a work queue and mask their
1596 * IMR bits until the work is done. Other interrupts can be processed without
1597 * the work queue. */
1598static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001599{
Deepak Sa6706b42014-03-15 20:23:22 +05301600 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001601 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001602 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001603 if (dev_priv->rps.interrupts_enabled) {
1604 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1605 queue_work(dev_priv->wq, &dev_priv->rps.work);
1606 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001607 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001608 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001609
Imre Deakc9a9a262014-11-05 20:48:37 +02001610 if (INTEL_INFO(dev_priv)->gen >= 8)
1611 return;
1612
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001613 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001614 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001615 notify_ring(&dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001616
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001617 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1618 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001619 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001620}
1621
Daniel Vetter5a21b662016-05-24 17:13:53 +02001622static bool intel_pipe_handle_vblank(struct drm_i915_private *dev_priv,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001623 enum pipe pipe)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001624{
Daniel Vetter5a21b662016-05-24 17:13:53 +02001625 bool ret;
1626
1627 ret = drm_handle_vblank(dev_priv->dev, pipe);
1628 if (ret)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001629 intel_finish_page_flip_mmio(dev_priv, pipe);
Daniel Vetter5a21b662016-05-24 17:13:53 +02001630
1631 return ret;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001632}
1633
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001634static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1635 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001636{
Imre Deakc1874ed2014-02-04 21:35:46 +02001637 int pipe;
1638
Imre Deak58ead0d2014-02-04 21:35:47 +02001639 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001640
1641 if (!dev_priv->display_irqs_enabled) {
1642 spin_unlock(&dev_priv->irq_lock);
1643 return;
1644 }
1645
Damien Lespiau055e3932014-08-18 13:49:10 +01001646 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001647 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001648 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001649
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001650 /*
1651 * PIPESTAT bits get signalled even when the interrupt is
1652 * disabled with the mask bits, and some of the status bits do
1653 * not generate interrupts at all (like the underrun bit). Hence
1654 * we need to be careful that we only handle what we want to
1655 * handle.
1656 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001657
1658 /* fifo underruns are filterered in the underrun handler. */
1659 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001660
1661 switch (pipe) {
1662 case PIPE_A:
1663 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1664 break;
1665 case PIPE_B:
1666 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1667 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001668 case PIPE_C:
1669 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1670 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001671 }
1672 if (iir & iir_bit)
1673 mask |= dev_priv->pipestat_irq_mask[pipe];
1674
1675 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001676 continue;
1677
1678 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001679 mask |= PIPESTAT_INT_ENABLE_MASK;
1680 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001681
1682 /*
1683 * Clear the PIPE*STAT regs before the IIR
1684 */
Imre Deak91d181d2014-02-10 18:42:49 +02001685 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1686 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001687 I915_WRITE(reg, pipe_stats[pipe]);
1688 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001689 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001690}
1691
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001692static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001693 u32 pipe_stats[I915_MAX_PIPES])
1694{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001695 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001696
Damien Lespiau055e3932014-08-18 13:49:10 +01001697 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02001698 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1699 intel_pipe_handle_vblank(dev_priv, pipe))
1700 intel_check_page_flip(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001701
Maarten Lankhorst5251f042016-05-17 15:07:47 +02001702 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001703 intel_finish_page_flip_cs(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001704
1705 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001706 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001707
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001708 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1709 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001710 }
1711
1712 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001713 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001714}
1715
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001716static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001717{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001718 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001719
1720 if (hotplug_status)
1721 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1722
1723 return hotplug_status;
1724}
1725
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001726static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001727 u32 hotplug_status)
1728{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001729 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001730
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001731 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1732 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001733 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
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,
1737 hotplug_trigger, hpd_status_g4x,
1738 i9xx_port_hotplug_long_detect);
1739
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001740 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001741 }
Jani Nikula369712e2015-05-27 15:03:40 +03001742
1743 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001744 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001745 } else {
1746 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001747
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001748 if (hotplug_trigger) {
1749 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001750 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001751 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001752 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001753 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001754 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001755}
1756
Daniel Vetterff1f5252012-10-02 15:10:55 +02001757static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001758{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001759 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001760 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001761 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001762
Imre Deak2dd2a882015-02-24 11:14:30 +02001763 if (!intel_irqs_enabled(dev_priv))
1764 return IRQ_NONE;
1765
Imre Deak1f814da2015-12-16 02:52:19 +02001766 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1767 disable_rpm_wakeref_asserts(dev_priv);
1768
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001769 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001770 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001771 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001772 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001773 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001774
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001775 gt_iir = I915_READ(GTIIR);
1776 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001777 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001778
1779 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001780 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001781
1782 ret = IRQ_HANDLED;
1783
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001784 /*
1785 * Theory on interrupt generation, based on empirical evidence:
1786 *
1787 * x = ((VLV_IIR & VLV_IER) ||
1788 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1789 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1790 *
1791 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1792 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1793 * guarantee the CPU interrupt will be raised again even if we
1794 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1795 * bits this time around.
1796 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001797 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001798 ier = I915_READ(VLV_IER);
1799 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001800
1801 if (gt_iir)
1802 I915_WRITE(GTIIR, gt_iir);
1803 if (pm_iir)
1804 I915_WRITE(GEN6_PMIIR, pm_iir);
1805
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001806 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001807 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001808
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001809 /* Call regardless, as some status bits might not be
1810 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001811 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001812
1813 /*
1814 * VLV_IIR is single buffered, and reflects the level
1815 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1816 */
1817 if (iir)
1818 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001819
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001820 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001821 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1822 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001823
Ville Syrjälä52894872016-04-13 21:19:56 +03001824 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001825 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03001826 if (pm_iir)
1827 gen6_rps_irq_handler(dev_priv, pm_iir);
1828
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001829 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001830 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001831
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001832 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001833 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001834
Imre Deak1f814da2015-12-16 02:52:19 +02001835 enable_rpm_wakeref_asserts(dev_priv);
1836
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001837 return ret;
1838}
1839
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001840static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1841{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001842 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001843 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001844 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001845
Imre Deak2dd2a882015-02-24 11:14:30 +02001846 if (!intel_irqs_enabled(dev_priv))
1847 return IRQ_NONE;
1848
Imre Deak1f814da2015-12-16 02:52:19 +02001849 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1850 disable_rpm_wakeref_asserts(dev_priv);
1851
Chris Wilson579de732016-03-14 09:01:57 +00001852 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001853 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001854 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001855 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001856 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001857 u32 ier = 0;
1858
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001859 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1860 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001861
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001862 if (master_ctl == 0 && iir == 0)
1863 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001864
Oscar Mateo27b6c122014-06-16 16:11:00 +01001865 ret = IRQ_HANDLED;
1866
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001867 /*
1868 * Theory on interrupt generation, based on empirical evidence:
1869 *
1870 * x = ((VLV_IIR & VLV_IER) ||
1871 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1872 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1873 *
1874 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1875 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1876 * guarantee the CPU interrupt will be raised again even if we
1877 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1878 * bits this time around.
1879 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001880 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001881 ier = I915_READ(VLV_IER);
1882 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001883
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001884 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001885
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001886 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001887 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001888
Oscar Mateo27b6c122014-06-16 16:11:00 +01001889 /* Call regardless, as some status bits might not be
1890 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001891 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001892
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001893 /*
1894 * VLV_IIR is single buffered, and reflects the level
1895 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1896 */
1897 if (iir)
1898 I915_WRITE(VLV_IIR, iir);
1899
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001900 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03001901 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001902 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001903
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001904 gen8_gt_irq_handler(dev_priv, gt_iir);
1905
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001906 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001907 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001908
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001909 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00001910 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001911
Imre Deak1f814da2015-12-16 02:52:19 +02001912 enable_rpm_wakeref_asserts(dev_priv);
1913
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001914 return ret;
1915}
1916
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001917static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1918 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03001919 const u32 hpd[HPD_NUM_PINS])
1920{
Ville Syrjälä40e56412015-08-27 23:56:10 +03001921 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1922
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001923 /*
1924 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1925 * unless we touch the hotplug register, even if hotplug_trigger is
1926 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1927 * errors.
1928 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03001929 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001930 if (!hotplug_trigger) {
1931 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1932 PORTD_HOTPLUG_STATUS_MASK |
1933 PORTC_HOTPLUG_STATUS_MASK |
1934 PORTB_HOTPLUG_STATUS_MASK;
1935 dig_hotplug_reg &= ~mask;
1936 }
1937
Ville Syrjälä40e56412015-08-27 23:56:10 +03001938 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001939 if (!hotplug_trigger)
1940 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03001941
1942 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1943 dig_hotplug_reg, hpd,
1944 pch_port_hotplug_long_detect);
1945
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001946 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03001947}
1948
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001949static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001950{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001951 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001952 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001953
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001954 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001955
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001956 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1957 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1958 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001959 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001960 port_name(port));
1961 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001962
Daniel Vetterce99c252012-12-01 13:53:47 +01001963 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001964 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01001965
Jesse Barnes776ad802011-01-04 15:09:39 -08001966 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001967 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08001968
1969 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1970 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1971
1972 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1973 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1974
1975 if (pch_iir & SDE_POISON)
1976 DRM_ERROR("PCH poison interrupt\n");
1977
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001978 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001979 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001980 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1981 pipe_name(pipe),
1982 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001983
1984 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1985 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1986
1987 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1988 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1989
Jesse Barnes776ad802011-01-04 15:09:39 -08001990 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001991 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001992
1993 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001994 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001995}
1996
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001997static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03001998{
Paulo Zanoni86642812013-04-12 17:57:57 -03001999 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002000 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002001
Paulo Zanonide032bf2013-04-12 17:57:58 -03002002 if (err_int & ERR_INT_POISON)
2003 DRM_ERROR("Poison interrupt\n");
2004
Damien Lespiau055e3932014-08-18 13:49:10 +01002005 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002006 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2007 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002008
Daniel Vetter5a69b892013-10-16 22:55:52 +02002009 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002010 if (IS_IVYBRIDGE(dev_priv))
2011 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002012 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002013 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002014 }
2015 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002016
Paulo Zanoni86642812013-04-12 17:57:57 -03002017 I915_WRITE(GEN7_ERR_INT, err_int);
2018}
2019
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002020static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002021{
Paulo Zanoni86642812013-04-12 17:57:57 -03002022 u32 serr_int = I915_READ(SERR_INT);
2023
Paulo Zanonide032bf2013-04-12 17:57:58 -03002024 if (serr_int & SERR_INT_POISON)
2025 DRM_ERROR("PCH poison interrupt\n");
2026
Paulo Zanoni86642812013-04-12 17:57:57 -03002027 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002028 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002029
2030 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002031 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002032
2033 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002034 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002035
2036 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002037}
2038
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002039static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002040{
Adam Jackson23e81d62012-06-06 15:45:44 -04002041 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002042 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002043
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002044 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002045
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002046 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2047 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2048 SDE_AUDIO_POWER_SHIFT_CPT);
2049 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2050 port_name(port));
2051 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002052
2053 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002054 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002055
2056 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002057 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002058
2059 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2060 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2061
2062 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2063 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2064
2065 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002066 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002067 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2068 pipe_name(pipe),
2069 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002070
2071 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002072 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002073}
2074
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002075static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002076{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002077 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2078 ~SDE_PORTE_HOTPLUG_SPT;
2079 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2080 u32 pin_mask = 0, long_mask = 0;
2081
2082 if (hotplug_trigger) {
2083 u32 dig_hotplug_reg;
2084
2085 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2086 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2087
2088 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2089 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002090 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002091 }
2092
2093 if (hotplug2_trigger) {
2094 u32 dig_hotplug_reg;
2095
2096 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2097 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2098
2099 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2100 dig_hotplug_reg, hpd_spt,
2101 spt_port_hotplug2_long_detect);
2102 }
2103
2104 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002105 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002106
2107 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002108 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002109}
2110
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002111static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2112 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002113 const u32 hpd[HPD_NUM_PINS])
2114{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002115 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2116
2117 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2118 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2119
2120 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2121 dig_hotplug_reg, hpd,
2122 ilk_port_hotplug_long_detect);
2123
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002124 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002125}
2126
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002127static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2128 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002129{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002130 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002131 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2132
Ville Syrjälä40e56412015-08-27 23:56:10 +03002133 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002134 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002135
2136 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002137 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002138
2139 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002140 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002141
Paulo Zanonic008bc62013-07-12 16:35:10 -03002142 if (de_iir & DE_POISON)
2143 DRM_ERROR("Poison interrupt\n");
2144
Damien Lespiau055e3932014-08-18 13:49:10 +01002145 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002146 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2147 intel_pipe_handle_vblank(dev_priv, pipe))
2148 intel_check_page_flip(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002149
Daniel Vetter40da17c22013-10-21 18:04:36 +02002150 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002151 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002152
Daniel Vetter40da17c22013-10-21 18:04:36 +02002153 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002154 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002155
Daniel Vetter40da17c22013-10-21 18:04:36 +02002156 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002157 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002158 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002159 }
2160
2161 /* check event from PCH */
2162 if (de_iir & DE_PCH_EVENT) {
2163 u32 pch_iir = I915_READ(SDEIIR);
2164
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002165 if (HAS_PCH_CPT(dev_priv))
2166 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002167 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002168 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002169
2170 /* should clear PCH hotplug event before clear CPU irq */
2171 I915_WRITE(SDEIIR, pch_iir);
2172 }
2173
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002174 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2175 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002176}
2177
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002178static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2179 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002180{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002181 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002182 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2183
Ville Syrjälä40e56412015-08-27 23:56:10 +03002184 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002185 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002186
2187 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002188 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002189
2190 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002191 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002192
2193 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002194 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002195
Damien Lespiau055e3932014-08-18 13:49:10 +01002196 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002197 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2198 intel_pipe_handle_vblank(dev_priv, pipe))
2199 intel_check_page_flip(dev_priv, pipe);
Daniel Vetter40da17c22013-10-21 18:04:36 +02002200
2201 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002202 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002203 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002204 }
2205
2206 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002207 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002208 u32 pch_iir = I915_READ(SDEIIR);
2209
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002210 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002211
2212 /* clear PCH hotplug event before clear CPU irq */
2213 I915_WRITE(SDEIIR, pch_iir);
2214 }
2215}
2216
Oscar Mateo72c90f62014-06-16 16:10:57 +01002217/*
2218 * To handle irqs with the minimum potential races with fresh interrupts, we:
2219 * 1 - Disable Master Interrupt Control.
2220 * 2 - Find the source(s) of the interrupt.
2221 * 3 - Clear the Interrupt Identity bits (IIR).
2222 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2223 * 5 - Re-enable Master Interrupt Control.
2224 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002225static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002226{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002227 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002228 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002229 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002230 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002231
Imre Deak2dd2a882015-02-24 11:14:30 +02002232 if (!intel_irqs_enabled(dev_priv))
2233 return IRQ_NONE;
2234
Imre Deak1f814da2015-12-16 02:52:19 +02002235 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2236 disable_rpm_wakeref_asserts(dev_priv);
2237
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002238 /* disable master interrupt before clearing iir */
2239 de_ier = I915_READ(DEIER);
2240 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002241 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002242
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002243 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2244 * interrupts will will be stored on its back queue, and then we'll be
2245 * able to process them after we restore SDEIER (as soon as we restore
2246 * it, we'll get an interrupt if SDEIIR still has something to process
2247 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002248 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002249 sde_ier = I915_READ(SDEIER);
2250 I915_WRITE(SDEIER, 0);
2251 POSTING_READ(SDEIER);
2252 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002253
Oscar Mateo72c90f62014-06-16 16:10:57 +01002254 /* Find, clear, then process each source of interrupt */
2255
Chris Wilson0e434062012-05-09 21:45:44 +01002256 gt_iir = I915_READ(GTIIR);
2257 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002258 I915_WRITE(GTIIR, gt_iir);
2259 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002260 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002261 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002262 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002263 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002264 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002265
2266 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002267 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002268 I915_WRITE(DEIIR, de_iir);
2269 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002270 if (INTEL_GEN(dev_priv) >= 7)
2271 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002272 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002273 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002274 }
2275
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002276 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002277 u32 pm_iir = I915_READ(GEN6_PMIIR);
2278 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002279 I915_WRITE(GEN6_PMIIR, pm_iir);
2280 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002281 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002282 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002283 }
2284
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002285 I915_WRITE(DEIER, de_ier);
2286 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002287 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002288 I915_WRITE(SDEIER, sde_ier);
2289 POSTING_READ(SDEIER);
2290 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002291
Imre Deak1f814da2015-12-16 02:52:19 +02002292 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2293 enable_rpm_wakeref_asserts(dev_priv);
2294
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002295 return ret;
2296}
2297
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002298static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2299 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002300 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302301{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002302 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302303
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002304 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2305 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302306
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002307 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002308 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002309 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002310
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002311 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302312}
2313
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002314static irqreturn_t
2315gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002316{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002317 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002318 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002319 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002320
Ben Widawskyabd58f02013-11-02 21:07:09 -07002321 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002322 iir = I915_READ(GEN8_DE_MISC_IIR);
2323 if (iir) {
2324 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002325 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002326 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002327 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002328 else
2329 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002330 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002331 else
2332 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002333 }
2334
Daniel Vetter6d766f02013-11-07 14:49:55 +01002335 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002336 iir = I915_READ(GEN8_DE_PORT_IIR);
2337 if (iir) {
2338 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302339 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002340
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002341 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002342 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002343
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002344 tmp_mask = GEN8_AUX_CHANNEL_A;
2345 if (INTEL_INFO(dev_priv)->gen >= 9)
2346 tmp_mask |= GEN9_AUX_CHANNEL_B |
2347 GEN9_AUX_CHANNEL_C |
2348 GEN9_AUX_CHANNEL_D;
2349
2350 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002351 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302352 found = true;
2353 }
2354
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002355 if (IS_BROXTON(dev_priv)) {
2356 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2357 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002358 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2359 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002360 found = true;
2361 }
2362 } else if (IS_BROADWELL(dev_priv)) {
2363 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2364 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002365 ilk_hpd_irq_handler(dev_priv,
2366 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002367 found = true;
2368 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302369 }
2370
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002371 if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
2372 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302373 found = true;
2374 }
2375
Shashank Sharmad04a4922014-08-22 17:40:41 +05302376 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002377 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002378 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002379 else
2380 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002381 }
2382
Damien Lespiau055e3932014-08-18 13:49:10 +01002383 for_each_pipe(dev_priv, pipe) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002384 u32 flip_done, fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002385
Daniel Vetterc42664c2013-11-07 11:05:40 +01002386 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2387 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002388
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002389 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2390 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002391 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002392 continue;
2393 }
2394
2395 ret = IRQ_HANDLED;
2396 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2397
Daniel Vetter5a21b662016-05-24 17:13:53 +02002398 if (iir & GEN8_PIPE_VBLANK &&
2399 intel_pipe_handle_vblank(dev_priv, pipe))
2400 intel_check_page_flip(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002401
2402 flip_done = iir;
2403 if (INTEL_INFO(dev_priv)->gen >= 9)
2404 flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE;
2405 else
2406 flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE;
2407
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002408 if (flip_done)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002409 intel_finish_page_flip_cs(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002410
2411 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002412 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002413
2414 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2415 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2416
2417 fault_errors = iir;
2418 if (INTEL_INFO(dev_priv)->gen >= 9)
2419 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2420 else
2421 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2422
2423 if (fault_errors)
2424 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2425 pipe_name(pipe),
2426 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002427 }
2428
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002429 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302430 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002431 /*
2432 * FIXME(BDW): Assume for now that the new interrupt handling
2433 * scheme also closed the SDE interrupt handling race we've seen
2434 * on older pch-split platforms. But this needs testing.
2435 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002436 iir = I915_READ(SDEIIR);
2437 if (iir) {
2438 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002439 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002440
2441 if (HAS_PCH_SPT(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002442 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002443 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002444 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002445 } else {
2446 /*
2447 * Like on previous PCH there seems to be something
2448 * fishy going on with forwarding PCH interrupts.
2449 */
2450 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2451 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002452 }
2453
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002454 return ret;
2455}
2456
2457static irqreturn_t gen8_irq_handler(int irq, void *arg)
2458{
2459 struct drm_device *dev = arg;
2460 struct drm_i915_private *dev_priv = dev->dev_private;
2461 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002462 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002463 irqreturn_t ret;
2464
2465 if (!intel_irqs_enabled(dev_priv))
2466 return IRQ_NONE;
2467
2468 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2469 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2470 if (!master_ctl)
2471 return IRQ_NONE;
2472
2473 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2474
2475 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2476 disable_rpm_wakeref_asserts(dev_priv);
2477
2478 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002479 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2480 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002481 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2482
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002483 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2484 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002485
Imre Deak1f814da2015-12-16 02:52:19 +02002486 enable_rpm_wakeref_asserts(dev_priv);
2487
Ben Widawskyabd58f02013-11-02 21:07:09 -07002488 return ret;
2489}
2490
Daniel Vetter17e1df02013-09-08 21:57:13 +02002491static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2492 bool reset_completed)
2493{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002494 struct intel_engine_cs *engine;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002495
2496 /*
2497 * Notify all waiters for GPU completion events that reset state has
2498 * been changed, and that they need to restart their wait after
2499 * checking for potential errors (and bail out to drop locks if there is
2500 * a gpu reset pending so that i915_error_work_func can acquire them).
2501 */
2502
2503 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002504 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002505 wake_up_all(&engine->irq_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002506
2507 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2508 wake_up_all(&dev_priv->pending_flip_queue);
2509
2510 /*
2511 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2512 * reset state is cleared.
2513 */
2514 if (reset_completed)
2515 wake_up_all(&dev_priv->gpu_error.reset_queue);
2516}
2517
Jesse Barnes8a905232009-07-11 16:48:03 -04002518/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002519 * i915_reset_and_wakeup - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002520 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002521 *
2522 * Fire an error uevent so userspace can see that a hang or error
2523 * was detected.
2524 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002525static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002526{
Chris Wilsonc0336662016-05-06 15:40:21 +01002527 struct kobject *kobj = &dev_priv->dev->primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002528 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2529 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2530 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002531 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002532
Chris Wilsonc0336662016-05-06 15:40:21 +01002533 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002534
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002535 /*
2536 * Note that there's only one work item which does gpu resets, so we
2537 * need not worry about concurrent gpu resets potentially incrementing
2538 * error->reset_counter twice. We only need to take care of another
2539 * racing irq/hangcheck declaring the gpu dead for a second time. A
2540 * quick check for that is good enough: schedule_work ensures the
2541 * correct ordering between hang detection and this work item, and since
2542 * the reset in-progress bit is only ever set by code outside of this
2543 * work we don't need to worry about any other races.
2544 */
Chris Wilsond98c52c2016-04-13 17:35:05 +01002545 if (i915_reset_in_progress(&dev_priv->gpu_error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002546 DRM_DEBUG_DRIVER("resetting chip\n");
Chris Wilsonc0336662016-05-06 15:40:21 +01002547 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002548
Daniel Vetter17e1df02013-09-08 21:57:13 +02002549 /*
Imre Deakf454c692014-04-23 01:09:04 +03002550 * In most cases it's guaranteed that we get here with an RPM
2551 * reference held, for example because there is a pending GPU
2552 * request that won't finish until the reset is done. This
2553 * isn't the case at least when we get here by doing a
2554 * simulated reset via debugs, so get an RPM reference.
2555 */
2556 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002557
Chris Wilsonc0336662016-05-06 15:40:21 +01002558 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002559
Imre Deakf454c692014-04-23 01:09:04 +03002560 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002561 * All state reset _must_ be completed before we update the
2562 * reset counter, for otherwise waiters might miss the reset
2563 * pending state and not properly drop locks, resulting in
2564 * deadlocks with the reset work.
2565 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002566 ret = i915_reset(dev_priv);
Daniel Vetterf69061b2012-12-06 09:01:42 +01002567
Chris Wilsonc0336662016-05-06 15:40:21 +01002568 intel_finish_reset(dev_priv);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002569
Imre Deakf454c692014-04-23 01:09:04 +03002570 intel_runtime_pm_put(dev_priv);
2571
Chris Wilsond98c52c2016-04-13 17:35:05 +01002572 if (ret == 0)
Chris Wilsonc0336662016-05-06 15:40:21 +01002573 kobject_uevent_env(kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002574 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002575
Daniel Vetter17e1df02013-09-08 21:57:13 +02002576 /*
2577 * Note: The wake_up also serves as a memory barrier so that
2578 * waiters see the update value of the reset counter atomic_t.
2579 */
2580 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002581 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002582}
2583
Chris Wilsonc0336662016-05-06 15:40:21 +01002584static void i915_report_and_clear_eir(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002585{
Ben Widawskybd9854f2012-08-23 15:18:09 -07002586 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002587 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002588 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002589
Chris Wilson35aed2e2010-05-27 13:18:12 +01002590 if (!eir)
2591 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002592
Joe Perchesa70491c2012-03-18 13:00:11 -07002593 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002594
Chris Wilsonc0336662016-05-06 15:40:21 +01002595 i915_get_extra_instdone(dev_priv, instdone);
Ben Widawskybd9854f2012-08-23 15:18:09 -07002596
Chris Wilsonc0336662016-05-06 15:40:21 +01002597 if (IS_G4X(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002598 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2599 u32 ipeir = I915_READ(IPEIR_I965);
2600
Joe Perchesa70491c2012-03-18 13:00:11 -07002601 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2602 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002603 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2604 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002605 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002606 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002607 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002608 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002609 }
2610 if (eir & GM45_ERROR_PAGE_TABLE) {
2611 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002612 pr_err("page table error\n");
2613 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002614 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002615 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002616 }
2617 }
2618
Chris Wilsonc0336662016-05-06 15:40:21 +01002619 if (!IS_GEN2(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002620 if (eir & I915_ERROR_PAGE_TABLE) {
2621 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002622 pr_err("page table error\n");
2623 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002624 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002625 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002626 }
2627 }
2628
2629 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002630 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002631 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002632 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002633 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002634 /* pipestat has already been acked */
2635 }
2636 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002637 pr_err("instruction error\n");
2638 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002639 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2640 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsonc0336662016-05-06 15:40:21 +01002641 if (INTEL_GEN(dev_priv) < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002642 u32 ipeir = I915_READ(IPEIR);
2643
Joe Perchesa70491c2012-03-18 13:00:11 -07002644 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2645 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002646 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002647 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002648 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002649 } else {
2650 u32 ipeir = I915_READ(IPEIR_I965);
2651
Joe Perchesa70491c2012-03-18 13:00:11 -07002652 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2653 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002654 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002655 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002656 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002657 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002658 }
2659 }
2660
2661 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002662 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002663 eir = I915_READ(EIR);
2664 if (eir) {
2665 /*
2666 * some errors might have become stuck,
2667 * mask them.
2668 */
2669 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2670 I915_WRITE(EMR, I915_READ(EMR) | eir);
2671 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2672 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002673}
2674
2675/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002676 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002677 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002678 * @engine_mask: mask representing engines that are hung
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002679 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002680 * dump it to the syslog. Also call i915_capture_error_state() to make
2681 * sure we get a record and make it available in debugfs. Fire a uevent
2682 * so userspace knows something bad happened (should trigger collection
2683 * of a ring dump etc.).
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002684 * @fmt: Error message format string
Chris Wilson35aed2e2010-05-27 13:18:12 +01002685 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002686void i915_handle_error(struct drm_i915_private *dev_priv,
2687 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002688 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002689{
Mika Kuoppala58174462014-02-25 17:11:26 +02002690 va_list args;
2691 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002692
Mika Kuoppala58174462014-02-25 17:11:26 +02002693 va_start(args, fmt);
2694 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2695 va_end(args);
2696
Chris Wilsonc0336662016-05-06 15:40:21 +01002697 i915_capture_error_state(dev_priv, engine_mask, error_msg);
2698 i915_report_and_clear_eir(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002699
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002700 if (engine_mask) {
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002701 atomic_or(I915_RESET_IN_PROGRESS_FLAG,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002702 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002703
Ben Gamari11ed50e2009-09-14 17:48:45 -04002704 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002705 * Wakeup waiting processes so that the reset function
2706 * i915_reset_and_wakeup doesn't deadlock trying to grab
2707 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002708 * processes will see a reset in progress and back off,
2709 * releasing their locks and then wait for the reset completion.
2710 * We must do this for _all_ gpu waiters that might hold locks
2711 * that the reset work needs to acquire.
2712 *
2713 * Note: The wake_up serves as the required memory barrier to
2714 * ensure that the waiters see the updated value of the reset
2715 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002716 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002717 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002718 }
2719
Chris Wilsonc0336662016-05-06 15:40:21 +01002720 i915_reset_and_wakeup(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002721}
2722
Keith Packard42f52ef2008-10-18 19:39:29 -07002723/* Called from drm generic code, passed 'crtc' which
2724 * we use as a pipe index
2725 */
Thierry Reding88e72712015-09-24 18:35:31 +02002726static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002727{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002728 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002729 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002730
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002731 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002732 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002733 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002734 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002735 else
Keith Packard7c463582008-11-04 02:03:27 -08002736 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002737 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002738 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002739
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002740 return 0;
2741}
2742
Thierry Reding88e72712015-09-24 18:35:31 +02002743static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002744{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002745 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002746 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002747 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002748 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002749
Jesse Barnesf796cf82011-04-07 13:58:17 -07002750 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002751 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002752 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2753
2754 return 0;
2755}
2756
Thierry Reding88e72712015-09-24 18:35:31 +02002757static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002758{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002759 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002760 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002761
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002762 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002763 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002764 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002765 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2766
2767 return 0;
2768}
2769
Thierry Reding88e72712015-09-24 18:35:31 +02002770static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002771{
2772 struct drm_i915_private *dev_priv = dev->dev_private;
2773 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002774
Ben Widawskyabd58f02013-11-02 21:07:09 -07002775 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002776 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002777 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002778
Ben Widawskyabd58f02013-11-02 21:07:09 -07002779 return 0;
2780}
2781
Keith Packard42f52ef2008-10-18 19:39:29 -07002782/* Called from drm generic code, passed 'crtc' which
2783 * we use as a pipe index
2784 */
Thierry Reding88e72712015-09-24 18:35:31 +02002785static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002786{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002787 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002788 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002789
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002790 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002791 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002792 PIPE_VBLANK_INTERRUPT_STATUS |
2793 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002794 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2795}
2796
Thierry Reding88e72712015-09-24 18:35:31 +02002797static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002798{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002799 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002800 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002801 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002802 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002803
2804 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002805 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002806 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2807}
2808
Thierry Reding88e72712015-09-24 18:35:31 +02002809static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002810{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002811 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002812 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002813
2814 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002815 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002816 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002817 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2818}
2819
Thierry Reding88e72712015-09-24 18:35:31 +02002820static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002821{
2822 struct drm_i915_private *dev_priv = dev->dev_private;
2823 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002824
Ben Widawskyabd58f02013-11-02 21:07:09 -07002825 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002826 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002827 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2828}
2829
Chris Wilson9107e9d2013-06-10 11:20:20 +01002830static bool
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002831ring_idle(struct intel_engine_cs *engine, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002832{
Chris Wilsoncffa7812016-04-07 07:29:18 +01002833 return i915_seqno_passed(seqno,
2834 READ_ONCE(engine->last_submitted_seqno));
Ben Gamarif65d9422009-09-14 17:48:44 -04002835}
2836
Daniel Vettera028c4b2014-03-15 00:08:56 +01002837static bool
Chris Wilsonc0336662016-05-06 15:40:21 +01002838ipehr_is_semaphore_wait(struct drm_i915_private *dev_priv, u32 ipehr)
Daniel Vettera028c4b2014-03-15 00:08:56 +01002839{
Chris Wilsonc0336662016-05-06 15:40:21 +01002840 if (INTEL_GEN(dev_priv) >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002841 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002842 } else {
2843 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2844 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2845 MI_SEMAPHORE_REGISTER);
2846 }
2847}
2848
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002849static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002850semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr,
2851 u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002852{
Chris Wilsonc0336662016-05-06 15:40:21 +01002853 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002854 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002855
Chris Wilsonc0336662016-05-06 15:40:21 +01002856 if (INTEL_GEN(dev_priv) >= 8) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002857 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002858 if (engine == signaller)
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002859 continue;
2860
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002861 if (offset == signaller->semaphore.signal_ggtt[engine->id])
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002862 return signaller;
2863 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002864 } else {
2865 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2866
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002867 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002868 if(engine == signaller)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002869 continue;
2870
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002871 if (sync_bits == signaller->semaphore.mbox.wait[engine->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002872 return signaller;
2873 }
2874 }
2875
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002876 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002877 engine->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002878
2879 return NULL;
2880}
2881
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002882static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002883semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002884{
Chris Wilsonc0336662016-05-06 15:40:21 +01002885 struct drm_i915_private *dev_priv = engine->i915;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002886 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002887 u64 offset = 0;
2888 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002889
Tomas Elf381e8ae2015-10-08 19:31:33 +01002890 /*
2891 * This function does not support execlist mode - any attempt to
2892 * proceed further into this function will result in a kernel panic
2893 * when dereferencing ring->buffer, which is not set up in execlist
2894 * mode.
2895 *
2896 * The correct way of doing it would be to derive the currently
2897 * executing ring buffer from the current context, which is derived
2898 * from the currently running request. Unfortunately, to get the
2899 * current request we would have to grab the struct_mutex before doing
2900 * anything else, which would be ill-advised since some other thread
2901 * might have grabbed it already and managed to hang itself, causing
2902 * the hang checker to deadlock.
2903 *
2904 * Therefore, this function does not support execlist mode in its
2905 * current form. Just return NULL and move on.
2906 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002907 if (engine->buffer == NULL)
Tomas Elf381e8ae2015-10-08 19:31:33 +01002908 return NULL;
2909
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002910 ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
Chris Wilsonc0336662016-05-06 15:40:21 +01002911 if (!ipehr_is_semaphore_wait(engine->i915, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002912 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002913
Daniel Vetter88fe4292014-03-15 00:08:55 +01002914 /*
2915 * HEAD is likely pointing to the dword after the actual command,
2916 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002917 * or 4 dwords depending on the semaphore wait command size.
2918 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002919 * point at at batch, and semaphores are always emitted into the
2920 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002921 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002922 head = I915_READ_HEAD(engine) & HEAD_ADDR;
Chris Wilsonc0336662016-05-06 15:40:21 +01002923 backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002924
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002925 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002926 /*
2927 * Be paranoid and presume the hw has gone off into the wild -
2928 * our ring is smaller than what the hardware (and hence
2929 * HEAD_ADDR) allows. Also handles wrap-around.
2930 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002931 head &= engine->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002932
2933 /* This here seems to blow up */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002934 cmd = ioread32(engine->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002935 if (cmd == ipehr)
2936 break;
2937
Daniel Vetter88fe4292014-03-15 00:08:55 +01002938 head -= 4;
2939 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002940
Daniel Vetter88fe4292014-03-15 00:08:55 +01002941 if (!i)
2942 return NULL;
2943
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002944 *seqno = ioread32(engine->buffer->virtual_start + head + 4) + 1;
Chris Wilsonc0336662016-05-06 15:40:21 +01002945 if (INTEL_GEN(dev_priv) >= 8) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002946 offset = ioread32(engine->buffer->virtual_start + head + 12);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002947 offset <<= 32;
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002948 offset = ioread32(engine->buffer->virtual_start + head + 8);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002949 }
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002950 return semaphore_wait_to_signaller_ring(engine, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002951}
2952
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002953static int semaphore_passed(struct intel_engine_cs *engine)
Chris Wilson6274f212013-06-10 11:20:21 +01002954{
Chris Wilsonc0336662016-05-06 15:40:21 +01002955 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002956 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002957 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002958
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002959 engine->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002960
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002961 signaller = semaphore_waits_for(engine, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002962 if (signaller == NULL)
2963 return -1;
2964
2965 /* Prevent pathological recursion due to driver bugs */
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00002966 if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES)
Chris Wilson6274f212013-06-10 11:20:21 +01002967 return -1;
2968
Chris Wilsonc04e0f32016-04-09 10:57:54 +01002969 if (i915_seqno_passed(signaller->get_seqno(signaller), seqno))
Chris Wilson4be17382014-06-06 10:22:29 +01002970 return 1;
2971
Chris Wilsona0d036b2014-07-19 12:40:42 +01002972 /* cursory check for an unkickable deadlock */
2973 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2974 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002975 return -1;
2976
2977 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002978}
2979
2980static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2981{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002982 struct intel_engine_cs *engine;
Chris Wilson6274f212013-06-10 11:20:21 +01002983
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002984 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002985 engine->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002986}
2987
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002988static bool subunits_stuck(struct intel_engine_cs *engine)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002989{
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002990 u32 instdone[I915_NUM_INSTDONE_REG];
2991 bool stuck;
2992 int i;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002993
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002994 if (engine->id != RCS)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002995 return true;
2996
Chris Wilsonc0336662016-05-06 15:40:21 +01002997 i915_get_extra_instdone(engine->i915, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002998
2999 /* There might be unstable subunit states even when
3000 * actual head is not moving. Filter out the unstable ones by
3001 * accumulating the undone -> done transitions and only
3002 * consider those as progress.
3003 */
3004 stuck = true;
3005 for (i = 0; i < I915_NUM_INSTDONE_REG; i++) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003006 const u32 tmp = instdone[i] | engine->hangcheck.instdone[i];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003007
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003008 if (tmp != engine->hangcheck.instdone[i])
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003009 stuck = false;
3010
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003011 engine->hangcheck.instdone[i] |= tmp;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003012 }
3013
3014 return stuck;
3015}
3016
3017static enum intel_ring_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003018head_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003019{
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003020 if (acthd != engine->hangcheck.acthd) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003021
3022 /* Clear subunit states on head movement */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003023 memset(engine->hangcheck.instdone, 0,
3024 sizeof(engine->hangcheck.instdone));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003025
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003026 return HANGCHECK_ACTIVE;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003027 }
Chris Wilson6274f212013-06-10 11:20:21 +01003028
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003029 if (!subunits_stuck(engine))
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003030 return HANGCHECK_ACTIVE;
3031
3032 return HANGCHECK_HUNG;
3033}
3034
3035static enum intel_ring_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003036ring_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003037{
Chris Wilsonc0336662016-05-06 15:40:21 +01003038 struct drm_i915_private *dev_priv = engine->i915;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003039 enum intel_ring_hangcheck_action ha;
3040 u32 tmp;
3041
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003042 ha = head_stuck(engine, acthd);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003043 if (ha != HANGCHECK_HUNG)
3044 return ha;
3045
Chris Wilsonc0336662016-05-06 15:40:21 +01003046 if (IS_GEN2(dev_priv))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003047 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003048
3049 /* Is the chip hanging on a WAIT_FOR_EVENT?
3050 * If so we can simply poke the RB_WAIT bit
3051 * and break the hang. This should work on
3052 * all but the second generation chipsets.
3053 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003054 tmp = I915_READ_CTL(engine);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003055 if (tmp & RING_WAIT) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003056 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003057 "Kicking stuck wait on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003058 engine->name);
3059 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003060 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003061 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003062
Chris Wilsonc0336662016-05-06 15:40:21 +01003063 if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003064 switch (semaphore_passed(engine)) {
Chris Wilson6274f212013-06-10 11:20:21 +01003065 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003066 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003067 case 1:
Chris Wilsonc0336662016-05-06 15:40:21 +01003068 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003069 "Kicking stuck semaphore on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003070 engine->name);
3071 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003072 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003073 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003074 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003075 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003076 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003077
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003078 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003079}
3080
Chris Wilson12471ba2016-04-09 10:57:55 +01003081static unsigned kick_waiters(struct intel_engine_cs *engine)
3082{
Chris Wilsonc0336662016-05-06 15:40:21 +01003083 struct drm_i915_private *i915 = engine->i915;
Chris Wilson12471ba2016-04-09 10:57:55 +01003084 unsigned user_interrupts = READ_ONCE(engine->user_interrupts);
3085
3086 if (engine->hangcheck.user_interrupts == user_interrupts &&
3087 !test_and_set_bit(engine->id, &i915->gpu_error.missed_irq_rings)) {
3088 if (!(i915->gpu_error.test_irq_rings & intel_engine_flag(engine)))
3089 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
3090 engine->name);
3091 else
3092 DRM_INFO("Fake missed irq on %s\n",
3093 engine->name);
3094 wake_up_all(&engine->irq_queue);
3095 }
3096
3097 return user_interrupts;
3098}
Chris Wilson737b1502015-01-26 18:03:03 +02003099/*
Ben Gamarif65d9422009-09-14 17:48:44 -04003100 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003101 * batchbuffers in a long time. We keep track per ring seqno progress and
3102 * if there are no progress, hangcheck score for that ring is increased.
3103 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3104 * we kick the ring. If we see no progress on three subsequent calls
3105 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003106 */
Chris Wilson737b1502015-01-26 18:03:03 +02003107static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04003108{
Chris Wilson737b1502015-01-26 18:03:03 +02003109 struct drm_i915_private *dev_priv =
3110 container_of(work, typeof(*dev_priv),
3111 gpu_error.hangcheck_work.work);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003112 struct intel_engine_cs *engine;
Dave Gordonc3232b12016-03-23 18:19:53 +00003113 enum intel_engine_id id;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003114 int busy_count = 0, rings_hung = 0;
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00003115 bool stuck[I915_NUM_ENGINES] = { 0 };
Chris Wilson9107e9d2013-06-10 11:20:20 +01003116#define BUSY 1
3117#define KICK 5
3118#define HUNG 20
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003119#define ACTIVE_DECAY 15
Chris Wilson893eead2010-10-27 14:44:35 +01003120
Jani Nikulad330a952014-01-21 11:24:25 +02003121 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003122 return;
3123
Imre Deak1f814da2015-12-16 02:52:19 +02003124 /*
3125 * The hangcheck work is synced during runtime suspend, we don't
3126 * require a wakeref. TODO: instead of disabling the asserts make
3127 * sure that we hold a reference when this work is running.
3128 */
3129 DISABLE_RPM_WAKEREF_ASSERTS(dev_priv);
3130
Mika Kuoppala75714942015-12-16 09:26:48 +02003131 /* As enabling the GPU requires fairly extensive mmio access,
3132 * periodically arm the mmio checker to see if we are triggering
3133 * any invalid access.
3134 */
3135 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
3136
Dave Gordonc3232b12016-03-23 18:19:53 +00003137 for_each_engine_id(engine, dev_priv, id) {
Chris Wilson50877442014-03-21 12:41:53 +00003138 u64 acthd;
3139 u32 seqno;
Chris Wilson12471ba2016-04-09 10:57:55 +01003140 unsigned user_interrupts;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003141 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01003142
Chris Wilson6274f212013-06-10 11:20:21 +01003143 semaphore_clear_deadlocks(dev_priv);
3144
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003145 /* We don't strictly need an irq-barrier here, as we are not
3146 * serving an interrupt request, be paranoid in case the
3147 * barrier has side-effects (such as preventing a broken
3148 * cacheline snoop) and so be sure that we can see the seqno
3149 * advance. If the seqno should stick, due to a stale
3150 * cacheline, we would erroneously declare the GPU hung.
3151 */
3152 if (engine->irq_seqno_barrier)
3153 engine->irq_seqno_barrier(engine);
3154
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003155 acthd = intel_ring_get_active_head(engine);
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003156 seqno = engine->get_seqno(engine);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003157
Chris Wilson12471ba2016-04-09 10:57:55 +01003158 /* Reset stuck interrupts between batch advances */
3159 user_interrupts = 0;
3160
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003161 if (engine->hangcheck.seqno == seqno) {
3162 if (ring_idle(engine, seqno)) {
3163 engine->hangcheck.action = HANGCHECK_IDLE;
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003164 if (waitqueue_active(&engine->irq_queue)) {
Chris Wilson094f9a52013-09-25 17:34:55 +01003165 /* Safeguard against driver failure */
Chris Wilson12471ba2016-04-09 10:57:55 +01003166 user_interrupts = kick_waiters(engine);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003167 engine->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003168 } else
3169 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003170 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003171 /* We always increment the hangcheck score
3172 * if the ring is busy and still processing
3173 * the same request, so that no single request
3174 * can run indefinitely (such as a chain of
3175 * batches). The only time we do not increment
3176 * the hangcheck score on this ring, if this
3177 * ring is in a legitimate wait for another
3178 * ring. In that case the waiting ring is a
3179 * victim and we want to be sure we catch the
3180 * right culprit. Then every time we do kick
3181 * the ring, add a small increment to the
3182 * score so that we can catch a batch that is
3183 * being repeatedly kicked and so responsible
3184 * for stalling the machine.
3185 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003186 engine->hangcheck.action = ring_stuck(engine,
3187 acthd);
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003188
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003189 switch (engine->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003190 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003191 case HANGCHECK_WAIT:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003192 break;
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003193 case HANGCHECK_ACTIVE:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003194 engine->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003195 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003196 case HANGCHECK_KICK:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003197 engine->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003198 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003199 case HANGCHECK_HUNG:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003200 engine->hangcheck.score += HUNG;
Dave Gordonc3232b12016-03-23 18:19:53 +00003201 stuck[id] = true;
Chris Wilson6274f212013-06-10 11:20:21 +01003202 break;
3203 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003204 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003205 } else {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003206 engine->hangcheck.action = HANGCHECK_ACTIVE;
Mika Kuoppalada661462013-09-06 16:03:28 +03003207
Chris Wilson9107e9d2013-06-10 11:20:20 +01003208 /* Gradually reduce the count so that we catch DoS
3209 * attempts across multiple batches.
3210 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003211 if (engine->hangcheck.score > 0)
3212 engine->hangcheck.score -= ACTIVE_DECAY;
3213 if (engine->hangcheck.score < 0)
3214 engine->hangcheck.score = 0;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003215
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003216 /* Clear head and subunit states on seqno movement */
Chris Wilson12471ba2016-04-09 10:57:55 +01003217 acthd = 0;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003218
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003219 memset(engine->hangcheck.instdone, 0,
3220 sizeof(engine->hangcheck.instdone));
Chris Wilsond1e61e72012-04-10 17:00:41 +01003221 }
3222
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003223 engine->hangcheck.seqno = seqno;
3224 engine->hangcheck.acthd = acthd;
Chris Wilson12471ba2016-04-09 10:57:55 +01003225 engine->hangcheck.user_interrupts = user_interrupts;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003226 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003227 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003228
Dave Gordonc3232b12016-03-23 18:19:53 +00003229 for_each_engine_id(engine, dev_priv, id) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003230 if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003231 DRM_INFO("%s on %s\n",
Dave Gordonc3232b12016-03-23 18:19:53 +00003232 stuck[id] ? "stuck" : "no progress",
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003233 engine->name);
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00003234 rings_hung |= intel_engine_flag(engine);
Mika Kuoppala92cab732013-05-24 17:16:07 +03003235 }
3236 }
3237
Imre Deak1f814da2015-12-16 02:52:19 +02003238 if (rings_hung) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003239 i915_handle_error(dev_priv, rings_hung, "Engine(s) hung");
Imre Deak1f814da2015-12-16 02:52:19 +02003240 goto out;
3241 }
Ben Gamarif65d9422009-09-14 17:48:44 -04003242
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003243 if (busy_count)
3244 /* Reset timer case chip hangs without another request
3245 * being added */
Chris Wilsonc0336662016-05-06 15:40:21 +01003246 i915_queue_hangcheck(dev_priv);
Imre Deak1f814da2015-12-16 02:52:19 +02003247
3248out:
3249 ENABLE_RPM_WAKEREF_ASSERTS(dev_priv);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003250}
3251
Chris Wilsonc0336662016-05-06 15:40:21 +01003252void i915_queue_hangcheck(struct drm_i915_private *dev_priv)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003253{
Chris Wilsonc0336662016-05-06 15:40:21 +01003254 struct i915_gpu_error *e = &dev_priv->gpu_error;
Chris Wilson672e7b72014-11-19 09:47:19 +00003255
Jani Nikulad330a952014-01-21 11:24:25 +02003256 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003257 return;
3258
Chris Wilson737b1502015-01-26 18:03:03 +02003259 /* Don't continually defer the hangcheck so that it is always run at
3260 * least once after work has been scheduled on any ring. Otherwise,
3261 * we will ignore a hung ring if a second ring is kept busy.
3262 */
3263
3264 queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
3265 round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003266}
3267
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003268static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003269{
3270 struct drm_i915_private *dev_priv = dev->dev_private;
3271
3272 if (HAS_PCH_NOP(dev))
3273 return;
3274
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003275 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003276
3277 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3278 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003279}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003280
Paulo Zanoni622364b2014-04-01 15:37:22 -03003281/*
3282 * SDEIER is also touched by the interrupt handler to work around missed PCH
3283 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3284 * instead we unconditionally enable all PCH interrupt sources here, but then
3285 * only unmask them as needed with SDEIMR.
3286 *
3287 * This function needs to be called before interrupts are enabled.
3288 */
3289static void ibx_irq_pre_postinstall(struct drm_device *dev)
3290{
3291 struct drm_i915_private *dev_priv = dev->dev_private;
3292
3293 if (HAS_PCH_NOP(dev))
3294 return;
3295
3296 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003297 I915_WRITE(SDEIER, 0xffffffff);
3298 POSTING_READ(SDEIER);
3299}
3300
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003301static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003302{
3303 struct drm_i915_private *dev_priv = dev->dev_private;
3304
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003305 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003306 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003307 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003308}
3309
Ville Syrjälä70591a42014-10-30 19:42:58 +02003310static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3311{
3312 enum pipe pipe;
3313
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003314 if (IS_CHERRYVIEW(dev_priv))
3315 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3316 else
3317 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3318
Ville Syrjäläad22d102016-04-12 18:56:14 +03003319 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003320 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3321
Ville Syrjäläad22d102016-04-12 18:56:14 +03003322 for_each_pipe(dev_priv, pipe) {
3323 I915_WRITE(PIPESTAT(pipe),
3324 PIPE_FIFO_UNDERRUN_STATUS |
3325 PIPESTAT_INT_STATUS_MASK);
3326 dev_priv->pipestat_irq_mask[pipe] = 0;
3327 }
Ville Syrjälä70591a42014-10-30 19:42:58 +02003328
3329 GEN5_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003330 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003331}
3332
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003333static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3334{
3335 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003336 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003337 enum pipe pipe;
3338
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003339 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3340 PIPE_CRC_DONE_INTERRUPT_STATUS;
3341
3342 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3343 for_each_pipe(dev_priv, pipe)
3344 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3345
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003346 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3347 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3348 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003349 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003350 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003351
3352 WARN_ON(dev_priv->irq_mask != ~0);
3353
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003354 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003355
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003356 GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003357}
3358
3359/* drm_dma.h hooks
3360*/
3361static void ironlake_irq_reset(struct drm_device *dev)
3362{
3363 struct drm_i915_private *dev_priv = dev->dev_private;
3364
3365 I915_WRITE(HWSTAM, 0xffffffff);
3366
3367 GEN5_IRQ_RESET(DE);
3368 if (IS_GEN7(dev))
3369 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3370
3371 gen5_gt_irq_reset(dev);
3372
3373 ibx_irq_reset(dev);
3374}
3375
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003376static void valleyview_irq_preinstall(struct drm_device *dev)
3377{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003378 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003379
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003380 I915_WRITE(VLV_MASTER_IER, 0);
3381 POSTING_READ(VLV_MASTER_IER);
3382
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003383 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003384
Ville Syrjäläad22d102016-04-12 18:56:14 +03003385 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003386 if (dev_priv->display_irqs_enabled)
3387 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003388 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003389}
3390
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003391static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3392{
3393 GEN8_IRQ_RESET_NDX(GT, 0);
3394 GEN8_IRQ_RESET_NDX(GT, 1);
3395 GEN8_IRQ_RESET_NDX(GT, 2);
3396 GEN8_IRQ_RESET_NDX(GT, 3);
3397}
3398
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003399static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003400{
3401 struct drm_i915_private *dev_priv = dev->dev_private;
3402 int pipe;
3403
Ben Widawskyabd58f02013-11-02 21:07:09 -07003404 I915_WRITE(GEN8_MASTER_IRQ, 0);
3405 POSTING_READ(GEN8_MASTER_IRQ);
3406
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003407 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003408
Damien Lespiau055e3932014-08-18 13:49:10 +01003409 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003410 if (intel_display_power_is_enabled(dev_priv,
3411 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003412 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003413
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003414 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3415 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3416 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003417
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303418 if (HAS_PCH_SPLIT(dev))
3419 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003420}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003421
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003422void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3423 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003424{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003425 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003426 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003427
Daniel Vetter13321782014-09-15 14:55:29 +02003428 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003429 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3430 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3431 dev_priv->de_irq_mask[pipe],
3432 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003433 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003434}
3435
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003436void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3437 unsigned int pipe_mask)
3438{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003439 enum pipe pipe;
3440
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003441 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003442 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3443 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003444 spin_unlock_irq(&dev_priv->irq_lock);
3445
3446 /* make sure we're done processing display irqs */
3447 synchronize_irq(dev_priv->dev->irq);
3448}
3449
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003450static void cherryview_irq_preinstall(struct drm_device *dev)
3451{
3452 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003453
3454 I915_WRITE(GEN8_MASTER_IRQ, 0);
3455 POSTING_READ(GEN8_MASTER_IRQ);
3456
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003457 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003458
3459 GEN5_IRQ_RESET(GEN8_PCU_);
3460
Ville Syrjäläad22d102016-04-12 18:56:14 +03003461 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003462 if (dev_priv->display_irqs_enabled)
3463 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003464 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003465}
3466
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003467static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003468 const u32 hpd[HPD_NUM_PINS])
3469{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003470 struct intel_encoder *encoder;
3471 u32 enabled_irqs = 0;
3472
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003473 for_each_intel_encoder(dev_priv->dev, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003474 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3475 enabled_irqs |= hpd[encoder->hpd_pin];
3476
3477 return enabled_irqs;
3478}
3479
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003480static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003481{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003482 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003483
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003484 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003485 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003486 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003487 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003488 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003489 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003490 }
3491
Daniel Vetterfee884e2013-07-04 23:35:21 +02003492 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003493
3494 /*
3495 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003496 * duration to 2ms (which is the minimum in the Display Port spec).
3497 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003498 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003499 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3500 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3501 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3502 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3503 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003504 /*
3505 * When CPU and PCH are on the same package, port A
3506 * HPD must be enabled in both north and south.
3507 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003508 if (HAS_PCH_LPT_LP(dev_priv))
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003509 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003510 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003511}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003512
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003513static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003514{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003515 u32 hotplug_irqs, hotplug, enabled_irqs;
3516
3517 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003518 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003519
3520 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3521
3522 /* Enable digital hotplug on the PCH */
3523 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3524 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003525 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003526 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3527
3528 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3529 hotplug |= PORTE_HOTPLUG_ENABLE;
3530 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003531}
3532
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003533static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003534{
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003535 u32 hotplug_irqs, hotplug, enabled_irqs;
3536
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003537 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003538 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003539 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003540
3541 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003542 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003543 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003544 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003545
3546 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003547 } else {
3548 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003549 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003550
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003551 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3552 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003553
3554 /*
3555 * Enable digital hotplug on the CPU, and configure the DP short pulse
3556 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003557 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003558 */
3559 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3560 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3561 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3562 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3563
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003564 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003565}
3566
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003567static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003568{
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003569 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003570
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003571 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003572 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003573
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003574 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003575
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003576 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3577 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3578 PORTA_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303579
3580 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3581 hotplug, enabled_irqs);
3582 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3583
3584 /*
3585 * For BXT invert bit has to be set based on AOB design
3586 * for HPD detection logic, update it based on VBT fields.
3587 */
3588
3589 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3590 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3591 hotplug |= BXT_DDIA_HPD_INVERT;
3592 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3593 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3594 hotplug |= BXT_DDIB_HPD_INVERT;
3595 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3596 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3597 hotplug |= BXT_DDIC_HPD_INVERT;
3598
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003599 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003600}
3601
Paulo Zanonid46da432013-02-08 17:35:15 -02003602static void ibx_irq_postinstall(struct drm_device *dev)
3603{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003604 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003605 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003606
Daniel Vetter692a04c2013-05-29 21:43:05 +02003607 if (HAS_PCH_NOP(dev))
3608 return;
3609
Paulo Zanoni105b1222014-04-01 15:37:17 -03003610 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003611 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003612 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003613 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003614
Ville Syrjäläb51a2842015-09-18 20:03:41 +03003615 gen5_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003616 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003617}
3618
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003619static void gen5_gt_irq_postinstall(struct drm_device *dev)
3620{
3621 struct drm_i915_private *dev_priv = dev->dev_private;
3622 u32 pm_irqs, gt_irqs;
3623
3624 pm_irqs = gt_irqs = 0;
3625
3626 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003627 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003628 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003629 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3630 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003631 }
3632
3633 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3634 if (IS_GEN5(dev)) {
3635 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3636 ILK_BSD_USER_INTERRUPT;
3637 } else {
3638 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3639 }
3640
Paulo Zanoni35079892014-04-01 15:37:15 -03003641 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003642
3643 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003644 /*
3645 * RPS interrupts will get enabled/disabled on demand when RPS
3646 * itself is enabled/disabled.
3647 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003648 if (HAS_VEBOX(dev))
3649 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3650
Paulo Zanoni605cd252013-08-06 18:57:15 -03003651 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003652 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003653 }
3654}
3655
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003656static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003657{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003658 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003659 u32 display_mask, extra_mask;
3660
3661 if (INTEL_INFO(dev)->gen >= 7) {
3662 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3663 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3664 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003665 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003666 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003667 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3668 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003669 } else {
3670 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3671 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003672 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003673 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3674 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003675 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3676 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3677 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003678 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003679
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003680 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003681
Paulo Zanoni0c841212014-04-01 15:37:27 -03003682 I915_WRITE(HWSTAM, 0xeffe);
3683
Paulo Zanoni622364b2014-04-01 15:37:22 -03003684 ibx_irq_pre_postinstall(dev);
3685
Paulo Zanoni35079892014-04-01 15:37:15 -03003686 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003687
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003688 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003689
Paulo Zanonid46da432013-02-08 17:35:15 -02003690 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003691
Jesse Barnesf97108d2010-01-29 11:27:07 -08003692 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003693 /* Enable PCU event interrupts
3694 *
3695 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003696 * setup is guaranteed to run in single-threaded context. But we
3697 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003698 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003699 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003700 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003701 }
3702
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003703 return 0;
3704}
3705
Imre Deakf8b79e52014-03-04 19:23:07 +02003706void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3707{
3708 assert_spin_locked(&dev_priv->irq_lock);
3709
3710 if (dev_priv->display_irqs_enabled)
3711 return;
3712
3713 dev_priv->display_irqs_enabled = true;
3714
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003715 if (intel_irqs_enabled(dev_priv)) {
3716 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003717 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003718 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003719}
3720
3721void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3722{
3723 assert_spin_locked(&dev_priv->irq_lock);
3724
3725 if (!dev_priv->display_irqs_enabled)
3726 return;
3727
3728 dev_priv->display_irqs_enabled = false;
3729
Imre Deak950eaba2014-09-08 15:21:09 +03003730 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003731 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003732}
3733
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003734
3735static int valleyview_irq_postinstall(struct drm_device *dev)
3736{
3737 struct drm_i915_private *dev_priv = dev->dev_private;
3738
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003739 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003740
Ville Syrjäläad22d102016-04-12 18:56:14 +03003741 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003742 if (dev_priv->display_irqs_enabled)
3743 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003744 spin_unlock_irq(&dev_priv->irq_lock);
3745
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003746 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003747 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003748
3749 return 0;
3750}
3751
Ben Widawskyabd58f02013-11-02 21:07:09 -07003752static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3753{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003754 /* These are interrupts we'll toggle with the ring mask register */
3755 uint32_t gt_interrupts[] = {
3756 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003757 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003758 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3759 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003760 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003761 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3762 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3763 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003764 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003765 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3766 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003767 };
3768
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003769 if (HAS_L3_DPF(dev_priv))
3770 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3771
Ben Widawsky09610212014-05-15 20:58:08 +03003772 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303773 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3774 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003775 /*
3776 * RPS interrupts will get enabled/disabled on demand when RPS itself
3777 * is enabled/disabled.
3778 */
3779 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303780 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003781}
3782
3783static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3784{
Damien Lespiau770de832014-03-20 20:45:01 +00003785 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3786 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003787 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3788 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003789 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003790 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003791
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003792 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003793 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3794 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003795 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3796 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303797 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003798 de_port_masked |= BXT_DE_PORT_GMBUS;
3799 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003800 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3801 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003802 }
Damien Lespiau770de832014-03-20 20:45:01 +00003803
3804 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3805 GEN8_PIPE_FIFO_UNDERRUN;
3806
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003807 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003808 if (IS_BROXTON(dev_priv))
3809 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3810 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003811 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3812
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003813 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3814 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3815 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003816
Damien Lespiau055e3932014-08-18 13:49:10 +01003817 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003818 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003819 POWER_DOMAIN_PIPE(pipe)))
3820 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3821 dev_priv->de_irq_mask[pipe],
3822 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003823
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003824 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ville Syrjälä11825b02016-05-19 12:14:43 +03003825 GEN5_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003826}
3827
3828static int gen8_irq_postinstall(struct drm_device *dev)
3829{
3830 struct drm_i915_private *dev_priv = dev->dev_private;
3831
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303832 if (HAS_PCH_SPLIT(dev))
3833 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003834
Ben Widawskyabd58f02013-11-02 21:07:09 -07003835 gen8_gt_irq_postinstall(dev_priv);
3836 gen8_de_irq_postinstall(dev_priv);
3837
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303838 if (HAS_PCH_SPLIT(dev))
3839 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003840
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003841 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003842 POSTING_READ(GEN8_MASTER_IRQ);
3843
3844 return 0;
3845}
3846
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003847static int cherryview_irq_postinstall(struct drm_device *dev)
3848{
3849 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003850
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003851 gen8_gt_irq_postinstall(dev_priv);
3852
Ville Syrjäläad22d102016-04-12 18:56:14 +03003853 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003854 if (dev_priv->display_irqs_enabled)
3855 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003856 spin_unlock_irq(&dev_priv->irq_lock);
3857
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003858 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003859 POSTING_READ(GEN8_MASTER_IRQ);
3860
3861 return 0;
3862}
3863
Ben Widawskyabd58f02013-11-02 21:07:09 -07003864static void gen8_irq_uninstall(struct drm_device *dev)
3865{
3866 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003867
3868 if (!dev_priv)
3869 return;
3870
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003871 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003872}
3873
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003874static void valleyview_irq_uninstall(struct drm_device *dev)
3875{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003876 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003877
3878 if (!dev_priv)
3879 return;
3880
Imre Deak843d0e72014-04-14 20:24:23 +03003881 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003882 POSTING_READ(VLV_MASTER_IER);
Imre Deak843d0e72014-04-14 20:24:23 +03003883
Ville Syrjälä893fce82014-10-30 19:42:56 +02003884 gen5_gt_irq_reset(dev);
3885
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003886 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003887
Ville Syrjäläad22d102016-04-12 18:56:14 +03003888 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003889 if (dev_priv->display_irqs_enabled)
3890 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003891 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003892}
3893
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003894static void cherryview_irq_uninstall(struct drm_device *dev)
3895{
3896 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003897
3898 if (!dev_priv)
3899 return;
3900
3901 I915_WRITE(GEN8_MASTER_IRQ, 0);
3902 POSTING_READ(GEN8_MASTER_IRQ);
3903
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003904 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003905
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003906 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003907
Ville Syrjäläad22d102016-04-12 18:56:14 +03003908 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003909 if (dev_priv->display_irqs_enabled)
3910 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003911 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003912}
3913
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003914static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003915{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003916 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003917
3918 if (!dev_priv)
3919 return;
3920
Paulo Zanonibe30b292014-04-01 15:37:25 -03003921 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003922}
3923
Chris Wilsonc2798b12012-04-22 21:13:57 +01003924static void i8xx_irq_preinstall(struct drm_device * dev)
3925{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003926 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003927 int pipe;
3928
Damien Lespiau055e3932014-08-18 13:49:10 +01003929 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003930 I915_WRITE(PIPESTAT(pipe), 0);
3931 I915_WRITE16(IMR, 0xffff);
3932 I915_WRITE16(IER, 0x0);
3933 POSTING_READ16(IER);
3934}
3935
3936static int i8xx_irq_postinstall(struct drm_device *dev)
3937{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003938 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003939
Chris Wilsonc2798b12012-04-22 21:13:57 +01003940 I915_WRITE16(EMR,
3941 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3942
3943 /* Unmask the interrupts that we always want on. */
3944 dev_priv->irq_mask =
3945 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3946 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3947 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003948 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003949 I915_WRITE16(IMR, dev_priv->irq_mask);
3950
3951 I915_WRITE16(IER,
3952 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3953 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003954 I915_USER_INTERRUPT);
3955 POSTING_READ16(IER);
3956
Daniel Vetter379ef822013-10-16 22:55:56 +02003957 /* Interrupt setup is already guaranteed to be single-threaded, this is
3958 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003959 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003960 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3961 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003962 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003963
Chris Wilsonc2798b12012-04-22 21:13:57 +01003964 return 0;
3965}
3966
Daniel Vetter5a21b662016-05-24 17:13:53 +02003967/*
3968 * Returns true when a page flip has completed.
3969 */
3970static bool i8xx_handle_vblank(struct drm_i915_private *dev_priv,
3971 int plane, int pipe, u32 iir)
3972{
3973 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3974
3975 if (!intel_pipe_handle_vblank(dev_priv, pipe))
3976 return false;
3977
3978 if ((iir & flip_pending) == 0)
3979 goto check_page_flip;
3980
3981 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3982 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3983 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3984 * the flip is completed (no longer pending). Since this doesn't raise
3985 * an interrupt per se, we watch for the change at vblank.
3986 */
3987 if (I915_READ16(ISR) & flip_pending)
3988 goto check_page_flip;
3989
3990 intel_finish_page_flip_cs(dev_priv, pipe);
3991 return true;
3992
3993check_page_flip:
3994 intel_check_page_flip(dev_priv, pipe);
3995 return false;
3996}
3997
Daniel Vetterff1f5252012-10-02 15:10:55 +02003998static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003999{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004000 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004001 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004002 u16 iir, new_iir;
4003 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01004004 int pipe;
4005 u16 flip_mask =
4006 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4007 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Imre Deak1f814da2015-12-16 02:52:19 +02004008 irqreturn_t ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004009
Imre Deak2dd2a882015-02-24 11:14:30 +02004010 if (!intel_irqs_enabled(dev_priv))
4011 return IRQ_NONE;
4012
Imre Deak1f814da2015-12-16 02:52:19 +02004013 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4014 disable_rpm_wakeref_asserts(dev_priv);
4015
4016 ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004017 iir = I915_READ16(IIR);
4018 if (iir == 0)
Imre Deak1f814da2015-12-16 02:52:19 +02004019 goto out;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004020
4021 while (iir & ~flip_mask) {
4022 /* Can't rely on pipestat interrupt bit in iir as it might
4023 * have been cleared after the pipestat interrupt was received.
4024 * It doesn't set the bit in iir again, but it still produces
4025 * interrupts (for non-MSI).
4026 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004027 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004028 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004029 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004030
Damien Lespiau055e3932014-08-18 13:49:10 +01004031 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004032 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004033 pipe_stats[pipe] = I915_READ(reg);
4034
4035 /*
4036 * Clear the PIPE*STAT regs before the IIR
4037 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004038 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004039 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004040 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004041 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004042
4043 I915_WRITE16(IIR, iir & ~flip_mask);
4044 new_iir = I915_READ16(IIR); /* Flush posted writes */
4045
Chris Wilsonc2798b12012-04-22 21:13:57 +01004046 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004047 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004048
Damien Lespiau055e3932014-08-18 13:49:10 +01004049 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004050 int plane = pipe;
4051 if (HAS_FBC(dev_priv))
4052 plane = !plane;
4053
4054 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4055 i8xx_handle_vblank(dev_priv, plane, pipe, iir))
4056 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004057
Daniel Vetter4356d582013-10-16 22:55:55 +02004058 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004059 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004060
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004061 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4062 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4063 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02004064 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01004065
4066 iir = new_iir;
4067 }
Imre Deak1f814da2015-12-16 02:52:19 +02004068 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004069
Imre Deak1f814da2015-12-16 02:52:19 +02004070out:
4071 enable_rpm_wakeref_asserts(dev_priv);
4072
4073 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004074}
4075
4076static void i8xx_irq_uninstall(struct drm_device * dev)
4077{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004078 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004079 int pipe;
4080
Damien Lespiau055e3932014-08-18 13:49:10 +01004081 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004082 /* Clear enable bits; then clear status bits */
4083 I915_WRITE(PIPESTAT(pipe), 0);
4084 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4085 }
4086 I915_WRITE16(IMR, 0xffff);
4087 I915_WRITE16(IER, 0x0);
4088 I915_WRITE16(IIR, I915_READ16(IIR));
4089}
4090
Chris Wilsona266c7d2012-04-24 22:59:44 +01004091static void i915_irq_preinstall(struct drm_device * dev)
4092{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004093 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004094 int pipe;
4095
Chris Wilsona266c7d2012-04-24 22:59:44 +01004096 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004097 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004098 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4099 }
4100
Chris Wilson00d98eb2012-04-24 22:59:48 +01004101 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004102 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004103 I915_WRITE(PIPESTAT(pipe), 0);
4104 I915_WRITE(IMR, 0xffffffff);
4105 I915_WRITE(IER, 0x0);
4106 POSTING_READ(IER);
4107}
4108
4109static int i915_irq_postinstall(struct drm_device *dev)
4110{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004111 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01004112 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004113
Chris Wilson38bde182012-04-24 22:59:50 +01004114 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4115
4116 /* Unmask the interrupts that we always want on. */
4117 dev_priv->irq_mask =
4118 ~(I915_ASLE_INTERRUPT |
4119 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4120 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4121 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02004122 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004123
4124 enable_mask =
4125 I915_ASLE_INTERRUPT |
4126 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4127 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004128 I915_USER_INTERRUPT;
4129
Chris Wilsona266c7d2012-04-24 22:59:44 +01004130 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004131 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004132 POSTING_READ(PORT_HOTPLUG_EN);
4133
Chris Wilsona266c7d2012-04-24 22:59:44 +01004134 /* Enable in IER... */
4135 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4136 /* and unmask in IMR */
4137 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4138 }
4139
Chris Wilsona266c7d2012-04-24 22:59:44 +01004140 I915_WRITE(IMR, dev_priv->irq_mask);
4141 I915_WRITE(IER, enable_mask);
4142 POSTING_READ(IER);
4143
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004144 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004145
Daniel Vetter379ef822013-10-16 22:55:56 +02004146 /* Interrupt setup is already guaranteed to be single-threaded, this is
4147 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004148 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004149 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4150 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004151 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004152
Daniel Vetter20afbda2012-12-11 14:05:07 +01004153 return 0;
4154}
4155
Daniel Vetter5a21b662016-05-24 17:13:53 +02004156/*
4157 * Returns true when a page flip has completed.
4158 */
4159static bool i915_handle_vblank(struct drm_i915_private *dev_priv,
4160 int plane, int pipe, u32 iir)
4161{
4162 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4163
4164 if (!intel_pipe_handle_vblank(dev_priv, pipe))
4165 return false;
4166
4167 if ((iir & flip_pending) == 0)
4168 goto check_page_flip;
4169
4170 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4171 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4172 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4173 * the flip is completed (no longer pending). Since this doesn't raise
4174 * an interrupt per se, we watch for the change at vblank.
4175 */
4176 if (I915_READ(ISR) & flip_pending)
4177 goto check_page_flip;
4178
4179 intel_finish_page_flip_cs(dev_priv, pipe);
4180 return true;
4181
4182check_page_flip:
4183 intel_check_page_flip(dev_priv, pipe);
4184 return false;
4185}
4186
Daniel Vetterff1f5252012-10-02 15:10:55 +02004187static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004188{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004189 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004190 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01004191 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004192 u32 flip_mask =
4193 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4194 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004195 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004196
Imre Deak2dd2a882015-02-24 11:14:30 +02004197 if (!intel_irqs_enabled(dev_priv))
4198 return IRQ_NONE;
4199
Imre Deak1f814da2015-12-16 02:52:19 +02004200 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4201 disable_rpm_wakeref_asserts(dev_priv);
4202
Chris Wilsona266c7d2012-04-24 22:59:44 +01004203 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004204 do {
4205 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004206 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004207
4208 /* Can't rely on pipestat interrupt bit in iir as it might
4209 * have been cleared after the pipestat interrupt was received.
4210 * It doesn't set the bit in iir again, but it still produces
4211 * interrupts (for non-MSI).
4212 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004213 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004214 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004215 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004216
Damien Lespiau055e3932014-08-18 13:49:10 +01004217 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004218 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004219 pipe_stats[pipe] = I915_READ(reg);
4220
Chris Wilson38bde182012-04-24 22:59:50 +01004221 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004222 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004223 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004224 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004225 }
4226 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004227 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004228
4229 if (!irq_received)
4230 break;
4231
Chris Wilsona266c7d2012-04-24 22:59:44 +01004232 /* Consume port. Then clear IIR or we'll miss events */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004233 if (I915_HAS_HOTPLUG(dev_priv) &&
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004234 iir & I915_DISPLAY_PORT_INTERRUPT) {
4235 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4236 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004237 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004238 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004239
Chris Wilson38bde182012-04-24 22:59:50 +01004240 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004241 new_iir = I915_READ(IIR); /* Flush posted writes */
4242
Chris Wilsona266c7d2012-04-24 22:59:44 +01004243 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004244 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004245
Damien Lespiau055e3932014-08-18 13:49:10 +01004246 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004247 int plane = pipe;
4248 if (HAS_FBC(dev_priv))
4249 plane = !plane;
4250
4251 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4252 i915_handle_vblank(dev_priv, plane, pipe, iir))
4253 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004254
4255 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4256 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004257
4258 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004259 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004260
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004261 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4262 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4263 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004264 }
4265
Chris Wilsona266c7d2012-04-24 22:59:44 +01004266 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004267 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004268
4269 /* With MSI, interrupts are only generated when iir
4270 * transitions from zero to nonzero. If another bit got
4271 * set while we were handling the existing iir bits, then
4272 * we would never get another interrupt.
4273 *
4274 * This is fine on non-MSI as well, as if we hit this path
4275 * we avoid exiting the interrupt handler only to generate
4276 * another one.
4277 *
4278 * Note that for MSI this could cause a stray interrupt report
4279 * if an interrupt landed in the time between writing IIR and
4280 * the posting read. This should be rare enough to never
4281 * trigger the 99% of 100,000 interrupts test for disabling
4282 * stray interrupts.
4283 */
Chris Wilson38bde182012-04-24 22:59:50 +01004284 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004285 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004286 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004287
Imre Deak1f814da2015-12-16 02:52:19 +02004288 enable_rpm_wakeref_asserts(dev_priv);
4289
Chris Wilsona266c7d2012-04-24 22:59:44 +01004290 return ret;
4291}
4292
4293static void i915_irq_uninstall(struct drm_device * dev)
4294{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004295 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004296 int pipe;
4297
Chris Wilsona266c7d2012-04-24 22:59:44 +01004298 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004299 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004300 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4301 }
4302
Chris Wilson00d98eb2012-04-24 22:59:48 +01004303 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004304 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004305 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004306 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004307 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4308 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004309 I915_WRITE(IMR, 0xffffffff);
4310 I915_WRITE(IER, 0x0);
4311
Chris Wilsona266c7d2012-04-24 22:59:44 +01004312 I915_WRITE(IIR, I915_READ(IIR));
4313}
4314
4315static void i965_irq_preinstall(struct drm_device * dev)
4316{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004317 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004318 int pipe;
4319
Egbert Eich0706f172015-09-23 16:15:27 +02004320 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004321 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004322
4323 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004324 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004325 I915_WRITE(PIPESTAT(pipe), 0);
4326 I915_WRITE(IMR, 0xffffffff);
4327 I915_WRITE(IER, 0x0);
4328 POSTING_READ(IER);
4329}
4330
4331static int i965_irq_postinstall(struct drm_device *dev)
4332{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004333 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004334 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004335 u32 error_mask;
4336
Chris Wilsona266c7d2012-04-24 22:59:44 +01004337 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004338 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004339 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004340 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4341 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4342 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4343 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4344 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4345
4346 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004347 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4348 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004349 enable_mask |= I915_USER_INTERRUPT;
4350
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004351 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004352 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004353
Daniel Vetterb79480b2013-06-27 17:52:10 +02004354 /* Interrupt setup is already guaranteed to be single-threaded, this is
4355 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004356 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004357 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4358 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4359 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004360 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004361
Chris Wilsona266c7d2012-04-24 22:59:44 +01004362 /*
4363 * Enable some error detection, note the instruction error mask
4364 * bit is reserved, so we leave it masked.
4365 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004366 if (IS_G4X(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004367 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4368 GM45_ERROR_MEM_PRIV |
4369 GM45_ERROR_CP_PRIV |
4370 I915_ERROR_MEMORY_REFRESH);
4371 } else {
4372 error_mask = ~(I915_ERROR_PAGE_TABLE |
4373 I915_ERROR_MEMORY_REFRESH);
4374 }
4375 I915_WRITE(EMR, error_mask);
4376
4377 I915_WRITE(IMR, dev_priv->irq_mask);
4378 I915_WRITE(IER, enable_mask);
4379 POSTING_READ(IER);
4380
Egbert Eich0706f172015-09-23 16:15:27 +02004381 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004382 POSTING_READ(PORT_HOTPLUG_EN);
4383
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004384 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004385
4386 return 0;
4387}
4388
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004389static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004390{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004391 u32 hotplug_en;
4392
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004393 assert_spin_locked(&dev_priv->irq_lock);
4394
Ville Syrjälä778eb332015-01-09 14:21:13 +02004395 /* Note HDMI and DP share hotplug bits */
4396 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004397 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004398 /* Programming the CRT detection parameters tends
4399 to generate a spurious hotplug event about three
4400 seconds later. So just do it once.
4401 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004402 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004403 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004404 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004405
Ville Syrjälä778eb332015-01-09 14:21:13 +02004406 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004407 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004408 HOTPLUG_INT_EN_MASK |
4409 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4410 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4411 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004412}
4413
Daniel Vetterff1f5252012-10-02 15:10:55 +02004414static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004415{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004416 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004417 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004418 u32 iir, new_iir;
4419 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004420 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004421 u32 flip_mask =
4422 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4423 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004424
Imre Deak2dd2a882015-02-24 11:14:30 +02004425 if (!intel_irqs_enabled(dev_priv))
4426 return IRQ_NONE;
4427
Imre Deak1f814da2015-12-16 02:52:19 +02004428 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4429 disable_rpm_wakeref_asserts(dev_priv);
4430
Chris Wilsona266c7d2012-04-24 22:59:44 +01004431 iir = I915_READ(IIR);
4432
Chris Wilsona266c7d2012-04-24 22:59:44 +01004433 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004434 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004435 bool blc_event = false;
4436
Chris Wilsona266c7d2012-04-24 22:59:44 +01004437 /* Can't rely on pipestat interrupt bit in iir as it might
4438 * have been cleared after the pipestat interrupt was received.
4439 * It doesn't set the bit in iir again, but it still produces
4440 * interrupts (for non-MSI).
4441 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004442 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004443 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004444 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004445
Damien Lespiau055e3932014-08-18 13:49:10 +01004446 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004447 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004448 pipe_stats[pipe] = I915_READ(reg);
4449
4450 /*
4451 * Clear the PIPE*STAT regs before the IIR
4452 */
4453 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004454 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004455 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004456 }
4457 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004458 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004459
4460 if (!irq_received)
4461 break;
4462
4463 ret = IRQ_HANDLED;
4464
4465 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004466 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
4467 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4468 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004469 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004470 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004471
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004472 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004473 new_iir = I915_READ(IIR); /* Flush posted writes */
4474
Chris Wilsona266c7d2012-04-24 22:59:44 +01004475 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004476 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004477 if (iir & I915_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004478 notify_ring(&dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004479
Damien Lespiau055e3932014-08-18 13:49:10 +01004480 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004481 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
4482 i915_handle_vblank(dev_priv, pipe, pipe, iir))
4483 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004484
4485 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4486 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004487
4488 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004489 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004490
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004491 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4492 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004493 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004494
4495 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004496 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004497
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004498 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004499 gmbus_irq_handler(dev_priv);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004500
Chris Wilsona266c7d2012-04-24 22:59:44 +01004501 /* With MSI, interrupts are only generated when iir
4502 * transitions from zero to nonzero. If another bit got
4503 * set while we were handling the existing iir bits, then
4504 * we would never get another interrupt.
4505 *
4506 * This is fine on non-MSI as well, as if we hit this path
4507 * we avoid exiting the interrupt handler only to generate
4508 * another one.
4509 *
4510 * Note that for MSI this could cause a stray interrupt report
4511 * if an interrupt landed in the time between writing IIR and
4512 * the posting read. This should be rare enough to never
4513 * trigger the 99% of 100,000 interrupts test for disabling
4514 * stray interrupts.
4515 */
4516 iir = new_iir;
4517 }
4518
Imre Deak1f814da2015-12-16 02:52:19 +02004519 enable_rpm_wakeref_asserts(dev_priv);
4520
Chris Wilsona266c7d2012-04-24 22:59:44 +01004521 return ret;
4522}
4523
4524static void i965_irq_uninstall(struct drm_device * dev)
4525{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004526 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004527 int pipe;
4528
4529 if (!dev_priv)
4530 return;
4531
Egbert Eich0706f172015-09-23 16:15:27 +02004532 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004533 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004534
4535 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004536 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004537 I915_WRITE(PIPESTAT(pipe), 0);
4538 I915_WRITE(IMR, 0xffffffff);
4539 I915_WRITE(IER, 0x0);
4540
Damien Lespiau055e3932014-08-18 13:49:10 +01004541 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004542 I915_WRITE(PIPESTAT(pipe),
4543 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4544 I915_WRITE(IIR, I915_READ(IIR));
4545}
4546
Daniel Vetterfca52a52014-09-30 10:56:45 +02004547/**
4548 * intel_irq_init - initializes irq support
4549 * @dev_priv: i915 device instance
4550 *
4551 * This function initializes all the irq support including work items, timers
4552 * and all the vtables. It does not setup the interrupt itself though.
4553 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004554void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004555{
Daniel Vetterb9632912014-09-30 10:56:44 +02004556 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004557
Jani Nikula77913b32015-06-18 13:06:16 +03004558 intel_hpd_init_work(dev_priv);
4559
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004560 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004561 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004562
Deepak Sa6706b42014-03-15 20:23:22 +05304563 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004564 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004565 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004566 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004567 else
4568 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304569
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304570 dev_priv->rps.pm_intr_keep = 0;
4571
4572 /*
4573 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
4574 * if GEN6_PM_UP_EI_EXPIRED is masked.
4575 *
4576 * TODO: verify if this can be reproduced on VLV,CHV.
4577 */
4578 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
4579 dev_priv->rps.pm_intr_keep |= GEN6_PM_RP_UP_EI_EXPIRED;
4580
4581 if (INTEL_INFO(dev_priv)->gen >= 8)
4582 dev_priv->rps.pm_intr_keep |= GEN8_PMINTR_REDIRECT_TO_NON_DISP;
4583
Chris Wilson737b1502015-01-26 18:03:03 +02004584 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4585 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004586
Daniel Vetterb9632912014-09-30 10:56:44 +02004587 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004588 dev->max_vblank_count = 0;
4589 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004590 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004591 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004592 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004593 } else {
4594 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4595 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004596 }
4597
Ville Syrjälä21da2702014-08-06 14:49:55 +03004598 /*
4599 * Opt out of the vblank disable timer on everything except gen2.
4600 * Gen2 doesn't have a hardware frame counter and so depends on
4601 * vblank interrupts to produce sane vblank seuquence numbers.
4602 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004603 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004604 dev->vblank_disable_immediate = true;
4605
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004606 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4607 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004608
Daniel Vetterb9632912014-09-30 10:56:44 +02004609 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004610 dev->driver->irq_handler = cherryview_irq_handler;
4611 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4612 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4613 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4614 dev->driver->enable_vblank = valleyview_enable_vblank;
4615 dev->driver->disable_vblank = valleyview_disable_vblank;
4616 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004617 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004618 dev->driver->irq_handler = valleyview_irq_handler;
4619 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4620 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4621 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4622 dev->driver->enable_vblank = valleyview_enable_vblank;
4623 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004624 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004625 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004626 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004627 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004628 dev->driver->irq_postinstall = gen8_irq_postinstall;
4629 dev->driver->irq_uninstall = gen8_irq_uninstall;
4630 dev->driver->enable_vblank = gen8_enable_vblank;
4631 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004632 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004633 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004634 else if (HAS_PCH_SPT(dev))
4635 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4636 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004637 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004638 } else if (HAS_PCH_SPLIT(dev)) {
4639 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004640 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004641 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4642 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4643 dev->driver->enable_vblank = ironlake_enable_vblank;
4644 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004645 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004646 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004647 if (IS_GEN2(dev_priv)) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004648 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4649 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4650 dev->driver->irq_handler = i8xx_irq_handler;
4651 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004652 } else if (IS_GEN3(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004653 dev->driver->irq_preinstall = i915_irq_preinstall;
4654 dev->driver->irq_postinstall = i915_irq_postinstall;
4655 dev->driver->irq_uninstall = i915_irq_uninstall;
4656 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004657 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004658 dev->driver->irq_preinstall = i965_irq_preinstall;
4659 dev->driver->irq_postinstall = i965_irq_postinstall;
4660 dev->driver->irq_uninstall = i965_irq_uninstall;
4661 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004662 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004663 if (I915_HAS_HOTPLUG(dev_priv))
4664 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004665 dev->driver->enable_vblank = i915_enable_vblank;
4666 dev->driver->disable_vblank = i915_disable_vblank;
4667 }
4668}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004669
Daniel Vetterfca52a52014-09-30 10:56:45 +02004670/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004671 * intel_irq_install - enables the hardware interrupt
4672 * @dev_priv: i915 device instance
4673 *
4674 * This function enables the hardware interrupt handling, but leaves the hotplug
4675 * handling still disabled. It is called after intel_irq_init().
4676 *
4677 * In the driver load and resume code we need working interrupts in a few places
4678 * but don't want to deal with the hassle of concurrent probe and hotplug
4679 * workers. Hence the split into this two-stage approach.
4680 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004681int intel_irq_install(struct drm_i915_private *dev_priv)
4682{
4683 /*
4684 * We enable some interrupt sources in our postinstall hooks, so mark
4685 * interrupts as enabled _before_ actually enabling them to avoid
4686 * special cases in our ordering checks.
4687 */
4688 dev_priv->pm.irqs_enabled = true;
4689
4690 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4691}
4692
Daniel Vetterfca52a52014-09-30 10:56:45 +02004693/**
4694 * intel_irq_uninstall - finilizes all irq handling
4695 * @dev_priv: i915 device instance
4696 *
4697 * This stops interrupt and hotplug handling and unregisters and frees all
4698 * resources acquired in the init functions.
4699 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004700void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4701{
4702 drm_irq_uninstall(dev_priv->dev);
4703 intel_hpd_cancel_work(dev_priv);
4704 dev_priv->pm.irqs_enabled = false;
4705}
4706
Daniel Vetterfca52a52014-09-30 10:56:45 +02004707/**
4708 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4709 * @dev_priv: i915 device instance
4710 *
4711 * This function is used to disable interrupts at runtime, both in the runtime
4712 * pm and the system suspend/resume code.
4713 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004714void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004715{
Daniel Vetterb9632912014-09-30 10:56:44 +02004716 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004717 dev_priv->pm.irqs_enabled = false;
Imre Deak2dd2a882015-02-24 11:14:30 +02004718 synchronize_irq(dev_priv->dev->irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004719}
4720
Daniel Vetterfca52a52014-09-30 10:56:45 +02004721/**
4722 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4723 * @dev_priv: i915 device instance
4724 *
4725 * This function is used to enable interrupts at runtime, both in the runtime
4726 * pm and the system suspend/resume code.
4727 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004728void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004729{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004730 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004731 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4732 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004733}