blob: 6a07ef38fb479b2779b16362874de898e04c194c [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
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300129#define GEN3_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
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300139#define GEN2_IRQ_RESET(type) do { \
140 I915_WRITE16(type##IMR, 0xffff); \
141 POSTING_READ16(type##IMR); \
142 I915_WRITE16(type##IER, 0); \
143 I915_WRITE16(type##IIR, 0xffff); \
144 POSTING_READ16(type##IIR); \
145 I915_WRITE16(type##IIR, 0xffff); \
146 POSTING_READ16(type##IIR); \
147} while (0)
148
Paulo Zanoni337ba012014-04-01 15:37:16 -0300149/*
150 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
151 */
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300152static void gen3_assert_iir_is_zero(struct drm_i915_private *dev_priv,
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200153 i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300154{
155 u32 val = I915_READ(reg);
156
157 if (val == 0)
158 return;
159
160 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200161 i915_mmio_reg_offset(reg), val);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300162 I915_WRITE(reg, 0xffffffff);
163 POSTING_READ(reg);
164 I915_WRITE(reg, 0xffffffff);
165 POSTING_READ(reg);
166}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300167
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300168static void gen2_assert_iir_is_zero(struct drm_i915_private *dev_priv,
169 i915_reg_t reg)
170{
171 u16 val = I915_READ16(reg);
172
173 if (val == 0)
174 return;
175
176 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
177 i915_mmio_reg_offset(reg), val);
178 I915_WRITE16(reg, 0xffff);
179 POSTING_READ16(reg);
180 I915_WRITE16(reg, 0xffff);
181 POSTING_READ16(reg);
182}
183
Paulo Zanoni35079892014-04-01 15:37:15 -0300184#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300185 gen3_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300186 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200187 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
188 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300189} while (0)
190
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300191#define GEN3_IRQ_INIT(type, imr_val, ier_val) do { \
192 gen3_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300193 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200194 I915_WRITE(type##IMR, (imr_val)); \
195 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300196} while (0)
197
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300198#define GEN2_IRQ_INIT(type, imr_val, ier_val) do { \
199 gen2_assert_iir_is_zero(dev_priv, type##IIR); \
200 I915_WRITE16(type##IER, (ier_val)); \
201 I915_WRITE16(type##IMR, (imr_val)); \
202 POSTING_READ16(type##IMR); \
203} while (0)
204
Imre Deakc9a9a262014-11-05 20:48:37 +0200205static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530206static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Imre Deakc9a9a262014-11-05 20:48:37 +0200207
Egbert Eich0706f172015-09-23 16:15:27 +0200208/* For display hotplug interrupt */
209static inline void
210i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
211 uint32_t mask,
212 uint32_t bits)
213{
214 uint32_t val;
215
Chris Wilson67520412017-03-02 13:28:01 +0000216 lockdep_assert_held(&dev_priv->irq_lock);
Egbert Eich0706f172015-09-23 16:15:27 +0200217 WARN_ON(bits & ~mask);
218
219 val = I915_READ(PORT_HOTPLUG_EN);
220 val &= ~mask;
221 val |= bits;
222 I915_WRITE(PORT_HOTPLUG_EN, val);
223}
224
225/**
226 * i915_hotplug_interrupt_update - update hotplug interrupt enable
227 * @dev_priv: driver private
228 * @mask: bits to update
229 * @bits: bits to enable
230 * NOTE: the HPD enable bits are modified both inside and outside
231 * of an interrupt context. To avoid that read-modify-write cycles
232 * interfer, these bits are protected by a spinlock. Since this
233 * function is usually not called from a context where the lock is
234 * held already, this function acquires the lock itself. A non-locking
235 * version is also available.
236 */
237void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
238 uint32_t mask,
239 uint32_t bits)
240{
241 spin_lock_irq(&dev_priv->irq_lock);
242 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
243 spin_unlock_irq(&dev_priv->irq_lock);
244}
245
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300246/**
247 * ilk_update_display_irq - update DEIMR
248 * @dev_priv: driver private
249 * @interrupt_mask: mask of interrupt bits to update
250 * @enabled_irq_mask: mask of interrupt bits to enable
251 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200252void ilk_update_display_irq(struct drm_i915_private *dev_priv,
253 uint32_t interrupt_mask,
254 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800255{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300256 uint32_t new_val;
257
Chris Wilson67520412017-03-02 13:28:01 +0000258 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200259
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300260 WARN_ON(enabled_irq_mask & ~interrupt_mask);
261
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700262 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300263 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300264
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300265 new_val = dev_priv->irq_mask;
266 new_val &= ~interrupt_mask;
267 new_val |= (~enabled_irq_mask & interrupt_mask);
268
269 if (new_val != dev_priv->irq_mask) {
270 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000271 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000272 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800273 }
274}
275
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300276/**
277 * ilk_update_gt_irq - update GTIMR
278 * @dev_priv: driver private
279 * @interrupt_mask: mask of interrupt bits to update
280 * @enabled_irq_mask: mask of interrupt bits to enable
281 */
282static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
283 uint32_t interrupt_mask,
284 uint32_t enabled_irq_mask)
285{
Chris Wilson67520412017-03-02 13:28:01 +0000286 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300287
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100288 WARN_ON(enabled_irq_mask & ~interrupt_mask);
289
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700290 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300291 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300292
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300293 dev_priv->gt_irq_mask &= ~interrupt_mask;
294 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
295 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300296}
297
Daniel Vetter480c8032014-07-16 09:49:40 +0200298void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300299{
300 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100301 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300302}
303
Daniel Vetter480c8032014-07-16 09:49:40 +0200304void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300305{
306 ilk_update_gt_irq(dev_priv, mask, 0);
307}
308
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200309static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200310{
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700311 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
Imre Deakb900b942014-11-05 20:48:48 +0200312}
313
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200314static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200315{
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700316 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
Imre Deaka72fbc32014-11-05 20:48:31 +0200317}
318
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200319static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200320{
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700321 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
Imre Deakb900b942014-11-05 20:48:48 +0200322}
323
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300324/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200325 * snb_update_pm_irq - update GEN6_PMIMR
326 * @dev_priv: driver private
327 * @interrupt_mask: mask of interrupt bits to update
328 * @enabled_irq_mask: mask of interrupt bits to enable
329 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300330static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
331 uint32_t interrupt_mask,
332 uint32_t enabled_irq_mask)
333{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300334 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300335
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100336 WARN_ON(enabled_irq_mask & ~interrupt_mask);
337
Chris Wilson67520412017-03-02 13:28:01 +0000338 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300339
Akash Goelf4e9af42016-10-12 21:54:30 +0530340 new_val = dev_priv->pm_imr;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300341 new_val &= ~interrupt_mask;
342 new_val |= (~enabled_irq_mask & interrupt_mask);
343
Akash Goelf4e9af42016-10-12 21:54:30 +0530344 if (new_val != dev_priv->pm_imr) {
345 dev_priv->pm_imr = new_val;
346 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_imr);
Imre Deaka72fbc32014-11-05 20:48:31 +0200347 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300348 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300349}
350
Akash Goelf4e9af42016-10-12 21:54:30 +0530351void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300352{
Imre Deak9939fba2014-11-20 23:01:47 +0200353 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
354 return;
355
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300356 snb_update_pm_irq(dev_priv, mask, mask);
357}
358
Akash Goelf4e9af42016-10-12 21:54:30 +0530359static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Imre Deak9939fba2014-11-20 23:01:47 +0200360{
361 snb_update_pm_irq(dev_priv, mask, 0);
362}
363
Akash Goelf4e9af42016-10-12 21:54:30 +0530364void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300365{
Imre Deak9939fba2014-11-20 23:01:47 +0200366 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
367 return;
368
Akash Goelf4e9af42016-10-12 21:54:30 +0530369 __gen6_mask_pm_irq(dev_priv, mask);
370}
371
Oscar Mateo3814fd72017-08-23 16:58:24 -0700372static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530373{
374 i915_reg_t reg = gen6_pm_iir(dev_priv);
375
Chris Wilson67520412017-03-02 13:28:01 +0000376 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530377
378 I915_WRITE(reg, reset_mask);
379 I915_WRITE(reg, reset_mask);
380 POSTING_READ(reg);
381}
382
Oscar Mateo3814fd72017-08-23 16:58:24 -0700383static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530384{
Chris Wilson67520412017-03-02 13:28:01 +0000385 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530386
387 dev_priv->pm_ier |= enable_mask;
388 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
389 gen6_unmask_pm_irq(dev_priv, enable_mask);
390 /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */
391}
392
Oscar Mateo3814fd72017-08-23 16:58:24 -0700393static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530394{
Chris Wilson67520412017-03-02 13:28:01 +0000395 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530396
397 dev_priv->pm_ier &= ~disable_mask;
398 __gen6_mask_pm_irq(dev_priv, disable_mask);
399 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
400 /* though a barrier is missing here, but don't really need a one */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300401}
402
Chris Wilsondc979972016-05-10 14:10:04 +0100403void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200404{
Imre Deak3cc134e2014-11-19 15:30:03 +0200405 spin_lock_irq(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530406 gen6_reset_pm_iir(dev_priv, dev_priv->pm_rps_events);
Imre Deak096fad92015-03-23 19:11:35 +0200407 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200408 spin_unlock_irq(&dev_priv->irq_lock);
409}
410
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100411void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200412{
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100413 if (READ_ONCE(dev_priv->rps.interrupts_enabled))
414 return;
415
Imre Deakb900b942014-11-05 20:48:48 +0200416 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100417 WARN_ON_ONCE(dev_priv->rps.pm_iir);
418 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200419 dev_priv->rps.interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200420 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200421
Imre Deakb900b942014-11-05 20:48:48 +0200422 spin_unlock_irq(&dev_priv->irq_lock);
423}
424
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100425void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200426{
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100427 if (!READ_ONCE(dev_priv->rps.interrupts_enabled))
428 return;
429
Imre Deakd4d70aa2014-11-19 15:30:04 +0200430 spin_lock_irq(&dev_priv->irq_lock);
431 dev_priv->rps.interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200432
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100433 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200434
Akash Goelf4e9af42016-10-12 21:54:30 +0530435 gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200436
437 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100438 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100439
440 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700441 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100442 * we will reset the GPU to minimum frequencies, so the current
443 * state of the worker can be discarded.
444 */
445 cancel_work_sync(&dev_priv->rps.work);
446 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200447}
448
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530449void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
450{
451 spin_lock_irq(&dev_priv->irq_lock);
452 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
453 spin_unlock_irq(&dev_priv->irq_lock);
454}
455
456void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
457{
458 spin_lock_irq(&dev_priv->irq_lock);
459 if (!dev_priv->guc.interrupts_enabled) {
460 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
461 dev_priv->pm_guc_events);
462 dev_priv->guc.interrupts_enabled = true;
463 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
464 }
465 spin_unlock_irq(&dev_priv->irq_lock);
466}
467
468void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
469{
470 spin_lock_irq(&dev_priv->irq_lock);
471 dev_priv->guc.interrupts_enabled = false;
472
473 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
474
475 spin_unlock_irq(&dev_priv->irq_lock);
476 synchronize_irq(dev_priv->drm.irq);
477
478 gen9_reset_guc_interrupts(dev_priv);
479}
480
Ben Widawsky09610212014-05-15 20:58:08 +0300481/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200482 * bdw_update_port_irq - update DE port interrupt
483 * @dev_priv: driver private
484 * @interrupt_mask: mask of interrupt bits to update
485 * @enabled_irq_mask: mask of interrupt bits to enable
486 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300487static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
488 uint32_t interrupt_mask,
489 uint32_t enabled_irq_mask)
490{
491 uint32_t new_val;
492 uint32_t old_val;
493
Chris Wilson67520412017-03-02 13:28:01 +0000494 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300495
496 WARN_ON(enabled_irq_mask & ~interrupt_mask);
497
498 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
499 return;
500
501 old_val = I915_READ(GEN8_DE_PORT_IMR);
502
503 new_val = old_val;
504 new_val &= ~interrupt_mask;
505 new_val |= (~enabled_irq_mask & interrupt_mask);
506
507 if (new_val != old_val) {
508 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
509 POSTING_READ(GEN8_DE_PORT_IMR);
510 }
511}
512
513/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200514 * bdw_update_pipe_irq - update DE pipe interrupt
515 * @dev_priv: driver private
516 * @pipe: pipe whose interrupt to update
517 * @interrupt_mask: mask of interrupt bits to update
518 * @enabled_irq_mask: mask of interrupt bits to enable
519 */
520void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
521 enum pipe pipe,
522 uint32_t interrupt_mask,
523 uint32_t enabled_irq_mask)
524{
525 uint32_t new_val;
526
Chris Wilson67520412017-03-02 13:28:01 +0000527 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200528
529 WARN_ON(enabled_irq_mask & ~interrupt_mask);
530
531 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
532 return;
533
534 new_val = dev_priv->de_irq_mask[pipe];
535 new_val &= ~interrupt_mask;
536 new_val |= (~enabled_irq_mask & interrupt_mask);
537
538 if (new_val != dev_priv->de_irq_mask[pipe]) {
539 dev_priv->de_irq_mask[pipe] = new_val;
540 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
541 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
542 }
543}
544
545/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200546 * ibx_display_interrupt_update - update SDEIMR
547 * @dev_priv: driver private
548 * @interrupt_mask: mask of interrupt bits to update
549 * @enabled_irq_mask: mask of interrupt bits to enable
550 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200551void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
552 uint32_t interrupt_mask,
553 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200554{
555 uint32_t sdeimr = I915_READ(SDEIMR);
556 sdeimr &= ~interrupt_mask;
557 sdeimr |= (~enabled_irq_mask & interrupt_mask);
558
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100559 WARN_ON(enabled_irq_mask & ~interrupt_mask);
560
Chris Wilson67520412017-03-02 13:28:01 +0000561 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200562
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700563 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300564 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300565
Daniel Vetterfee884e2013-07-04 23:35:21 +0200566 I915_WRITE(SDEIMR, sdeimr);
567 POSTING_READ(SDEIMR);
568}
Paulo Zanoni86642812013-04-12 17:57:57 -0300569
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300570u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
571 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800572{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300573 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200574 u32 enable_mask = status_mask << 16;
575
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300576 lockdep_assert_held(&dev_priv->irq_lock);
577
578 if (INTEL_GEN(dev_priv) < 5)
579 goto out;
580
Imre Deak10c59c52014-02-10 18:42:48 +0200581 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300582 * On pipe A we don't support the PSR interrupt yet,
583 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200584 */
585 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
586 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300587 /*
588 * On pipe B and C we don't support the PSR interrupt yet, on pipe
589 * A the same bit is for perf counters which we don't use either.
590 */
591 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
592 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200593
594 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
595 SPRITE0_FLIP_DONE_INT_EN_VLV |
596 SPRITE1_FLIP_DONE_INT_EN_VLV);
597 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
598 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
599 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
600 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
601
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300602out:
603 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
604 status_mask & ~PIPESTAT_INT_STATUS_MASK,
605 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
606 pipe_name(pipe), enable_mask, status_mask);
607
Imre Deak10c59c52014-02-10 18:42:48 +0200608 return enable_mask;
609}
610
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300611void i915_enable_pipestat(struct drm_i915_private *dev_priv,
612 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200613{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300614 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200615 u32 enable_mask;
616
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300617 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
618 "pipe %c: status_mask=0x%x\n",
619 pipe_name(pipe), status_mask);
620
621 lockdep_assert_held(&dev_priv->irq_lock);
622 WARN_ON(!intel_irqs_enabled(dev_priv));
623
624 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
625 return;
626
627 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
628 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
629
630 I915_WRITE(reg, enable_mask | status_mask);
631 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200632}
633
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300634void i915_disable_pipestat(struct drm_i915_private *dev_priv,
635 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200636{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300637 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200638 u32 enable_mask;
639
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300640 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
641 "pipe %c: status_mask=0x%x\n",
642 pipe_name(pipe), status_mask);
643
644 lockdep_assert_held(&dev_priv->irq_lock);
645 WARN_ON(!intel_irqs_enabled(dev_priv));
646
647 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
648 return;
649
650 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
651 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
652
653 I915_WRITE(reg, enable_mask | status_mask);
654 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200655}
656
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000657/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300658 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100659 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000660 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100661static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000662{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100663 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300664 return;
665
Daniel Vetter13321782014-09-15 14:55:29 +0200666 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000667
Imre Deak755e9012014-02-10 18:42:47 +0200668 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100669 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200670 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200671 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000672
Daniel Vetter13321782014-09-15 14:55:29 +0200673 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000674}
675
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300676/*
677 * This timing diagram depicts the video signal in and
678 * around the vertical blanking period.
679 *
680 * Assumptions about the fictitious mode used in this example:
681 * vblank_start >= 3
682 * vsync_start = vblank_start + 1
683 * vsync_end = vblank_start + 2
684 * vtotal = vblank_start + 3
685 *
686 * start of vblank:
687 * latch double buffered registers
688 * increment frame counter (ctg+)
689 * generate start of vblank interrupt (gen4+)
690 * |
691 * | frame start:
692 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
693 * | may be shifted forward 1-3 extra lines via PIPECONF
694 * | |
695 * | | start of vsync:
696 * | | generate vsync interrupt
697 * | | |
698 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
699 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
700 * ----va---> <-----------------vb--------------------> <--------va-------------
701 * | | <----vs-----> |
702 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
703 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
704 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
705 * | | |
706 * last visible pixel first visible pixel
707 * | increment frame counter (gen3/4)
708 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
709 *
710 * x = horizontal active
711 * _ = horizontal blanking
712 * hs = horizontal sync
713 * va = vertical active
714 * vb = vertical blanking
715 * vs = vertical sync
716 * vbs = vblank_start (number)
717 *
718 * Summary:
719 * - most events happen at the start of horizontal sync
720 * - frame start happens at the start of horizontal blank, 1-4 lines
721 * (depending on PIPECONF settings) after the start of vblank
722 * - gen3/4 pixel and frame counter are synchronized with the start
723 * of horizontal active on the first line of vertical active
724 */
725
Keith Packard42f52ef2008-10-18 19:39:29 -0700726/* Called from drm generic code, passed a 'crtc', which
727 * we use as a pipe index
728 */
Thierry Reding88e72712015-09-24 18:35:31 +0200729static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700730{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100731 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200732 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300733 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200734 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200735 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700736
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100737 htotal = mode->crtc_htotal;
738 hsync_start = mode->crtc_hsync_start;
739 vbl_start = mode->crtc_vblank_start;
740 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
741 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300742
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300743 /* Convert to pixel count */
744 vbl_start *= htotal;
745
746 /* Start of vblank event occurs at start of hsync */
747 vbl_start -= htotal - hsync_start;
748
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800749 high_frame = PIPEFRAME(pipe);
750 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100751
Ville Syrjälä694e4092017-03-09 17:44:30 +0200752 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
753
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700754 /*
755 * High & low register fields aren't synchronized, so make sure
756 * we get a low value that's stable across two reads of the high
757 * register.
758 */
759 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200760 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
761 low = I915_READ_FW(low_frame);
762 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700763 } while (high1 != high2);
764
Ville Syrjälä694e4092017-03-09 17:44:30 +0200765 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
766
Chris Wilson5eddb702010-09-11 13:48:45 +0100767 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300768 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100769 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300770
771 /*
772 * The frame counter increments at beginning of active.
773 * Cook up a vblank counter by also checking the pixel
774 * counter against vblank start.
775 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200776 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700777}
778
Dave Airlie974e59b2015-10-30 09:45:33 +1000779static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800780{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100781 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800782
Ville Syrjälä649636e2015-09-22 19:50:01 +0300783 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800784}
785
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300786/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300787static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
788{
789 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100790 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200791 const struct drm_display_mode *mode;
792 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300793 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300794 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300795
Ville Syrjälä72259532017-03-02 19:15:05 +0200796 if (!crtc->active)
797 return -1;
798
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200799 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
800 mode = &vblank->hwmode;
801
Ville Syrjälä80715b22014-05-15 20:23:23 +0300802 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300803 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
804 vtotal /= 2;
805
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100806 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300807 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300808 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300809 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300810
811 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700812 * On HSW, the DSL reg (0x70000) appears to return 0 if we
813 * read it just before the start of vblank. So try it again
814 * so we don't accidentally end up spanning a vblank frame
815 * increment, causing the pipe_update_end() code to squak at us.
816 *
817 * The nature of this problem means we can't simply check the ISR
818 * bit and return the vblank start value; nor can we use the scanline
819 * debug register in the transcoder as it appears to have the same
820 * problem. We may need to extend this to include other platforms,
821 * but so far testing only shows the problem on HSW.
822 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100823 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700824 int i, temp;
825
826 for (i = 0; i < 100; i++) {
827 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200828 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700829 if (temp != position) {
830 position = temp;
831 break;
832 }
833 }
834 }
835
836 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300837 * See update_scanline_offset() for the details on the
838 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300839 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300840 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300841}
842
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200843static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
844 bool in_vblank_irq, int *vpos, int *hpos,
845 ktime_t *stime, ktime_t *etime,
846 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100847{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100848 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200849 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
850 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300851 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300852 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100853 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100854
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200855 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100856 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800857 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200858 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100859 }
860
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300861 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300862 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300863 vtotal = mode->crtc_vtotal;
864 vbl_start = mode->crtc_vblank_start;
865 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100866
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200867 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
868 vbl_start = DIV_ROUND_UP(vbl_start, 2);
869 vbl_end /= 2;
870 vtotal /= 2;
871 }
872
Mario Kleinerad3543e2013-10-30 05:13:08 +0100873 /*
874 * Lock uncore.lock, as we will do multiple timing critical raw
875 * register reads, potentially with preemption disabled, so the
876 * following code must not block on uncore.lock.
877 */
878 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300879
Mario Kleinerad3543e2013-10-30 05:13:08 +0100880 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
881
882 /* Get optional system timestamp before query. */
883 if (stime)
884 *stime = ktime_get();
885
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100886 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100887 /* No obvious pixelcount register. Only query vertical
888 * scanout position from Display scan line register.
889 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300890 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100891 } else {
892 /* Have access to pixelcount since start of frame.
893 * We can split this into vertical and horizontal
894 * scanout position.
895 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300896 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100897
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300898 /* convert to pixel counts */
899 vbl_start *= htotal;
900 vbl_end *= htotal;
901 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300902
903 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300904 * In interlaced modes, the pixel counter counts all pixels,
905 * so one field will have htotal more pixels. In order to avoid
906 * the reported position from jumping backwards when the pixel
907 * counter is beyond the length of the shorter field, just
908 * clamp the position the length of the shorter field. This
909 * matches how the scanline counter based position works since
910 * the scanline counter doesn't count the two half lines.
911 */
912 if (position >= vtotal)
913 position = vtotal - 1;
914
915 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300916 * Start of vblank interrupt is triggered at start of hsync,
917 * just prior to the first active line of vblank. However we
918 * consider lines to start at the leading edge of horizontal
919 * active. So, should we get here before we've crossed into
920 * the horizontal active of the first line in vblank, we would
921 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
922 * always add htotal-hsync_start to the current pixel position.
923 */
924 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300925 }
926
Mario Kleinerad3543e2013-10-30 05:13:08 +0100927 /* Get optional system timestamp after query. */
928 if (etime)
929 *etime = ktime_get();
930
931 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
932
933 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
934
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300935 /*
936 * While in vblank, position will be negative
937 * counting up towards 0 at vbl_end. And outside
938 * vblank, position will be positive counting
939 * up since vbl_end.
940 */
941 if (position >= vbl_start)
942 position -= vbl_end;
943 else
944 position += vtotal - vbl_end;
945
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100946 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300947 *vpos = position;
948 *hpos = 0;
949 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100950 *vpos = position / htotal;
951 *hpos = position - (*vpos * htotal);
952 }
953
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200954 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100955}
956
Ville Syrjäläa225f072014-04-29 13:35:45 +0300957int intel_get_crtc_scanline(struct intel_crtc *crtc)
958{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100959 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +0300960 unsigned long irqflags;
961 int position;
962
963 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
964 position = __intel_get_crtc_scanline(crtc);
965 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
966
967 return position;
968}
969
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100970static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800971{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000972 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200973 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200974
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200975 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800976
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200977 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
978
Daniel Vetter20e4d402012-08-08 23:35:39 +0200979 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200980
Jesse Barnes7648fa92010-05-20 14:28:11 -0700981 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000982 busy_up = I915_READ(RCPREVBSYTUPAVG);
983 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800984 max_avg = I915_READ(RCBMAXAVG);
985 min_avg = I915_READ(RCBMINAVG);
986
987 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000988 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200989 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
990 new_delay = dev_priv->ips.cur_delay - 1;
991 if (new_delay < dev_priv->ips.max_delay)
992 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000993 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200994 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
995 new_delay = dev_priv->ips.cur_delay + 1;
996 if (new_delay > dev_priv->ips.min_delay)
997 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800998 }
999
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001000 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001001 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001002
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001003 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001004
Jesse Barnesf97108d2010-01-29 11:27:07 -08001005 return;
1006}
1007
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001008static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001009{
Chris Wilson56299fb2017-02-27 20:58:48 +00001010 struct drm_i915_gem_request *rq = NULL;
1011 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001012
Chris Wilson2246bea2017-02-17 15:13:00 +00001013 atomic_inc(&engine->irq_count);
Chris Wilson538b2572017-01-24 15:18:05 +00001014 set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson56299fb2017-02-27 20:58:48 +00001015
Chris Wilson61d3dc72017-03-03 19:08:24 +00001016 spin_lock(&engine->breadcrumbs.irq_lock);
1017 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001018 if (wait) {
Chris Wilson17b51ad2017-09-18 17:27:33 +01001019 bool wakeup = engine->irq_seqno_barrier;
1020
Chris Wilson56299fb2017-02-27 20:58:48 +00001021 /* We use a callback from the dma-fence to submit
1022 * requests after waiting on our own requests. To
1023 * ensure minimum delay in queuing the next request to
1024 * hardware, signal the fence now rather than wait for
1025 * the signaler to be woken up. We still wake up the
1026 * waiter in order to handle the irq-seqno coherency
1027 * issues (we may receive the interrupt before the
1028 * seqno is written, see __i915_request_irq_complete())
1029 * and to handle coalescing of multiple seqno updates
1030 * and many waiters.
1031 */
1032 if (i915_seqno_passed(intel_engine_get_seqno(engine),
Chris Wilson17b51ad2017-09-18 17:27:33 +01001033 wait->seqno)) {
Chris Wilsonde4d2102017-09-18 17:27:34 +01001034 struct drm_i915_gem_request *waiter = wait->request;
1035
Chris Wilson17b51ad2017-09-18 17:27:33 +01001036 wakeup = true;
1037 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Chris Wilsonde4d2102017-09-18 17:27:34 +01001038 &waiter->fence.flags) &&
1039 intel_wait_check_request(wait, waiter))
1040 rq = i915_gem_request_get(waiter);
Chris Wilson17b51ad2017-09-18 17:27:33 +01001041 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001042
Chris Wilson17b51ad2017-09-18 17:27:33 +01001043 if (wakeup)
1044 wake_up_process(wait->tsk);
Chris Wilson67b807a82017-02-27 20:58:50 +00001045 } else {
1046 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001047 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001048 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001049
Chris Wilson24754d72017-03-03 14:45:57 +00001050 if (rq) {
Chris Wilson56299fb2017-02-27 20:58:48 +00001051 dma_fence_signal(&rq->fence);
Chris Wilson24754d72017-03-03 14:45:57 +00001052 i915_gem_request_put(rq);
1053 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001054
1055 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001056}
1057
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001058static void vlv_c0_read(struct drm_i915_private *dev_priv,
1059 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001060{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001061 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001062 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1063 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001064}
1065
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001066void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1067{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001068 memset(&dev_priv->rps.ei, 0, sizeof(dev_priv->rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001069}
1070
1071static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1072{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001073 const struct intel_rps_ei *prev = &dev_priv->rps.ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001074 struct intel_rps_ei now;
1075 u32 events = 0;
1076
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001077 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001078 return 0;
1079
1080 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001081
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001082 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001083 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001084 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001085
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001086 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001087
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001088 time *= dev_priv->czclk_freq;
1089
1090 /* Workload can be split between render + media,
1091 * e.g. SwapBuffers being blitted in X after being rendered in
1092 * mesa. To account for this we need to combine both engines
1093 * into our activity counter.
1094 */
Chris Wilson569884e2017-03-09 21:12:31 +00001095 render = now.render_c0 - prev->render_c0;
1096 media = now.media_c0 - prev->media_c0;
1097 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001098 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001099
1100 if (c0 > time * dev_priv->rps.up_threshold)
1101 events = GEN6_PM_RP_UP_THRESHOLD;
1102 else if (c0 < time * dev_priv->rps.down_threshold)
1103 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001104 }
1105
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001106 dev_priv->rps.ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001107 return events;
Deepak S31685c22014-07-03 17:33:01 -04001108}
1109
Ben Widawsky4912d042011-04-25 11:25:20 -07001110static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001111{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001112 struct drm_i915_private *dev_priv =
1113 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001114 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001115 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001116 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001117
Daniel Vetter59cdb632013-07-04 23:35:28 +02001118 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001119 if (dev_priv->rps.interrupts_enabled) {
1120 pm_iir = fetch_and_zero(&dev_priv->rps.pm_iir);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001121 client_boost = atomic_read(&dev_priv->rps.num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001122 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001123 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001124
Paulo Zanoni60611c12013-08-15 11:50:01 -03001125 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301126 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001127 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001128 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001129
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001130 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001131
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001132 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1133
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001134 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001135 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001136 min = dev_priv->rps.min_freq_softlimit;
1137 max = dev_priv->rps.max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001138 if (client_boost)
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001139 max = dev_priv->rps.max_freq;
1140 if (client_boost && new_delay < dev_priv->rps.boost_freq) {
1141 new_delay = dev_priv->rps.boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001142 adj = 0;
1143 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001144 if (adj > 0)
1145 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001146 else /* CHV needs even encode values */
1147 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301148
1149 if (new_delay >= dev_priv->rps.max_freq_softlimit)
1150 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001151 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001152 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001153 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001154 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1155 new_delay = dev_priv->rps.efficient_freq;
Chris Wilson17136d52017-02-10 15:03:47 +00001156 else if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
Ben Widawskyb39fb292014-03-19 18:31:11 -07001157 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001158 adj = 0;
1159 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1160 if (adj < 0)
1161 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001162 else /* CHV needs even encode values */
1163 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301164
1165 if (new_delay <= dev_priv->rps.min_freq_softlimit)
1166 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001167 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001168 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001169 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001170
Chris Wilsonedcf2842015-04-07 16:20:29 +01001171 dev_priv->rps.last_adj = adj;
1172
Ben Widawsky79249632012-09-07 19:43:42 -07001173 /* sysfs frequency interfaces may have snuck in while servicing the
1174 * interrupt
1175 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001176 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001177 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301178
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001179 if (intel_set_rps(dev_priv, new_delay)) {
1180 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
1181 dev_priv->rps.last_adj = 0;
1182 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001183
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001184 mutex_unlock(&dev_priv->rps.hw_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001185
1186out:
1187 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1188 spin_lock_irq(&dev_priv->irq_lock);
1189 if (dev_priv->rps.interrupts_enabled)
1190 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1191 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001192}
1193
Ben Widawskye3689192012-05-25 16:56:22 -07001194
1195/**
1196 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1197 * occurred.
1198 * @work: workqueue struct
1199 *
1200 * Doesn't actually do anything except notify userspace. As a consequence of
1201 * this event, userspace should try to remap the bad rows since statistically
1202 * it is likely the same row is more likely to go bad again.
1203 */
1204static void ivybridge_parity_work(struct work_struct *work)
1205{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001206 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001207 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001208 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001209 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001210 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001211 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001212
1213 /* We must turn off DOP level clock gating to access the L3 registers.
1214 * In order to prevent a get/put style interface, acquire struct mutex
1215 * any time we access those registers.
1216 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001217 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001218
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001219 /* If we've screwed up tracking, just let the interrupt fire again */
1220 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1221 goto out;
1222
Ben Widawskye3689192012-05-25 16:56:22 -07001223 misccpctl = I915_READ(GEN7_MISCCPCTL);
1224 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1225 POSTING_READ(GEN7_MISCCPCTL);
1226
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001227 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001228 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001229
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001230 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001231 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001232 break;
1233
1234 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1235
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001236 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001237
1238 error_status = I915_READ(reg);
1239 row = GEN7_PARITY_ERROR_ROW(error_status);
1240 bank = GEN7_PARITY_ERROR_BANK(error_status);
1241 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1242
1243 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1244 POSTING_READ(reg);
1245
1246 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1247 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1248 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1249 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1250 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1251 parity_event[5] = NULL;
1252
Chris Wilson91c8a322016-07-05 10:40:23 +01001253 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001254 KOBJ_CHANGE, parity_event);
1255
1256 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1257 slice, row, bank, subbank);
1258
1259 kfree(parity_event[4]);
1260 kfree(parity_event[3]);
1261 kfree(parity_event[2]);
1262 kfree(parity_event[1]);
1263 }
Ben Widawskye3689192012-05-25 16:56:22 -07001264
1265 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1266
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001267out:
1268 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001269 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001270 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001271 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001272
Chris Wilson91c8a322016-07-05 10:40:23 +01001273 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001274}
1275
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001276static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1277 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001278{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001279 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001280 return;
1281
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001282 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001283 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001284 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001285
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001286 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001287 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1288 dev_priv->l3_parity.which_slice |= 1 << 1;
1289
1290 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1291 dev_priv->l3_parity.which_slice |= 1 << 0;
1292
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001293 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001294}
1295
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001296static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001297 u32 gt_iir)
1298{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001299 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301300 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001301 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301302 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001303}
1304
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001305static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001306 u32 gt_iir)
1307{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001308 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301309 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001310 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301311 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001312 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301313 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001314
Ben Widawskycc609d52013-05-28 19:22:29 -07001315 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1316 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001317 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1318 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001319
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001320 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1321 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001322}
1323
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001324static void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001325gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001326{
Mika Kuoppalab620e872017-09-22 15:43:03 +03001327 struct intel_engine_execlists * const execlists = &engine->execlists;
Chris Wilson31de7352017-03-16 12:56:18 +00001328 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001329
1330 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) {
Mika Kuoppalab620e872017-09-22 15:43:03 +03001331 if (port_count(&execlists->port[0])) {
Chris Wilson955a4b82017-05-17 13:10:07 +01001332 __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted);
Chris Wilsona4b2b012017-05-17 13:10:01 +01001333 tasklet = true;
1334 }
Chris Wilsonf7470262017-01-24 15:20:21 +00001335 }
Chris Wilson31de7352017-03-16 12:56:18 +00001336
1337 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) {
1338 notify_ring(engine);
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001339 tasklet |= i915_modparams.enable_guc_submission;
Chris Wilson31de7352017-03-16 12:56:18 +00001340 }
1341
1342 if (tasklet)
Mika Kuoppalab620e872017-09-22 15:43:03 +03001343 tasklet_hi_schedule(&execlists->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001344}
1345
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001346static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1347 u32 master_ctl,
1348 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001349{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001350 irqreturn_t ret = IRQ_NONE;
1351
1352 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001353 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1354 if (gt_iir[0]) {
1355 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001356 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001357 } else
1358 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1359 }
1360
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001361 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001362 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1363 if (gt_iir[1]) {
1364 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001365 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001366 } else
1367 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1368 }
1369
Chris Wilson74cdb332015-04-07 16:21:05 +01001370 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001371 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1372 if (gt_iir[3]) {
1373 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001374 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001375 } else
1376 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1377 }
1378
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301379 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001380 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301381 if (gt_iir[2] & (dev_priv->pm_rps_events |
1382 dev_priv->pm_guc_events)) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001383 I915_WRITE_FW(GEN8_GT_IIR(2),
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301384 gt_iir[2] & (dev_priv->pm_rps_events |
1385 dev_priv->pm_guc_events));
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001386 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001387 } else
1388 DRM_ERROR("The master control interrupt lied (PM)!\n");
1389 }
1390
Ben Widawskyabd58f02013-11-02 21:07:09 -07001391 return ret;
1392}
1393
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001394static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1395 u32 gt_iir[4])
1396{
1397 if (gt_iir[0]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301398 gen8_cs_irq_handler(dev_priv->engine[RCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001399 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301400 gen8_cs_irq_handler(dev_priv->engine[BCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001401 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1402 }
1403
1404 if (gt_iir[1]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301405 gen8_cs_irq_handler(dev_priv->engine[VCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001406 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301407 gen8_cs_irq_handler(dev_priv->engine[VCS2],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001408 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1409 }
1410
1411 if (gt_iir[3])
Akash Goel3b3f1652016-10-13 22:44:48 +05301412 gen8_cs_irq_handler(dev_priv->engine[VECS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001413 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1414
1415 if (gt_iir[2] & dev_priv->pm_rps_events)
1416 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301417
1418 if (gt_iir[2] & dev_priv->pm_guc_events)
1419 gen9_guc_irq_handler(dev_priv, gt_iir[2]);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001420}
1421
Imre Deak63c88d22015-07-20 14:43:39 -07001422static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1423{
1424 switch (port) {
1425 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001426 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001427 case PORT_B:
1428 return val & PORTB_HOTPLUG_LONG_DETECT;
1429 case PORT_C:
1430 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001431 default:
1432 return false;
1433 }
1434}
1435
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001436static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1437{
1438 switch (port) {
1439 case PORT_E:
1440 return val & PORTE_HOTPLUG_LONG_DETECT;
1441 default:
1442 return false;
1443 }
1444}
1445
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001446static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1447{
1448 switch (port) {
1449 case PORT_A:
1450 return val & PORTA_HOTPLUG_LONG_DETECT;
1451 case PORT_B:
1452 return val & PORTB_HOTPLUG_LONG_DETECT;
1453 case PORT_C:
1454 return val & PORTC_HOTPLUG_LONG_DETECT;
1455 case PORT_D:
1456 return val & PORTD_HOTPLUG_LONG_DETECT;
1457 default:
1458 return false;
1459 }
1460}
1461
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001462static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1463{
1464 switch (port) {
1465 case PORT_A:
1466 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1467 default:
1468 return false;
1469 }
1470}
1471
Jani Nikula676574d2015-05-28 15:43:53 +03001472static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001473{
1474 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001475 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001476 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001477 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001478 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001479 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001480 return val & PORTD_HOTPLUG_LONG_DETECT;
1481 default:
1482 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001483 }
1484}
1485
Jani Nikula676574d2015-05-28 15:43:53 +03001486static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001487{
1488 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001489 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001490 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001491 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001492 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001493 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001494 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1495 default:
1496 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001497 }
1498}
1499
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001500/*
1501 * Get a bit mask of pins that have triggered, and which ones may be long.
1502 * This can be called multiple times with the same masks to accumulate
1503 * hotplug detection results from several registers.
1504 *
1505 * Note that the caller is expected to zero out the masks initially.
1506 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001507static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001508 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001509 const u32 hpd[HPD_NUM_PINS],
1510 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001511{
Jani Nikula8c841e52015-06-18 13:06:17 +03001512 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001513 int i;
1514
Jani Nikula676574d2015-05-28 15:43:53 +03001515 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001516 if ((hpd[i] & hotplug_trigger) == 0)
1517 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001518
Jani Nikula8c841e52015-06-18 13:06:17 +03001519 *pin_mask |= BIT(i);
1520
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07001521 port = intel_hpd_pin_to_port(i);
1522 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001523 continue;
1524
Imre Deakfd63e2a2015-07-21 15:32:44 -07001525 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001526 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001527 }
1528
1529 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1530 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1531
1532}
1533
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001534static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001535{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001536 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001537}
1538
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001539static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001540{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001541 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001542}
1543
Shuang He8bf1e9f2013-10-15 18:55:27 +01001544#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001545static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1546 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001547 uint32_t crc0, uint32_t crc1,
1548 uint32_t crc2, uint32_t crc3,
1549 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001550{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001551 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1552 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001553 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1554 struct drm_driver *driver = dev_priv->drm.driver;
1555 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001556 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001557
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001558 spin_lock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001559 if (pipe_crc->source) {
1560 if (!pipe_crc->entries) {
1561 spin_unlock(&pipe_crc->lock);
1562 DRM_DEBUG_KMS("spurious interrupt\n");
1563 return;
1564 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001565
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001566 head = pipe_crc->head;
1567 tail = pipe_crc->tail;
1568
1569 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1570 spin_unlock(&pipe_crc->lock);
1571 DRM_ERROR("CRC buffer overflowing\n");
1572 return;
1573 }
1574
1575 entry = &pipe_crc->entries[head];
1576
1577 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1578 entry->crc[0] = crc0;
1579 entry->crc[1] = crc1;
1580 entry->crc[2] = crc2;
1581 entry->crc[3] = crc3;
1582 entry->crc[4] = crc4;
1583
1584 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1585 pipe_crc->head = head;
1586
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001587 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001588
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001589 wake_up_interruptible(&pipe_crc->wq);
1590 } else {
1591 /*
1592 * For some not yet identified reason, the first CRC is
1593 * bonkers. So let's just wait for the next vblank and read
1594 * out the buggy result.
1595 *
1596 * On CHV sometimes the second CRC is bonkers as well, so
1597 * don't trust that one either.
1598 */
1599 if (pipe_crc->skipped == 0 ||
1600 (IS_CHERRYVIEW(dev_priv) && pipe_crc->skipped == 1)) {
1601 pipe_crc->skipped++;
1602 spin_unlock(&pipe_crc->lock);
1603 return;
1604 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001605 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001606 crcs[0] = crc0;
1607 crcs[1] = crc1;
1608 crcs[2] = crc2;
1609 crcs[3] = crc3;
1610 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001611 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001612 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001613 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001614 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001615}
Daniel Vetter277de952013-10-18 16:37:07 +02001616#else
1617static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001618display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1619 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001620 uint32_t crc0, uint32_t crc1,
1621 uint32_t crc2, uint32_t crc3,
1622 uint32_t crc4) {}
1623#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001624
Daniel Vetter277de952013-10-18 16:37:07 +02001625
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001626static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1627 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001628{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001629 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001630 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1631 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001632}
1633
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001634static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1635 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001636{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001637 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001638 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1639 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1640 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1641 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1642 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001643}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001644
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001645static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1646 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001647{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001648 uint32_t res1, res2;
1649
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001650 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001651 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1652 else
1653 res1 = 0;
1654
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001655 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001656 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1657 else
1658 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001659
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001660 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001661 I915_READ(PIPE_CRC_RES_RED(pipe)),
1662 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1663 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1664 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001665}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001666
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001667/* The RPS events need forcewake, so we add them to a work queue and mask their
1668 * IMR bits until the work is done. Other interrupts can be processed without
1669 * the work queue. */
1670static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001671{
Deepak Sa6706b42014-03-15 20:23:22 +05301672 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001673 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301674 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001675 if (dev_priv->rps.interrupts_enabled) {
1676 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001677 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001678 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001679 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001680 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001681
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001682 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001683 return;
1684
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001685 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001686 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301687 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001688
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001689 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1690 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001691 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001692}
1693
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301694static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1695{
1696 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) {
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301697 /* Sample the log buffer flush related bits & clear them out now
1698 * itself from the message identity register to minimize the
1699 * probability of losing a flush interrupt, when there are back
1700 * to back flush interrupts.
1701 * There can be a new flush interrupt, for different log buffer
1702 * type (like for ISR), whilst Host is handling one (for DPC).
1703 * Since same bit is used in message register for ISR & DPC, it
1704 * could happen that GuC sets the bit for 2nd interrupt but Host
1705 * clears out the bit on handling the 1st interrupt.
1706 */
1707 u32 msg, flush;
1708
1709 msg = I915_READ(SOFT_SCRATCH(15));
Arkadiusz Hilera80bc452016-11-25 18:59:34 +01001710 flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED |
1711 INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER);
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301712 if (flush) {
1713 /* Clear the message bits that are handled */
1714 I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
1715
1716 /* Handle flush interrupt in bottom half */
Oscar Mateoe7465472017-03-22 10:39:48 -07001717 queue_work(dev_priv->guc.log.runtime.flush_wq,
1718 &dev_priv->guc.log.runtime.flush_work);
Akash Goel5aa1ee42016-10-12 21:54:36 +05301719
1720 dev_priv->guc.log.flush_interrupt_count++;
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301721 } else {
1722 /* Not clearing of unhandled event bits won't result in
1723 * re-triggering of the interrupt.
1724 */
1725 }
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301726 }
1727}
1728
Ville Syrjälä44d92412017-08-18 21:36:51 +03001729static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1730{
1731 enum pipe pipe;
1732
1733 for_each_pipe(dev_priv, pipe) {
1734 I915_WRITE(PIPESTAT(pipe),
1735 PIPESTAT_INT_STATUS_MASK |
1736 PIPE_FIFO_UNDERRUN_STATUS);
1737
1738 dev_priv->pipestat_irq_mask[pipe] = 0;
1739 }
1740}
1741
Ville Syrjäläeb643432017-08-18 21:36:59 +03001742static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1743 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001744{
Imre Deakc1874ed2014-02-04 21:35:46 +02001745 int pipe;
1746
Imre Deak58ead0d2014-02-04 21:35:47 +02001747 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001748
1749 if (!dev_priv->display_irqs_enabled) {
1750 spin_unlock(&dev_priv->irq_lock);
1751 return;
1752 }
1753
Damien Lespiau055e3932014-08-18 13:49:10 +01001754 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001755 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001756 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001757
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001758 /*
1759 * PIPESTAT bits get signalled even when the interrupt is
1760 * disabled with the mask bits, and some of the status bits do
1761 * not generate interrupts at all (like the underrun bit). Hence
1762 * we need to be careful that we only handle what we want to
1763 * handle.
1764 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001765
1766 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001767 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001768
1769 switch (pipe) {
1770 case PIPE_A:
1771 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1772 break;
1773 case PIPE_B:
1774 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1775 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001776 case PIPE_C:
1777 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1778 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001779 }
1780 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001781 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001782
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001783 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001784 continue;
1785
1786 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001787 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1788 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001789
1790 /*
1791 * Clear the PIPE*STAT regs before the IIR
1792 */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001793 if (pipe_stats[pipe])
1794 I915_WRITE(reg, enable_mask | pipe_stats[pipe]);
Imre Deakc1874ed2014-02-04 21:35:46 +02001795 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001796 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001797}
1798
Ville Syrjäläeb643432017-08-18 21:36:59 +03001799static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1800 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1801{
1802 enum pipe pipe;
1803
1804 for_each_pipe(dev_priv, pipe) {
1805 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1806 drm_handle_vblank(&dev_priv->drm, pipe);
1807
1808 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1809 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1810
1811 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1812 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1813 }
1814}
1815
1816static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1817 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1818{
1819 bool blc_event = false;
1820 enum pipe pipe;
1821
1822 for_each_pipe(dev_priv, pipe) {
1823 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1824 drm_handle_vblank(&dev_priv->drm, pipe);
1825
1826 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1827 blc_event = true;
1828
1829 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1830 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1831
1832 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1833 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1834 }
1835
1836 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1837 intel_opregion_asle_intr(dev_priv);
1838}
1839
1840static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1841 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1842{
1843 bool blc_event = false;
1844 enum pipe pipe;
1845
1846 for_each_pipe(dev_priv, pipe) {
1847 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1848 drm_handle_vblank(&dev_priv->drm, pipe);
1849
1850 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1851 blc_event = true;
1852
1853 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1854 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1855
1856 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1857 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1858 }
1859
1860 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1861 intel_opregion_asle_intr(dev_priv);
1862
1863 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1864 gmbus_irq_handler(dev_priv);
1865}
1866
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001867static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001868 u32 pipe_stats[I915_MAX_PIPES])
1869{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001870 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001871
Damien Lespiau055e3932014-08-18 13:49:10 +01001872 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001873 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1874 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001875
1876 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001877 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001878
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001879 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1880 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001881 }
1882
1883 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001884 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001885}
1886
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001887static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001888{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001889 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001890
1891 if (hotplug_status)
1892 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1893
1894 return hotplug_status;
1895}
1896
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001897static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001898 u32 hotplug_status)
1899{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001900 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001901
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001902 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1903 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001904 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001905
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001906 if (hotplug_trigger) {
1907 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1908 hotplug_trigger, hpd_status_g4x,
1909 i9xx_port_hotplug_long_detect);
1910
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001911 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001912 }
Jani Nikula369712e2015-05-27 15:03:40 +03001913
1914 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001915 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001916 } else {
1917 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001918
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001919 if (hotplug_trigger) {
1920 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001921 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001922 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001923 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001924 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001925 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001926}
1927
Daniel Vetterff1f5252012-10-02 15:10:55 +02001928static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001929{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001930 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001931 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001932 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001933
Imre Deak2dd2a882015-02-24 11:14:30 +02001934 if (!intel_irqs_enabled(dev_priv))
1935 return IRQ_NONE;
1936
Imre Deak1f814da2015-12-16 02:52:19 +02001937 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1938 disable_rpm_wakeref_asserts(dev_priv);
1939
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001940 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001941 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001942 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001943 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001944 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001945
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001946 gt_iir = I915_READ(GTIIR);
1947 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001948 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001949
1950 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001951 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001952
1953 ret = IRQ_HANDLED;
1954
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001955 /*
1956 * Theory on interrupt generation, based on empirical evidence:
1957 *
1958 * x = ((VLV_IIR & VLV_IER) ||
1959 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1960 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1961 *
1962 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1963 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1964 * guarantee the CPU interrupt will be raised again even if we
1965 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1966 * bits this time around.
1967 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001968 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001969 ier = I915_READ(VLV_IER);
1970 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001971
1972 if (gt_iir)
1973 I915_WRITE(GTIIR, gt_iir);
1974 if (pm_iir)
1975 I915_WRITE(GEN6_PMIIR, pm_iir);
1976
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001977 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001978 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001979
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001980 /* Call regardless, as some status bits might not be
1981 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03001982 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001983
Jerome Anandeef57322017-01-25 04:27:49 +05301984 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1985 I915_LPE_PIPE_B_INTERRUPT))
1986 intel_lpe_audio_irq_handler(dev_priv);
1987
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001988 /*
1989 * VLV_IIR is single buffered, and reflects the level
1990 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
1991 */
1992 if (iir)
1993 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001994
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001995 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001996 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
1997 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001998
Ville Syrjälä52894872016-04-13 21:19:56 +03001999 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002000 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002001 if (pm_iir)
2002 gen6_rps_irq_handler(dev_priv, pm_iir);
2003
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002004 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002005 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002006
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002007 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002008 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002009
Imre Deak1f814da2015-12-16 02:52:19 +02002010 enable_rpm_wakeref_asserts(dev_priv);
2011
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002012 return ret;
2013}
2014
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002015static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2016{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002017 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002018 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002019 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002020
Imre Deak2dd2a882015-02-24 11:14:30 +02002021 if (!intel_irqs_enabled(dev_priv))
2022 return IRQ_NONE;
2023
Imre Deak1f814da2015-12-16 02:52:19 +02002024 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2025 disable_rpm_wakeref_asserts(dev_priv);
2026
Chris Wilson579de732016-03-14 09:01:57 +00002027 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002028 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002029 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002030 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002031 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002032 u32 ier = 0;
2033
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002034 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2035 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002036
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002037 if (master_ctl == 0 && iir == 0)
2038 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002039
Oscar Mateo27b6c122014-06-16 16:11:00 +01002040 ret = IRQ_HANDLED;
2041
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002042 /*
2043 * Theory on interrupt generation, based on empirical evidence:
2044 *
2045 * x = ((VLV_IIR & VLV_IER) ||
2046 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2047 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2048 *
2049 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2050 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2051 * guarantee the CPU interrupt will be raised again even if we
2052 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2053 * bits this time around.
2054 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002055 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002056 ier = I915_READ(VLV_IER);
2057 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002058
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002059 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002060
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002061 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002062 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002063
Oscar Mateo27b6c122014-06-16 16:11:00 +01002064 /* Call regardless, as some status bits might not be
2065 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002066 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002067
Jerome Anandeef57322017-01-25 04:27:49 +05302068 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2069 I915_LPE_PIPE_B_INTERRUPT |
2070 I915_LPE_PIPE_C_INTERRUPT))
2071 intel_lpe_audio_irq_handler(dev_priv);
2072
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002073 /*
2074 * VLV_IIR is single buffered, and reflects the level
2075 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2076 */
2077 if (iir)
2078 I915_WRITE(VLV_IIR, iir);
2079
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002080 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002081 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002082 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002083
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002084 gen8_gt_irq_handler(dev_priv, gt_iir);
2085
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002086 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002087 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002088
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002089 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002090 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002091
Imre Deak1f814da2015-12-16 02:52:19 +02002092 enable_rpm_wakeref_asserts(dev_priv);
2093
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002094 return ret;
2095}
2096
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002097static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2098 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002099 const u32 hpd[HPD_NUM_PINS])
2100{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002101 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2102
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002103 /*
2104 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2105 * unless we touch the hotplug register, even if hotplug_trigger is
2106 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2107 * errors.
2108 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002109 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002110 if (!hotplug_trigger) {
2111 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2112 PORTD_HOTPLUG_STATUS_MASK |
2113 PORTC_HOTPLUG_STATUS_MASK |
2114 PORTB_HOTPLUG_STATUS_MASK;
2115 dig_hotplug_reg &= ~mask;
2116 }
2117
Ville Syrjälä40e56412015-08-27 23:56:10 +03002118 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002119 if (!hotplug_trigger)
2120 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002121
2122 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2123 dig_hotplug_reg, hpd,
2124 pch_port_hotplug_long_detect);
2125
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002126 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002127}
2128
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002129static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002130{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002131 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002132 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002133
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002134 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002135
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002136 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2137 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2138 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002139 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002140 port_name(port));
2141 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002142
Daniel Vetterce99c252012-12-01 13:53:47 +01002143 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002144 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002145
Jesse Barnes776ad802011-01-04 15:09:39 -08002146 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002147 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002148
2149 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2150 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2151
2152 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2153 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2154
2155 if (pch_iir & SDE_POISON)
2156 DRM_ERROR("PCH poison interrupt\n");
2157
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002158 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002159 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002160 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2161 pipe_name(pipe),
2162 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002163
2164 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2165 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2166
2167 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2168 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2169
Jesse Barnes776ad802011-01-04 15:09:39 -08002170 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002171 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002172
2173 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002174 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002175}
2176
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002177static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002178{
Paulo Zanoni86642812013-04-12 17:57:57 -03002179 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002180 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002181
Paulo Zanonide032bf2013-04-12 17:57:58 -03002182 if (err_int & ERR_INT_POISON)
2183 DRM_ERROR("Poison interrupt\n");
2184
Damien Lespiau055e3932014-08-18 13:49:10 +01002185 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002186 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2187 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002188
Daniel Vetter5a69b892013-10-16 22:55:52 +02002189 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002190 if (IS_IVYBRIDGE(dev_priv))
2191 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002192 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002193 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002194 }
2195 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002196
Paulo Zanoni86642812013-04-12 17:57:57 -03002197 I915_WRITE(GEN7_ERR_INT, err_int);
2198}
2199
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002200static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002201{
Paulo Zanoni86642812013-04-12 17:57:57 -03002202 u32 serr_int = I915_READ(SERR_INT);
2203
Paulo Zanonide032bf2013-04-12 17:57:58 -03002204 if (serr_int & SERR_INT_POISON)
2205 DRM_ERROR("PCH poison interrupt\n");
2206
Paulo Zanoni86642812013-04-12 17:57:57 -03002207 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002208 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002209
2210 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002211 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002212
2213 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002214 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002215
2216 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002217}
2218
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002219static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002220{
Adam Jackson23e81d62012-06-06 15:45:44 -04002221 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002222 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002223
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002224 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002225
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002226 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2227 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2228 SDE_AUDIO_POWER_SHIFT_CPT);
2229 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2230 port_name(port));
2231 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002232
2233 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002234 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002235
2236 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002237 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002238
2239 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2240 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2241
2242 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2243 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2244
2245 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002246 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002247 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2248 pipe_name(pipe),
2249 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002250
2251 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002252 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002253}
2254
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002255static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002256{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002257 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2258 ~SDE_PORTE_HOTPLUG_SPT;
2259 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2260 u32 pin_mask = 0, long_mask = 0;
2261
2262 if (hotplug_trigger) {
2263 u32 dig_hotplug_reg;
2264
2265 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2266 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2267
2268 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2269 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002270 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002271 }
2272
2273 if (hotplug2_trigger) {
2274 u32 dig_hotplug_reg;
2275
2276 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2277 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2278
2279 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2280 dig_hotplug_reg, hpd_spt,
2281 spt_port_hotplug2_long_detect);
2282 }
2283
2284 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002285 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002286
2287 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002288 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002289}
2290
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002291static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2292 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002293 const u32 hpd[HPD_NUM_PINS])
2294{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002295 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2296
2297 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2298 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2299
2300 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2301 dig_hotplug_reg, hpd,
2302 ilk_port_hotplug_long_detect);
2303
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002304 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002305}
2306
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002307static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2308 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002309{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002310 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002311 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2312
Ville Syrjälä40e56412015-08-27 23:56:10 +03002313 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002314 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002315
2316 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002317 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002318
2319 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002320 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002321
Paulo Zanonic008bc62013-07-12 16:35:10 -03002322 if (de_iir & DE_POISON)
2323 DRM_ERROR("Poison interrupt\n");
2324
Damien Lespiau055e3932014-08-18 13:49:10 +01002325 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002326 if (de_iir & DE_PIPE_VBLANK(pipe))
2327 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002328
Daniel Vetter40da17c22013-10-21 18:04:36 +02002329 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002330 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002331
Daniel Vetter40da17c22013-10-21 18:04:36 +02002332 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002333 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002334 }
2335
2336 /* check event from PCH */
2337 if (de_iir & DE_PCH_EVENT) {
2338 u32 pch_iir = I915_READ(SDEIIR);
2339
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002340 if (HAS_PCH_CPT(dev_priv))
2341 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002342 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002343 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002344
2345 /* should clear PCH hotplug event before clear CPU irq */
2346 I915_WRITE(SDEIIR, pch_iir);
2347 }
2348
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002349 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2350 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002351}
2352
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002353static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2354 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002355{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002356 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002357 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2358
Ville Syrjälä40e56412015-08-27 23:56:10 +03002359 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002360 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002361
2362 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002363 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002364
2365 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002366 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002367
2368 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002369 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002370
Damien Lespiau055e3932014-08-18 13:49:10 +01002371 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002372 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2373 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002374 }
2375
2376 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002377 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002378 u32 pch_iir = I915_READ(SDEIIR);
2379
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002380 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002381
2382 /* clear PCH hotplug event before clear CPU irq */
2383 I915_WRITE(SDEIIR, pch_iir);
2384 }
2385}
2386
Oscar Mateo72c90f62014-06-16 16:10:57 +01002387/*
2388 * To handle irqs with the minimum potential races with fresh interrupts, we:
2389 * 1 - Disable Master Interrupt Control.
2390 * 2 - Find the source(s) of the interrupt.
2391 * 3 - Clear the Interrupt Identity bits (IIR).
2392 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2393 * 5 - Re-enable Master Interrupt Control.
2394 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002395static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002396{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002397 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002398 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002399 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002400 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002401
Imre Deak2dd2a882015-02-24 11:14:30 +02002402 if (!intel_irqs_enabled(dev_priv))
2403 return IRQ_NONE;
2404
Imre Deak1f814da2015-12-16 02:52:19 +02002405 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2406 disable_rpm_wakeref_asserts(dev_priv);
2407
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002408 /* disable master interrupt before clearing iir */
2409 de_ier = I915_READ(DEIER);
2410 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002411 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002412
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002413 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2414 * interrupts will will be stored on its back queue, and then we'll be
2415 * able to process them after we restore SDEIER (as soon as we restore
2416 * it, we'll get an interrupt if SDEIIR still has something to process
2417 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002418 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002419 sde_ier = I915_READ(SDEIER);
2420 I915_WRITE(SDEIER, 0);
2421 POSTING_READ(SDEIER);
2422 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002423
Oscar Mateo72c90f62014-06-16 16:10:57 +01002424 /* Find, clear, then process each source of interrupt */
2425
Chris Wilson0e434062012-05-09 21:45:44 +01002426 gt_iir = I915_READ(GTIIR);
2427 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002428 I915_WRITE(GTIIR, gt_iir);
2429 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002430 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002431 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002432 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002433 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002434 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002435
2436 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002437 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002438 I915_WRITE(DEIIR, de_iir);
2439 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002440 if (INTEL_GEN(dev_priv) >= 7)
2441 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002442 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002443 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002444 }
2445
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002446 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002447 u32 pm_iir = I915_READ(GEN6_PMIIR);
2448 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002449 I915_WRITE(GEN6_PMIIR, pm_iir);
2450 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002451 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002452 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002453 }
2454
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002455 I915_WRITE(DEIER, de_ier);
2456 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002457 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002458 I915_WRITE(SDEIER, sde_ier);
2459 POSTING_READ(SDEIER);
2460 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002461
Imre Deak1f814da2015-12-16 02:52:19 +02002462 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2463 enable_rpm_wakeref_asserts(dev_priv);
2464
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002465 return ret;
2466}
2467
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002468static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2469 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002470 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302471{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002472 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302473
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002474 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2475 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302476
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002477 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002478 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002479 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002480
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002481 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302482}
2483
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002484static irqreturn_t
2485gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002486{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002487 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002488 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002489 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002490
Ben Widawskyabd58f02013-11-02 21:07:09 -07002491 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002492 iir = I915_READ(GEN8_DE_MISC_IIR);
2493 if (iir) {
2494 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002495 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002496 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002497 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002498 else
2499 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002500 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002501 else
2502 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002503 }
2504
Daniel Vetter6d766f02013-11-07 14:49:55 +01002505 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002506 iir = I915_READ(GEN8_DE_PORT_IIR);
2507 if (iir) {
2508 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302509 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002510
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002511 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002512 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002513
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002514 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002515 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002516 tmp_mask |= GEN9_AUX_CHANNEL_B |
2517 GEN9_AUX_CHANNEL_C |
2518 GEN9_AUX_CHANNEL_D;
2519
2520 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002521 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302522 found = true;
2523 }
2524
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002525 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002526 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2527 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002528 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2529 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002530 found = true;
2531 }
2532 } else if (IS_BROADWELL(dev_priv)) {
2533 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2534 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002535 ilk_hpd_irq_handler(dev_priv,
2536 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002537 found = true;
2538 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302539 }
2540
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002541 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002542 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302543 found = true;
2544 }
2545
Shashank Sharmad04a4922014-08-22 17:40:41 +05302546 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002547 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002548 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002549 else
2550 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002551 }
2552
Damien Lespiau055e3932014-08-18 13:49:10 +01002553 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002554 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002555
Daniel Vetterc42664c2013-11-07 11:05:40 +01002556 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2557 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002558
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002559 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2560 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002561 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002562 continue;
2563 }
2564
2565 ret = IRQ_HANDLED;
2566 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2567
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002568 if (iir & GEN8_PIPE_VBLANK)
2569 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002570
2571 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002572 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002573
2574 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2575 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2576
2577 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002578 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002579 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2580 else
2581 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2582
2583 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002584 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002585 pipe_name(pipe),
2586 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002587 }
2588
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002589 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302590 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002591 /*
2592 * FIXME(BDW): Assume for now that the new interrupt handling
2593 * scheme also closed the SDE interrupt handling race we've seen
2594 * on older pch-split platforms. But this needs testing.
2595 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002596 iir = I915_READ(SDEIIR);
2597 if (iir) {
2598 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002599 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002600
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002601 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2602 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002603 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002604 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002605 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002606 } else {
2607 /*
2608 * Like on previous PCH there seems to be something
2609 * fishy going on with forwarding PCH interrupts.
2610 */
2611 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2612 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002613 }
2614
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002615 return ret;
2616}
2617
2618static irqreturn_t gen8_irq_handler(int irq, void *arg)
2619{
2620 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002621 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002622 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002623 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002624 irqreturn_t ret;
2625
2626 if (!intel_irqs_enabled(dev_priv))
2627 return IRQ_NONE;
2628
2629 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2630 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2631 if (!master_ctl)
2632 return IRQ_NONE;
2633
2634 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2635
2636 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2637 disable_rpm_wakeref_asserts(dev_priv);
2638
2639 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002640 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2641 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002642 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2643
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002644 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2645 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002646
Imre Deak1f814da2015-12-16 02:52:19 +02002647 enable_rpm_wakeref_asserts(dev_priv);
2648
Ben Widawskyabd58f02013-11-02 21:07:09 -07002649 return ret;
2650}
2651
Chris Wilson36703e72017-06-22 11:56:25 +01002652struct wedge_me {
2653 struct delayed_work work;
2654 struct drm_i915_private *i915;
2655 const char *name;
2656};
2657
2658static void wedge_me(struct work_struct *work)
2659{
2660 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2661
2662 dev_err(w->i915->drm.dev,
2663 "%s timed out, cancelling all in-flight rendering.\n",
2664 w->name);
2665 i915_gem_set_wedged(w->i915);
2666}
2667
2668static void __init_wedge(struct wedge_me *w,
2669 struct drm_i915_private *i915,
2670 long timeout,
2671 const char *name)
2672{
2673 w->i915 = i915;
2674 w->name = name;
2675
2676 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2677 schedule_delayed_work(&w->work, timeout);
2678}
2679
2680static void __fini_wedge(struct wedge_me *w)
2681{
2682 cancel_delayed_work_sync(&w->work);
2683 destroy_delayed_work_on_stack(&w->work);
2684 w->i915 = NULL;
2685}
2686
2687#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2688 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2689 (W)->i915; \
2690 __fini_wedge((W)))
2691
Jesse Barnes8a905232009-07-11 16:48:03 -04002692/**
Chris Wilsond5367302017-06-20 10:57:43 +01002693 * i915_reset_device - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002694 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002695 *
2696 * Fire an error uevent so userspace can see that a hang or error
2697 * was detected.
2698 */
Chris Wilsond5367302017-06-20 10:57:43 +01002699static void i915_reset_device(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002700{
Chris Wilson91c8a322016-07-05 10:40:23 +01002701 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002702 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2703 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2704 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002705 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002706
Chris Wilsonc0336662016-05-06 15:40:21 +01002707 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002708
Chris Wilson8af29b02016-09-09 14:11:47 +01002709 DRM_DEBUG_DRIVER("resetting chip\n");
2710 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2711
Chris Wilson36703e72017-06-22 11:56:25 +01002712 /* Use a watchdog to ensure that our reset completes */
2713 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
2714 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002715
Chris Wilson36703e72017-06-22 11:56:25 +01002716 /* Signal that locked waiters should reset the GPU */
2717 set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags);
2718 wake_up_all(&dev_priv->gpu_error.wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00002719
Chris Wilson36703e72017-06-22 11:56:25 +01002720 /* Wait for anyone holding the lock to wakeup, without
2721 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01002722 */
Chris Wilson36703e72017-06-22 11:56:25 +01002723 do {
2724 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilson535275d2017-07-21 13:32:37 +01002725 i915_reset(dev_priv, 0);
Chris Wilson36703e72017-06-22 11:56:25 +01002726 mutex_unlock(&dev_priv->drm.struct_mutex);
2727 }
2728 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2729 I915_RESET_HANDOFF,
2730 TASK_UNINTERRUPTIBLE,
2731 1));
Chris Wilson780f2622016-09-09 14:11:52 +01002732
Chris Wilson36703e72017-06-22 11:56:25 +01002733 intel_finish_reset(dev_priv);
2734 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02002735
Chris Wilson780f2622016-09-09 14:11:52 +01002736 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002737 kobject_uevent_env(kobj,
2738 KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002739}
2740
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002741static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002742{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002743 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04002744
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002745 if (!IS_GEN2(dev_priv))
2746 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04002747
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002748 if (INTEL_GEN(dev_priv) < 4)
2749 I915_WRITE(IPEIR, I915_READ(IPEIR));
2750 else
2751 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002752
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002753 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04002754 eir = I915_READ(EIR);
2755 if (eir) {
2756 /*
2757 * some errors might have become stuck,
2758 * mask them.
2759 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002760 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002761 I915_WRITE(EMR, I915_READ(EMR) | eir);
2762 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2763 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002764}
2765
2766/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002767 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002768 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002769 * @engine_mask: mask representing engines that are hung
Michel Thierry87c390b2017-01-11 20:18:08 -08002770 * @fmt: Error message format string
2771 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002772 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002773 * dump it to the syslog. Also call i915_capture_error_state() to make
2774 * sure we get a record and make it available in debugfs. Fire a uevent
2775 * so userspace knows something bad happened (should trigger collection
2776 * of a ring dump etc.).
2777 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002778void i915_handle_error(struct drm_i915_private *dev_priv,
2779 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002780 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002781{
Michel Thierry142bc7d2017-06-20 10:57:46 +01002782 struct intel_engine_cs *engine;
2783 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02002784 va_list args;
2785 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002786
Mika Kuoppala58174462014-02-25 17:11:26 +02002787 va_start(args, fmt);
2788 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2789 va_end(args);
2790
Chris Wilson1604a862017-03-14 17:18:40 +00002791 /*
2792 * In most cases it's guaranteed that we get here with an RPM
2793 * reference held, for example because there is a pending GPU
2794 * request that won't finish until the reset is done. This
2795 * isn't the case at least when we get here by doing a
2796 * simulated reset via debugfs, so get an RPM reference.
2797 */
2798 intel_runtime_pm_get(dev_priv);
2799
Chris Wilsonc0336662016-05-06 15:40:21 +01002800 i915_capture_error_state(dev_priv, engine_mask, error_msg);
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002801 i915_clear_error_registers(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002802
Michel Thierry142bc7d2017-06-20 10:57:46 +01002803 /*
2804 * Try engine reset when available. We fall back to full reset if
2805 * single reset fails.
2806 */
2807 if (intel_has_reset_engine(dev_priv)) {
2808 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02002809 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01002810 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2811 &dev_priv->gpu_error.flags))
2812 continue;
2813
Chris Wilson535275d2017-07-21 13:32:37 +01002814 if (i915_reset_engine(engine, 0) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01002815 engine_mask &= ~intel_engine_flag(engine);
2816
2817 clear_bit(I915_RESET_ENGINE + engine->id,
2818 &dev_priv->gpu_error.flags);
2819 wake_up_bit(&dev_priv->gpu_error.flags,
2820 I915_RESET_ENGINE + engine->id);
2821 }
2822 }
2823
Chris Wilson8af29b02016-09-09 14:11:47 +01002824 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00002825 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04002826
Michel Thierry142bc7d2017-06-20 10:57:46 +01002827 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01002828 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
2829 wait_event(dev_priv->gpu_error.reset_queue,
2830 !test_bit(I915_RESET_BACKOFF,
2831 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00002832 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01002833 }
Chris Wilson8af29b02016-09-09 14:11:47 +01002834
Michel Thierry142bc7d2017-06-20 10:57:46 +01002835 /* Prevent any other reset-engine attempt. */
2836 for_each_engine(engine, dev_priv, tmp) {
2837 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2838 &dev_priv->gpu_error.flags))
2839 wait_on_bit(&dev_priv->gpu_error.flags,
2840 I915_RESET_ENGINE + engine->id,
2841 TASK_UNINTERRUPTIBLE);
2842 }
2843
Chris Wilsond5367302017-06-20 10:57:43 +01002844 i915_reset_device(dev_priv);
2845
Michel Thierry142bc7d2017-06-20 10:57:46 +01002846 for_each_engine(engine, dev_priv, tmp) {
2847 clear_bit(I915_RESET_ENGINE + engine->id,
2848 &dev_priv->gpu_error.flags);
2849 }
2850
Chris Wilsond5367302017-06-20 10:57:43 +01002851 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
2852 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00002853
2854out:
2855 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002856}
2857
Keith Packard42f52ef2008-10-18 19:39:29 -07002858/* Called from drm generic code, passed 'crtc' which
2859 * we use as a pipe index
2860 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002861static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002862{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002863 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002864 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002865
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002866 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01002867 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2868 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2869
2870 return 0;
2871}
2872
2873static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
2874{
2875 struct drm_i915_private *dev_priv = to_i915(dev);
2876 unsigned long irqflags;
2877
2878 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2879 i915_enable_pipestat(dev_priv, pipe,
2880 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002881 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002882
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002883 return 0;
2884}
2885
Thierry Reding88e72712015-09-24 18:35:31 +02002886static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002887{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002888 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002889 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002890 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002891 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002892
Jesse Barnesf796cf82011-04-07 13:58:17 -07002893 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002894 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002895 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2896
2897 return 0;
2898}
2899
Thierry Reding88e72712015-09-24 18:35:31 +02002900static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002901{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002902 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002903 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002904
Ben Widawskyabd58f02013-11-02 21:07:09 -07002905 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002906 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002907 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002908
Ben Widawskyabd58f02013-11-02 21:07:09 -07002909 return 0;
2910}
2911
Keith Packard42f52ef2008-10-18 19:39:29 -07002912/* Called from drm generic code, passed 'crtc' which
2913 * we use as a pipe index
2914 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002915static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
2916{
2917 struct drm_i915_private *dev_priv = to_i915(dev);
2918 unsigned long irqflags;
2919
2920 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2921 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2922 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2923}
2924
2925static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002926{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002927 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002928 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002929
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002930 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002931 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002932 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002933 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2934}
2935
Thierry Reding88e72712015-09-24 18:35:31 +02002936static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002937{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002938 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002939 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002940 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002941 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002942
2943 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002944 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002945 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2946}
2947
Thierry Reding88e72712015-09-24 18:35:31 +02002948static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002949{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002950 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002951 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002952
Ben Widawskyabd58f02013-11-02 21:07:09 -07002953 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002954 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002955 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2956}
2957
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00002958static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03002959{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002960 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03002961 return;
2962
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03002963 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03002964
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002965 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03002966 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03002967}
Paulo Zanoni105b1222014-04-01 15:37:17 -03002968
Paulo Zanoni622364b2014-04-01 15:37:22 -03002969/*
2970 * SDEIER is also touched by the interrupt handler to work around missed PCH
2971 * interrupts. Hence we can't update it after the interrupt handler is enabled -
2972 * instead we unconditionally enable all PCH interrupt sources here, but then
2973 * only unmask them as needed with SDEIMR.
2974 *
2975 * This function needs to be called before interrupts are enabled.
2976 */
2977static void ibx_irq_pre_postinstall(struct drm_device *dev)
2978{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002979 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03002980
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002981 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03002982 return;
2983
2984 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03002985 I915_WRITE(SDEIER, 0xffffffff);
2986 POSTING_READ(SDEIER);
2987}
2988
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00002989static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002990{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03002991 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00002992 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03002993 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002994}
2995
Ville Syrjälä70591a42014-10-30 19:42:58 +02002996static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
2997{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03002998 if (IS_CHERRYVIEW(dev_priv))
2999 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3000 else
3001 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3002
Ville Syrjäläad22d102016-04-12 18:56:14 +03003003 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003004 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3005
Ville Syrjälä44d92412017-08-18 21:36:51 +03003006 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003007
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003008 GEN3_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003009 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003010}
3011
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003012static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3013{
3014 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003015 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003016 enum pipe pipe;
3017
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003018 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003019
3020 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3021 for_each_pipe(dev_priv, pipe)
3022 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3023
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003024 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3025 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003026 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3027 I915_LPE_PIPE_A_INTERRUPT |
3028 I915_LPE_PIPE_B_INTERRUPT;
3029
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003030 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003031 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3032 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003033
3034 WARN_ON(dev_priv->irq_mask != ~0);
3035
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003036 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003037
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003038 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003039}
3040
3041/* drm_dma.h hooks
3042*/
3043static void ironlake_irq_reset(struct drm_device *dev)
3044{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003045 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003046
Ville Syrjäläd420a502017-08-18 21:37:03 +03003047 if (IS_GEN5(dev_priv))
3048 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003049
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003050 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003051 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003052 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3053
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003054 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003055
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003056 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003057}
3058
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003059static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003060{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003061 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003062
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003063 I915_WRITE(VLV_MASTER_IER, 0);
3064 POSTING_READ(VLV_MASTER_IER);
3065
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003066 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003067
Ville Syrjäläad22d102016-04-12 18:56:14 +03003068 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003069 if (dev_priv->display_irqs_enabled)
3070 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003071 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003072}
3073
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003074static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3075{
3076 GEN8_IRQ_RESET_NDX(GT, 0);
3077 GEN8_IRQ_RESET_NDX(GT, 1);
3078 GEN8_IRQ_RESET_NDX(GT, 2);
3079 GEN8_IRQ_RESET_NDX(GT, 3);
3080}
3081
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003082static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003083{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003084 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003085 int pipe;
3086
Ben Widawskyabd58f02013-11-02 21:07:09 -07003087 I915_WRITE(GEN8_MASTER_IRQ, 0);
3088 POSTING_READ(GEN8_MASTER_IRQ);
3089
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003090 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003091
Damien Lespiau055e3932014-08-18 13:49:10 +01003092 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003093 if (intel_display_power_is_enabled(dev_priv,
3094 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003095 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003096
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003097 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3098 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3099 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003100
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003101 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003102 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003103}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003104
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003105void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003106 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003107{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003108 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003109 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003110
Daniel Vetter13321782014-09-15 14:55:29 +02003111 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003112 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3113 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3114 dev_priv->de_irq_mask[pipe],
3115 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003116 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003117}
3118
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003119void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003120 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003121{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003122 enum pipe pipe;
3123
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003124 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003125 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3126 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003127 spin_unlock_irq(&dev_priv->irq_lock);
3128
3129 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003130 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003131}
3132
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003133static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003134{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003135 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003136
3137 I915_WRITE(GEN8_MASTER_IRQ, 0);
3138 POSTING_READ(GEN8_MASTER_IRQ);
3139
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003140 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003141
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003142 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003143
Ville Syrjäläad22d102016-04-12 18:56:14 +03003144 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003145 if (dev_priv->display_irqs_enabled)
3146 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003147 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003148}
3149
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003150static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003151 const u32 hpd[HPD_NUM_PINS])
3152{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003153 struct intel_encoder *encoder;
3154 u32 enabled_irqs = 0;
3155
Chris Wilson91c8a322016-07-05 10:40:23 +01003156 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003157 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3158 enabled_irqs |= hpd[encoder->hpd_pin];
3159
3160 return enabled_irqs;
3161}
3162
Imre Deak1a56b1a2017-01-27 11:39:21 +02003163static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3164{
3165 u32 hotplug;
3166
3167 /*
3168 * Enable digital hotplug on the PCH, and configure the DP short pulse
3169 * duration to 2ms (which is the minimum in the Display Port spec).
3170 * The pulse duration bits are reserved on LPT+.
3171 */
3172 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3173 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3174 PORTC_PULSE_DURATION_MASK |
3175 PORTD_PULSE_DURATION_MASK);
3176 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3177 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3178 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3179 /*
3180 * When CPU and PCH are on the same package, port A
3181 * HPD must be enabled in both north and south.
3182 */
3183 if (HAS_PCH_LPT_LP(dev_priv))
3184 hotplug |= PORTA_HOTPLUG_ENABLE;
3185 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3186}
3187
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003188static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003189{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003190 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003191
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003192 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003193 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003194 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003195 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003196 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003197 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003198 }
3199
Daniel Vetterfee884e2013-07-04 23:35:21 +02003200 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003201
Imre Deak1a56b1a2017-01-27 11:39:21 +02003202 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003203}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003204
Imre Deak2a57d9c2017-01-27 11:39:18 +02003205static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3206{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003207 u32 val, hotplug;
3208
3209 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3210 if (HAS_PCH_CNP(dev_priv)) {
3211 val = I915_READ(SOUTH_CHICKEN1);
3212 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3213 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3214 I915_WRITE(SOUTH_CHICKEN1, val);
3215 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003216
3217 /* Enable digital hotplug on the PCH */
3218 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3219 hotplug |= PORTA_HOTPLUG_ENABLE |
3220 PORTB_HOTPLUG_ENABLE |
3221 PORTC_HOTPLUG_ENABLE |
3222 PORTD_HOTPLUG_ENABLE;
3223 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3224
3225 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3226 hotplug |= PORTE_HOTPLUG_ENABLE;
3227 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3228}
3229
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003230static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003231{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003232 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003233
3234 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003235 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003236
3237 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3238
Imre Deak2a57d9c2017-01-27 11:39:18 +02003239 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003240}
3241
Imre Deak1a56b1a2017-01-27 11:39:21 +02003242static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3243{
3244 u32 hotplug;
3245
3246 /*
3247 * Enable digital hotplug on the CPU, and configure the DP short pulse
3248 * duration to 2ms (which is the minimum in the Display Port spec)
3249 * The pulse duration bits are reserved on HSW+.
3250 */
3251 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3252 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3253 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3254 DIGITAL_PORTA_PULSE_DURATION_2ms;
3255 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3256}
3257
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003258static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003259{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003260 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003261
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003262 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003263 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003264 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003265
3266 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003267 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003268 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003269 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003270
3271 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003272 } else {
3273 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003274 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003275
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003276 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3277 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003278
Imre Deak1a56b1a2017-01-27 11:39:21 +02003279 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003280
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003281 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003282}
3283
Imre Deak2a57d9c2017-01-27 11:39:18 +02003284static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3285 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003286{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003287 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003288
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003289 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003290 hotplug |= PORTA_HOTPLUG_ENABLE |
3291 PORTB_HOTPLUG_ENABLE |
3292 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303293
3294 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3295 hotplug, enabled_irqs);
3296 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3297
3298 /*
3299 * For BXT invert bit has to be set based on AOB design
3300 * for HPD detection logic, update it based on VBT fields.
3301 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303302 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3303 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3304 hotplug |= BXT_DDIA_HPD_INVERT;
3305 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3306 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3307 hotplug |= BXT_DDIB_HPD_INVERT;
3308 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3309 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3310 hotplug |= BXT_DDIC_HPD_INVERT;
3311
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003312 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003313}
3314
Imre Deak2a57d9c2017-01-27 11:39:18 +02003315static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3316{
3317 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3318}
3319
3320static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3321{
3322 u32 hotplug_irqs, enabled_irqs;
3323
3324 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3325 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3326
3327 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3328
3329 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3330}
3331
Paulo Zanonid46da432013-02-08 17:35:15 -02003332static void ibx_irq_postinstall(struct drm_device *dev)
3333{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003334 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003335 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003336
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003337 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003338 return;
3339
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003340 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003341 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003342 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003343 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003344 else
3345 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003346
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003347 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003348 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003349
3350 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3351 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003352 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003353 else
3354 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003355}
3356
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003357static void gen5_gt_irq_postinstall(struct drm_device *dev)
3358{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003359 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003360 u32 pm_irqs, gt_irqs;
3361
3362 pm_irqs = gt_irqs = 0;
3363
3364 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003365 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003366 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003367 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3368 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003369 }
3370
3371 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003372 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003373 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003374 } else {
3375 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3376 }
3377
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003378 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003379
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003380 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003381 /*
3382 * RPS interrupts will get enabled/disabled on demand when RPS
3383 * itself is enabled/disabled.
3384 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303385 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003386 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303387 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3388 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003389
Akash Goelf4e9af42016-10-12 21:54:30 +05303390 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003391 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003392 }
3393}
3394
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003395static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003396{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003397 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003398 u32 display_mask, extra_mask;
3399
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003400 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003401 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003402 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003403 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003404 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3405 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003406 } else {
3407 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003408 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3409 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003410 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3411 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3412 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003413 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003414
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003415 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003416
Paulo Zanoni622364b2014-04-01 15:37:22 -03003417 ibx_irq_pre_postinstall(dev);
3418
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003419 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003420
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003421 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003422
Imre Deak1a56b1a2017-01-27 11:39:21 +02003423 ilk_hpd_detection_setup(dev_priv);
3424
Paulo Zanonid46da432013-02-08 17:35:15 -02003425 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003426
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003427 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003428 /* Enable PCU event interrupts
3429 *
3430 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003431 * setup is guaranteed to run in single-threaded context. But we
3432 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003433 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003434 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003435 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003436 }
3437
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003438 return 0;
3439}
3440
Imre Deakf8b79e52014-03-04 19:23:07 +02003441void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3442{
Chris Wilson67520412017-03-02 13:28:01 +00003443 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003444
3445 if (dev_priv->display_irqs_enabled)
3446 return;
3447
3448 dev_priv->display_irqs_enabled = true;
3449
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003450 if (intel_irqs_enabled(dev_priv)) {
3451 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003452 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003453 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003454}
3455
3456void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3457{
Chris Wilson67520412017-03-02 13:28:01 +00003458 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003459
3460 if (!dev_priv->display_irqs_enabled)
3461 return;
3462
3463 dev_priv->display_irqs_enabled = false;
3464
Imre Deak950eaba2014-09-08 15:21:09 +03003465 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003466 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003467}
3468
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003469
3470static int valleyview_irq_postinstall(struct drm_device *dev)
3471{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003472 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003473
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003474 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003475
Ville Syrjäläad22d102016-04-12 18:56:14 +03003476 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003477 if (dev_priv->display_irqs_enabled)
3478 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003479 spin_unlock_irq(&dev_priv->irq_lock);
3480
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003481 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003482 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003483
3484 return 0;
3485}
3486
Ben Widawskyabd58f02013-11-02 21:07:09 -07003487static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3488{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003489 /* These are interrupts we'll toggle with the ring mask register */
3490 uint32_t gt_interrupts[] = {
3491 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003492 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003493 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3494 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003495 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003496 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3497 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3498 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003499 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003500 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3501 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003502 };
3503
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003504 if (HAS_L3_DPF(dev_priv))
3505 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3506
Akash Goelf4e9af42016-10-12 21:54:30 +05303507 dev_priv->pm_ier = 0x0;
3508 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303509 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3510 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003511 /*
3512 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303513 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003514 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303515 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303516 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003517}
3518
3519static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3520{
Damien Lespiau770de832014-03-20 20:45:01 +00003521 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3522 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003523 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3524 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003525 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003526 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003527
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003528 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003529 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003530 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3531 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003532 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003533 de_port_masked |= BXT_DE_PORT_GMBUS;
3534 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003535 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003536 }
Damien Lespiau770de832014-03-20 20:45:01 +00003537
3538 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3539 GEN8_PIPE_FIFO_UNDERRUN;
3540
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003541 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003542 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003543 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3544 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003545 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3546
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003547 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3548 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3549 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003550
Damien Lespiau055e3932014-08-18 13:49:10 +01003551 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003552 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003553 POWER_DOMAIN_PIPE(pipe)))
3554 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3555 dev_priv->de_irq_mask[pipe],
3556 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003557
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003558 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3559 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003560
3561 if (IS_GEN9_LP(dev_priv))
3562 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003563 else if (IS_BROADWELL(dev_priv))
3564 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003565}
3566
3567static int gen8_irq_postinstall(struct drm_device *dev)
3568{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003569 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003570
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003571 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303572 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003573
Ben Widawskyabd58f02013-11-02 21:07:09 -07003574 gen8_gt_irq_postinstall(dev_priv);
3575 gen8_de_irq_postinstall(dev_priv);
3576
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003577 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303578 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003579
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003580 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003581 POSTING_READ(GEN8_MASTER_IRQ);
3582
3583 return 0;
3584}
3585
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003586static int cherryview_irq_postinstall(struct drm_device *dev)
3587{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003588 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003589
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003590 gen8_gt_irq_postinstall(dev_priv);
3591
Ville Syrjäläad22d102016-04-12 18:56:14 +03003592 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003593 if (dev_priv->display_irqs_enabled)
3594 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003595 spin_unlock_irq(&dev_priv->irq_lock);
3596
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003597 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003598 POSTING_READ(GEN8_MASTER_IRQ);
3599
3600 return 0;
3601}
3602
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003603static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003604{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003605 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003606
Ville Syrjälä44d92412017-08-18 21:36:51 +03003607 i9xx_pipestat_irq_reset(dev_priv);
3608
Ville Syrjäläd420a502017-08-18 21:37:03 +03003609 I915_WRITE16(HWSTAM, 0xffff);
3610
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003611 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01003612}
3613
3614static int i8xx_irq_postinstall(struct drm_device *dev)
3615{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003616 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003617 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003618
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003619 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
3620 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01003621
3622 /* Unmask the interrupts that we always want on. */
3623 dev_priv->irq_mask =
3624 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003625 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003626
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003627 enable_mask =
3628 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3629 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3630 I915_USER_INTERRUPT;
3631
3632 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003633
Daniel Vetter379ef822013-10-16 22:55:56 +02003634 /* Interrupt setup is already guaranteed to be single-threaded, this is
3635 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003636 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003637 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3638 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003639 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003640
Chris Wilsonc2798b12012-04-22 21:13:57 +01003641 return 0;
3642}
3643
Daniel Vetterff1f5252012-10-02 15:10:55 +02003644static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003645{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003646 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003647 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003648 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003649
Imre Deak2dd2a882015-02-24 11:14:30 +02003650 if (!intel_irqs_enabled(dev_priv))
3651 return IRQ_NONE;
3652
Imre Deak1f814da2015-12-16 02:52:19 +02003653 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3654 disable_rpm_wakeref_asserts(dev_priv);
3655
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003656 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003657 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003658 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03003659
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003660 iir = I915_READ16(IIR);
3661 if (iir == 0)
3662 break;
3663
3664 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003665
Ville Syrjäläeb643432017-08-18 21:36:59 +03003666 /* Call regardless, as some status bits might not be
3667 * signalled in iir */
3668 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003669
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003670 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003671
Chris Wilsonc2798b12012-04-22 21:13:57 +01003672 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303673 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003674
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003675 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3676 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3677
Ville Syrjäläeb643432017-08-18 21:36:59 +03003678 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003679 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003680
Imre Deak1f814da2015-12-16 02:52:19 +02003681 enable_rpm_wakeref_asserts(dev_priv);
3682
3683 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003684}
3685
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003686static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003687{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003688 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003689
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003690 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003691 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003692 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3693 }
3694
Ville Syrjälä44d92412017-08-18 21:36:51 +03003695 i9xx_pipestat_irq_reset(dev_priv);
3696
Ville Syrjäläd420a502017-08-18 21:37:03 +03003697 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003698
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003699 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003700}
3701
3702static int i915_irq_postinstall(struct drm_device *dev)
3703{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003704 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01003705 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003706
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003707 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
3708 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01003709
3710 /* Unmask the interrupts that we always want on. */
3711 dev_priv->irq_mask =
3712 ~(I915_ASLE_INTERRUPT |
3713 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003714 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003715
3716 enable_mask =
3717 I915_ASLE_INTERRUPT |
3718 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3719 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003720 I915_USER_INTERRUPT;
3721
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003722 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003723 /* Enable in IER... */
3724 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3725 /* and unmask in IMR */
3726 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3727 }
3728
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003729 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003730
Daniel Vetter379ef822013-10-16 22:55:56 +02003731 /* Interrupt setup is already guaranteed to be single-threaded, this is
3732 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003733 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003734 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3735 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003736 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003737
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003738 i915_enable_asle_pipestat(dev_priv);
3739
Daniel Vetter20afbda2012-12-11 14:05:07 +01003740 return 0;
3741}
3742
Daniel Vetterff1f5252012-10-02 15:10:55 +02003743static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003744{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003745 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003746 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003747 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003748
Imre Deak2dd2a882015-02-24 11:14:30 +02003749 if (!intel_irqs_enabled(dev_priv))
3750 return IRQ_NONE;
3751
Imre Deak1f814da2015-12-16 02:52:19 +02003752 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3753 disable_rpm_wakeref_asserts(dev_priv);
3754
Chris Wilson38bde182012-04-24 22:59:50 +01003755 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003756 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003757 u32 hotplug_status = 0;
3758 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003759
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003760 iir = I915_READ(IIR);
3761 if (iir == 0)
3762 break;
3763
3764 ret = IRQ_HANDLED;
3765
3766 if (I915_HAS_HOTPLUG(dev_priv) &&
3767 iir & I915_DISPLAY_PORT_INTERRUPT)
3768 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003769
Ville Syrjäläeb643432017-08-18 21:36:59 +03003770 /* Call regardless, as some status bits might not be
3771 * signalled in iir */
3772 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003773
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003774 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003775
Chris Wilsona266c7d2012-04-24 22:59:44 +01003776 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303777 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003778
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003779 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3780 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003781
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003782 if (hotplug_status)
3783 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3784
3785 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3786 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003787
Imre Deak1f814da2015-12-16 02:52:19 +02003788 enable_rpm_wakeref_asserts(dev_priv);
3789
Chris Wilsona266c7d2012-04-24 22:59:44 +01003790 return ret;
3791}
3792
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003793static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003794{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003795 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003796
Egbert Eich0706f172015-09-23 16:15:27 +02003797 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01003798 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003799
Ville Syrjälä44d92412017-08-18 21:36:51 +03003800 i9xx_pipestat_irq_reset(dev_priv);
3801
Ville Syrjäläd420a502017-08-18 21:37:03 +03003802 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003803
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003804 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003805}
3806
3807static int i965_irq_postinstall(struct drm_device *dev)
3808{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003809 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003810 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003811 u32 error_mask;
3812
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003813 /*
3814 * Enable some error detection, note the instruction error mask
3815 * bit is reserved, so we leave it masked.
3816 */
3817 if (IS_G4X(dev_priv)) {
3818 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3819 GM45_ERROR_MEM_PRIV |
3820 GM45_ERROR_CP_PRIV |
3821 I915_ERROR_MEMORY_REFRESH);
3822 } else {
3823 error_mask = ~(I915_ERROR_PAGE_TABLE |
3824 I915_ERROR_MEMORY_REFRESH);
3825 }
3826 I915_WRITE(EMR, error_mask);
3827
Chris Wilsona266c7d2012-04-24 22:59:44 +01003828 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003829 dev_priv->irq_mask =
3830 ~(I915_ASLE_INTERRUPT |
3831 I915_DISPLAY_PORT_INTERRUPT |
3832 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3833 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3834 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003835
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003836 enable_mask =
3837 I915_ASLE_INTERRUPT |
3838 I915_DISPLAY_PORT_INTERRUPT |
3839 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3840 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3841 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3842 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003843
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003844 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003845 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003846
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003847 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
3848
Daniel Vetterb79480b2013-06-27 17:52:10 +02003849 /* Interrupt setup is already guaranteed to be single-threaded, this is
3850 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003851 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003852 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3853 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3854 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003855 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003856
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003857 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003858
3859 return 0;
3860}
3861
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003862static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003863{
Daniel Vetter20afbda2012-12-11 14:05:07 +01003864 u32 hotplug_en;
3865
Chris Wilson67520412017-03-02 13:28:01 +00003866 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003867
Ville Syrjälä778eb332015-01-09 14:21:13 +02003868 /* Note HDMI and DP share hotplug bits */
3869 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003870 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02003871 /* Programming the CRT detection parameters tends
3872 to generate a spurious hotplug event about three
3873 seconds later. So just do it once.
3874 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003875 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02003876 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02003877 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003878
Ville Syrjälä778eb332015-01-09 14:21:13 +02003879 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02003880 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03003881 HOTPLUG_INT_EN_MASK |
3882 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
3883 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
3884 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003885}
3886
Daniel Vetterff1f5252012-10-02 15:10:55 +02003887static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003888{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003889 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003890 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003891 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003892
Imre Deak2dd2a882015-02-24 11:14:30 +02003893 if (!intel_irqs_enabled(dev_priv))
3894 return IRQ_NONE;
3895
Imre Deak1f814da2015-12-16 02:52:19 +02003896 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3897 disable_rpm_wakeref_asserts(dev_priv);
3898
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003899 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003900 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003901 u32 hotplug_status = 0;
3902 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003903
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003904 iir = I915_READ(IIR);
3905 if (iir == 0)
3906 break;
3907
3908 ret = IRQ_HANDLED;
3909
3910 if (iir & I915_DISPLAY_PORT_INTERRUPT)
3911 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003912
Ville Syrjäläeb643432017-08-18 21:36:59 +03003913 /* Call regardless, as some status bits might not be
3914 * signalled in iir */
3915 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003916
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003917 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003918
Chris Wilsona266c7d2012-04-24 22:59:44 +01003919 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303920 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003921
Chris Wilsona266c7d2012-04-24 22:59:44 +01003922 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303923 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003924
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003925 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3926 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003927
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003928 if (hotplug_status)
3929 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3930
3931 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3932 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003933
Imre Deak1f814da2015-12-16 02:52:19 +02003934 enable_rpm_wakeref_asserts(dev_priv);
3935
Chris Wilsona266c7d2012-04-24 22:59:44 +01003936 return ret;
3937}
3938
Daniel Vetterfca52a52014-09-30 10:56:45 +02003939/**
3940 * intel_irq_init - initializes irq support
3941 * @dev_priv: i915 device instance
3942 *
3943 * This function initializes all the irq support including work items, timers
3944 * and all the vtables. It does not setup the interrupt itself though.
3945 */
Daniel Vetterb9632912014-09-30 10:56:44 +02003946void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003947{
Chris Wilson91c8a322016-07-05 10:40:23 +01003948 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003949 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01003950
Jani Nikula77913b32015-06-18 13:06:16 +03003951 intel_hpd_init_work(dev_priv);
3952
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003953 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003954
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003955 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003956 for (i = 0; i < MAX_L3_SLICES; ++i)
3957 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01003958
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00003959 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303960 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
3961
Deepak Sa6706b42014-03-15 20:23:22 +05303962 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08003963 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03003964 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00003965 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04003966 else
3967 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05303968
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05303969 dev_priv->rps.pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303970
3971 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03003972 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303973 * if GEN6_PM_UP_EI_EXPIRED is masked.
3974 *
3975 * TODO: verify if this can be reproduced on VLV,CHV.
3976 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003977 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05303978 dev_priv->rps.pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303979
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003980 if (INTEL_GEN(dev_priv) >= 8)
Chris Wilson655d49e2017-03-12 13:27:45 +00003981 dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303982
Daniel Vetterb9632912014-09-30 10:56:44 +02003983 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07003984 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003985 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003986 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003987 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03003988 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003989 } else {
3990 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3991 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003992 }
3993
Ville Syrjälä21da2702014-08-06 14:49:55 +03003994 /*
3995 * Opt out of the vblank disable timer on everything except gen2.
3996 * Gen2 doesn't have a hardware frame counter and so depends on
3997 * vblank interrupts to produce sane vblank seuquence numbers.
3998 */
Daniel Vetterb9632912014-09-30 10:56:44 +02003999 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004000 dev->vblank_disable_immediate = true;
4001
Chris Wilson262fd482017-02-15 13:15:47 +00004002 /* Most platforms treat the display irq block as an always-on
4003 * power domain. vlv/chv can disable it at runtime and need
4004 * special care to avoid writing any of the display block registers
4005 * outside of the power domain. We defer setting up the display irqs
4006 * in this case to the runtime pm.
4007 */
4008 dev_priv->display_irqs_enabled = true;
4009 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4010 dev_priv->display_irqs_enabled = false;
4011
Lyude317eaa92017-02-03 21:18:25 -05004012 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4013
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004014 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004015 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004016
Daniel Vetterb9632912014-09-30 10:56:44 +02004017 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004018 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004019 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004020 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004021 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004022 dev->driver->enable_vblank = i965_enable_vblank;
4023 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004024 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004025 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004026 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004027 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004028 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004029 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004030 dev->driver->enable_vblank = i965_enable_vblank;
4031 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004032 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004033 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004034 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004035 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004036 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004037 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004038 dev->driver->enable_vblank = gen8_enable_vblank;
4039 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004040 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004041 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004042 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4043 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004044 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4045 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004046 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004047 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004048 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004049 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004050 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004051 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004052 dev->driver->enable_vblank = ironlake_enable_vblank;
4053 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004054 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004055 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004056 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004057 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004058 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4059 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004060 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004061 dev->driver->enable_vblank = i8xx_enable_vblank;
4062 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004063 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004064 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004065 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004066 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004067 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004068 dev->driver->enable_vblank = i8xx_enable_vblank;
4069 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004070 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004071 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004072 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004073 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004074 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004075 dev->driver->enable_vblank = i965_enable_vblank;
4076 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004077 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004078 if (I915_HAS_HOTPLUG(dev_priv))
4079 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004080 }
4081}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004082
Daniel Vetterfca52a52014-09-30 10:56:45 +02004083/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004084 * intel_irq_fini - deinitializes IRQ support
4085 * @i915: i915 device instance
4086 *
4087 * This function deinitializes all the IRQ support.
4088 */
4089void intel_irq_fini(struct drm_i915_private *i915)
4090{
4091 int i;
4092
4093 for (i = 0; i < MAX_L3_SLICES; ++i)
4094 kfree(i915->l3_parity.remap_info[i]);
4095}
4096
4097/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004098 * intel_irq_install - enables the hardware interrupt
4099 * @dev_priv: i915 device instance
4100 *
4101 * This function enables the hardware interrupt handling, but leaves the hotplug
4102 * handling still disabled. It is called after intel_irq_init().
4103 *
4104 * In the driver load and resume code we need working interrupts in a few places
4105 * but don't want to deal with the hassle of concurrent probe and hotplug
4106 * workers. Hence the split into this two-stage approach.
4107 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004108int intel_irq_install(struct drm_i915_private *dev_priv)
4109{
4110 /*
4111 * We enable some interrupt sources in our postinstall hooks, so mark
4112 * interrupts as enabled _before_ actually enabling them to avoid
4113 * special cases in our ordering checks.
4114 */
4115 dev_priv->pm.irqs_enabled = true;
4116
Chris Wilson91c8a322016-07-05 10:40:23 +01004117 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004118}
4119
Daniel Vetterfca52a52014-09-30 10:56:45 +02004120/**
4121 * intel_irq_uninstall - finilizes all irq handling
4122 * @dev_priv: i915 device instance
4123 *
4124 * This stops interrupt and hotplug handling and unregisters and frees all
4125 * resources acquired in the init functions.
4126 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004127void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4128{
Chris Wilson91c8a322016-07-05 10:40:23 +01004129 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004130 intel_hpd_cancel_work(dev_priv);
4131 dev_priv->pm.irqs_enabled = false;
4132}
4133
Daniel Vetterfca52a52014-09-30 10:56:45 +02004134/**
4135 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4136 * @dev_priv: i915 device instance
4137 *
4138 * This function is used to disable interrupts at runtime, both in the runtime
4139 * pm and the system suspend/resume code.
4140 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004141void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004142{
Chris Wilson91c8a322016-07-05 10:40:23 +01004143 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004144 dev_priv->pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004145 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004146}
4147
Daniel Vetterfca52a52014-09-30 10:56:45 +02004148/**
4149 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4150 * @dev_priv: i915 device instance
4151 *
4152 * This function is used to enable interrupts at runtime, both in the runtime
4153 * pm and the system suspend/resume code.
4154 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004155void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004156{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004157 dev_priv->pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004158 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4159 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004160}