blob: 82358d4e0cc2aa8e6b336fda7cb312985b7851a4 [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Daniel Vetterfca52a52014-09-30 10:56:45 +020040/**
41 * DOC: interrupt handling
42 *
43 * These functions provide the basic support for enabling and disabling the
44 * interrupt handling support. There's a lot more functionality in i915_irq.c
45 * and related files, but that will be described in separate chapters.
46 */
47
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +030048static const u32 hpd_ilk[HPD_NUM_PINS] = {
49 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
50};
51
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +030052static const u32 hpd_ivb[HPD_NUM_PINS] = {
53 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
54};
55
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +030056static const u32 hpd_bdw[HPD_NUM_PINS] = {
57 [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
58};
59
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020060static const u32 hpd_ibx[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050061 [HPD_CRT] = SDE_CRT_HOTPLUG,
62 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
63 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
64 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
65 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
66};
67
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020068static const u32 hpd_cpt[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050069 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010070 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050071 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
72 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
73 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
74};
75
Xiong Zhang26951ca2015-08-17 15:55:50 +080076static const u32 hpd_spt[HPD_NUM_PINS] = {
Ville Syrjälä74c0b392015-08-27 23:56:07 +030077 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
Xiong Zhang26951ca2015-08-17 15:55:50 +080078 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
79 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
80 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
81 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
82};
83
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020084static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050085 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
86 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
87 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
88 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
89 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
90 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
91};
92
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020093static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050094 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
95 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
96 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
97 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
98 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
99 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
100};
101
Ville Syrjälä4bca26d2015-05-11 20:49:10 +0300102static const u32 hpd_status_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -0500103 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
104 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
105 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
106 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
107 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
108 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
109};
110
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200111/* BXT hpd list */
112static const u32 hpd_bxt[HPD_NUM_PINS] = {
Sonika Jindal7f3561b2015-08-10 10:35:35 +0530113 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200114 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
115 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
116};
117
Paulo Zanoni5c502442014-04-01 15:37:11 -0300118/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300119#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300120 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
121 POSTING_READ(GEN8_##type##_IMR(which)); \
122 I915_WRITE(GEN8_##type##_IER(which), 0); \
123 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
124 POSTING_READ(GEN8_##type##_IIR(which)); \
125 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
126 POSTING_READ(GEN8_##type##_IIR(which)); \
127} while (0)
128
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300129#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300130 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300131 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300132 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300133 I915_WRITE(type##IIR, 0xffffffff); \
134 POSTING_READ(type##IIR); \
135 I915_WRITE(type##IIR, 0xffffffff); \
136 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300137} while (0)
138
Paulo Zanoni337ba012014-04-01 15:37:16 -0300139/*
140 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
141 */
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200142static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv,
143 i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300144{
145 u32 val = I915_READ(reg);
146
147 if (val == 0)
148 return;
149
150 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200151 i915_mmio_reg_offset(reg), val);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300152 I915_WRITE(reg, 0xffffffff);
153 POSTING_READ(reg);
154 I915_WRITE(reg, 0xffffffff);
155 POSTING_READ(reg);
156}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300157
Paulo Zanoni35079892014-04-01 15:37:15 -0300158#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300159 gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300160 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200161 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
162 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300163} while (0)
164
165#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300166 gen5_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300167 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200168 I915_WRITE(type##IMR, (imr_val)); \
169 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300170} while (0)
171
Imre Deakc9a9a262014-11-05 20:48:37 +0200172static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
173
Egbert Eich0706f172015-09-23 16:15:27 +0200174/* For display hotplug interrupt */
175static inline void
176i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
177 uint32_t mask,
178 uint32_t bits)
179{
180 uint32_t val;
181
182 assert_spin_locked(&dev_priv->irq_lock);
183 WARN_ON(bits & ~mask);
184
185 val = I915_READ(PORT_HOTPLUG_EN);
186 val &= ~mask;
187 val |= bits;
188 I915_WRITE(PORT_HOTPLUG_EN, val);
189}
190
191/**
192 * i915_hotplug_interrupt_update - update hotplug interrupt enable
193 * @dev_priv: driver private
194 * @mask: bits to update
195 * @bits: bits to enable
196 * NOTE: the HPD enable bits are modified both inside and outside
197 * of an interrupt context. To avoid that read-modify-write cycles
198 * interfer, these bits are protected by a spinlock. Since this
199 * function is usually not called from a context where the lock is
200 * held already, this function acquires the lock itself. A non-locking
201 * version is also available.
202 */
203void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
204 uint32_t mask,
205 uint32_t bits)
206{
207 spin_lock_irq(&dev_priv->irq_lock);
208 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
209 spin_unlock_irq(&dev_priv->irq_lock);
210}
211
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300212/**
213 * ilk_update_display_irq - update DEIMR
214 * @dev_priv: driver private
215 * @interrupt_mask: mask of interrupt bits to update
216 * @enabled_irq_mask: mask of interrupt bits to enable
217 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200218void ilk_update_display_irq(struct drm_i915_private *dev_priv,
219 uint32_t interrupt_mask,
220 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800221{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300222 uint32_t new_val;
223
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200224 assert_spin_locked(&dev_priv->irq_lock);
225
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300226 WARN_ON(enabled_irq_mask & ~interrupt_mask);
227
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700228 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300229 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300230
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300231 new_val = dev_priv->irq_mask;
232 new_val &= ~interrupt_mask;
233 new_val |= (~enabled_irq_mask & interrupt_mask);
234
235 if (new_val != dev_priv->irq_mask) {
236 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000237 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000238 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800239 }
240}
241
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300242/**
243 * ilk_update_gt_irq - update GTIMR
244 * @dev_priv: driver private
245 * @interrupt_mask: mask of interrupt bits to update
246 * @enabled_irq_mask: mask of interrupt bits to enable
247 */
248static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
249 uint32_t interrupt_mask,
250 uint32_t enabled_irq_mask)
251{
252 assert_spin_locked(&dev_priv->irq_lock);
253
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100254 WARN_ON(enabled_irq_mask & ~interrupt_mask);
255
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700256 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300257 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300258
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300259 dev_priv->gt_irq_mask &= ~interrupt_mask;
260 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
261 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300262}
263
Daniel Vetter480c8032014-07-16 09:49:40 +0200264void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300265{
266 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100267 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300268}
269
Daniel Vetter480c8032014-07-16 09:49:40 +0200270void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300271{
272 ilk_update_gt_irq(dev_priv, mask, 0);
273}
274
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200275static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200276{
277 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
278}
279
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200280static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200281{
282 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
283}
284
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200285static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200286{
287 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
288}
289
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300290/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200291 * snb_update_pm_irq - update GEN6_PMIMR
292 * @dev_priv: driver private
293 * @interrupt_mask: mask of interrupt bits to update
294 * @enabled_irq_mask: mask of interrupt bits to enable
295 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300296static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
297 uint32_t interrupt_mask,
298 uint32_t enabled_irq_mask)
299{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300300 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300301
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100302 WARN_ON(enabled_irq_mask & ~interrupt_mask);
303
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300304 assert_spin_locked(&dev_priv->irq_lock);
305
Paulo Zanoni605cd252013-08-06 18:57:15 -0300306 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300307 new_val &= ~interrupt_mask;
308 new_val |= (~enabled_irq_mask & interrupt_mask);
309
Paulo Zanoni605cd252013-08-06 18:57:15 -0300310 if (new_val != dev_priv->pm_irq_mask) {
311 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200312 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
313 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300314 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300315}
316
Daniel Vetter480c8032014-07-16 09:49:40 +0200317void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300318{
Imre Deak9939fba2014-11-20 23:01:47 +0200319 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
320 return;
321
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300322 snb_update_pm_irq(dev_priv, mask, mask);
323}
324
Imre Deak9939fba2014-11-20 23:01:47 +0200325static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
326 uint32_t mask)
327{
328 snb_update_pm_irq(dev_priv, mask, 0);
329}
330
Daniel Vetter480c8032014-07-16 09:49:40 +0200331void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300332{
Imre Deak9939fba2014-11-20 23:01:47 +0200333 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
334 return;
335
336 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300337}
338
Chris Wilsondc979972016-05-10 14:10:04 +0100339void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200340{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200341 i915_reg_t reg = gen6_pm_iir(dev_priv);
Imre Deak3cc134e2014-11-19 15:30:03 +0200342
343 spin_lock_irq(&dev_priv->irq_lock);
344 I915_WRITE(reg, dev_priv->pm_rps_events);
345 I915_WRITE(reg, dev_priv->pm_rps_events);
346 POSTING_READ(reg);
Imre Deak096fad92015-03-23 19:11:35 +0200347 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200348 spin_unlock_irq(&dev_priv->irq_lock);
349}
350
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100351void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200352{
Imre Deakb900b942014-11-05 20:48:48 +0200353 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100354 WARN_ON_ONCE(dev_priv->rps.pm_iir);
355 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200356 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200357 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
358 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200359 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200360
Imre Deakb900b942014-11-05 20:48:48 +0200361 spin_unlock_irq(&dev_priv->irq_lock);
362}
363
Imre Deak59d02a12014-12-19 19:33:26 +0200364u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
365{
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +0530366 return (mask & ~dev_priv->rps.pm_intr_keep);
Imre Deak59d02a12014-12-19 19:33:26 +0200367}
368
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100369void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200370{
Imre Deakd4d70aa2014-11-19 15:30:04 +0200371 spin_lock_irq(&dev_priv->irq_lock);
372 dev_priv->rps.interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200373
Imre Deak59d02a12014-12-19 19:33:26 +0200374 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200375
376 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200377 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
378 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200379
380 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100381 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100382
383 /* Now that we will not be generating any more work, flush any
384 * outsanding tasks. As we are called on the RPS idle path,
385 * we will reset the GPU to minimum frequencies, so the current
386 * state of the worker can be discarded.
387 */
388 cancel_work_sync(&dev_priv->rps.work);
389 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200390}
391
Ben Widawsky09610212014-05-15 20:58:08 +0300392/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200393 * bdw_update_port_irq - update DE port interrupt
394 * @dev_priv: driver private
395 * @interrupt_mask: mask of interrupt bits to update
396 * @enabled_irq_mask: mask of interrupt bits to enable
397 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300398static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
399 uint32_t interrupt_mask,
400 uint32_t enabled_irq_mask)
401{
402 uint32_t new_val;
403 uint32_t old_val;
404
405 assert_spin_locked(&dev_priv->irq_lock);
406
407 WARN_ON(enabled_irq_mask & ~interrupt_mask);
408
409 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
410 return;
411
412 old_val = I915_READ(GEN8_DE_PORT_IMR);
413
414 new_val = old_val;
415 new_val &= ~interrupt_mask;
416 new_val |= (~enabled_irq_mask & interrupt_mask);
417
418 if (new_val != old_val) {
419 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
420 POSTING_READ(GEN8_DE_PORT_IMR);
421 }
422}
423
424/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200425 * bdw_update_pipe_irq - update DE pipe interrupt
426 * @dev_priv: driver private
427 * @pipe: pipe whose interrupt to update
428 * @interrupt_mask: mask of interrupt bits to update
429 * @enabled_irq_mask: mask of interrupt bits to enable
430 */
431void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
432 enum pipe pipe,
433 uint32_t interrupt_mask,
434 uint32_t enabled_irq_mask)
435{
436 uint32_t new_val;
437
438 assert_spin_locked(&dev_priv->irq_lock);
439
440 WARN_ON(enabled_irq_mask & ~interrupt_mask);
441
442 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
443 return;
444
445 new_val = dev_priv->de_irq_mask[pipe];
446 new_val &= ~interrupt_mask;
447 new_val |= (~enabled_irq_mask & interrupt_mask);
448
449 if (new_val != dev_priv->de_irq_mask[pipe]) {
450 dev_priv->de_irq_mask[pipe] = new_val;
451 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
452 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
453 }
454}
455
456/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200457 * ibx_display_interrupt_update - update SDEIMR
458 * @dev_priv: driver private
459 * @interrupt_mask: mask of interrupt bits to update
460 * @enabled_irq_mask: mask of interrupt bits to enable
461 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200462void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
463 uint32_t interrupt_mask,
464 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200465{
466 uint32_t sdeimr = I915_READ(SDEIMR);
467 sdeimr &= ~interrupt_mask;
468 sdeimr |= (~enabled_irq_mask & interrupt_mask);
469
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100470 WARN_ON(enabled_irq_mask & ~interrupt_mask);
471
Daniel Vetterfee884e2013-07-04 23:35:21 +0200472 assert_spin_locked(&dev_priv->irq_lock);
473
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700474 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300475 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300476
Daniel Vetterfee884e2013-07-04 23:35:21 +0200477 I915_WRITE(SDEIMR, sdeimr);
478 POSTING_READ(SDEIMR);
479}
Paulo Zanoni86642812013-04-12 17:57:57 -0300480
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100481static void
Imre Deak755e9012014-02-10 18:42:47 +0200482__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
483 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800484{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200485 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200486 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800487
Daniel Vetterb79480b2013-06-27 17:52:10 +0200488 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200489 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200490
Ville Syrjälä04feced2014-04-03 13:28:33 +0300491 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
492 status_mask & ~PIPESTAT_INT_STATUS_MASK,
493 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
494 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200495 return;
496
497 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200498 return;
499
Imre Deak91d181d2014-02-10 18:42:49 +0200500 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
501
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200502 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200503 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200504 I915_WRITE(reg, pipestat);
505 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800506}
507
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100508static void
Imre Deak755e9012014-02-10 18:42:47 +0200509__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
510 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800511{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200512 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200513 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800514
Daniel Vetterb79480b2013-06-27 17:52:10 +0200515 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200516 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200517
Ville Syrjälä04feced2014-04-03 13:28:33 +0300518 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
519 status_mask & ~PIPESTAT_INT_STATUS_MASK,
520 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
521 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200522 return;
523
Imre Deak755e9012014-02-10 18:42:47 +0200524 if ((pipestat & enable_mask) == 0)
525 return;
526
Imre Deak91d181d2014-02-10 18:42:49 +0200527 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
528
Imre Deak755e9012014-02-10 18:42:47 +0200529 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200530 I915_WRITE(reg, pipestat);
531 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800532}
533
Imre Deak10c59c52014-02-10 18:42:48 +0200534static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
535{
536 u32 enable_mask = status_mask << 16;
537
538 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300539 * On pipe A we don't support the PSR interrupt yet,
540 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200541 */
542 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
543 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300544 /*
545 * On pipe B and C we don't support the PSR interrupt yet, on pipe
546 * A the same bit is for perf counters which we don't use either.
547 */
548 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
549 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200550
551 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
552 SPRITE0_FLIP_DONE_INT_EN_VLV |
553 SPRITE1_FLIP_DONE_INT_EN_VLV);
554 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
555 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
556 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
557 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
558
559 return enable_mask;
560}
561
Imre Deak755e9012014-02-10 18:42:47 +0200562void
563i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
564 u32 status_mask)
565{
566 u32 enable_mask;
567
Wayne Boyer666a4532015-12-09 12:29:35 -0800568 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100569 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200570 status_mask);
571 else
572 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200573 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
574}
575
576void
577i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
578 u32 status_mask)
579{
580 u32 enable_mask;
581
Wayne Boyer666a4532015-12-09 12:29:35 -0800582 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100583 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200584 status_mask);
585 else
586 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200587 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
588}
589
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000590/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300591 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100592 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000593 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100594static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000595{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100596 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300597 return;
598
Daniel Vetter13321782014-09-15 14:55:29 +0200599 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000600
Imre Deak755e9012014-02-10 18:42:47 +0200601 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100602 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200603 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200604 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000605
Daniel Vetter13321782014-09-15 14:55:29 +0200606 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000607}
608
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300609/*
610 * This timing diagram depicts the video signal in and
611 * around the vertical blanking period.
612 *
613 * Assumptions about the fictitious mode used in this example:
614 * vblank_start >= 3
615 * vsync_start = vblank_start + 1
616 * vsync_end = vblank_start + 2
617 * vtotal = vblank_start + 3
618 *
619 * start of vblank:
620 * latch double buffered registers
621 * increment frame counter (ctg+)
622 * generate start of vblank interrupt (gen4+)
623 * |
624 * | frame start:
625 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
626 * | may be shifted forward 1-3 extra lines via PIPECONF
627 * | |
628 * | | start of vsync:
629 * | | generate vsync interrupt
630 * | | |
631 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
632 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
633 * ----va---> <-----------------vb--------------------> <--------va-------------
634 * | | <----vs-----> |
635 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
636 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
637 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
638 * | | |
639 * last visible pixel first visible pixel
640 * | increment frame counter (gen3/4)
641 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
642 *
643 * x = horizontal active
644 * _ = horizontal blanking
645 * hs = horizontal sync
646 * va = vertical active
647 * vb = vertical blanking
648 * vs = vertical sync
649 * vbs = vblank_start (number)
650 *
651 * Summary:
652 * - most events happen at the start of horizontal sync
653 * - frame start happens at the start of horizontal blank, 1-4 lines
654 * (depending on PIPECONF settings) after the start of vblank
655 * - gen3/4 pixel and frame counter are synchronized with the start
656 * of horizontal active on the first line of vertical active
657 */
658
Keith Packard42f52ef2008-10-18 19:39:29 -0700659/* Called from drm generic code, passed a 'crtc', which
660 * we use as a pipe index
661 */
Thierry Reding88e72712015-09-24 18:35:31 +0200662static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700663{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100664 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200665 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300666 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100667 struct intel_crtc *intel_crtc =
668 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200669 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700670
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100671 htotal = mode->crtc_htotal;
672 hsync_start = mode->crtc_hsync_start;
673 vbl_start = mode->crtc_vblank_start;
674 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
675 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300676
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300677 /* Convert to pixel count */
678 vbl_start *= htotal;
679
680 /* Start of vblank event occurs at start of hsync */
681 vbl_start -= htotal - hsync_start;
682
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800683 high_frame = PIPEFRAME(pipe);
684 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100685
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700686 /*
687 * High & low register fields aren't synchronized, so make sure
688 * we get a low value that's stable across two reads of the high
689 * register.
690 */
691 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100692 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300693 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100694 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700695 } while (high1 != high2);
696
Chris Wilson5eddb702010-09-11 13:48:45 +0100697 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300698 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100699 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300700
701 /*
702 * The frame counter increments at beginning of active.
703 * Cook up a vblank counter by also checking the pixel
704 * counter against vblank start.
705 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200706 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700707}
708
Dave Airlie974e59b2015-10-30 09:45:33 +1000709static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800710{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100711 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800712
Ville Syrjälä649636e2015-09-22 19:50:01 +0300713 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800714}
715
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300716/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300717static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
718{
719 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100720 struct drm_i915_private *dev_priv = to_i915(dev);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200721 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300722 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300723 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300724
Ville Syrjälä80715b22014-05-15 20:23:23 +0300725 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300726 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
727 vtotal /= 2;
728
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100729 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300730 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300731 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300732 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300733
734 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700735 * On HSW, the DSL reg (0x70000) appears to return 0 if we
736 * read it just before the start of vblank. So try it again
737 * so we don't accidentally end up spanning a vblank frame
738 * increment, causing the pipe_update_end() code to squak at us.
739 *
740 * The nature of this problem means we can't simply check the ISR
741 * bit and return the vblank start value; nor can we use the scanline
742 * debug register in the transcoder as it appears to have the same
743 * problem. We may need to extend this to include other platforms,
744 * but so far testing only shows the problem on HSW.
745 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100746 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700747 int i, temp;
748
749 for (i = 0; i < 100; i++) {
750 udelay(1);
751 temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) &
752 DSL_LINEMASK_GEN3;
753 if (temp != position) {
754 position = temp;
755 break;
756 }
757 }
758 }
759
760 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300761 * See update_scanline_offset() for the details on the
762 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300763 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300764 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300765}
766
Thierry Reding88e72712015-09-24 18:35:31 +0200767static int i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200768 unsigned int flags, int *vpos, int *hpos,
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300769 ktime_t *stime, ktime_t *etime,
770 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100771{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100772 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300773 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
774 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300775 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300776 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100777 bool in_vbl = true;
778 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100779 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100780
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200781 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100782 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800783 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100784 return 0;
785 }
786
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300787 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300788 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300789 vtotal = mode->crtc_vtotal;
790 vbl_start = mode->crtc_vblank_start;
791 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100792
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200793 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
794 vbl_start = DIV_ROUND_UP(vbl_start, 2);
795 vbl_end /= 2;
796 vtotal /= 2;
797 }
798
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300799 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
800
Mario Kleinerad3543e2013-10-30 05:13:08 +0100801 /*
802 * Lock uncore.lock, as we will do multiple timing critical raw
803 * register reads, potentially with preemption disabled, so the
804 * following code must not block on uncore.lock.
805 */
806 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300807
Mario Kleinerad3543e2013-10-30 05:13:08 +0100808 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
809
810 /* Get optional system timestamp before query. */
811 if (stime)
812 *stime = ktime_get();
813
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100814 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100815 /* No obvious pixelcount register. Only query vertical
816 * scanout position from Display scan line register.
817 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300818 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100819 } else {
820 /* Have access to pixelcount since start of frame.
821 * We can split this into vertical and horizontal
822 * scanout position.
823 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300824 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100825
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300826 /* convert to pixel counts */
827 vbl_start *= htotal;
828 vbl_end *= htotal;
829 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300830
831 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300832 * In interlaced modes, the pixel counter counts all pixels,
833 * so one field will have htotal more pixels. In order to avoid
834 * the reported position from jumping backwards when the pixel
835 * counter is beyond the length of the shorter field, just
836 * clamp the position the length of the shorter field. This
837 * matches how the scanline counter based position works since
838 * the scanline counter doesn't count the two half lines.
839 */
840 if (position >= vtotal)
841 position = vtotal - 1;
842
843 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300844 * Start of vblank interrupt is triggered at start of hsync,
845 * just prior to the first active line of vblank. However we
846 * consider lines to start at the leading edge of horizontal
847 * active. So, should we get here before we've crossed into
848 * the horizontal active of the first line in vblank, we would
849 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
850 * always add htotal-hsync_start to the current pixel position.
851 */
852 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300853 }
854
Mario Kleinerad3543e2013-10-30 05:13:08 +0100855 /* Get optional system timestamp after query. */
856 if (etime)
857 *etime = ktime_get();
858
859 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
860
861 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
862
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300863 in_vbl = position >= vbl_start && position < vbl_end;
864
865 /*
866 * While in vblank, position will be negative
867 * counting up towards 0 at vbl_end. And outside
868 * vblank, position will be positive counting
869 * up since vbl_end.
870 */
871 if (position >= vbl_start)
872 position -= vbl_end;
873 else
874 position += vtotal - vbl_end;
875
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100876 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300877 *vpos = position;
878 *hpos = 0;
879 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100880 *vpos = position / htotal;
881 *hpos = position - (*vpos * htotal);
882 }
883
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100884 /* In vblank? */
885 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200886 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100887
888 return ret;
889}
890
Ville Syrjäläa225f072014-04-29 13:35:45 +0300891int intel_get_crtc_scanline(struct intel_crtc *crtc)
892{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100893 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +0300894 unsigned long irqflags;
895 int position;
896
897 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
898 position = __intel_get_crtc_scanline(crtc);
899 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
900
901 return position;
902}
903
Thierry Reding88e72712015-09-24 18:35:31 +0200904static int i915_get_vblank_timestamp(struct drm_device *dev, unsigned int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100905 int *max_error,
906 struct timeval *vblank_time,
907 unsigned flags)
908{
Chris Wilson4041b852011-01-22 10:07:56 +0000909 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100910
Thierry Reding88e72712015-09-24 18:35:31 +0200911 if (pipe >= INTEL_INFO(dev)->num_pipes) {
912 DRM_ERROR("Invalid crtc %u\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100913 return -EINVAL;
914 }
915
916 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000917 crtc = intel_get_crtc_for_pipe(dev, pipe);
918 if (crtc == NULL) {
Thierry Reding88e72712015-09-24 18:35:31 +0200919 DRM_ERROR("Invalid crtc %u\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000920 return -EINVAL;
921 }
922
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200923 if (!crtc->hwmode.crtc_clock) {
Thierry Reding88e72712015-09-24 18:35:31 +0200924 DRM_DEBUG_KMS("crtc %u is disabled\n", pipe);
Chris Wilson4041b852011-01-22 10:07:56 +0000925 return -EBUSY;
926 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100927
928 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000929 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
930 vblank_time, flags,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200931 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100932}
933
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100934static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800935{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000936 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200937 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200938
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200939 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800940
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200941 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
942
Daniel Vetter20e4d402012-08-08 23:35:39 +0200943 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200944
Jesse Barnes7648fa92010-05-20 14:28:11 -0700945 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000946 busy_up = I915_READ(RCPREVBSYTUPAVG);
947 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800948 max_avg = I915_READ(RCBMAXAVG);
949 min_avg = I915_READ(RCBMINAVG);
950
951 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000952 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200953 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
954 new_delay = dev_priv->ips.cur_delay - 1;
955 if (new_delay < dev_priv->ips.max_delay)
956 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000957 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200958 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
959 new_delay = dev_priv->ips.cur_delay + 1;
960 if (new_delay > dev_priv->ips.min_delay)
961 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800962 }
963
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100964 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200965 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800966
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200967 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200968
Jesse Barnesf97108d2010-01-29 11:27:07 -0800969 return;
970}
971
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +0000972static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +0100973{
Chris Wilsonaca34b62016-07-06 12:39:02 +0100974 smp_store_mb(engine->breadcrumbs.irq_posted, true);
Chris Wilson83348ba2016-08-09 17:47:51 +0100975 if (intel_engine_wakeup(engine))
Chris Wilson688e6c72016-07-01 17:23:15 +0100976 trace_i915_gem_request_notify(engine);
Chris Wilson549f7362010-10-19 11:19:32 +0100977}
978
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000979static void vlv_c0_read(struct drm_i915_private *dev_priv,
980 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400981{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000982 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
983 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
984 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400985}
986
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000987static bool vlv_c0_above(struct drm_i915_private *dev_priv,
988 const struct intel_rps_ei *old,
989 const struct intel_rps_ei *now,
990 int threshold)
Deepak S31685c22014-07-03 17:33:01 -0400991{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000992 u64 time, c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +0300993 unsigned int mul = 100;
Deepak S31685c22014-07-03 17:33:01 -0400994
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000995 if (old->cz_clock == 0)
996 return false;
Deepak S31685c22014-07-03 17:33:01 -0400997
Ville Syrjälä7bad74d2015-09-24 23:29:20 +0300998 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
999 mul <<= 8;
1000
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001001 time = now->cz_clock - old->cz_clock;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001002 time *= threshold * dev_priv->czclk_freq;
Deepak S31685c22014-07-03 17:33:01 -04001003
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001004 /* Workload can be split between render + media, e.g. SwapBuffers
1005 * being blitted in X after being rendered in mesa. To account for
1006 * this we need to combine both engines into our activity counter.
1007 */
1008 c0 = now->render_c0 - old->render_c0;
1009 c0 += now->media_c0 - old->media_c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001010 c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC;
Deepak S31685c22014-07-03 17:33:01 -04001011
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001012 return c0 >= time;
1013}
Deepak S31685c22014-07-03 17:33:01 -04001014
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001015void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1016{
1017 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
1018 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001019}
1020
1021static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1022{
1023 struct intel_rps_ei now;
1024 u32 events = 0;
1025
Chris Wilson6f4b12f82015-03-18 09:48:23 +00001026 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001027 return 0;
1028
1029 vlv_c0_read(dev_priv, &now);
1030 if (now.cz_clock == 0)
1031 return 0;
Deepak S31685c22014-07-03 17:33:01 -04001032
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001033 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1034 if (!vlv_c0_above(dev_priv,
1035 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001036 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001037 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1038 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -04001039 }
1040
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001041 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1042 if (vlv_c0_above(dev_priv,
1043 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001044 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001045 events |= GEN6_PM_RP_UP_THRESHOLD;
1046 dev_priv->rps.up_ei = now;
1047 }
1048
1049 return events;
Deepak S31685c22014-07-03 17:33:01 -04001050}
1051
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001052static bool any_waiters(struct drm_i915_private *dev_priv)
1053{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00001054 struct intel_engine_cs *engine;
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001055
Dave Gordonb4ac5af2016-03-24 11:20:38 +00001056 for_each_engine(engine, dev_priv)
Chris Wilson688e6c72016-07-01 17:23:15 +01001057 if (intel_engine_has_waiter(engine))
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001058 return true;
1059
1060 return false;
1061}
1062
Ben Widawsky4912d042011-04-25 11:25:20 -07001063static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001064{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001065 struct drm_i915_private *dev_priv =
1066 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001067 bool client_boost;
1068 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001069 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001070
Daniel Vetter59cdb632013-07-04 23:35:28 +02001071 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001072 /* Speed up work cancelation during disabling rps interrupts. */
1073 if (!dev_priv->rps.interrupts_enabled) {
1074 spin_unlock_irq(&dev_priv->irq_lock);
1075 return;
1076 }
Imre Deak1f814da2015-12-16 02:52:19 +02001077
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001078 pm_iir = dev_priv->rps.pm_iir;
1079 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001080 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1081 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001082 client_boost = dev_priv->rps.client_boost;
1083 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001084 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001085
Paulo Zanoni60611c12013-08-15 11:50:01 -03001086 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301087 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001088
Chris Wilson8d3afd72015-05-21 21:01:47 +01001089 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilsonc33d2472016-07-04 08:08:36 +01001090 return;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001091
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001092 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001093
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001094 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1095
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001096 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001097 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001098 min = dev_priv->rps.min_freq_softlimit;
1099 max = dev_priv->rps.max_freq_softlimit;
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001100 if (client_boost || any_waiters(dev_priv))
1101 max = dev_priv->rps.max_freq;
1102 if (client_boost && new_delay < dev_priv->rps.boost_freq) {
1103 new_delay = dev_priv->rps.boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001104 adj = 0;
1105 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001106 if (adj > 0)
1107 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001108 else /* CHV needs even encode values */
1109 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001110 /*
1111 * For better performance, jump directly
1112 * to RPe if we're below it.
1113 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001114 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001115 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001116 adj = 0;
1117 }
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001118 } else if (client_boost || any_waiters(dev_priv)) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001119 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001120 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001121 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1122 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001123 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001124 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001125 adj = 0;
1126 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1127 if (adj < 0)
1128 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001129 else /* CHV needs even encode values */
1130 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001131 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001132 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001133 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001134
Chris Wilsonedcf2842015-04-07 16:20:29 +01001135 dev_priv->rps.last_adj = adj;
1136
Ben Widawsky79249632012-09-07 19:43:42 -07001137 /* sysfs frequency interfaces may have snuck in while servicing the
1138 * interrupt
1139 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001140 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001141 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301142
Chris Wilsondc979972016-05-10 14:10:04 +01001143 intel_set_rps(dev_priv, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001144
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001145 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001146}
1147
Ben Widawskye3689192012-05-25 16:56:22 -07001148
1149/**
1150 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1151 * occurred.
1152 * @work: workqueue struct
1153 *
1154 * Doesn't actually do anything except notify userspace. As a consequence of
1155 * this event, userspace should try to remap the bad rows since statistically
1156 * it is likely the same row is more likely to go bad again.
1157 */
1158static void ivybridge_parity_work(struct work_struct *work)
1159{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001160 struct drm_i915_private *dev_priv =
1161 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001162 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001163 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001164 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001165 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001166
1167 /* We must turn off DOP level clock gating to access the L3 registers.
1168 * In order to prevent a get/put style interface, acquire struct mutex
1169 * any time we access those registers.
1170 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001171 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001172
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001173 /* If we've screwed up tracking, just let the interrupt fire again */
1174 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1175 goto out;
1176
Ben Widawskye3689192012-05-25 16:56:22 -07001177 misccpctl = I915_READ(GEN7_MISCCPCTL);
1178 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1179 POSTING_READ(GEN7_MISCCPCTL);
1180
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001181 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001182 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001183
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001184 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001185 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001186 break;
1187
1188 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1189
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001190 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001191
1192 error_status = I915_READ(reg);
1193 row = GEN7_PARITY_ERROR_ROW(error_status);
1194 bank = GEN7_PARITY_ERROR_BANK(error_status);
1195 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1196
1197 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1198 POSTING_READ(reg);
1199
1200 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1201 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1202 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1203 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1204 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1205 parity_event[5] = NULL;
1206
Chris Wilson91c8a322016-07-05 10:40:23 +01001207 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001208 KOBJ_CHANGE, parity_event);
1209
1210 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1211 slice, row, bank, subbank);
1212
1213 kfree(parity_event[4]);
1214 kfree(parity_event[3]);
1215 kfree(parity_event[2]);
1216 kfree(parity_event[1]);
1217 }
Ben Widawskye3689192012-05-25 16:56:22 -07001218
1219 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1220
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001221out:
1222 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001223 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001224 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001225 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001226
Chris Wilson91c8a322016-07-05 10:40:23 +01001227 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001228}
1229
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001230static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1231 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001232{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001233 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001234 return;
1235
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001236 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001237 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001238 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001239
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001240 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001241 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1242 dev_priv->l3_parity.which_slice |= 1 << 1;
1243
1244 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1245 dev_priv->l3_parity.which_slice |= 1 << 0;
1246
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001247 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001248}
1249
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001250static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001251 u32 gt_iir)
1252{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001253 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001254 notify_ring(&dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001255 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001256 notify_ring(&dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001257}
1258
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001259static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001260 u32 gt_iir)
1261{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001262 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001263 notify_ring(&dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001264 if (gt_iir & GT_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001265 notify_ring(&dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001266 if (gt_iir & GT_BLT_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001267 notify_ring(&dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001268
Ben Widawskycc609d52013-05-28 19:22:29 -07001269 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1270 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001271 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1272 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001273
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001274 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1275 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001276}
1277
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001278static __always_inline void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001279gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001280{
1281 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift))
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001282 notify_ring(engine);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001283 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift))
Tvrtko Ursulin27af5ee2016-04-04 12:11:56 +01001284 tasklet_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001285}
1286
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001287static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1288 u32 master_ctl,
1289 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001290{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001291 irqreturn_t ret = IRQ_NONE;
1292
1293 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001294 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1295 if (gt_iir[0]) {
1296 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001297 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001298 } else
1299 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1300 }
1301
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001302 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001303 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1304 if (gt_iir[1]) {
1305 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001306 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001307 } else
1308 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1309 }
1310
Chris Wilson74cdb332015-04-07 16:21:05 +01001311 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001312 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1313 if (gt_iir[3]) {
1314 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001315 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001316 } else
1317 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1318 }
1319
Ben Widawsky09610212014-05-15 20:58:08 +03001320 if (master_ctl & GEN8_GT_PM_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001321 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
1322 if (gt_iir[2] & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001323 I915_WRITE_FW(GEN8_GT_IIR(2),
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001324 gt_iir[2] & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001325 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001326 } else
1327 DRM_ERROR("The master control interrupt lied (PM)!\n");
1328 }
1329
Ben Widawskyabd58f02013-11-02 21:07:09 -07001330 return ret;
1331}
1332
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001333static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1334 u32 gt_iir[4])
1335{
1336 if (gt_iir[0]) {
1337 gen8_cs_irq_handler(&dev_priv->engine[RCS],
1338 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
1339 gen8_cs_irq_handler(&dev_priv->engine[BCS],
1340 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1341 }
1342
1343 if (gt_iir[1]) {
1344 gen8_cs_irq_handler(&dev_priv->engine[VCS],
1345 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
1346 gen8_cs_irq_handler(&dev_priv->engine[VCS2],
1347 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1348 }
1349
1350 if (gt_iir[3])
1351 gen8_cs_irq_handler(&dev_priv->engine[VECS],
1352 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1353
1354 if (gt_iir[2] & dev_priv->pm_rps_events)
1355 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
1356}
1357
Imre Deak63c88d22015-07-20 14:43:39 -07001358static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1359{
1360 switch (port) {
1361 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001362 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001363 case PORT_B:
1364 return val & PORTB_HOTPLUG_LONG_DETECT;
1365 case PORT_C:
1366 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001367 default:
1368 return false;
1369 }
1370}
1371
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001372static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1373{
1374 switch (port) {
1375 case PORT_E:
1376 return val & PORTE_HOTPLUG_LONG_DETECT;
1377 default:
1378 return false;
1379 }
1380}
1381
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001382static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1383{
1384 switch (port) {
1385 case PORT_A:
1386 return val & PORTA_HOTPLUG_LONG_DETECT;
1387 case PORT_B:
1388 return val & PORTB_HOTPLUG_LONG_DETECT;
1389 case PORT_C:
1390 return val & PORTC_HOTPLUG_LONG_DETECT;
1391 case PORT_D:
1392 return val & PORTD_HOTPLUG_LONG_DETECT;
1393 default:
1394 return false;
1395 }
1396}
1397
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001398static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1399{
1400 switch (port) {
1401 case PORT_A:
1402 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1403 default:
1404 return false;
1405 }
1406}
1407
Jani Nikula676574d2015-05-28 15:43:53 +03001408static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001409{
1410 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001411 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001412 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001413 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001414 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001415 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001416 return val & PORTD_HOTPLUG_LONG_DETECT;
1417 default:
1418 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001419 }
1420}
1421
Jani Nikula676574d2015-05-28 15:43:53 +03001422static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001423{
1424 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001425 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001426 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001427 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001428 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001429 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001430 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1431 default:
1432 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001433 }
1434}
1435
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001436/*
1437 * Get a bit mask of pins that have triggered, and which ones may be long.
1438 * This can be called multiple times with the same masks to accumulate
1439 * hotplug detection results from several registers.
1440 *
1441 * Note that the caller is expected to zero out the masks initially.
1442 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001443static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001444 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001445 const u32 hpd[HPD_NUM_PINS],
1446 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001447{
Jani Nikula8c841e52015-06-18 13:06:17 +03001448 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001449 int i;
1450
Jani Nikula676574d2015-05-28 15:43:53 +03001451 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001452 if ((hpd[i] & hotplug_trigger) == 0)
1453 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001454
Jani Nikula8c841e52015-06-18 13:06:17 +03001455 *pin_mask |= BIT(i);
1456
Imre Deakcc24fcd2015-07-21 15:32:45 -07001457 if (!intel_hpd_pin_to_port(i, &port))
1458 continue;
1459
Imre Deakfd63e2a2015-07-21 15:32:44 -07001460 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001461 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001462 }
1463
1464 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1465 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1466
1467}
1468
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001469static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001470{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001471 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001472}
1473
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001474static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001475{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001476 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001477}
1478
Shuang He8bf1e9f2013-10-15 18:55:27 +01001479#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001480static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1481 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001482 uint32_t crc0, uint32_t crc1,
1483 uint32_t crc2, uint32_t crc3,
1484 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001485{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001486 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1487 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001488 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001489
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001490 spin_lock(&pipe_crc->lock);
1491
Damien Lespiau0c912c72013-10-15 18:55:37 +01001492 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001493 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001494 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001495 return;
1496 }
1497
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001498 head = pipe_crc->head;
1499 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001500
1501 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001502 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001503 DRM_ERROR("CRC buffer overflowing\n");
1504 return;
1505 }
1506
1507 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001508
Chris Wilson91c8a322016-07-05 10:40:23 +01001509 entry->frame = dev_priv->drm.driver->get_vblank_counter(&dev_priv->drm,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001510 pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001511 entry->crc[0] = crc0;
1512 entry->crc[1] = crc1;
1513 entry->crc[2] = crc2;
1514 entry->crc[3] = crc3;
1515 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001516
1517 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001518 pipe_crc->head = head;
1519
1520 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001521
1522 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001523}
Daniel Vetter277de952013-10-18 16:37:07 +02001524#else
1525static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001526display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1527 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001528 uint32_t crc0, uint32_t crc1,
1529 uint32_t crc2, uint32_t crc3,
1530 uint32_t crc4) {}
1531#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001532
Daniel Vetter277de952013-10-18 16:37:07 +02001533
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001534static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1535 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001536{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001537 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001538 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1539 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001540}
1541
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001542static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1543 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001544{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001545 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001546 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1547 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1548 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1549 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1550 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001551}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001552
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001553static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1554 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001555{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001556 uint32_t res1, res2;
1557
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001558 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001559 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1560 else
1561 res1 = 0;
1562
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001563 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001564 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1565 else
1566 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001567
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001568 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001569 I915_READ(PIPE_CRC_RES_RED(pipe)),
1570 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1571 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1572 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001573}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001574
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001575/* The RPS events need forcewake, so we add them to a work queue and mask their
1576 * IMR bits until the work is done. Other interrupts can be processed without
1577 * the work queue. */
1578static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001579{
Deepak Sa6706b42014-03-15 20:23:22 +05301580 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001581 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001582 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001583 if (dev_priv->rps.interrupts_enabled) {
1584 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001585 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001586 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001587 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001588 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001589
Imre Deakc9a9a262014-11-05 20:48:37 +02001590 if (INTEL_INFO(dev_priv)->gen >= 8)
1591 return;
1592
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001593 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001594 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00001595 notify_ring(&dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001596
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001597 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1598 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001599 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001600}
1601
Daniel Vetter5a21b662016-05-24 17:13:53 +02001602static bool intel_pipe_handle_vblank(struct drm_i915_private *dev_priv,
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001603 enum pipe pipe)
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001604{
Daniel Vetter5a21b662016-05-24 17:13:53 +02001605 bool ret;
1606
Chris Wilson91c8a322016-07-05 10:40:23 +01001607 ret = drm_handle_vblank(&dev_priv->drm, pipe);
Daniel Vetter5a21b662016-05-24 17:13:53 +02001608 if (ret)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001609 intel_finish_page_flip_mmio(dev_priv, pipe);
Daniel Vetter5a21b662016-05-24 17:13:53 +02001610
1611 return ret;
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001612}
1613
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001614static void valleyview_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1615 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001616{
Imre Deakc1874ed2014-02-04 21:35:46 +02001617 int pipe;
1618
Imre Deak58ead0d2014-02-04 21:35:47 +02001619 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001620
1621 if (!dev_priv->display_irqs_enabled) {
1622 spin_unlock(&dev_priv->irq_lock);
1623 return;
1624 }
1625
Damien Lespiau055e3932014-08-18 13:49:10 +01001626 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001627 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001628 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001629
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001630 /*
1631 * PIPESTAT bits get signalled even when the interrupt is
1632 * disabled with the mask bits, and some of the status bits do
1633 * not generate interrupts at all (like the underrun bit). Hence
1634 * we need to be careful that we only handle what we want to
1635 * handle.
1636 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001637
1638 /* fifo underruns are filterered in the underrun handler. */
1639 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001640
1641 switch (pipe) {
1642 case PIPE_A:
1643 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1644 break;
1645 case PIPE_B:
1646 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1647 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001648 case PIPE_C:
1649 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1650 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001651 }
1652 if (iir & iir_bit)
1653 mask |= dev_priv->pipestat_irq_mask[pipe];
1654
1655 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001656 continue;
1657
1658 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001659 mask |= PIPESTAT_INT_ENABLE_MASK;
1660 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001661
1662 /*
1663 * Clear the PIPE*STAT regs before the IIR
1664 */
Imre Deak91d181d2014-02-10 18:42:49 +02001665 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1666 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001667 I915_WRITE(reg, pipe_stats[pipe]);
1668 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001669 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001670}
1671
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001672static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001673 u32 pipe_stats[I915_MAX_PIPES])
1674{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001675 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001676
Damien Lespiau055e3932014-08-18 13:49:10 +01001677 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02001678 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1679 intel_pipe_handle_vblank(dev_priv, pipe))
1680 intel_check_page_flip(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001681
Maarten Lankhorst5251f042016-05-17 15:07:47 +02001682 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02001683 intel_finish_page_flip_cs(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001684
1685 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001686 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001687
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001688 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1689 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001690 }
1691
1692 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001693 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001694}
1695
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001696static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001697{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001698 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001699
1700 if (hotplug_status)
1701 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1702
1703 return hotplug_status;
1704}
1705
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001706static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001707 u32 hotplug_status)
1708{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001709 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001710
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001711 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1712 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001713 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001714
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001715 if (hotplug_trigger) {
1716 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1717 hotplug_trigger, hpd_status_g4x,
1718 i9xx_port_hotplug_long_detect);
1719
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001720 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001721 }
Jani Nikula369712e2015-05-27 15:03:40 +03001722
1723 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001724 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001725 } else {
1726 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001727
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001728 if (hotplug_trigger) {
1729 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001730 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001731 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001732 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001733 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001734 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001735}
1736
Daniel Vetterff1f5252012-10-02 15:10:55 +02001737static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001738{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001739 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001740 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001741 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001742
Imre Deak2dd2a882015-02-24 11:14:30 +02001743 if (!intel_irqs_enabled(dev_priv))
1744 return IRQ_NONE;
1745
Imre Deak1f814da2015-12-16 02:52:19 +02001746 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1747 disable_rpm_wakeref_asserts(dev_priv);
1748
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001749 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001750 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001751 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001752 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001753 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001754
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001755 gt_iir = I915_READ(GTIIR);
1756 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001757 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001758
1759 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001760 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001761
1762 ret = IRQ_HANDLED;
1763
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001764 /*
1765 * Theory on interrupt generation, based on empirical evidence:
1766 *
1767 * x = ((VLV_IIR & VLV_IER) ||
1768 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1769 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1770 *
1771 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1772 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1773 * guarantee the CPU interrupt will be raised again even if we
1774 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1775 * bits this time around.
1776 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001777 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001778 ier = I915_READ(VLV_IER);
1779 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001780
1781 if (gt_iir)
1782 I915_WRITE(GTIIR, gt_iir);
1783 if (pm_iir)
1784 I915_WRITE(GEN6_PMIIR, pm_iir);
1785
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001786 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001787 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001788
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001789 /* Call regardless, as some status bits might not be
1790 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001791 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001792
1793 /*
1794 * VLV_IIR is single buffered, and reflects the level
1795 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1796 */
1797 if (iir)
1798 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001799
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001800 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001801 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1802 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001803
Ville Syrjälä52894872016-04-13 21:19:56 +03001804 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001805 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03001806 if (pm_iir)
1807 gen6_rps_irq_handler(dev_priv, pm_iir);
1808
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001809 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001810 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001811
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001812 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001813 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001814
Imre Deak1f814da2015-12-16 02:52:19 +02001815 enable_rpm_wakeref_asserts(dev_priv);
1816
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001817 return ret;
1818}
1819
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001820static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1821{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001822 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001823 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001824 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001825
Imre Deak2dd2a882015-02-24 11:14:30 +02001826 if (!intel_irqs_enabled(dev_priv))
1827 return IRQ_NONE;
1828
Imre Deak1f814da2015-12-16 02:52:19 +02001829 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1830 disable_rpm_wakeref_asserts(dev_priv);
1831
Chris Wilson579de732016-03-14 09:01:57 +00001832 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001833 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001834 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001835 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001836 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001837 u32 ier = 0;
1838
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001839 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1840 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001841
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001842 if (master_ctl == 0 && iir == 0)
1843 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001844
Oscar Mateo27b6c122014-06-16 16:11:00 +01001845 ret = IRQ_HANDLED;
1846
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001847 /*
1848 * Theory on interrupt generation, based on empirical evidence:
1849 *
1850 * x = ((VLV_IIR & VLV_IER) ||
1851 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
1852 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
1853 *
1854 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1855 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
1856 * guarantee the CPU interrupt will be raised again even if we
1857 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
1858 * bits this time around.
1859 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001860 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001861 ier = I915_READ(VLV_IER);
1862 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001863
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001864 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001865
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001866 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001867 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001868
Oscar Mateo27b6c122014-06-16 16:11:00 +01001869 /* Call regardless, as some status bits might not be
1870 * signalled in iir */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001871 valleyview_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001872
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001873 /*
1874 * VLV_IIR is single buffered, and reflects the level
1875 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1876 */
1877 if (iir)
1878 I915_WRITE(VLV_IIR, iir);
1879
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001880 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03001881 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001882 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001883
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001884 gen8_gt_irq_handler(dev_priv, gt_iir);
1885
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001886 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001887 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001888
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001889 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00001890 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001891
Imre Deak1f814da2015-12-16 02:52:19 +02001892 enable_rpm_wakeref_asserts(dev_priv);
1893
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001894 return ret;
1895}
1896
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001897static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
1898 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03001899 const u32 hpd[HPD_NUM_PINS])
1900{
Ville Syrjälä40e56412015-08-27 23:56:10 +03001901 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1902
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001903 /*
1904 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
1905 * unless we touch the hotplug register, even if hotplug_trigger is
1906 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
1907 * errors.
1908 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03001909 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001910 if (!hotplug_trigger) {
1911 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
1912 PORTD_HOTPLUG_STATUS_MASK |
1913 PORTC_HOTPLUG_STATUS_MASK |
1914 PORTB_HOTPLUG_STATUS_MASK;
1915 dig_hotplug_reg &= ~mask;
1916 }
1917
Ville Syrjälä40e56412015-08-27 23:56:10 +03001918 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02001919 if (!hotplug_trigger)
1920 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03001921
1922 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1923 dig_hotplug_reg, hpd,
1924 pch_port_hotplug_long_detect);
1925
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001926 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03001927}
1928
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001929static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001930{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001931 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001932 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001933
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001934 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001935
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001936 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1937 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1938 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001939 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001940 port_name(port));
1941 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001942
Daniel Vetterce99c252012-12-01 13:53:47 +01001943 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001944 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01001945
Jesse Barnes776ad802011-01-04 15:09:39 -08001946 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001947 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08001948
1949 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1950 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1951
1952 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1953 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1954
1955 if (pch_iir & SDE_POISON)
1956 DRM_ERROR("PCH poison interrupt\n");
1957
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001958 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001959 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001960 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1961 pipe_name(pipe),
1962 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001963
1964 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1965 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1966
1967 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1968 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1969
Jesse Barnes776ad802011-01-04 15:09:39 -08001970 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001971 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001972
1973 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001974 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001975}
1976
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001977static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03001978{
Paulo Zanoni86642812013-04-12 17:57:57 -03001979 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001980 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001981
Paulo Zanonide032bf2013-04-12 17:57:58 -03001982 if (err_int & ERR_INT_POISON)
1983 DRM_ERROR("Poison interrupt\n");
1984
Damien Lespiau055e3932014-08-18 13:49:10 +01001985 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001986 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1987 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03001988
Daniel Vetter5a69b892013-10-16 22:55:52 +02001989 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001990 if (IS_IVYBRIDGE(dev_priv))
1991 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001992 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001993 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001994 }
1995 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001996
Paulo Zanoni86642812013-04-12 17:57:57 -03001997 I915_WRITE(GEN7_ERR_INT, err_int);
1998}
1999
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002000static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002001{
Paulo Zanoni86642812013-04-12 17:57:57 -03002002 u32 serr_int = I915_READ(SERR_INT);
2003
Paulo Zanonide032bf2013-04-12 17:57:58 -03002004 if (serr_int & SERR_INT_POISON)
2005 DRM_ERROR("PCH poison interrupt\n");
2006
Paulo Zanoni86642812013-04-12 17:57:57 -03002007 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002008 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002009
2010 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002011 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002012
2013 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002014 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002015
2016 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002017}
2018
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002019static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002020{
Adam Jackson23e81d62012-06-06 15:45:44 -04002021 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002022 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002023
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002024 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002025
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002026 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2027 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2028 SDE_AUDIO_POWER_SHIFT_CPT);
2029 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2030 port_name(port));
2031 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002032
2033 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002034 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002035
2036 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002037 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002038
2039 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2040 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2041
2042 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2043 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2044
2045 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002046 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002047 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2048 pipe_name(pipe),
2049 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002050
2051 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002052 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002053}
2054
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002055static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002056{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002057 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2058 ~SDE_PORTE_HOTPLUG_SPT;
2059 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2060 u32 pin_mask = 0, long_mask = 0;
2061
2062 if (hotplug_trigger) {
2063 u32 dig_hotplug_reg;
2064
2065 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2066 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2067
2068 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2069 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002070 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002071 }
2072
2073 if (hotplug2_trigger) {
2074 u32 dig_hotplug_reg;
2075
2076 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2077 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2078
2079 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2080 dig_hotplug_reg, hpd_spt,
2081 spt_port_hotplug2_long_detect);
2082 }
2083
2084 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002085 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002086
2087 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002088 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002089}
2090
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002091static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2092 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002093 const u32 hpd[HPD_NUM_PINS])
2094{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002095 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2096
2097 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2098 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2099
2100 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2101 dig_hotplug_reg, hpd,
2102 ilk_port_hotplug_long_detect);
2103
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002104 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002105}
2106
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002107static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2108 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002109{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002110 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002111 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2112
Ville Syrjälä40e56412015-08-27 23:56:10 +03002113 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002114 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002115
2116 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002117 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002118
2119 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002120 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002121
Paulo Zanonic008bc62013-07-12 16:35:10 -03002122 if (de_iir & DE_POISON)
2123 DRM_ERROR("Poison interrupt\n");
2124
Damien Lespiau055e3932014-08-18 13:49:10 +01002125 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002126 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2127 intel_pipe_handle_vblank(dev_priv, pipe))
2128 intel_check_page_flip(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002129
Daniel Vetter40da17c22013-10-21 18:04:36 +02002130 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002131 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002132
Daniel Vetter40da17c22013-10-21 18:04:36 +02002133 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002134 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002135
Daniel Vetter40da17c22013-10-21 18:04:36 +02002136 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002137 if (de_iir & DE_PLANE_FLIP_DONE(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002138 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002139 }
2140
2141 /* check event from PCH */
2142 if (de_iir & DE_PCH_EVENT) {
2143 u32 pch_iir = I915_READ(SDEIIR);
2144
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002145 if (HAS_PCH_CPT(dev_priv))
2146 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002147 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002148 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002149
2150 /* should clear PCH hotplug event before clear CPU irq */
2151 I915_WRITE(SDEIIR, pch_iir);
2152 }
2153
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002154 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2155 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002156}
2157
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002158static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2159 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002160{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002161 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002162 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2163
Ville Syrjälä40e56412015-08-27 23:56:10 +03002164 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002165 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002166
2167 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002168 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002169
2170 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002171 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002172
2173 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002174 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002175
Damien Lespiau055e3932014-08-18 13:49:10 +01002176 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02002177 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2178 intel_pipe_handle_vblank(dev_priv, pipe))
2179 intel_check_page_flip(dev_priv, pipe);
Daniel Vetter40da17c22013-10-21 18:04:36 +02002180
2181 /* plane/pipes map 1:1 on ilk+ */
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002182 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe))
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002183 intel_finish_page_flip_cs(dev_priv, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002184 }
2185
2186 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002187 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002188 u32 pch_iir = I915_READ(SDEIIR);
2189
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002190 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002191
2192 /* clear PCH hotplug event before clear CPU irq */
2193 I915_WRITE(SDEIIR, pch_iir);
2194 }
2195}
2196
Oscar Mateo72c90f62014-06-16 16:10:57 +01002197/*
2198 * To handle irqs with the minimum potential races with fresh interrupts, we:
2199 * 1 - Disable Master Interrupt Control.
2200 * 2 - Find the source(s) of the interrupt.
2201 * 3 - Clear the Interrupt Identity bits (IIR).
2202 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2203 * 5 - Re-enable Master Interrupt Control.
2204 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002205static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002206{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002207 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002208 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002209 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002210 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002211
Imre Deak2dd2a882015-02-24 11:14:30 +02002212 if (!intel_irqs_enabled(dev_priv))
2213 return IRQ_NONE;
2214
Imre Deak1f814da2015-12-16 02:52:19 +02002215 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2216 disable_rpm_wakeref_asserts(dev_priv);
2217
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002218 /* disable master interrupt before clearing iir */
2219 de_ier = I915_READ(DEIER);
2220 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002221 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002222
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002223 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2224 * interrupts will will be stored on its back queue, and then we'll be
2225 * able to process them after we restore SDEIER (as soon as we restore
2226 * it, we'll get an interrupt if SDEIIR still has something to process
2227 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002228 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002229 sde_ier = I915_READ(SDEIER);
2230 I915_WRITE(SDEIER, 0);
2231 POSTING_READ(SDEIER);
2232 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002233
Oscar Mateo72c90f62014-06-16 16:10:57 +01002234 /* Find, clear, then process each source of interrupt */
2235
Chris Wilson0e434062012-05-09 21:45:44 +01002236 gt_iir = I915_READ(GTIIR);
2237 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002238 I915_WRITE(GTIIR, gt_iir);
2239 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002240 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002241 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002242 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002243 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002244 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002245
2246 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002247 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002248 I915_WRITE(DEIIR, de_iir);
2249 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002250 if (INTEL_GEN(dev_priv) >= 7)
2251 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002252 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002253 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002254 }
2255
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002256 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002257 u32 pm_iir = I915_READ(GEN6_PMIIR);
2258 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002259 I915_WRITE(GEN6_PMIIR, pm_iir);
2260 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002261 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002262 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002263 }
2264
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002265 I915_WRITE(DEIER, de_ier);
2266 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002267 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002268 I915_WRITE(SDEIER, sde_ier);
2269 POSTING_READ(SDEIER);
2270 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002271
Imre Deak1f814da2015-12-16 02:52:19 +02002272 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2273 enable_rpm_wakeref_asserts(dev_priv);
2274
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002275 return ret;
2276}
2277
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002278static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2279 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002280 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302281{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002282 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302283
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002284 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2285 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302286
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002287 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002288 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002289 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002290
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002291 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302292}
2293
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002294static irqreturn_t
2295gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002296{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002297 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002298 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002299 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002300
Ben Widawskyabd58f02013-11-02 21:07:09 -07002301 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002302 iir = I915_READ(GEN8_DE_MISC_IIR);
2303 if (iir) {
2304 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002305 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002306 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002307 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002308 else
2309 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002310 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002311 else
2312 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002313 }
2314
Daniel Vetter6d766f02013-11-07 14:49:55 +01002315 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002316 iir = I915_READ(GEN8_DE_PORT_IIR);
2317 if (iir) {
2318 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302319 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002320
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002321 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002322 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002323
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002324 tmp_mask = GEN8_AUX_CHANNEL_A;
2325 if (INTEL_INFO(dev_priv)->gen >= 9)
2326 tmp_mask |= GEN9_AUX_CHANNEL_B |
2327 GEN9_AUX_CHANNEL_C |
2328 GEN9_AUX_CHANNEL_D;
2329
2330 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002331 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302332 found = true;
2333 }
2334
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002335 if (IS_BROXTON(dev_priv)) {
2336 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2337 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002338 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2339 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002340 found = true;
2341 }
2342 } else if (IS_BROADWELL(dev_priv)) {
2343 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2344 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002345 ilk_hpd_irq_handler(dev_priv,
2346 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002347 found = true;
2348 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302349 }
2350
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002351 if (IS_BROXTON(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
2352 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302353 found = true;
2354 }
2355
Shashank Sharmad04a4922014-08-22 17:40:41 +05302356 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002357 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002358 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002359 else
2360 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002361 }
2362
Damien Lespiau055e3932014-08-18 13:49:10 +01002363 for_each_pipe(dev_priv, pipe) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002364 u32 flip_done, fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002365
Daniel Vetterc42664c2013-11-07 11:05:40 +01002366 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2367 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002368
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002369 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2370 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002371 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002372 continue;
2373 }
2374
2375 ret = IRQ_HANDLED;
2376 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2377
Daniel Vetter5a21b662016-05-24 17:13:53 +02002378 if (iir & GEN8_PIPE_VBLANK &&
2379 intel_pipe_handle_vblank(dev_priv, pipe))
2380 intel_check_page_flip(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002381
2382 flip_done = iir;
2383 if (INTEL_INFO(dev_priv)->gen >= 9)
2384 flip_done &= GEN9_PIPE_PLANE1_FLIP_DONE;
2385 else
2386 flip_done &= GEN8_PIPE_PRIMARY_FLIP_DONE;
2387
Maarten Lankhorst5251f042016-05-17 15:07:47 +02002388 if (flip_done)
Maarten Lankhorst51cbaf02016-05-17 15:07:49 +02002389 intel_finish_page_flip_cs(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002390
2391 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002392 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002393
2394 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2395 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2396
2397 fault_errors = iir;
2398 if (INTEL_INFO(dev_priv)->gen >= 9)
2399 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2400 else
2401 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2402
2403 if (fault_errors)
2404 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2405 pipe_name(pipe),
2406 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002407 }
2408
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002409 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302410 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002411 /*
2412 * FIXME(BDW): Assume for now that the new interrupt handling
2413 * scheme also closed the SDE interrupt handling race we've seen
2414 * on older pch-split platforms. But this needs testing.
2415 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002416 iir = I915_READ(SDEIIR);
2417 if (iir) {
2418 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002419 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002420
Rodrigo Vivi22dea0b2016-07-01 17:07:12 -07002421 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002422 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002423 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002424 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002425 } else {
2426 /*
2427 * Like on previous PCH there seems to be something
2428 * fishy going on with forwarding PCH interrupts.
2429 */
2430 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2431 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002432 }
2433
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002434 return ret;
2435}
2436
2437static irqreturn_t gen8_irq_handler(int irq, void *arg)
2438{
2439 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002440 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002441 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002442 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002443 irqreturn_t ret;
2444
2445 if (!intel_irqs_enabled(dev_priv))
2446 return IRQ_NONE;
2447
2448 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2449 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2450 if (!master_ctl)
2451 return IRQ_NONE;
2452
2453 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2454
2455 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2456 disable_rpm_wakeref_asserts(dev_priv);
2457
2458 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002459 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2460 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002461 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2462
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002463 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2464 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002465
Imre Deak1f814da2015-12-16 02:52:19 +02002466 enable_rpm_wakeref_asserts(dev_priv);
2467
Ben Widawskyabd58f02013-11-02 21:07:09 -07002468 return ret;
2469}
2470
Chris Wilson1f15b762016-07-01 17:23:14 +01002471static void i915_error_wake_up(struct drm_i915_private *dev_priv)
Daniel Vetter17e1df02013-09-08 21:57:13 +02002472{
Daniel Vetter17e1df02013-09-08 21:57:13 +02002473 /*
2474 * Notify all waiters for GPU completion events that reset state has
2475 * been changed, and that they need to restart their wait after
2476 * checking for potential errors (and bail out to drop locks if there is
2477 * a gpu reset pending so that i915_error_work_func can acquire them).
2478 */
2479
2480 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
Chris Wilson1f15b762016-07-01 17:23:14 +01002481 wake_up_all(&dev_priv->gpu_error.wait_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002482
2483 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2484 wake_up_all(&dev_priv->pending_flip_queue);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002485}
2486
Jesse Barnes8a905232009-07-11 16:48:03 -04002487/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002488 * i915_reset_and_wakeup - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002489 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002490 *
2491 * Fire an error uevent so userspace can see that a hang or error
2492 * was detected.
2493 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002494static void i915_reset_and_wakeup(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002495{
Chris Wilson91c8a322016-07-05 10:40:23 +01002496 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002497 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2498 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2499 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002500 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002501
Chris Wilsonc0336662016-05-06 15:40:21 +01002502 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002503
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002504 /*
2505 * Note that there's only one work item which does gpu resets, so we
2506 * need not worry about concurrent gpu resets potentially incrementing
2507 * error->reset_counter twice. We only need to take care of another
2508 * racing irq/hangcheck declaring the gpu dead for a second time. A
2509 * quick check for that is good enough: schedule_work ensures the
2510 * correct ordering between hang detection and this work item, and since
2511 * the reset in-progress bit is only ever set by code outside of this
2512 * work we don't need to worry about any other races.
2513 */
Chris Wilsond98c52c2016-04-13 17:35:05 +01002514 if (i915_reset_in_progress(&dev_priv->gpu_error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002515 DRM_DEBUG_DRIVER("resetting chip\n");
Chris Wilsonc0336662016-05-06 15:40:21 +01002516 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002517
Daniel Vetter17e1df02013-09-08 21:57:13 +02002518 /*
Imre Deakf454c692014-04-23 01:09:04 +03002519 * In most cases it's guaranteed that we get here with an RPM
2520 * reference held, for example because there is a pending GPU
2521 * request that won't finish until the reset is done. This
2522 * isn't the case at least when we get here by doing a
2523 * simulated reset via debugs, so get an RPM reference.
2524 */
2525 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002526
Chris Wilsonc0336662016-05-06 15:40:21 +01002527 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002528
Imre Deakf454c692014-04-23 01:09:04 +03002529 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002530 * All state reset _must_ be completed before we update the
2531 * reset counter, for otherwise waiters might miss the reset
2532 * pending state and not properly drop locks, resulting in
2533 * deadlocks with the reset work.
2534 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002535 ret = i915_reset(dev_priv);
Daniel Vetterf69061b2012-12-06 09:01:42 +01002536
Chris Wilsonc0336662016-05-06 15:40:21 +01002537 intel_finish_reset(dev_priv);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002538
Imre Deakf454c692014-04-23 01:09:04 +03002539 intel_runtime_pm_put(dev_priv);
2540
Chris Wilsond98c52c2016-04-13 17:35:05 +01002541 if (ret == 0)
Chris Wilsonc0336662016-05-06 15:40:21 +01002542 kobject_uevent_env(kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002543 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002544
Daniel Vetter17e1df02013-09-08 21:57:13 +02002545 /*
2546 * Note: The wake_up also serves as a memory barrier so that
2547 * waiters see the update value of the reset counter atomic_t.
2548 */
Chris Wilson1f15b762016-07-01 17:23:14 +01002549 wake_up_all(&dev_priv->gpu_error.reset_queue);
Ben Gamarif316a422009-09-14 17:48:46 -04002550 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002551}
2552
Chris Wilsonc0336662016-05-06 15:40:21 +01002553static void i915_report_and_clear_eir(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002554{
Ben Widawskybd9854f2012-08-23 15:18:09 -07002555 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002556 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002557 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002558
Chris Wilson35aed2e2010-05-27 13:18:12 +01002559 if (!eir)
2560 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002561
Joe Perchesa70491c2012-03-18 13:00:11 -07002562 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002563
Chris Wilsonc0336662016-05-06 15:40:21 +01002564 i915_get_extra_instdone(dev_priv, instdone);
Ben Widawskybd9854f2012-08-23 15:18:09 -07002565
Chris Wilsonc0336662016-05-06 15:40:21 +01002566 if (IS_G4X(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002567 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2568 u32 ipeir = I915_READ(IPEIR_I965);
2569
Joe Perchesa70491c2012-03-18 13:00:11 -07002570 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2571 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002572 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2573 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002574 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002575 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002576 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002577 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002578 }
2579 if (eir & GM45_ERROR_PAGE_TABLE) {
2580 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002581 pr_err("page table error\n");
2582 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002583 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002584 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002585 }
2586 }
2587
Chris Wilsonc0336662016-05-06 15:40:21 +01002588 if (!IS_GEN2(dev_priv)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002589 if (eir & I915_ERROR_PAGE_TABLE) {
2590 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002591 pr_err("page table error\n");
2592 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002593 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002594 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002595 }
2596 }
2597
2598 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002599 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002600 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002601 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002602 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002603 /* pipestat has already been acked */
2604 }
2605 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002606 pr_err("instruction error\n");
2607 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002608 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2609 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsonc0336662016-05-06 15:40:21 +01002610 if (INTEL_GEN(dev_priv) < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002611 u32 ipeir = I915_READ(IPEIR);
2612
Joe Perchesa70491c2012-03-18 13:00:11 -07002613 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2614 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002615 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002616 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002617 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002618 } else {
2619 u32 ipeir = I915_READ(IPEIR_I965);
2620
Joe Perchesa70491c2012-03-18 13:00:11 -07002621 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2622 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002623 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002624 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002625 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002626 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002627 }
2628 }
2629
2630 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002631 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002632 eir = I915_READ(EIR);
2633 if (eir) {
2634 /*
2635 * some errors might have become stuck,
2636 * mask them.
2637 */
2638 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2639 I915_WRITE(EMR, I915_READ(EMR) | eir);
2640 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2641 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002642}
2643
2644/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002645 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002646 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002647 * @engine_mask: mask representing engines that are hung
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002648 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002649 * dump it to the syslog. Also call i915_capture_error_state() to make
2650 * sure we get a record and make it available in debugfs. Fire a uevent
2651 * so userspace knows something bad happened (should trigger collection
2652 * of a ring dump etc.).
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002653 * @fmt: Error message format string
Chris Wilson35aed2e2010-05-27 13:18:12 +01002654 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002655void i915_handle_error(struct drm_i915_private *dev_priv,
2656 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002657 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002658{
Mika Kuoppala58174462014-02-25 17:11:26 +02002659 va_list args;
2660 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002661
Mika Kuoppala58174462014-02-25 17:11:26 +02002662 va_start(args, fmt);
2663 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2664 va_end(args);
2665
Chris Wilsonc0336662016-05-06 15:40:21 +01002666 i915_capture_error_state(dev_priv, engine_mask, error_msg);
2667 i915_report_and_clear_eir(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002668
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002669 if (engine_mask) {
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002670 atomic_or(I915_RESET_IN_PROGRESS_FLAG,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002671 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002672
Ben Gamari11ed50e2009-09-14 17:48:45 -04002673 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002674 * Wakeup waiting processes so that the reset function
2675 * i915_reset_and_wakeup doesn't deadlock trying to grab
2676 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002677 * processes will see a reset in progress and back off,
2678 * releasing their locks and then wait for the reset completion.
2679 * We must do this for _all_ gpu waiters that might hold locks
2680 * that the reset work needs to acquire.
2681 *
2682 * Note: The wake_up serves as the required memory barrier to
2683 * ensure that the waiters see the updated value of the reset
2684 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002685 */
Chris Wilson1f15b762016-07-01 17:23:14 +01002686 i915_error_wake_up(dev_priv);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002687 }
2688
Chris Wilsonc0336662016-05-06 15:40:21 +01002689 i915_reset_and_wakeup(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002690}
2691
Keith Packard42f52ef2008-10-18 19:39:29 -07002692/* Called from drm generic code, passed 'crtc' which
2693 * we use as a pipe index
2694 */
Thierry Reding88e72712015-09-24 18:35:31 +02002695static int i915_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002696{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002697 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002698 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002699
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002700 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002701 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002702 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002703 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002704 else
Keith Packard7c463582008-11-04 02:03:27 -08002705 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002706 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002707 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002708
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002709 return 0;
2710}
2711
Thierry Reding88e72712015-09-24 18:35:31 +02002712static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002713{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002714 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002715 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002716 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002717 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002718
Jesse Barnesf796cf82011-04-07 13:58:17 -07002719 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002720 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002721 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2722
2723 return 0;
2724}
2725
Thierry Reding88e72712015-09-24 18:35:31 +02002726static int valleyview_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002727{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002728 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002729 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002730
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002731 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002732 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002733 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002734 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2735
2736 return 0;
2737}
2738
Thierry Reding88e72712015-09-24 18:35:31 +02002739static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002740{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002741 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002742 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002743
Ben Widawskyabd58f02013-11-02 21:07:09 -07002744 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002745 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002746 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002747
Ben Widawskyabd58f02013-11-02 21:07:09 -07002748 return 0;
2749}
2750
Keith Packard42f52ef2008-10-18 19:39:29 -07002751/* Called from drm generic code, passed 'crtc' which
2752 * we use as a pipe index
2753 */
Thierry Reding88e72712015-09-24 18:35:31 +02002754static void i915_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002755{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002756 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002757 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002758
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002759 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002760 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002761 PIPE_VBLANK_INTERRUPT_STATUS |
2762 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002763 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2764}
2765
Thierry Reding88e72712015-09-24 18:35:31 +02002766static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002767{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002768 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002769 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002770 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c22013-10-21 18:04:36 +02002771 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002772
2773 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002774 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002775 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2776}
2777
Thierry Reding88e72712015-09-24 18:35:31 +02002778static void valleyview_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002779{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002780 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002781 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002782
2783 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002784 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002785 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002786 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2787}
2788
Thierry Reding88e72712015-09-24 18:35:31 +02002789static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002790{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002791 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002792 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002793
Ben Widawskyabd58f02013-11-02 21:07:09 -07002794 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002795 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002796 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2797}
2798
Chris Wilson9107e9d2013-06-10 11:20:20 +01002799static bool
Chris Wilson31bb59c2016-07-01 17:23:27 +01002800ipehr_is_semaphore_wait(struct intel_engine_cs *engine, u32 ipehr)
Daniel Vettera028c4b2014-03-15 00:08:56 +01002801{
Chris Wilson31bb59c2016-07-01 17:23:27 +01002802 if (INTEL_GEN(engine->i915) >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002803 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002804 } else {
2805 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2806 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2807 MI_SEMAPHORE_REGISTER);
2808 }
2809}
2810
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002811static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002812semaphore_wait_to_signaller_ring(struct intel_engine_cs *engine, u32 ipehr,
2813 u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002814{
Chris Wilsonc0336662016-05-06 15:40:21 +01002815 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002816 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002817
Chris Wilsonc0336662016-05-06 15:40:21 +01002818 if (INTEL_GEN(dev_priv) >= 8) {
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002819 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002820 if (engine == signaller)
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002821 continue;
2822
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002823 if (offset == signaller->semaphore.signal_ggtt[engine->id])
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002824 return signaller;
2825 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002826 } else {
2827 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2828
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002829 for_each_engine(signaller, dev_priv) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002830 if(engine == signaller)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002831 continue;
2832
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002833 if (sync_bits == signaller->semaphore.mbox.wait[engine->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002834 return signaller;
2835 }
2836 }
2837
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002838 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002839 engine->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002840
2841 return NULL;
2842}
2843
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002844static struct intel_engine_cs *
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002845semaphore_waits_for(struct intel_engine_cs *engine, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002846{
Chris Wilsonc0336662016-05-06 15:40:21 +01002847 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson406ea8d2016-07-20 13:31:55 +01002848 void __iomem *vaddr;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002849 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002850 u64 offset = 0;
2851 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002852
Tomas Elf381e8ae2015-10-08 19:31:33 +01002853 /*
2854 * This function does not support execlist mode - any attempt to
2855 * proceed further into this function will result in a kernel panic
2856 * when dereferencing ring->buffer, which is not set up in execlist
2857 * mode.
2858 *
2859 * The correct way of doing it would be to derive the currently
2860 * executing ring buffer from the current context, which is derived
2861 * from the currently running request. Unfortunately, to get the
2862 * current request we would have to grab the struct_mutex before doing
2863 * anything else, which would be ill-advised since some other thread
2864 * might have grabbed it already and managed to hang itself, causing
2865 * the hang checker to deadlock.
2866 *
2867 * Therefore, this function does not support execlist mode in its
2868 * current form. Just return NULL and move on.
2869 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002870 if (engine->buffer == NULL)
Tomas Elf381e8ae2015-10-08 19:31:33 +01002871 return NULL;
2872
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002873 ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
Chris Wilson31bb59c2016-07-01 17:23:27 +01002874 if (!ipehr_is_semaphore_wait(engine, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002875 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002876
Daniel Vetter88fe4292014-03-15 00:08:55 +01002877 /*
2878 * HEAD is likely pointing to the dword after the actual command,
2879 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002880 * or 4 dwords depending on the semaphore wait command size.
2881 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002882 * point at at batch, and semaphores are always emitted into the
2883 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002884 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002885 head = I915_READ_HEAD(engine) & HEAD_ADDR;
Chris Wilsonc0336662016-05-06 15:40:21 +01002886 backwards = (INTEL_GEN(dev_priv) >= 8) ? 5 : 4;
Chris Wilsonf2f0ed72016-07-20 13:31:56 +01002887 vaddr = (void __iomem *)engine->buffer->vaddr;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002888
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002889 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002890 /*
2891 * Be paranoid and presume the hw has gone off into the wild -
2892 * our ring is smaller than what the hardware (and hence
2893 * HEAD_ADDR) allows. Also handles wrap-around.
2894 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002895 head &= engine->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002896
2897 /* This here seems to blow up */
Chris Wilson406ea8d2016-07-20 13:31:55 +01002898 cmd = ioread32(vaddr + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002899 if (cmd == ipehr)
2900 break;
2901
Daniel Vetter88fe4292014-03-15 00:08:55 +01002902 head -= 4;
2903 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002904
Daniel Vetter88fe4292014-03-15 00:08:55 +01002905 if (!i)
2906 return NULL;
2907
Chris Wilson406ea8d2016-07-20 13:31:55 +01002908 *seqno = ioread32(vaddr + head + 4) + 1;
Chris Wilsonc0336662016-05-06 15:40:21 +01002909 if (INTEL_GEN(dev_priv) >= 8) {
Chris Wilson406ea8d2016-07-20 13:31:55 +01002910 offset = ioread32(vaddr + head + 12);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002911 offset <<= 32;
Chris Wilson406ea8d2016-07-20 13:31:55 +01002912 offset |= ioread32(vaddr + head + 8);
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002913 }
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002914 return semaphore_wait_to_signaller_ring(engine, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002915}
2916
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002917static int semaphore_passed(struct intel_engine_cs *engine)
Chris Wilson6274f212013-06-10 11:20:21 +01002918{
Chris Wilsonc0336662016-05-06 15:40:21 +01002919 struct drm_i915_private *dev_priv = engine->i915;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002920 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002921 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002922
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002923 engine->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002924
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002925 signaller = semaphore_waits_for(engine, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002926 if (signaller == NULL)
2927 return -1;
2928
2929 /* Prevent pathological recursion due to driver bugs */
Tvrtko Ursulin666796d2016-03-16 11:00:39 +00002930 if (signaller->hangcheck.deadlock >= I915_NUM_ENGINES)
Chris Wilson6274f212013-06-10 11:20:21 +01002931 return -1;
2932
Chris Wilson1b7744e2016-07-01 17:23:17 +01002933 if (i915_seqno_passed(intel_engine_get_seqno(signaller), seqno))
Chris Wilson4be17382014-06-06 10:22:29 +01002934 return 1;
2935
Chris Wilsona0d036b2014-07-19 12:40:42 +01002936 /* cursory check for an unkickable deadlock */
2937 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2938 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002939 return -1;
2940
2941 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002942}
2943
2944static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2945{
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002946 struct intel_engine_cs *engine;
Chris Wilson6274f212013-06-10 11:20:21 +01002947
Dave Gordonb4ac5af2016-03-24 11:20:38 +00002948 for_each_engine(engine, dev_priv)
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00002949 engine->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002950}
2951
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002952static bool subunits_stuck(struct intel_engine_cs *engine)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002953{
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002954 u32 instdone[I915_NUM_INSTDONE_REG];
2955 bool stuck;
2956 int i;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002957
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002958 if (engine->id != RCS)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002959 return true;
2960
Chris Wilsonc0336662016-05-06 15:40:21 +01002961 i915_get_extra_instdone(engine->i915, instdone);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002962
2963 /* There might be unstable subunit states even when
2964 * actual head is not moving. Filter out the unstable ones by
2965 * accumulating the undone -> done transitions and only
2966 * consider those as progress.
2967 */
2968 stuck = true;
2969 for (i = 0; i < I915_NUM_INSTDONE_REG; i++) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002970 const u32 tmp = instdone[i] | engine->hangcheck.instdone[i];
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002971
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002972 if (tmp != engine->hangcheck.instdone[i])
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002973 stuck = false;
2974
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002975 engine->hangcheck.instdone[i] |= tmp;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002976 }
2977
2978 return stuck;
2979}
2980
Chris Wilson7e37f882016-08-02 22:50:21 +01002981static enum intel_engine_hangcheck_action
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002982head_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002983{
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002984 if (acthd != engine->hangcheck.acthd) {
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002985
2986 /* Clear subunit states on head movement */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002987 memset(engine->hangcheck.instdone, 0,
2988 sizeof(engine->hangcheck.instdone));
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002989
Mika Kuoppala24a65e62016-03-02 16:48:29 +02002990 return HANGCHECK_ACTIVE;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002991 }
Chris Wilson6274f212013-06-10 11:20:21 +01002992
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00002993 if (!subunits_stuck(engine))
Mika Kuoppala61642ff2015-12-01 17:56:12 +02002994 return HANGCHECK_ACTIVE;
2995
2996 return HANGCHECK_HUNG;
2997}
2998
Chris Wilson7e37f882016-08-02 22:50:21 +01002999static enum intel_engine_hangcheck_action
3000engine_stuck(struct intel_engine_cs *engine, u64 acthd)
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003001{
Chris Wilsonc0336662016-05-06 15:40:21 +01003002 struct drm_i915_private *dev_priv = engine->i915;
Chris Wilson7e37f882016-08-02 22:50:21 +01003003 enum intel_engine_hangcheck_action ha;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003004 u32 tmp;
3005
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003006 ha = head_stuck(engine, acthd);
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003007 if (ha != HANGCHECK_HUNG)
3008 return ha;
3009
Chris Wilsonc0336662016-05-06 15:40:21 +01003010 if (IS_GEN2(dev_priv))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003011 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003012
3013 /* Is the chip hanging on a WAIT_FOR_EVENT?
3014 * If so we can simply poke the RB_WAIT bit
3015 * and break the hang. This should work on
3016 * all but the second generation chipsets.
3017 */
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003018 tmp = I915_READ_CTL(engine);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003019 if (tmp & RING_WAIT) {
Chris Wilsonc0336662016-05-06 15:40:21 +01003020 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003021 "Kicking stuck wait on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003022 engine->name);
3023 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003024 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003025 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02003026
Chris Wilsonc0336662016-05-06 15:40:21 +01003027 if (INTEL_GEN(dev_priv) >= 6 && tmp & RING_WAIT_SEMAPHORE) {
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003028 switch (semaphore_passed(engine)) {
Chris Wilson6274f212013-06-10 11:20:21 +01003029 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003030 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003031 case 1:
Chris Wilsonc0336662016-05-06 15:40:21 +01003032 i915_handle_error(dev_priv, 0,
Mika Kuoppala58174462014-02-25 17:11:26 +02003033 "Kicking stuck semaphore on %s",
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00003034 engine->name);
3035 I915_WRITE_CTL(engine, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003036 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003037 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003038 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01003039 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003040 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003041
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003042 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03003043}
3044
Chris Wilson737b1502015-01-26 18:03:03 +02003045/*
Ben Gamarif65d9422009-09-14 17:48:44 -04003046 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003047 * batchbuffers in a long time. We keep track per ring seqno progress and
3048 * if there are no progress, hangcheck score for that ring is increased.
3049 * Further, acthd is inspected to see if the ring is stuck. On stuck case
3050 * we kick the ring. If we see no progress on three subsequent calls
3051 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04003052 */
Chris Wilson737b1502015-01-26 18:03:03 +02003053static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04003054{
Chris Wilson737b1502015-01-26 18:03:03 +02003055 struct drm_i915_private *dev_priv =
3056 container_of(work, typeof(*dev_priv),
3057 gpu_error.hangcheck_work.work);
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003058 struct intel_engine_cs *engine;
Chris Wilson2b284282016-07-04 08:48:32 +01003059 unsigned int hung = 0, stuck = 0;
3060 int busy_count = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003061#define BUSY 1
3062#define KICK 5
3063#define HUNG 20
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003064#define ACTIVE_DECAY 15
Chris Wilson893eead2010-10-27 14:44:35 +01003065
Jani Nikulad330a952014-01-21 11:24:25 +02003066 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07003067 return;
3068
Chris Wilsonb1379d42016-07-05 08:54:36 +01003069 if (!READ_ONCE(dev_priv->gt.awake))
Chris Wilson67d97da2016-07-04 08:08:31 +01003070 return;
Imre Deak1f814da2015-12-16 02:52:19 +02003071
Mika Kuoppala75714942015-12-16 09:26:48 +02003072 /* As enabling the GPU requires fairly extensive mmio access,
3073 * periodically arm the mmio checker to see if we are triggering
3074 * any invalid access.
3075 */
3076 intel_uncore_arm_unclaimed_mmio_detection(dev_priv);
3077
Chris Wilson2b284282016-07-04 08:48:32 +01003078 for_each_engine(engine, dev_priv) {
Chris Wilson688e6c72016-07-01 17:23:15 +01003079 bool busy = intel_engine_has_waiter(engine);
Chris Wilson50877442014-03-21 12:41:53 +00003080 u64 acthd;
3081 u32 seqno;
Chris Wilson34730fe2016-08-20 15:54:08 +01003082 u32 submit;
Chris Wilsonb4519512012-05-11 14:29:30 +01003083
Chris Wilson6274f212013-06-10 11:20:21 +01003084 semaphore_clear_deadlocks(dev_priv);
3085
Chris Wilsonc04e0f32016-04-09 10:57:54 +01003086 /* We don't strictly need an irq-barrier here, as we are not
3087 * serving an interrupt request, be paranoid in case the
3088 * barrier has side-effects (such as preventing a broken
3089 * cacheline snoop) and so be sure that we can see the seqno
3090 * advance. If the seqno should stick, due to a stale
3091 * cacheline, we would erroneously declare the GPU hung.
3092 */
3093 if (engine->irq_seqno_barrier)
3094 engine->irq_seqno_barrier(engine);
3095
Chris Wilson7e37f882016-08-02 22:50:21 +01003096 acthd = intel_engine_get_active_head(engine);
Chris Wilson1b7744e2016-07-01 17:23:17 +01003097 seqno = intel_engine_get_seqno(engine);
Chris Wilson34730fe2016-08-20 15:54:08 +01003098 submit = READ_ONCE(engine->last_submitted_seqno);
Chris Wilsond1e61e72012-04-10 17:00:41 +01003099
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003100 if (engine->hangcheck.seqno == seqno) {
Chris Wilson34730fe2016-08-20 15:54:08 +01003101 if (i915_seqno_passed(seqno, submit)) {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003102 engine->hangcheck.action = HANGCHECK_IDLE;
Chris Wilson05535722016-07-01 17:23:11 +01003103 if (busy) {
Chris Wilson094f9a52013-09-25 17:34:55 +01003104 /* Safeguard against driver failure */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003105 engine->hangcheck.score += BUSY;
Chris Wilson05535722016-07-01 17:23:11 +01003106 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003107 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01003108 /* We always increment the hangcheck score
Chris Wilson9930ca12016-07-27 09:07:30 +01003109 * if the engine is busy and still processing
Chris Wilson6274f212013-06-10 11:20:21 +01003110 * the same request, so that no single request
3111 * can run indefinitely (such as a chain of
3112 * batches). The only time we do not increment
3113 * the hangcheck score on this ring, if this
Chris Wilson9930ca12016-07-27 09:07:30 +01003114 * engine is in a legitimate wait for another
3115 * engine. In that case the waiting engine is a
Chris Wilson6274f212013-06-10 11:20:21 +01003116 * victim and we want to be sure we catch the
3117 * right culprit. Then every time we do kick
3118 * the ring, add a small increment to the
3119 * score so that we can catch a batch that is
3120 * being repeatedly kicked and so responsible
3121 * for stalling the machine.
3122 */
Chris Wilson7e37f882016-08-02 22:50:21 +01003123 engine->hangcheck.action =
3124 engine_stuck(engine, acthd);
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003125
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003126 switch (engine->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003127 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003128 case HANGCHECK_WAIT:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003129 break;
Mika Kuoppala24a65e62016-03-02 16:48:29 +02003130 case HANGCHECK_ACTIVE:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003131 engine->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003132 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003133 case HANGCHECK_KICK:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003134 engine->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003135 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003136 case HANGCHECK_HUNG:
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003137 engine->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003138 break;
3139 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003140 }
Chris Wilson2b284282016-07-04 08:48:32 +01003141
3142 if (engine->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
3143 hung |= intel_engine_flag(engine);
3144 if (engine->hangcheck.action != HANGCHECK_HUNG)
3145 stuck |= intel_engine_flag(engine);
3146 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003147 } else {
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003148 engine->hangcheck.action = HANGCHECK_ACTIVE;
Mika Kuoppalada661462013-09-06 16:03:28 +03003149
Chris Wilson9107e9d2013-06-10 11:20:20 +01003150 /* Gradually reduce the count so that we catch DoS
3151 * attempts across multiple batches.
3152 */
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003153 if (engine->hangcheck.score > 0)
3154 engine->hangcheck.score -= ACTIVE_DECAY;
3155 if (engine->hangcheck.score < 0)
3156 engine->hangcheck.score = 0;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003157
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003158 /* Clear head and subunit states on seqno movement */
Chris Wilson12471ba2016-04-09 10:57:55 +01003159 acthd = 0;
Mika Kuoppala61642ff2015-12-01 17:56:12 +02003160
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003161 memset(engine->hangcheck.instdone, 0,
3162 sizeof(engine->hangcheck.instdone));
Chris Wilsond1e61e72012-04-10 17:00:41 +01003163 }
3164
Tvrtko Ursuline2f80392016-03-16 11:00:36 +00003165 engine->hangcheck.seqno = seqno;
3166 engine->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003167 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003168 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003169
Chris Wilson2b284282016-07-04 08:48:32 +01003170 if (hung) {
3171 char msg[80];
Chris Wilsonbafb0fc2016-08-27 08:54:01 +01003172 unsigned int tmp;
Chris Wilson2b284282016-07-04 08:48:32 +01003173 int len;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003174
Chris Wilson2b284282016-07-04 08:48:32 +01003175 /* If some rings hung but others were still busy, only
3176 * blame the hanging rings in the synopsis.
3177 */
3178 if (stuck != hung)
3179 hung &= ~stuck;
3180 len = scnprintf(msg, sizeof(msg),
3181 "%s on ", stuck == hung ? "No progress" : "Hang");
Chris Wilsonbafb0fc2016-08-27 08:54:01 +01003182 for_each_engine_masked(engine, dev_priv, hung, tmp)
Chris Wilson2b284282016-07-04 08:48:32 +01003183 len += scnprintf(msg + len, sizeof(msg) - len,
3184 "%s, ", engine->name);
3185 msg[len-2] = '\0';
3186
3187 return i915_handle_error(dev_priv, hung, msg);
3188 }
Ben Gamarif65d9422009-09-14 17:48:44 -04003189
Chris Wilson05535722016-07-01 17:23:11 +01003190 /* Reset timer in case GPU hangs without another request being added */
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003191 if (busy_count)
Chris Wilsonc0336662016-05-06 15:40:21 +01003192 i915_queue_hangcheck(dev_priv);
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003193}
3194
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003195static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003196{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003197 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003198
3199 if (HAS_PCH_NOP(dev))
3200 return;
3201
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003202 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003203
3204 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3205 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003206}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003207
Paulo Zanoni622364b2014-04-01 15:37:22 -03003208/*
3209 * SDEIER is also touched by the interrupt handler to work around missed PCH
3210 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3211 * instead we unconditionally enable all PCH interrupt sources here, but then
3212 * only unmask them as needed with SDEIMR.
3213 *
3214 * This function needs to be called before interrupts are enabled.
3215 */
3216static void ibx_irq_pre_postinstall(struct drm_device *dev)
3217{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003218 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003219
3220 if (HAS_PCH_NOP(dev))
3221 return;
3222
3223 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003224 I915_WRITE(SDEIER, 0xffffffff);
3225 POSTING_READ(SDEIER);
3226}
3227
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003228static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003229{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003230 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003231
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003232 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003233 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003234 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003235}
3236
Ville Syrjälä70591a42014-10-30 19:42:58 +02003237static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3238{
3239 enum pipe pipe;
3240
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003241 if (IS_CHERRYVIEW(dev_priv))
3242 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3243 else
3244 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3245
Ville Syrjäläad22d102016-04-12 18:56:14 +03003246 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003247 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3248
Ville Syrjäläad22d102016-04-12 18:56:14 +03003249 for_each_pipe(dev_priv, pipe) {
3250 I915_WRITE(PIPESTAT(pipe),
3251 PIPE_FIFO_UNDERRUN_STATUS |
3252 PIPESTAT_INT_STATUS_MASK);
3253 dev_priv->pipestat_irq_mask[pipe] = 0;
3254 }
Ville Syrjälä70591a42014-10-30 19:42:58 +02003255
3256 GEN5_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003257 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003258}
3259
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003260static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3261{
3262 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003263 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003264 enum pipe pipe;
3265
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003266 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3267 PIPE_CRC_DONE_INTERRUPT_STATUS;
3268
3269 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3270 for_each_pipe(dev_priv, pipe)
3271 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3272
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003273 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3274 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3275 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003276 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003277 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003278
3279 WARN_ON(dev_priv->irq_mask != ~0);
3280
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003281 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003282
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003283 GEN5_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003284}
3285
3286/* drm_dma.h hooks
3287*/
3288static void ironlake_irq_reset(struct drm_device *dev)
3289{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003290 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003291
3292 I915_WRITE(HWSTAM, 0xffffffff);
3293
3294 GEN5_IRQ_RESET(DE);
3295 if (IS_GEN7(dev))
3296 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3297
3298 gen5_gt_irq_reset(dev);
3299
3300 ibx_irq_reset(dev);
3301}
3302
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003303static void valleyview_irq_preinstall(struct drm_device *dev)
3304{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003305 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003306
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003307 I915_WRITE(VLV_MASTER_IER, 0);
3308 POSTING_READ(VLV_MASTER_IER);
3309
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003310 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003311
Ville Syrjäläad22d102016-04-12 18:56:14 +03003312 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003313 if (dev_priv->display_irqs_enabled)
3314 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003315 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003316}
3317
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003318static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3319{
3320 GEN8_IRQ_RESET_NDX(GT, 0);
3321 GEN8_IRQ_RESET_NDX(GT, 1);
3322 GEN8_IRQ_RESET_NDX(GT, 2);
3323 GEN8_IRQ_RESET_NDX(GT, 3);
3324}
3325
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003326static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003327{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003328 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003329 int pipe;
3330
Ben Widawskyabd58f02013-11-02 21:07:09 -07003331 I915_WRITE(GEN8_MASTER_IRQ, 0);
3332 POSTING_READ(GEN8_MASTER_IRQ);
3333
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003334 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003335
Damien Lespiau055e3932014-08-18 13:49:10 +01003336 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003337 if (intel_display_power_is_enabled(dev_priv,
3338 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003339 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003340
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003341 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3342 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3343 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003344
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303345 if (HAS_PCH_SPLIT(dev))
3346 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003347}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003348
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003349void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3350 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003351{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003352 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003353 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003354
Daniel Vetter13321782014-09-15 14:55:29 +02003355 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003356 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3357 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3358 dev_priv->de_irq_mask[pipe],
3359 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003360 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003361}
3362
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003363void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
3364 unsigned int pipe_mask)
3365{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003366 enum pipe pipe;
3367
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003368 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003369 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3370 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003371 spin_unlock_irq(&dev_priv->irq_lock);
3372
3373 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003374 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003375}
3376
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003377static void cherryview_irq_preinstall(struct drm_device *dev)
3378{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003379 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003380
3381 I915_WRITE(GEN8_MASTER_IRQ, 0);
3382 POSTING_READ(GEN8_MASTER_IRQ);
3383
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003384 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003385
3386 GEN5_IRQ_RESET(GEN8_PCU_);
3387
Ville Syrjäläad22d102016-04-12 18:56:14 +03003388 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003389 if (dev_priv->display_irqs_enabled)
3390 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003391 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003392}
3393
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003394static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003395 const u32 hpd[HPD_NUM_PINS])
3396{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003397 struct intel_encoder *encoder;
3398 u32 enabled_irqs = 0;
3399
Chris Wilson91c8a322016-07-05 10:40:23 +01003400 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003401 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3402 enabled_irqs |= hpd[encoder->hpd_pin];
3403
3404 return enabled_irqs;
3405}
3406
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003407static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003408{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003409 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003410
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003411 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003412 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003413 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003414 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003415 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003416 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003417 }
3418
Daniel Vetterfee884e2013-07-04 23:35:21 +02003419 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003420
3421 /*
3422 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003423 * duration to 2ms (which is the minimum in the Display Port spec).
3424 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003425 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003426 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3427 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3428 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3429 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3430 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003431 /*
3432 * When CPU and PCH are on the same package, port A
3433 * HPD must be enabled in both north and south.
3434 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003435 if (HAS_PCH_LPT_LP(dev_priv))
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003436 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003437 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003438}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003439
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003440static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003441{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003442 u32 hotplug_irqs, hotplug, enabled_irqs;
3443
3444 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003445 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003446
3447 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3448
3449 /* Enable digital hotplug on the PCH */
3450 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3451 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003452 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003453 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3454
3455 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3456 hotplug |= PORTE_HOTPLUG_ENABLE;
3457 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003458}
3459
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003460static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003461{
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003462 u32 hotplug_irqs, hotplug, enabled_irqs;
3463
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003464 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003465 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003466 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003467
3468 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003469 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003470 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003471 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003472
3473 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003474 } else {
3475 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003476 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003477
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003478 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3479 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003480
3481 /*
3482 * Enable digital hotplug on the CPU, and configure the DP short pulse
3483 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003484 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003485 */
3486 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3487 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3488 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3489 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3490
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003491 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003492}
3493
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003494static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003495{
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003496 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003497
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003498 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003499 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003500
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003501 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003502
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003503 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3504 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3505 PORTA_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303506
3507 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3508 hotplug, enabled_irqs);
3509 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3510
3511 /*
3512 * For BXT invert bit has to be set based on AOB design
3513 * for HPD detection logic, update it based on VBT fields.
3514 */
3515
3516 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3517 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3518 hotplug |= BXT_DDIA_HPD_INVERT;
3519 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3520 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3521 hotplug |= BXT_DDIB_HPD_INVERT;
3522 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3523 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3524 hotplug |= BXT_DDIC_HPD_INVERT;
3525
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003526 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003527}
3528
Paulo Zanonid46da432013-02-08 17:35:15 -02003529static void ibx_irq_postinstall(struct drm_device *dev)
3530{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003531 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003532 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003533
Daniel Vetter692a04c2013-05-29 21:43:05 +02003534 if (HAS_PCH_NOP(dev))
3535 return;
3536
Paulo Zanoni105b1222014-04-01 15:37:17 -03003537 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003538 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003539 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003540 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003541
Ville Syrjäläb51a2842015-09-18 20:03:41 +03003542 gen5_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003543 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003544}
3545
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003546static void gen5_gt_irq_postinstall(struct drm_device *dev)
3547{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003548 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003549 u32 pm_irqs, gt_irqs;
3550
3551 pm_irqs = gt_irqs = 0;
3552
3553 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003554 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003555 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003556 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3557 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003558 }
3559
3560 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3561 if (IS_GEN5(dev)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003562 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003563 } else {
3564 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3565 }
3566
Paulo Zanoni35079892014-04-01 15:37:15 -03003567 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003568
3569 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003570 /*
3571 * RPS interrupts will get enabled/disabled on demand when RPS
3572 * itself is enabled/disabled.
3573 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003574 if (HAS_VEBOX(dev))
3575 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3576
Paulo Zanoni605cd252013-08-06 18:57:15 -03003577 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003578 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003579 }
3580}
3581
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003582static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003583{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003584 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003585 u32 display_mask, extra_mask;
3586
3587 if (INTEL_INFO(dev)->gen >= 7) {
3588 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3589 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3590 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003591 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003592 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003593 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3594 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003595 } else {
3596 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3597 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003598 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003599 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3600 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003601 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3602 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3603 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003604 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003605
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003606 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003607
Paulo Zanoni0c841212014-04-01 15:37:27 -03003608 I915_WRITE(HWSTAM, 0xeffe);
3609
Paulo Zanoni622364b2014-04-01 15:37:22 -03003610 ibx_irq_pre_postinstall(dev);
3611
Paulo Zanoni35079892014-04-01 15:37:15 -03003612 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003613
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003614 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003615
Paulo Zanonid46da432013-02-08 17:35:15 -02003616 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003617
Jesse Barnesf97108d2010-01-29 11:27:07 -08003618 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003619 /* Enable PCU event interrupts
3620 *
3621 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003622 * setup is guaranteed to run in single-threaded context. But we
3623 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003624 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003625 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003626 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003627 }
3628
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003629 return 0;
3630}
3631
Imre Deakf8b79e52014-03-04 19:23:07 +02003632void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3633{
3634 assert_spin_locked(&dev_priv->irq_lock);
3635
3636 if (dev_priv->display_irqs_enabled)
3637 return;
3638
3639 dev_priv->display_irqs_enabled = true;
3640
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003641 if (intel_irqs_enabled(dev_priv)) {
3642 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003643 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003644 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003645}
3646
3647void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3648{
3649 assert_spin_locked(&dev_priv->irq_lock);
3650
3651 if (!dev_priv->display_irqs_enabled)
3652 return;
3653
3654 dev_priv->display_irqs_enabled = false;
3655
Imre Deak950eaba2014-09-08 15:21:09 +03003656 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003657 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003658}
3659
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003660
3661static int valleyview_irq_postinstall(struct drm_device *dev)
3662{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003663 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003664
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003665 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003666
Ville Syrjäläad22d102016-04-12 18:56:14 +03003667 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003668 if (dev_priv->display_irqs_enabled)
3669 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003670 spin_unlock_irq(&dev_priv->irq_lock);
3671
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003672 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003673 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003674
3675 return 0;
3676}
3677
Ben Widawskyabd58f02013-11-02 21:07:09 -07003678static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3679{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003680 /* These are interrupts we'll toggle with the ring mask register */
3681 uint32_t gt_interrupts[] = {
3682 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003683 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003684 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3685 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003686 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003687 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3688 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3689 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003690 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003691 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3692 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003693 };
3694
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003695 if (HAS_L3_DPF(dev_priv))
3696 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3697
Ben Widawsky09610212014-05-15 20:58:08 +03003698 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303699 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3700 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003701 /*
3702 * RPS interrupts will get enabled/disabled on demand when RPS itself
3703 * is enabled/disabled.
3704 */
3705 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303706 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003707}
3708
3709static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3710{
Damien Lespiau770de832014-03-20 20:45:01 +00003711 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3712 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003713 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3714 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003715 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003716 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003717
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003718 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003719 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3720 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003721 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3722 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303723 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003724 de_port_masked |= BXT_DE_PORT_GMBUS;
3725 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003726 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3727 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003728 }
Damien Lespiau770de832014-03-20 20:45:01 +00003729
3730 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3731 GEN8_PIPE_FIFO_UNDERRUN;
3732
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003733 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003734 if (IS_BROXTON(dev_priv))
3735 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3736 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003737 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3738
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003739 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3740 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3741 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003742
Damien Lespiau055e3932014-08-18 13:49:10 +01003743 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003744 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003745 POWER_DOMAIN_PIPE(pipe)))
3746 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3747 dev_priv->de_irq_mask[pipe],
3748 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003749
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003750 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ville Syrjälä11825b02016-05-19 12:14:43 +03003751 GEN5_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003752}
3753
3754static int gen8_irq_postinstall(struct drm_device *dev)
3755{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003756 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003757
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303758 if (HAS_PCH_SPLIT(dev))
3759 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003760
Ben Widawskyabd58f02013-11-02 21:07:09 -07003761 gen8_gt_irq_postinstall(dev_priv);
3762 gen8_de_irq_postinstall(dev_priv);
3763
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303764 if (HAS_PCH_SPLIT(dev))
3765 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003766
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003767 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003768 POSTING_READ(GEN8_MASTER_IRQ);
3769
3770 return 0;
3771}
3772
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003773static int cherryview_irq_postinstall(struct drm_device *dev)
3774{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003775 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003776
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003777 gen8_gt_irq_postinstall(dev_priv);
3778
Ville Syrjäläad22d102016-04-12 18:56:14 +03003779 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003780 if (dev_priv->display_irqs_enabled)
3781 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003782 spin_unlock_irq(&dev_priv->irq_lock);
3783
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003784 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003785 POSTING_READ(GEN8_MASTER_IRQ);
3786
3787 return 0;
3788}
3789
Ben Widawskyabd58f02013-11-02 21:07:09 -07003790static void gen8_irq_uninstall(struct drm_device *dev)
3791{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003792 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003793
3794 if (!dev_priv)
3795 return;
3796
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003797 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003798}
3799
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003800static void valleyview_irq_uninstall(struct drm_device *dev)
3801{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003802 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003803
3804 if (!dev_priv)
3805 return;
3806
Imre Deak843d0e72014-04-14 20:24:23 +03003807 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003808 POSTING_READ(VLV_MASTER_IER);
Imre Deak843d0e72014-04-14 20:24:23 +03003809
Ville Syrjälä893fce82014-10-30 19:42:56 +02003810 gen5_gt_irq_reset(dev);
3811
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003812 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003813
Ville Syrjäläad22d102016-04-12 18:56:14 +03003814 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003815 if (dev_priv->display_irqs_enabled)
3816 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003817 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003818}
3819
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003820static void cherryview_irq_uninstall(struct drm_device *dev)
3821{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003822 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003823
3824 if (!dev_priv)
3825 return;
3826
3827 I915_WRITE(GEN8_MASTER_IRQ, 0);
3828 POSTING_READ(GEN8_MASTER_IRQ);
3829
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003830 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003831
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003832 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003833
Ville Syrjäläad22d102016-04-12 18:56:14 +03003834 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003835 if (dev_priv->display_irqs_enabled)
3836 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003837 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003838}
3839
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003840static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003841{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003842 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes46979952011-04-07 13:53:55 -07003843
3844 if (!dev_priv)
3845 return;
3846
Paulo Zanonibe30b292014-04-01 15:37:25 -03003847 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003848}
3849
Chris Wilsonc2798b12012-04-22 21:13:57 +01003850static void i8xx_irq_preinstall(struct drm_device * dev)
3851{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003852 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003853 int pipe;
3854
Damien Lespiau055e3932014-08-18 13:49:10 +01003855 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003856 I915_WRITE(PIPESTAT(pipe), 0);
3857 I915_WRITE16(IMR, 0xffff);
3858 I915_WRITE16(IER, 0x0);
3859 POSTING_READ16(IER);
3860}
3861
3862static int i8xx_irq_postinstall(struct drm_device *dev)
3863{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003864 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003865
Chris Wilsonc2798b12012-04-22 21:13:57 +01003866 I915_WRITE16(EMR,
3867 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3868
3869 /* Unmask the interrupts that we always want on. */
3870 dev_priv->irq_mask =
3871 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3872 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3873 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003874 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003875 I915_WRITE16(IMR, dev_priv->irq_mask);
3876
3877 I915_WRITE16(IER,
3878 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3879 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003880 I915_USER_INTERRUPT);
3881 POSTING_READ16(IER);
3882
Daniel Vetter379ef822013-10-16 22:55:56 +02003883 /* Interrupt setup is already guaranteed to be single-threaded, this is
3884 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003885 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003886 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3887 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003888 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003889
Chris Wilsonc2798b12012-04-22 21:13:57 +01003890 return 0;
3891}
3892
Daniel Vetter5a21b662016-05-24 17:13:53 +02003893/*
3894 * Returns true when a page flip has completed.
3895 */
3896static bool i8xx_handle_vblank(struct drm_i915_private *dev_priv,
3897 int plane, int pipe, u32 iir)
3898{
3899 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3900
3901 if (!intel_pipe_handle_vblank(dev_priv, pipe))
3902 return false;
3903
3904 if ((iir & flip_pending) == 0)
3905 goto check_page_flip;
3906
3907 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3908 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3909 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3910 * the flip is completed (no longer pending). Since this doesn't raise
3911 * an interrupt per se, we watch for the change at vblank.
3912 */
3913 if (I915_READ16(ISR) & flip_pending)
3914 goto check_page_flip;
3915
3916 intel_finish_page_flip_cs(dev_priv, pipe);
3917 return true;
3918
3919check_page_flip:
3920 intel_check_page_flip(dev_priv, pipe);
3921 return false;
3922}
3923
Daniel Vetterff1f5252012-10-02 15:10:55 +02003924static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003925{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003926 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003927 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003928 u16 iir, new_iir;
3929 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003930 int pipe;
3931 u16 flip_mask =
3932 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3933 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Imre Deak1f814da2015-12-16 02:52:19 +02003934 irqreturn_t ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003935
Imre Deak2dd2a882015-02-24 11:14:30 +02003936 if (!intel_irqs_enabled(dev_priv))
3937 return IRQ_NONE;
3938
Imre Deak1f814da2015-12-16 02:52:19 +02003939 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3940 disable_rpm_wakeref_asserts(dev_priv);
3941
3942 ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003943 iir = I915_READ16(IIR);
3944 if (iir == 0)
Imre Deak1f814da2015-12-16 02:52:19 +02003945 goto out;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003946
3947 while (iir & ~flip_mask) {
3948 /* Can't rely on pipestat interrupt bit in iir as it might
3949 * have been cleared after the pipestat interrupt was received.
3950 * It doesn't set the bit in iir again, but it still produces
3951 * interrupts (for non-MSI).
3952 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003953 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003954 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003955 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003956
Damien Lespiau055e3932014-08-18 13:49:10 +01003957 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02003958 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003959 pipe_stats[pipe] = I915_READ(reg);
3960
3961 /*
3962 * Clear the PIPE*STAT regs before the IIR
3963 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003964 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003965 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003966 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003967 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003968
3969 I915_WRITE16(IIR, iir & ~flip_mask);
3970 new_iir = I915_READ16(IIR); /* Flush posted writes */
3971
Chris Wilsonc2798b12012-04-22 21:13:57 +01003972 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00003973 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003974
Damien Lespiau055e3932014-08-18 13:49:10 +01003975 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02003976 int plane = pipe;
3977 if (HAS_FBC(dev_priv))
3978 plane = !plane;
3979
3980 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3981 i8xx_handle_vblank(dev_priv, plane, pipe, iir))
3982 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003983
Daniel Vetter4356d582013-10-16 22:55:55 +02003984 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003985 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003986
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003987 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3988 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3989 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003990 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003991
3992 iir = new_iir;
3993 }
Imre Deak1f814da2015-12-16 02:52:19 +02003994 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003995
Imre Deak1f814da2015-12-16 02:52:19 +02003996out:
3997 enable_rpm_wakeref_asserts(dev_priv);
3998
3999 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004000}
4001
4002static void i8xx_irq_uninstall(struct drm_device * dev)
4003{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004004 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004005 int pipe;
4006
Damien Lespiau055e3932014-08-18 13:49:10 +01004007 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004008 /* Clear enable bits; then clear status bits */
4009 I915_WRITE(PIPESTAT(pipe), 0);
4010 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4011 }
4012 I915_WRITE16(IMR, 0xffff);
4013 I915_WRITE16(IER, 0x0);
4014 I915_WRITE16(IIR, I915_READ16(IIR));
4015}
4016
Chris Wilsona266c7d2012-04-24 22:59:44 +01004017static void i915_irq_preinstall(struct drm_device * dev)
4018{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004019 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004020 int pipe;
4021
Chris Wilsona266c7d2012-04-24 22:59:44 +01004022 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004023 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004024 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4025 }
4026
Chris Wilson00d98eb2012-04-24 22:59:48 +01004027 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004028 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004029 I915_WRITE(PIPESTAT(pipe), 0);
4030 I915_WRITE(IMR, 0xffffffff);
4031 I915_WRITE(IER, 0x0);
4032 POSTING_READ(IER);
4033}
4034
4035static int i915_irq_postinstall(struct drm_device *dev)
4036{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004037 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004038 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004039
Chris Wilson38bde182012-04-24 22:59:50 +01004040 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
4041
4042 /* Unmask the interrupts that we always want on. */
4043 dev_priv->irq_mask =
4044 ~(I915_ASLE_INTERRUPT |
4045 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4046 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4047 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02004048 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004049
4050 enable_mask =
4051 I915_ASLE_INTERRUPT |
4052 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4053 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004054 I915_USER_INTERRUPT;
4055
Chris Wilsona266c7d2012-04-24 22:59:44 +01004056 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004057 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004058 POSTING_READ(PORT_HOTPLUG_EN);
4059
Chris Wilsona266c7d2012-04-24 22:59:44 +01004060 /* Enable in IER... */
4061 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4062 /* and unmask in IMR */
4063 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4064 }
4065
Chris Wilsona266c7d2012-04-24 22:59:44 +01004066 I915_WRITE(IMR, dev_priv->irq_mask);
4067 I915_WRITE(IER, enable_mask);
4068 POSTING_READ(IER);
4069
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004070 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004071
Daniel Vetter379ef822013-10-16 22:55:56 +02004072 /* Interrupt setup is already guaranteed to be single-threaded, this is
4073 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004074 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004075 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4076 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004077 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004078
Daniel Vetter20afbda2012-12-11 14:05:07 +01004079 return 0;
4080}
4081
Daniel Vetter5a21b662016-05-24 17:13:53 +02004082/*
4083 * Returns true when a page flip has completed.
4084 */
4085static bool i915_handle_vblank(struct drm_i915_private *dev_priv,
4086 int plane, int pipe, u32 iir)
4087{
4088 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4089
4090 if (!intel_pipe_handle_vblank(dev_priv, pipe))
4091 return false;
4092
4093 if ((iir & flip_pending) == 0)
4094 goto check_page_flip;
4095
4096 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4097 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4098 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4099 * the flip is completed (no longer pending). Since this doesn't raise
4100 * an interrupt per se, we watch for the change at vblank.
4101 */
4102 if (I915_READ(ISR) & flip_pending)
4103 goto check_page_flip;
4104
4105 intel_finish_page_flip_cs(dev_priv, pipe);
4106 return true;
4107
4108check_page_flip:
4109 intel_check_page_flip(dev_priv, pipe);
4110 return false;
4111}
4112
Daniel Vetterff1f5252012-10-02 15:10:55 +02004113static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004114{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004115 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004116 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson8291ee92012-04-24 22:59:47 +01004117 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004118 u32 flip_mask =
4119 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4120 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004121 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004122
Imre Deak2dd2a882015-02-24 11:14:30 +02004123 if (!intel_irqs_enabled(dev_priv))
4124 return IRQ_NONE;
4125
Imre Deak1f814da2015-12-16 02:52:19 +02004126 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4127 disable_rpm_wakeref_asserts(dev_priv);
4128
Chris Wilsona266c7d2012-04-24 22:59:44 +01004129 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004130 do {
4131 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004132 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004133
4134 /* Can't rely on pipestat interrupt bit in iir as it might
4135 * have been cleared after the pipestat interrupt was received.
4136 * It doesn't set the bit in iir again, but it still produces
4137 * interrupts (for non-MSI).
4138 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004139 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004140 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004141 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004142
Damien Lespiau055e3932014-08-18 13:49:10 +01004143 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004144 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004145 pipe_stats[pipe] = I915_READ(reg);
4146
Chris Wilson38bde182012-04-24 22:59:50 +01004147 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004148 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004149 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004150 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004151 }
4152 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004153 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004154
4155 if (!irq_received)
4156 break;
4157
Chris Wilsona266c7d2012-04-24 22:59:44 +01004158 /* Consume port. Then clear IIR or we'll miss events */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004159 if (I915_HAS_HOTPLUG(dev_priv) &&
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004160 iir & I915_DISPLAY_PORT_INTERRUPT) {
4161 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4162 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004163 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004164 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004165
Chris Wilson38bde182012-04-24 22:59:50 +01004166 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004167 new_iir = I915_READ(IIR); /* Flush posted writes */
4168
Chris Wilsona266c7d2012-04-24 22:59:44 +01004169 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004170 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004171
Damien Lespiau055e3932014-08-18 13:49:10 +01004172 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004173 int plane = pipe;
4174 if (HAS_FBC(dev_priv))
4175 plane = !plane;
4176
4177 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4178 i915_handle_vblank(dev_priv, plane, pipe, iir))
4179 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180
4181 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4182 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004183
4184 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004185 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004186
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004187 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4188 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4189 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004190 }
4191
Chris Wilsona266c7d2012-04-24 22:59:44 +01004192 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004193 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004194
4195 /* With MSI, interrupts are only generated when iir
4196 * transitions from zero to nonzero. If another bit got
4197 * set while we were handling the existing iir bits, then
4198 * we would never get another interrupt.
4199 *
4200 * This is fine on non-MSI as well, as if we hit this path
4201 * we avoid exiting the interrupt handler only to generate
4202 * another one.
4203 *
4204 * Note that for MSI this could cause a stray interrupt report
4205 * if an interrupt landed in the time between writing IIR and
4206 * the posting read. This should be rare enough to never
4207 * trigger the 99% of 100,000 interrupts test for disabling
4208 * stray interrupts.
4209 */
Chris Wilson38bde182012-04-24 22:59:50 +01004210 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004211 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004212 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004213
Imre Deak1f814da2015-12-16 02:52:19 +02004214 enable_rpm_wakeref_asserts(dev_priv);
4215
Chris Wilsona266c7d2012-04-24 22:59:44 +01004216 return ret;
4217}
4218
4219static void i915_irq_uninstall(struct drm_device * dev)
4220{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004221 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004222 int pipe;
4223
Chris Wilsona266c7d2012-04-24 22:59:44 +01004224 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004225 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004226 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4227 }
4228
Chris Wilson00d98eb2012-04-24 22:59:48 +01004229 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004230 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004231 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004232 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004233 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4234 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004235 I915_WRITE(IMR, 0xffffffff);
4236 I915_WRITE(IER, 0x0);
4237
Chris Wilsona266c7d2012-04-24 22:59:44 +01004238 I915_WRITE(IIR, I915_READ(IIR));
4239}
4240
4241static void i965_irq_preinstall(struct drm_device * dev)
4242{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004243 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004244 int pipe;
4245
Egbert Eich0706f172015-09-23 16:15:27 +02004246 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004247 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004248
4249 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004250 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004251 I915_WRITE(PIPESTAT(pipe), 0);
4252 I915_WRITE(IMR, 0xffffffff);
4253 I915_WRITE(IER, 0x0);
4254 POSTING_READ(IER);
4255}
4256
4257static int i965_irq_postinstall(struct drm_device *dev)
4258{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004259 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004260 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004261 u32 error_mask;
4262
Chris Wilsona266c7d2012-04-24 22:59:44 +01004263 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004264 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004265 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004266 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4267 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4268 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4269 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4270 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4271
4272 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004273 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4274 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004275 enable_mask |= I915_USER_INTERRUPT;
4276
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004277 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004278 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004279
Daniel Vetterb79480b2013-06-27 17:52:10 +02004280 /* Interrupt setup is already guaranteed to be single-threaded, this is
4281 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004282 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004283 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4284 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4285 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004286 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004287
Chris Wilsona266c7d2012-04-24 22:59:44 +01004288 /*
4289 * Enable some error detection, note the instruction error mask
4290 * bit is reserved, so we leave it masked.
4291 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004292 if (IS_G4X(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004293 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4294 GM45_ERROR_MEM_PRIV |
4295 GM45_ERROR_CP_PRIV |
4296 I915_ERROR_MEMORY_REFRESH);
4297 } else {
4298 error_mask = ~(I915_ERROR_PAGE_TABLE |
4299 I915_ERROR_MEMORY_REFRESH);
4300 }
4301 I915_WRITE(EMR, error_mask);
4302
4303 I915_WRITE(IMR, dev_priv->irq_mask);
4304 I915_WRITE(IER, enable_mask);
4305 POSTING_READ(IER);
4306
Egbert Eich0706f172015-09-23 16:15:27 +02004307 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004308 POSTING_READ(PORT_HOTPLUG_EN);
4309
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004310 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004311
4312 return 0;
4313}
4314
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004315static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004316{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004317 u32 hotplug_en;
4318
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004319 assert_spin_locked(&dev_priv->irq_lock);
4320
Ville Syrjälä778eb332015-01-09 14:21:13 +02004321 /* Note HDMI and DP share hotplug bits */
4322 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004323 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004324 /* Programming the CRT detection parameters tends
4325 to generate a spurious hotplug event about three
4326 seconds later. So just do it once.
4327 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004328 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004329 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004330 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004331
Ville Syrjälä778eb332015-01-09 14:21:13 +02004332 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004333 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004334 HOTPLUG_INT_EN_MASK |
4335 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4336 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4337 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004338}
4339
Daniel Vetterff1f5252012-10-02 15:10:55 +02004340static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004341{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004342 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004343 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004344 u32 iir, new_iir;
4345 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004346 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004347 u32 flip_mask =
4348 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4349 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004350
Imre Deak2dd2a882015-02-24 11:14:30 +02004351 if (!intel_irqs_enabled(dev_priv))
4352 return IRQ_NONE;
4353
Imre Deak1f814da2015-12-16 02:52:19 +02004354 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4355 disable_rpm_wakeref_asserts(dev_priv);
4356
Chris Wilsona266c7d2012-04-24 22:59:44 +01004357 iir = I915_READ(IIR);
4358
Chris Wilsona266c7d2012-04-24 22:59:44 +01004359 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004360 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004361 bool blc_event = false;
4362
Chris Wilsona266c7d2012-04-24 22:59:44 +01004363 /* Can't rely on pipestat interrupt bit in iir as it might
4364 * have been cleared after the pipestat interrupt was received.
4365 * It doesn't set the bit in iir again, but it still produces
4366 * interrupts (for non-MSI).
4367 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004368 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004369 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004370 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004371
Damien Lespiau055e3932014-08-18 13:49:10 +01004372 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02004373 i915_reg_t reg = PIPESTAT(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004374 pipe_stats[pipe] = I915_READ(reg);
4375
4376 /*
4377 * Clear the PIPE*STAT regs before the IIR
4378 */
4379 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004380 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004381 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004382 }
4383 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004384 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004385
4386 if (!irq_received)
4387 break;
4388
4389 ret = IRQ_HANDLED;
4390
4391 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004392 if (iir & I915_DISPLAY_PORT_INTERRUPT) {
4393 u32 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
4394 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004395 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03004396 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004397
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004398 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004399 new_iir = I915_READ(IIR); /* Flush posted writes */
4400
Chris Wilsona266c7d2012-04-24 22:59:44 +01004401 if (iir & I915_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004402 notify_ring(&dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004403 if (iir & I915_BSD_USER_INTERRUPT)
Tvrtko Ursulin4a570db2016-03-16 11:00:38 +00004404 notify_ring(&dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004405
Damien Lespiau055e3932014-08-18 13:49:10 +01004406 for_each_pipe(dev_priv, pipe) {
Daniel Vetter5a21b662016-05-24 17:13:53 +02004407 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
4408 i915_handle_vblank(dev_priv, pipe, pipe, iir))
4409 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004410
4411 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4412 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004413
4414 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004415 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004416
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004417 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4418 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004419 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004420
4421 if (blc_event || (iir & I915_ASLE_INTERRUPT))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004422 intel_opregion_asle_intr(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004423
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004424 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004425 gmbus_irq_handler(dev_priv);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004426
Chris Wilsona266c7d2012-04-24 22:59:44 +01004427 /* With MSI, interrupts are only generated when iir
4428 * transitions from zero to nonzero. If another bit got
4429 * set while we were handling the existing iir bits, then
4430 * we would never get another interrupt.
4431 *
4432 * This is fine on non-MSI as well, as if we hit this path
4433 * we avoid exiting the interrupt handler only to generate
4434 * another one.
4435 *
4436 * Note that for MSI this could cause a stray interrupt report
4437 * if an interrupt landed in the time between writing IIR and
4438 * the posting read. This should be rare enough to never
4439 * trigger the 99% of 100,000 interrupts test for disabling
4440 * stray interrupts.
4441 */
4442 iir = new_iir;
4443 }
4444
Imre Deak1f814da2015-12-16 02:52:19 +02004445 enable_rpm_wakeref_asserts(dev_priv);
4446
Chris Wilsona266c7d2012-04-24 22:59:44 +01004447 return ret;
4448}
4449
4450static void i965_irq_uninstall(struct drm_device * dev)
4451{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004452 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004453 int pipe;
4454
4455 if (!dev_priv)
4456 return;
4457
Egbert Eich0706f172015-09-23 16:15:27 +02004458 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004459 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004460
4461 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004462 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004463 I915_WRITE(PIPESTAT(pipe), 0);
4464 I915_WRITE(IMR, 0xffffffff);
4465 I915_WRITE(IER, 0x0);
4466
Damien Lespiau055e3932014-08-18 13:49:10 +01004467 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004468 I915_WRITE(PIPESTAT(pipe),
4469 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4470 I915_WRITE(IIR, I915_READ(IIR));
4471}
4472
Daniel Vetterfca52a52014-09-30 10:56:45 +02004473/**
4474 * intel_irq_init - initializes irq support
4475 * @dev_priv: i915 device instance
4476 *
4477 * This function initializes all the irq support including work items, timers
4478 * and all the vtables. It does not setup the interrupt itself though.
4479 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004480void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004481{
Chris Wilson91c8a322016-07-05 10:40:23 +01004482 struct drm_device *dev = &dev_priv->drm;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004483
Jani Nikula77913b32015-06-18 13:06:16 +03004484 intel_hpd_init_work(dev_priv);
4485
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004486 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004487 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004488
Deepak Sa6706b42014-03-15 20:23:22 +05304489 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004490 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004491 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004492 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004493 else
4494 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304495
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304496 dev_priv->rps.pm_intr_keep = 0;
4497
4498 /*
4499 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
4500 * if GEN6_PM_UP_EI_EXPIRED is masked.
4501 *
4502 * TODO: verify if this can be reproduced on VLV,CHV.
4503 */
4504 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
4505 dev_priv->rps.pm_intr_keep |= GEN6_PM_RP_UP_EI_EXPIRED;
4506
4507 if (INTEL_INFO(dev_priv)->gen >= 8)
4508 dev_priv->rps.pm_intr_keep |= GEN8_PMINTR_REDIRECT_TO_NON_DISP;
4509
Chris Wilson737b1502015-01-26 18:03:03 +02004510 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4511 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004512
Daniel Vetterb9632912014-09-30 10:56:44 +02004513 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004514 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004515 dev->max_vblank_count = 0;
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004516 dev->driver->get_vblank_counter = drm_vblank_no_hw_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004517 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004518 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004519 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004520 } else {
4521 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4522 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004523 }
4524
Ville Syrjälä21da2702014-08-06 14:49:55 +03004525 /*
4526 * Opt out of the vblank disable timer on everything except gen2.
4527 * Gen2 doesn't have a hardware frame counter and so depends on
4528 * vblank interrupts to produce sane vblank seuquence numbers.
4529 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004530 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004531 dev->vblank_disable_immediate = true;
4532
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004533 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4534 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004535
Daniel Vetterb9632912014-09-30 10:56:44 +02004536 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004537 dev->driver->irq_handler = cherryview_irq_handler;
4538 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4539 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4540 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4541 dev->driver->enable_vblank = valleyview_enable_vblank;
4542 dev->driver->disable_vblank = valleyview_disable_vblank;
4543 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004544 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004545 dev->driver->irq_handler = valleyview_irq_handler;
4546 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4547 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4548 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4549 dev->driver->enable_vblank = valleyview_enable_vblank;
4550 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004551 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004552 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004553 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004554 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004555 dev->driver->irq_postinstall = gen8_irq_postinstall;
4556 dev->driver->irq_uninstall = gen8_irq_uninstall;
4557 dev->driver->enable_vblank = gen8_enable_vblank;
4558 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004559 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004560 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi22dea0b2016-07-01 17:07:12 -07004561 else if (HAS_PCH_SPT(dev) || HAS_PCH_KBP(dev))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004562 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4563 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004564 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004565 } else if (HAS_PCH_SPLIT(dev)) {
4566 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004567 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004568 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4569 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4570 dev->driver->enable_vblank = ironlake_enable_vblank;
4571 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004572 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004573 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004574 if (IS_GEN2(dev_priv)) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004575 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4576 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4577 dev->driver->irq_handler = i8xx_irq_handler;
4578 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004579 } else if (IS_GEN3(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004580 dev->driver->irq_preinstall = i915_irq_preinstall;
4581 dev->driver->irq_postinstall = i915_irq_postinstall;
4582 dev->driver->irq_uninstall = i915_irq_uninstall;
4583 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004584 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004585 dev->driver->irq_preinstall = i965_irq_preinstall;
4586 dev->driver->irq_postinstall = i965_irq_postinstall;
4587 dev->driver->irq_uninstall = i965_irq_uninstall;
4588 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004589 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004590 if (I915_HAS_HOTPLUG(dev_priv))
4591 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004592 dev->driver->enable_vblank = i915_enable_vblank;
4593 dev->driver->disable_vblank = i915_disable_vblank;
4594 }
4595}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004596
Daniel Vetterfca52a52014-09-30 10:56:45 +02004597/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004598 * intel_irq_install - enables the hardware interrupt
4599 * @dev_priv: i915 device instance
4600 *
4601 * This function enables the hardware interrupt handling, but leaves the hotplug
4602 * handling still disabled. It is called after intel_irq_init().
4603 *
4604 * In the driver load and resume code we need working interrupts in a few places
4605 * but don't want to deal with the hassle of concurrent probe and hotplug
4606 * workers. Hence the split into this two-stage approach.
4607 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004608int intel_irq_install(struct drm_i915_private *dev_priv)
4609{
4610 /*
4611 * We enable some interrupt sources in our postinstall hooks, so mark
4612 * interrupts as enabled _before_ actually enabling them to avoid
4613 * special cases in our ordering checks.
4614 */
4615 dev_priv->pm.irqs_enabled = true;
4616
Chris Wilson91c8a322016-07-05 10:40:23 +01004617 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004618}
4619
Daniel Vetterfca52a52014-09-30 10:56:45 +02004620/**
4621 * intel_irq_uninstall - finilizes all irq handling
4622 * @dev_priv: i915 device instance
4623 *
4624 * This stops interrupt and hotplug handling and unregisters and frees all
4625 * resources acquired in the init functions.
4626 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004627void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4628{
Chris Wilson91c8a322016-07-05 10:40:23 +01004629 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004630 intel_hpd_cancel_work(dev_priv);
4631 dev_priv->pm.irqs_enabled = false;
4632}
4633
Daniel Vetterfca52a52014-09-30 10:56:45 +02004634/**
4635 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4636 * @dev_priv: i915 device instance
4637 *
4638 * This function is used to disable interrupts at runtime, both in the runtime
4639 * pm and the system suspend/resume code.
4640 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004641void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004642{
Chris Wilson91c8a322016-07-05 10:40:23 +01004643 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004644 dev_priv->pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004645 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004646}
4647
Daniel Vetterfca52a52014-09-30 10:56:45 +02004648/**
4649 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4650 * @dev_priv: i915 device instance
4651 *
4652 * This function is used to enable interrupts at runtime, both in the runtime
4653 * pm and the system suspend/resume code.
4654 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004655void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004656{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004657 dev_priv->pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004658 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4659 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004660}