blob: 4d0e8f76ed1a3ecc870f6c9ca01859f581ce3abb [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
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100570static void
Imre Deak755e9012014-02-10 18:42:47 +0200571__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
572 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800573{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200574 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200575 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800576
Chris Wilson67520412017-03-02 13:28:01 +0000577 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200578 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200579
Ville Syrjälä04feced2014-04-03 13:28:33 +0300580 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
581 status_mask & ~PIPESTAT_INT_STATUS_MASK,
582 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
583 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200584 return;
585
586 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200587 return;
588
Imre Deak91d181d2014-02-10 18:42:49 +0200589 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
590
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200591 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200592 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200593 I915_WRITE(reg, pipestat);
594 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800595}
596
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100597static void
Imre Deak755e9012014-02-10 18:42:47 +0200598__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
599 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800600{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200601 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200602 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800603
Chris Wilson67520412017-03-02 13:28:01 +0000604 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200605 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200606
Ville Syrjälä04feced2014-04-03 13:28:33 +0300607 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
608 status_mask & ~PIPESTAT_INT_STATUS_MASK,
609 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
610 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200611 return;
612
Imre Deak755e9012014-02-10 18:42:47 +0200613 if ((pipestat & enable_mask) == 0)
614 return;
615
Imre Deak91d181d2014-02-10 18:42:49 +0200616 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
617
Imre Deak755e9012014-02-10 18:42:47 +0200618 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200619 I915_WRITE(reg, pipestat);
620 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800621}
622
Imre Deak10c59c52014-02-10 18:42:48 +0200623static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
624{
625 u32 enable_mask = status_mask << 16;
626
627 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300628 * On pipe A we don't support the PSR interrupt yet,
629 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200630 */
631 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
632 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300633 /*
634 * On pipe B and C we don't support the PSR interrupt yet, on pipe
635 * A the same bit is for perf counters which we don't use either.
636 */
637 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
638 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200639
640 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
641 SPRITE0_FLIP_DONE_INT_EN_VLV |
642 SPRITE1_FLIP_DONE_INT_EN_VLV);
643 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
644 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
645 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
646 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
647
648 return enable_mask;
649}
650
Imre Deak755e9012014-02-10 18:42:47 +0200651void
652i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
653 u32 status_mask)
654{
655 u32 enable_mask;
656
Wayne Boyer666a4532015-12-09 12:29:35 -0800657 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100658 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200659 status_mask);
660 else
661 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200662 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
663}
664
665void
666i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
667 u32 status_mask)
668{
669 u32 enable_mask;
670
Wayne Boyer666a4532015-12-09 12:29:35 -0800671 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100672 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200673 status_mask);
674 else
675 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200676 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
677}
678
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000679/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300680 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100681 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000682 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100683static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000684{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100685 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300686 return;
687
Daniel Vetter13321782014-09-15 14:55:29 +0200688 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000689
Imre Deak755e9012014-02-10 18:42:47 +0200690 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100691 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200692 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200693 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000694
Daniel Vetter13321782014-09-15 14:55:29 +0200695 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000696}
697
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300698/*
699 * This timing diagram depicts the video signal in and
700 * around the vertical blanking period.
701 *
702 * Assumptions about the fictitious mode used in this example:
703 * vblank_start >= 3
704 * vsync_start = vblank_start + 1
705 * vsync_end = vblank_start + 2
706 * vtotal = vblank_start + 3
707 *
708 * start of vblank:
709 * latch double buffered registers
710 * increment frame counter (ctg+)
711 * generate start of vblank interrupt (gen4+)
712 * |
713 * | frame start:
714 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
715 * | may be shifted forward 1-3 extra lines via PIPECONF
716 * | |
717 * | | start of vsync:
718 * | | generate vsync interrupt
719 * | | |
720 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
721 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
722 * ----va---> <-----------------vb--------------------> <--------va-------------
723 * | | <----vs-----> |
724 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
725 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
726 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
727 * | | |
728 * last visible pixel first visible pixel
729 * | increment frame counter (gen3/4)
730 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
731 *
732 * x = horizontal active
733 * _ = horizontal blanking
734 * hs = horizontal sync
735 * va = vertical active
736 * vb = vertical blanking
737 * vs = vertical sync
738 * vbs = vblank_start (number)
739 *
740 * Summary:
741 * - most events happen at the start of horizontal sync
742 * - frame start happens at the start of horizontal blank, 1-4 lines
743 * (depending on PIPECONF settings) after the start of vblank
744 * - gen3/4 pixel and frame counter are synchronized with the start
745 * of horizontal active on the first line of vertical active
746 */
747
Keith Packard42f52ef2008-10-18 19:39:29 -0700748/* Called from drm generic code, passed a 'crtc', which
749 * we use as a pipe index
750 */
Thierry Reding88e72712015-09-24 18:35:31 +0200751static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700752{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100753 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200754 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300755 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200756 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200757 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700758
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100759 htotal = mode->crtc_htotal;
760 hsync_start = mode->crtc_hsync_start;
761 vbl_start = mode->crtc_vblank_start;
762 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
763 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300764
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300765 /* Convert to pixel count */
766 vbl_start *= htotal;
767
768 /* Start of vblank event occurs at start of hsync */
769 vbl_start -= htotal - hsync_start;
770
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800771 high_frame = PIPEFRAME(pipe);
772 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100773
Ville Syrjälä694e4092017-03-09 17:44:30 +0200774 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
775
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700776 /*
777 * High & low register fields aren't synchronized, so make sure
778 * we get a low value that's stable across two reads of the high
779 * register.
780 */
781 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200782 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
783 low = I915_READ_FW(low_frame);
784 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700785 } while (high1 != high2);
786
Ville Syrjälä694e4092017-03-09 17:44:30 +0200787 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
788
Chris Wilson5eddb702010-09-11 13:48:45 +0100789 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300790 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100791 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300792
793 /*
794 * The frame counter increments at beginning of active.
795 * Cook up a vblank counter by also checking the pixel
796 * counter against vblank start.
797 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200798 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700799}
800
Dave Airlie974e59b2015-10-30 09:45:33 +1000801static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800802{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100803 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800804
Ville Syrjälä649636e2015-09-22 19:50:01 +0300805 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800806}
807
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300808/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300809static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
810{
811 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100812 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200813 const struct drm_display_mode *mode;
814 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300815 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300816 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300817
Ville Syrjälä72259532017-03-02 19:15:05 +0200818 if (!crtc->active)
819 return -1;
820
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200821 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
822 mode = &vblank->hwmode;
823
Ville Syrjälä80715b22014-05-15 20:23:23 +0300824 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300825 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
826 vtotal /= 2;
827
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100828 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300829 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300830 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300831 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300832
833 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700834 * On HSW, the DSL reg (0x70000) appears to return 0 if we
835 * read it just before the start of vblank. So try it again
836 * so we don't accidentally end up spanning a vblank frame
837 * increment, causing the pipe_update_end() code to squak at us.
838 *
839 * The nature of this problem means we can't simply check the ISR
840 * bit and return the vblank start value; nor can we use the scanline
841 * debug register in the transcoder as it appears to have the same
842 * problem. We may need to extend this to include other platforms,
843 * but so far testing only shows the problem on HSW.
844 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100845 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700846 int i, temp;
847
848 for (i = 0; i < 100; i++) {
849 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200850 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700851 if (temp != position) {
852 position = temp;
853 break;
854 }
855 }
856 }
857
858 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300859 * See update_scanline_offset() for the details on the
860 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300861 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300862 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300863}
864
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200865static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
866 bool in_vblank_irq, int *vpos, int *hpos,
867 ktime_t *stime, ktime_t *etime,
868 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100869{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100870 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200871 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
872 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300873 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300874 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100875 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100876
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200877 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100878 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800879 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200880 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100881 }
882
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300883 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300884 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300885 vtotal = mode->crtc_vtotal;
886 vbl_start = mode->crtc_vblank_start;
887 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100888
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200889 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
890 vbl_start = DIV_ROUND_UP(vbl_start, 2);
891 vbl_end /= 2;
892 vtotal /= 2;
893 }
894
Mario Kleinerad3543e2013-10-30 05:13:08 +0100895 /*
896 * Lock uncore.lock, as we will do multiple timing critical raw
897 * register reads, potentially with preemption disabled, so the
898 * following code must not block on uncore.lock.
899 */
900 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300901
Mario Kleinerad3543e2013-10-30 05:13:08 +0100902 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
903
904 /* Get optional system timestamp before query. */
905 if (stime)
906 *stime = ktime_get();
907
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100908 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100909 /* No obvious pixelcount register. Only query vertical
910 * scanout position from Display scan line register.
911 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300912 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100913 } else {
914 /* Have access to pixelcount since start of frame.
915 * We can split this into vertical and horizontal
916 * scanout position.
917 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300918 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100919
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300920 /* convert to pixel counts */
921 vbl_start *= htotal;
922 vbl_end *= htotal;
923 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300924
925 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300926 * In interlaced modes, the pixel counter counts all pixels,
927 * so one field will have htotal more pixels. In order to avoid
928 * the reported position from jumping backwards when the pixel
929 * counter is beyond the length of the shorter field, just
930 * clamp the position the length of the shorter field. This
931 * matches how the scanline counter based position works since
932 * the scanline counter doesn't count the two half lines.
933 */
934 if (position >= vtotal)
935 position = vtotal - 1;
936
937 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300938 * Start of vblank interrupt is triggered at start of hsync,
939 * just prior to the first active line of vblank. However we
940 * consider lines to start at the leading edge of horizontal
941 * active. So, should we get here before we've crossed into
942 * the horizontal active of the first line in vblank, we would
943 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
944 * always add htotal-hsync_start to the current pixel position.
945 */
946 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300947 }
948
Mario Kleinerad3543e2013-10-30 05:13:08 +0100949 /* Get optional system timestamp after query. */
950 if (etime)
951 *etime = ktime_get();
952
953 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
954
955 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
956
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300957 /*
958 * While in vblank, position will be negative
959 * counting up towards 0 at vbl_end. And outside
960 * vblank, position will be positive counting
961 * up since vbl_end.
962 */
963 if (position >= vbl_start)
964 position -= vbl_end;
965 else
966 position += vtotal - vbl_end;
967
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100968 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300969 *vpos = position;
970 *hpos = 0;
971 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100972 *vpos = position / htotal;
973 *hpos = position - (*vpos * htotal);
974 }
975
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200976 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100977}
978
Ville Syrjäläa225f072014-04-29 13:35:45 +0300979int intel_get_crtc_scanline(struct intel_crtc *crtc)
980{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100981 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +0300982 unsigned long irqflags;
983 int position;
984
985 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
986 position = __intel_get_crtc_scanline(crtc);
987 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
988
989 return position;
990}
991
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100992static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800993{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000994 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200995 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200996
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200997 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800998
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200999 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1000
Daniel Vetter20e4d402012-08-08 23:35:39 +02001001 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001002
Jesse Barnes7648fa92010-05-20 14:28:11 -07001003 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001004 busy_up = I915_READ(RCPREVBSYTUPAVG);
1005 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001006 max_avg = I915_READ(RCBMAXAVG);
1007 min_avg = I915_READ(RCBMINAVG);
1008
1009 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001010 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001011 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1012 new_delay = dev_priv->ips.cur_delay - 1;
1013 if (new_delay < dev_priv->ips.max_delay)
1014 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001015 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001016 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1017 new_delay = dev_priv->ips.cur_delay + 1;
1018 if (new_delay > dev_priv->ips.min_delay)
1019 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001020 }
1021
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001022 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001023 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001024
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001025 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001026
Jesse Barnesf97108d2010-01-29 11:27:07 -08001027 return;
1028}
1029
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001030static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001031{
Chris Wilson56299fb2017-02-27 20:58:48 +00001032 struct drm_i915_gem_request *rq = NULL;
1033 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001034
Chris Wilson2246bea2017-02-17 15:13:00 +00001035 atomic_inc(&engine->irq_count);
Chris Wilson538b2572017-01-24 15:18:05 +00001036 set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson56299fb2017-02-27 20:58:48 +00001037
Chris Wilson61d3dc72017-03-03 19:08:24 +00001038 spin_lock(&engine->breadcrumbs.irq_lock);
1039 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001040 if (wait) {
1041 /* We use a callback from the dma-fence to submit
1042 * requests after waiting on our own requests. To
1043 * ensure minimum delay in queuing the next request to
1044 * hardware, signal the fence now rather than wait for
1045 * the signaler to be woken up. We still wake up the
1046 * waiter in order to handle the irq-seqno coherency
1047 * issues (we may receive the interrupt before the
1048 * seqno is written, see __i915_request_irq_complete())
1049 * and to handle coalescing of multiple seqno updates
1050 * and many waiters.
1051 */
1052 if (i915_seqno_passed(intel_engine_get_seqno(engine),
Chris Wilsondb939912017-03-15 21:07:26 +00001053 wait->seqno) &&
1054 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
1055 &wait->request->fence.flags))
Chris Wilson24754d72017-03-03 14:45:57 +00001056 rq = i915_gem_request_get(wait->request);
Chris Wilson56299fb2017-02-27 20:58:48 +00001057
1058 wake_up_process(wait->tsk);
Chris Wilson67b807a82017-02-27 20:58:50 +00001059 } else {
1060 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001061 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001062 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001063
Chris Wilson24754d72017-03-03 14:45:57 +00001064 if (rq) {
Chris Wilson56299fb2017-02-27 20:58:48 +00001065 dma_fence_signal(&rq->fence);
Chris Wilson24754d72017-03-03 14:45:57 +00001066 i915_gem_request_put(rq);
1067 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001068
1069 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001070}
1071
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001072static void vlv_c0_read(struct drm_i915_private *dev_priv,
1073 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001074{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001075 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001076 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1077 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001078}
1079
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001080void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1081{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001082 memset(&dev_priv->rps.ei, 0, sizeof(dev_priv->rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001083}
1084
1085static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1086{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001087 const struct intel_rps_ei *prev = &dev_priv->rps.ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001088 struct intel_rps_ei now;
1089 u32 events = 0;
1090
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001091 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001092 return 0;
1093
1094 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001095
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001096 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001097 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001098 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001099
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001100 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001101
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001102 time *= dev_priv->czclk_freq;
1103
1104 /* Workload can be split between render + media,
1105 * e.g. SwapBuffers being blitted in X after being rendered in
1106 * mesa. To account for this we need to combine both engines
1107 * into our activity counter.
1108 */
Chris Wilson569884e2017-03-09 21:12:31 +00001109 render = now.render_c0 - prev->render_c0;
1110 media = now.media_c0 - prev->media_c0;
1111 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001112 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001113
1114 if (c0 > time * dev_priv->rps.up_threshold)
1115 events = GEN6_PM_RP_UP_THRESHOLD;
1116 else if (c0 < time * dev_priv->rps.down_threshold)
1117 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001118 }
1119
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001120 dev_priv->rps.ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001121 return events;
Deepak S31685c22014-07-03 17:33:01 -04001122}
1123
Ben Widawsky4912d042011-04-25 11:25:20 -07001124static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001125{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001126 struct drm_i915_private *dev_priv =
1127 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001128 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001129 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001130 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001131
Daniel Vetter59cdb632013-07-04 23:35:28 +02001132 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001133 if (dev_priv->rps.interrupts_enabled) {
1134 pm_iir = fetch_and_zero(&dev_priv->rps.pm_iir);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001135 client_boost = atomic_read(&dev_priv->rps.num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001136 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001137 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001138
Paulo Zanoni60611c12013-08-15 11:50:01 -03001139 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301140 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001141 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001142 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001144 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001145
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001146 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1147
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001148 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001149 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001150 min = dev_priv->rps.min_freq_softlimit;
1151 max = dev_priv->rps.max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001152 if (client_boost)
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001153 max = dev_priv->rps.max_freq;
1154 if (client_boost && new_delay < dev_priv->rps.boost_freq) {
1155 new_delay = dev_priv->rps.boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001156 adj = 0;
1157 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001158 if (adj > 0)
1159 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001160 else /* CHV needs even encode values */
1161 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301162
1163 if (new_delay >= dev_priv->rps.max_freq_softlimit)
1164 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001165 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001166 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001167 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001168 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1169 new_delay = dev_priv->rps.efficient_freq;
Chris Wilson17136d52017-02-10 15:03:47 +00001170 else if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
Ben Widawskyb39fb292014-03-19 18:31:11 -07001171 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001172 adj = 0;
1173 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1174 if (adj < 0)
1175 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001176 else /* CHV needs even encode values */
1177 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301178
1179 if (new_delay <= dev_priv->rps.min_freq_softlimit)
1180 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001181 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001182 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001183 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001184
Chris Wilsonedcf2842015-04-07 16:20:29 +01001185 dev_priv->rps.last_adj = adj;
1186
Ben Widawsky79249632012-09-07 19:43:42 -07001187 /* sysfs frequency interfaces may have snuck in while servicing the
1188 * interrupt
1189 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001190 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001191 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301192
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001193 if (intel_set_rps(dev_priv, new_delay)) {
1194 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
1195 dev_priv->rps.last_adj = 0;
1196 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001197
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001198 mutex_unlock(&dev_priv->rps.hw_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001199
1200out:
1201 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1202 spin_lock_irq(&dev_priv->irq_lock);
1203 if (dev_priv->rps.interrupts_enabled)
1204 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1205 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001206}
1207
Ben Widawskye3689192012-05-25 16:56:22 -07001208
1209/**
1210 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1211 * occurred.
1212 * @work: workqueue struct
1213 *
1214 * Doesn't actually do anything except notify userspace. As a consequence of
1215 * this event, userspace should try to remap the bad rows since statistically
1216 * it is likely the same row is more likely to go bad again.
1217 */
1218static void ivybridge_parity_work(struct work_struct *work)
1219{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001220 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001221 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001222 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001223 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001224 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001225 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001226
1227 /* We must turn off DOP level clock gating to access the L3 registers.
1228 * In order to prevent a get/put style interface, acquire struct mutex
1229 * any time we access those registers.
1230 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001231 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001232
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001233 /* If we've screwed up tracking, just let the interrupt fire again */
1234 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1235 goto out;
1236
Ben Widawskye3689192012-05-25 16:56:22 -07001237 misccpctl = I915_READ(GEN7_MISCCPCTL);
1238 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1239 POSTING_READ(GEN7_MISCCPCTL);
1240
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001241 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001242 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001243
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001244 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001245 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001246 break;
1247
1248 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1249
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001250 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001251
1252 error_status = I915_READ(reg);
1253 row = GEN7_PARITY_ERROR_ROW(error_status);
1254 bank = GEN7_PARITY_ERROR_BANK(error_status);
1255 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1256
1257 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1258 POSTING_READ(reg);
1259
1260 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1261 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1262 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1263 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1264 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1265 parity_event[5] = NULL;
1266
Chris Wilson91c8a322016-07-05 10:40:23 +01001267 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001268 KOBJ_CHANGE, parity_event);
1269
1270 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1271 slice, row, bank, subbank);
1272
1273 kfree(parity_event[4]);
1274 kfree(parity_event[3]);
1275 kfree(parity_event[2]);
1276 kfree(parity_event[1]);
1277 }
Ben Widawskye3689192012-05-25 16:56:22 -07001278
1279 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1280
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001281out:
1282 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001283 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001284 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001285 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001286
Chris Wilson91c8a322016-07-05 10:40:23 +01001287 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001288}
1289
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001290static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1291 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001292{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001293 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001294 return;
1295
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001296 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001297 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001298 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001299
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001300 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001301 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1302 dev_priv->l3_parity.which_slice |= 1 << 1;
1303
1304 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1305 dev_priv->l3_parity.which_slice |= 1 << 0;
1306
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001307 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001308}
1309
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001310static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001311 u32 gt_iir)
1312{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001313 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301314 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001315 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301316 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001317}
1318
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001319static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001320 u32 gt_iir)
1321{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001322 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301323 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001324 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301325 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001326 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301327 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001328
Ben Widawskycc609d52013-05-28 19:22:29 -07001329 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1330 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001331 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1332 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001333
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001334 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1335 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001336}
1337
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001338static void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001339gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001340{
Chris Wilson31de7352017-03-16 12:56:18 +00001341 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001342
1343 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) {
Chris Wilsona4b2b012017-05-17 13:10:01 +01001344 if (port_count(&engine->execlist_port[0])) {
Chris Wilson955a4b82017-05-17 13:10:07 +01001345 __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted);
Chris Wilsona4b2b012017-05-17 13:10:01 +01001346 tasklet = true;
1347 }
Chris Wilsonf7470262017-01-24 15:20:21 +00001348 }
Chris Wilson31de7352017-03-16 12:56:18 +00001349
1350 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) {
1351 notify_ring(engine);
1352 tasklet |= i915.enable_guc_submission;
1353 }
1354
1355 if (tasklet)
1356 tasklet_hi_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001357}
1358
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001359static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1360 u32 master_ctl,
1361 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001362{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001363 irqreturn_t ret = IRQ_NONE;
1364
1365 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001366 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1367 if (gt_iir[0]) {
1368 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001369 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001370 } else
1371 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1372 }
1373
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001374 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001375 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1376 if (gt_iir[1]) {
1377 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001378 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001379 } else
1380 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1381 }
1382
Chris Wilson74cdb332015-04-07 16:21:05 +01001383 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001384 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1385 if (gt_iir[3]) {
1386 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001387 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001388 } else
1389 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1390 }
1391
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301392 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001393 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301394 if (gt_iir[2] & (dev_priv->pm_rps_events |
1395 dev_priv->pm_guc_events)) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001396 I915_WRITE_FW(GEN8_GT_IIR(2),
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301397 gt_iir[2] & (dev_priv->pm_rps_events |
1398 dev_priv->pm_guc_events));
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001399 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001400 } else
1401 DRM_ERROR("The master control interrupt lied (PM)!\n");
1402 }
1403
Ben Widawskyabd58f02013-11-02 21:07:09 -07001404 return ret;
1405}
1406
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001407static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1408 u32 gt_iir[4])
1409{
1410 if (gt_iir[0]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301411 gen8_cs_irq_handler(dev_priv->engine[RCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001412 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301413 gen8_cs_irq_handler(dev_priv->engine[BCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001414 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1415 }
1416
1417 if (gt_iir[1]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301418 gen8_cs_irq_handler(dev_priv->engine[VCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001419 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301420 gen8_cs_irq_handler(dev_priv->engine[VCS2],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001421 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1422 }
1423
1424 if (gt_iir[3])
Akash Goel3b3f1652016-10-13 22:44:48 +05301425 gen8_cs_irq_handler(dev_priv->engine[VECS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001426 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1427
1428 if (gt_iir[2] & dev_priv->pm_rps_events)
1429 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301430
1431 if (gt_iir[2] & dev_priv->pm_guc_events)
1432 gen9_guc_irq_handler(dev_priv, gt_iir[2]);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001433}
1434
Imre Deak63c88d22015-07-20 14:43:39 -07001435static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1436{
1437 switch (port) {
1438 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001439 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001440 case PORT_B:
1441 return val & PORTB_HOTPLUG_LONG_DETECT;
1442 case PORT_C:
1443 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001444 default:
1445 return false;
1446 }
1447}
1448
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001449static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1450{
1451 switch (port) {
1452 case PORT_E:
1453 return val & PORTE_HOTPLUG_LONG_DETECT;
1454 default:
1455 return false;
1456 }
1457}
1458
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001459static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1460{
1461 switch (port) {
1462 case PORT_A:
1463 return val & PORTA_HOTPLUG_LONG_DETECT;
1464 case PORT_B:
1465 return val & PORTB_HOTPLUG_LONG_DETECT;
1466 case PORT_C:
1467 return val & PORTC_HOTPLUG_LONG_DETECT;
1468 case PORT_D:
1469 return val & PORTD_HOTPLUG_LONG_DETECT;
1470 default:
1471 return false;
1472 }
1473}
1474
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001475static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1476{
1477 switch (port) {
1478 case PORT_A:
1479 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1480 default:
1481 return false;
1482 }
1483}
1484
Jani Nikula676574d2015-05-28 15:43:53 +03001485static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001486{
1487 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001488 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001489 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001490 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001491 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001492 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001493 return val & PORTD_HOTPLUG_LONG_DETECT;
1494 default:
1495 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001496 }
1497}
1498
Jani Nikula676574d2015-05-28 15:43:53 +03001499static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001500{
1501 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001502 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001503 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001504 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001505 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001506 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001507 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1508 default:
1509 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001510 }
1511}
1512
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001513/*
1514 * Get a bit mask of pins that have triggered, and which ones may be long.
1515 * This can be called multiple times with the same masks to accumulate
1516 * hotplug detection results from several registers.
1517 *
1518 * Note that the caller is expected to zero out the masks initially.
1519 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001520static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001521 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001522 const u32 hpd[HPD_NUM_PINS],
1523 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001524{
Jani Nikula8c841e52015-06-18 13:06:17 +03001525 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001526 int i;
1527
Jani Nikula676574d2015-05-28 15:43:53 +03001528 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001529 if ((hpd[i] & hotplug_trigger) == 0)
1530 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001531
Jani Nikula8c841e52015-06-18 13:06:17 +03001532 *pin_mask |= BIT(i);
1533
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07001534 port = intel_hpd_pin_to_port(i);
1535 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001536 continue;
1537
Imre Deakfd63e2a2015-07-21 15:32:44 -07001538 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001539 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001540 }
1541
1542 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1543 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1544
1545}
1546
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001547static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001548{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001549 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001550}
1551
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001552static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001553{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001554 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001555}
1556
Shuang He8bf1e9f2013-10-15 18:55:27 +01001557#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001558static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1559 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001560 uint32_t crc0, uint32_t crc1,
1561 uint32_t crc2, uint32_t crc3,
1562 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001563{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001564 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1565 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001566 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1567 struct drm_driver *driver = dev_priv->drm.driver;
1568 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001569 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001570
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001571 spin_lock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001572 if (pipe_crc->source) {
1573 if (!pipe_crc->entries) {
1574 spin_unlock(&pipe_crc->lock);
1575 DRM_DEBUG_KMS("spurious interrupt\n");
1576 return;
1577 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001578
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001579 head = pipe_crc->head;
1580 tail = pipe_crc->tail;
1581
1582 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1583 spin_unlock(&pipe_crc->lock);
1584 DRM_ERROR("CRC buffer overflowing\n");
1585 return;
1586 }
1587
1588 entry = &pipe_crc->entries[head];
1589
1590 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1591 entry->crc[0] = crc0;
1592 entry->crc[1] = crc1;
1593 entry->crc[2] = crc2;
1594 entry->crc[3] = crc3;
1595 entry->crc[4] = crc4;
1596
1597 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1598 pipe_crc->head = head;
1599
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001600 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001601
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001602 wake_up_interruptible(&pipe_crc->wq);
1603 } else {
1604 /*
1605 * For some not yet identified reason, the first CRC is
1606 * bonkers. So let's just wait for the next vblank and read
1607 * out the buggy result.
1608 *
1609 * On CHV sometimes the second CRC is bonkers as well, so
1610 * don't trust that one either.
1611 */
1612 if (pipe_crc->skipped == 0 ||
1613 (IS_CHERRYVIEW(dev_priv) && pipe_crc->skipped == 1)) {
1614 pipe_crc->skipped++;
1615 spin_unlock(&pipe_crc->lock);
1616 return;
1617 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001618 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001619 crcs[0] = crc0;
1620 crcs[1] = crc1;
1621 crcs[2] = crc2;
1622 crcs[3] = crc3;
1623 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001624 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001625 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001626 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001627 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001628}
Daniel Vetter277de952013-10-18 16:37:07 +02001629#else
1630static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001631display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1632 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001633 uint32_t crc0, uint32_t crc1,
1634 uint32_t crc2, uint32_t crc3,
1635 uint32_t crc4) {}
1636#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001637
Daniel Vetter277de952013-10-18 16:37:07 +02001638
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001639static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1640 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001641{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001642 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001643 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1644 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001645}
1646
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001647static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1648 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001649{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001650 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001651 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1652 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1653 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1654 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1655 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001656}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001657
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001658static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1659 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001660{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001661 uint32_t res1, res2;
1662
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001663 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001664 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1665 else
1666 res1 = 0;
1667
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001668 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001669 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1670 else
1671 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001672
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001673 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001674 I915_READ(PIPE_CRC_RES_RED(pipe)),
1675 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1676 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1677 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001678}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001679
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001680/* The RPS events need forcewake, so we add them to a work queue and mask their
1681 * IMR bits until the work is done. Other interrupts can be processed without
1682 * the work queue. */
1683static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001684{
Deepak Sa6706b42014-03-15 20:23:22 +05301685 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001686 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301687 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001688 if (dev_priv->rps.interrupts_enabled) {
1689 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001690 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001691 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001692 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001693 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001694
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001695 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001696 return;
1697
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001698 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001699 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301700 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001701
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001702 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1703 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001704 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001705}
1706
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301707static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1708{
1709 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) {
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301710 /* Sample the log buffer flush related bits & clear them out now
1711 * itself from the message identity register to minimize the
1712 * probability of losing a flush interrupt, when there are back
1713 * to back flush interrupts.
1714 * There can be a new flush interrupt, for different log buffer
1715 * type (like for ISR), whilst Host is handling one (for DPC).
1716 * Since same bit is used in message register for ISR & DPC, it
1717 * could happen that GuC sets the bit for 2nd interrupt but Host
1718 * clears out the bit on handling the 1st interrupt.
1719 */
1720 u32 msg, flush;
1721
1722 msg = I915_READ(SOFT_SCRATCH(15));
Arkadiusz Hilera80bc452016-11-25 18:59:34 +01001723 flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED |
1724 INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER);
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301725 if (flush) {
1726 /* Clear the message bits that are handled */
1727 I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
1728
1729 /* Handle flush interrupt in bottom half */
Oscar Mateoe7465472017-03-22 10:39:48 -07001730 queue_work(dev_priv->guc.log.runtime.flush_wq,
1731 &dev_priv->guc.log.runtime.flush_work);
Akash Goel5aa1ee42016-10-12 21:54:36 +05301732
1733 dev_priv->guc.log.flush_interrupt_count++;
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301734 } else {
1735 /* Not clearing of unhandled event bits won't result in
1736 * re-triggering of the interrupt.
1737 */
1738 }
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301739 }
1740}
1741
Ville Syrjälä44d92412017-08-18 21:36:51 +03001742static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1743{
1744 enum pipe pipe;
1745
1746 for_each_pipe(dev_priv, pipe) {
1747 I915_WRITE(PIPESTAT(pipe),
1748 PIPESTAT_INT_STATUS_MASK |
1749 PIPE_FIFO_UNDERRUN_STATUS);
1750
1751 dev_priv->pipestat_irq_mask[pipe] = 0;
1752 }
1753}
1754
Ville Syrjäläeb643432017-08-18 21:36:59 +03001755static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1756 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001757{
Imre Deakc1874ed2014-02-04 21:35:46 +02001758 int pipe;
1759
Imre Deak58ead0d2014-02-04 21:35:47 +02001760 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001761
1762 if (!dev_priv->display_irqs_enabled) {
1763 spin_unlock(&dev_priv->irq_lock);
1764 return;
1765 }
1766
Damien Lespiau055e3932014-08-18 13:49:10 +01001767 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001768 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001769 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001770
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001771 /*
1772 * PIPESTAT bits get signalled even when the interrupt is
1773 * disabled with the mask bits, and some of the status bits do
1774 * not generate interrupts at all (like the underrun bit). Hence
1775 * we need to be careful that we only handle what we want to
1776 * handle.
1777 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001778
1779 /* fifo underruns are filterered in the underrun handler. */
1780 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001781
1782 switch (pipe) {
1783 case PIPE_A:
1784 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1785 break;
1786 case PIPE_B:
1787 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1788 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001789 case PIPE_C:
1790 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1791 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001792 }
1793 if (iir & iir_bit)
1794 mask |= dev_priv->pipestat_irq_mask[pipe];
1795
1796 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001797 continue;
1798
1799 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001800 mask |= PIPESTAT_INT_ENABLE_MASK;
1801 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001802
1803 /*
1804 * Clear the PIPE*STAT regs before the IIR
1805 */
Imre Deak91d181d2014-02-10 18:42:49 +02001806 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1807 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001808 I915_WRITE(reg, pipe_stats[pipe]);
1809 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001810 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001811}
1812
Ville Syrjäläeb643432017-08-18 21:36:59 +03001813static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1814 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1815{
1816 enum pipe pipe;
1817
1818 for_each_pipe(dev_priv, pipe) {
1819 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1820 drm_handle_vblank(&dev_priv->drm, pipe);
1821
1822 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1823 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1824
1825 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1826 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1827 }
1828}
1829
1830static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1831 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1832{
1833 bool blc_event = false;
1834 enum pipe pipe;
1835
1836 for_each_pipe(dev_priv, pipe) {
1837 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1838 drm_handle_vblank(&dev_priv->drm, pipe);
1839
1840 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1841 blc_event = true;
1842
1843 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1844 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1845
1846 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1847 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1848 }
1849
1850 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1851 intel_opregion_asle_intr(dev_priv);
1852}
1853
1854static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1855 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1856{
1857 bool blc_event = false;
1858 enum pipe pipe;
1859
1860 for_each_pipe(dev_priv, pipe) {
1861 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1862 drm_handle_vblank(&dev_priv->drm, pipe);
1863
1864 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1865 blc_event = true;
1866
1867 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1868 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1869
1870 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1871 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1872 }
1873
1874 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1875 intel_opregion_asle_intr(dev_priv);
1876
1877 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1878 gmbus_irq_handler(dev_priv);
1879}
1880
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001881static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001882 u32 pipe_stats[I915_MAX_PIPES])
1883{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001884 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001885
Damien Lespiau055e3932014-08-18 13:49:10 +01001886 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001887 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1888 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001889
1890 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001891 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001892
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001893 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1894 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001895 }
1896
1897 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001898 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001899}
1900
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001901static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001902{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001903 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001904
1905 if (hotplug_status)
1906 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1907
1908 return hotplug_status;
1909}
1910
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001911static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001912 u32 hotplug_status)
1913{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001914 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001915
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001916 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1917 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001918 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001919
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001920 if (hotplug_trigger) {
1921 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1922 hotplug_trigger, hpd_status_g4x,
1923 i9xx_port_hotplug_long_detect);
1924
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001925 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001926 }
Jani Nikula369712e2015-05-27 15:03:40 +03001927
1928 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001929 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001930 } else {
1931 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001932
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001933 if (hotplug_trigger) {
1934 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001935 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001936 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001937 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001938 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001939 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001940}
1941
Daniel Vetterff1f5252012-10-02 15:10:55 +02001942static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001943{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001944 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001945 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001946 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001947
Imre Deak2dd2a882015-02-24 11:14:30 +02001948 if (!intel_irqs_enabled(dev_priv))
1949 return IRQ_NONE;
1950
Imre Deak1f814da2015-12-16 02:52:19 +02001951 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1952 disable_rpm_wakeref_asserts(dev_priv);
1953
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001954 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001955 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001956 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001957 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001958 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001959
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001960 gt_iir = I915_READ(GTIIR);
1961 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001962 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001963
1964 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001965 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001966
1967 ret = IRQ_HANDLED;
1968
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001969 /*
1970 * Theory on interrupt generation, based on empirical evidence:
1971 *
1972 * x = ((VLV_IIR & VLV_IER) ||
1973 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1974 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1975 *
1976 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1977 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1978 * guarantee the CPU interrupt will be raised again even if we
1979 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1980 * bits this time around.
1981 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001982 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001983 ier = I915_READ(VLV_IER);
1984 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001985
1986 if (gt_iir)
1987 I915_WRITE(GTIIR, gt_iir);
1988 if (pm_iir)
1989 I915_WRITE(GEN6_PMIIR, pm_iir);
1990
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001991 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001992 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001993
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001994 /* Call regardless, as some status bits might not be
1995 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03001996 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001997
Jerome Anandeef57322017-01-25 04:27:49 +05301998 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
1999 I915_LPE_PIPE_B_INTERRUPT))
2000 intel_lpe_audio_irq_handler(dev_priv);
2001
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002002 /*
2003 * VLV_IIR is single buffered, and reflects the level
2004 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2005 */
2006 if (iir)
2007 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002008
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002009 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002010 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2011 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002012
Ville Syrjälä52894872016-04-13 21:19:56 +03002013 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002014 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002015 if (pm_iir)
2016 gen6_rps_irq_handler(dev_priv, pm_iir);
2017
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002018 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002019 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002020
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002021 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002022 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002023
Imre Deak1f814da2015-12-16 02:52:19 +02002024 enable_rpm_wakeref_asserts(dev_priv);
2025
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002026 return ret;
2027}
2028
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002029static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2030{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002031 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002032 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002033 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002034
Imre Deak2dd2a882015-02-24 11:14:30 +02002035 if (!intel_irqs_enabled(dev_priv))
2036 return IRQ_NONE;
2037
Imre Deak1f814da2015-12-16 02:52:19 +02002038 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2039 disable_rpm_wakeref_asserts(dev_priv);
2040
Chris Wilson579de732016-03-14 09:01:57 +00002041 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002042 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002043 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002044 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002045 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002046 u32 ier = 0;
2047
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002048 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2049 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002050
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002051 if (master_ctl == 0 && iir == 0)
2052 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002053
Oscar Mateo27b6c122014-06-16 16:11:00 +01002054 ret = IRQ_HANDLED;
2055
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002056 /*
2057 * Theory on interrupt generation, based on empirical evidence:
2058 *
2059 * x = ((VLV_IIR & VLV_IER) ||
2060 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2061 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2062 *
2063 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2064 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2065 * guarantee the CPU interrupt will be raised again even if we
2066 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2067 * bits this time around.
2068 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002069 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002070 ier = I915_READ(VLV_IER);
2071 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002072
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002073 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002074
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002075 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002076 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002077
Oscar Mateo27b6c122014-06-16 16:11:00 +01002078 /* Call regardless, as some status bits might not be
2079 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002080 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002081
Jerome Anandeef57322017-01-25 04:27:49 +05302082 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2083 I915_LPE_PIPE_B_INTERRUPT |
2084 I915_LPE_PIPE_C_INTERRUPT))
2085 intel_lpe_audio_irq_handler(dev_priv);
2086
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002087 /*
2088 * VLV_IIR is single buffered, and reflects the level
2089 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2090 */
2091 if (iir)
2092 I915_WRITE(VLV_IIR, iir);
2093
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002094 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002095 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002096 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002097
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002098 gen8_gt_irq_handler(dev_priv, gt_iir);
2099
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002100 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002101 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002102
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002103 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002104 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002105
Imre Deak1f814da2015-12-16 02:52:19 +02002106 enable_rpm_wakeref_asserts(dev_priv);
2107
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002108 return ret;
2109}
2110
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002111static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2112 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002113 const u32 hpd[HPD_NUM_PINS])
2114{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002115 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2116
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002117 /*
2118 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2119 * unless we touch the hotplug register, even if hotplug_trigger is
2120 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2121 * errors.
2122 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002123 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002124 if (!hotplug_trigger) {
2125 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2126 PORTD_HOTPLUG_STATUS_MASK |
2127 PORTC_HOTPLUG_STATUS_MASK |
2128 PORTB_HOTPLUG_STATUS_MASK;
2129 dig_hotplug_reg &= ~mask;
2130 }
2131
Ville Syrjälä40e56412015-08-27 23:56:10 +03002132 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002133 if (!hotplug_trigger)
2134 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002135
2136 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2137 dig_hotplug_reg, hpd,
2138 pch_port_hotplug_long_detect);
2139
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002140 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002141}
2142
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002143static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002144{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002145 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002146 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002147
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002148 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002149
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002150 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2151 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2152 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002153 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002154 port_name(port));
2155 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002156
Daniel Vetterce99c252012-12-01 13:53:47 +01002157 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002158 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002159
Jesse Barnes776ad802011-01-04 15:09:39 -08002160 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002161 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002162
2163 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2164 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2165
2166 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2167 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2168
2169 if (pch_iir & SDE_POISON)
2170 DRM_ERROR("PCH poison interrupt\n");
2171
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002172 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002173 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002174 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2175 pipe_name(pipe),
2176 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002177
2178 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2179 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2180
2181 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2182 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2183
Jesse Barnes776ad802011-01-04 15:09:39 -08002184 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002185 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002186
2187 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002188 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002189}
2190
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002191static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002192{
Paulo Zanoni86642812013-04-12 17:57:57 -03002193 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002194 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002195
Paulo Zanonide032bf2013-04-12 17:57:58 -03002196 if (err_int & ERR_INT_POISON)
2197 DRM_ERROR("Poison interrupt\n");
2198
Damien Lespiau055e3932014-08-18 13:49:10 +01002199 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002200 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2201 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002202
Daniel Vetter5a69b892013-10-16 22:55:52 +02002203 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002204 if (IS_IVYBRIDGE(dev_priv))
2205 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002206 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002207 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002208 }
2209 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002210
Paulo Zanoni86642812013-04-12 17:57:57 -03002211 I915_WRITE(GEN7_ERR_INT, err_int);
2212}
2213
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002214static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002215{
Paulo Zanoni86642812013-04-12 17:57:57 -03002216 u32 serr_int = I915_READ(SERR_INT);
2217
Paulo Zanonide032bf2013-04-12 17:57:58 -03002218 if (serr_int & SERR_INT_POISON)
2219 DRM_ERROR("PCH poison interrupt\n");
2220
Paulo Zanoni86642812013-04-12 17:57:57 -03002221 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002222 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002223
2224 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002225 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002226
2227 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002228 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002229
2230 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002231}
2232
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002233static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002234{
Adam Jackson23e81d62012-06-06 15:45:44 -04002235 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002236 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002237
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002238 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002239
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002240 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2241 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2242 SDE_AUDIO_POWER_SHIFT_CPT);
2243 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2244 port_name(port));
2245 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002246
2247 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002248 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002249
2250 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002251 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002252
2253 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2254 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2255
2256 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2257 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2258
2259 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002260 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002261 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2262 pipe_name(pipe),
2263 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002264
2265 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002266 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002267}
2268
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002269static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002270{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002271 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2272 ~SDE_PORTE_HOTPLUG_SPT;
2273 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2274 u32 pin_mask = 0, long_mask = 0;
2275
2276 if (hotplug_trigger) {
2277 u32 dig_hotplug_reg;
2278
2279 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2280 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2281
2282 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2283 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002284 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002285 }
2286
2287 if (hotplug2_trigger) {
2288 u32 dig_hotplug_reg;
2289
2290 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2291 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2292
2293 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2294 dig_hotplug_reg, hpd_spt,
2295 spt_port_hotplug2_long_detect);
2296 }
2297
2298 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002299 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002300
2301 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002302 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002303}
2304
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002305static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2306 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002307 const u32 hpd[HPD_NUM_PINS])
2308{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002309 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2310
2311 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2312 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2313
2314 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2315 dig_hotplug_reg, hpd,
2316 ilk_port_hotplug_long_detect);
2317
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002318 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002319}
2320
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002321static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2322 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002323{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002324 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002325 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2326
Ville Syrjälä40e56412015-08-27 23:56:10 +03002327 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002328 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002329
2330 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002331 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002332
2333 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002334 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002335
Paulo Zanonic008bc62013-07-12 16:35:10 -03002336 if (de_iir & DE_POISON)
2337 DRM_ERROR("Poison interrupt\n");
2338
Damien Lespiau055e3932014-08-18 13:49:10 +01002339 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002340 if (de_iir & DE_PIPE_VBLANK(pipe))
2341 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002342
Daniel Vetter40da17c22013-10-21 18:04:36 +02002343 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002344 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002345
Daniel Vetter40da17c22013-10-21 18:04:36 +02002346 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002347 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002348 }
2349
2350 /* check event from PCH */
2351 if (de_iir & DE_PCH_EVENT) {
2352 u32 pch_iir = I915_READ(SDEIIR);
2353
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002354 if (HAS_PCH_CPT(dev_priv))
2355 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002356 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002357 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002358
2359 /* should clear PCH hotplug event before clear CPU irq */
2360 I915_WRITE(SDEIIR, pch_iir);
2361 }
2362
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002363 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2364 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002365}
2366
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002367static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2368 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002369{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002370 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002371 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2372
Ville Syrjälä40e56412015-08-27 23:56:10 +03002373 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002374 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002375
2376 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002377 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002378
2379 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002380 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002381
2382 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002383 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002384
Damien Lespiau055e3932014-08-18 13:49:10 +01002385 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002386 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2387 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002388 }
2389
2390 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002391 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002392 u32 pch_iir = I915_READ(SDEIIR);
2393
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002394 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002395
2396 /* clear PCH hotplug event before clear CPU irq */
2397 I915_WRITE(SDEIIR, pch_iir);
2398 }
2399}
2400
Oscar Mateo72c90f62014-06-16 16:10:57 +01002401/*
2402 * To handle irqs with the minimum potential races with fresh interrupts, we:
2403 * 1 - Disable Master Interrupt Control.
2404 * 2 - Find the source(s) of the interrupt.
2405 * 3 - Clear the Interrupt Identity bits (IIR).
2406 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2407 * 5 - Re-enable Master Interrupt Control.
2408 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002409static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002410{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002411 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002412 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002413 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002414 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002415
Imre Deak2dd2a882015-02-24 11:14:30 +02002416 if (!intel_irqs_enabled(dev_priv))
2417 return IRQ_NONE;
2418
Imre Deak1f814da2015-12-16 02:52:19 +02002419 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2420 disable_rpm_wakeref_asserts(dev_priv);
2421
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002422 /* disable master interrupt before clearing iir */
2423 de_ier = I915_READ(DEIER);
2424 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002425 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002426
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002427 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2428 * interrupts will will be stored on its back queue, and then we'll be
2429 * able to process them after we restore SDEIER (as soon as we restore
2430 * it, we'll get an interrupt if SDEIIR still has something to process
2431 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002432 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002433 sde_ier = I915_READ(SDEIER);
2434 I915_WRITE(SDEIER, 0);
2435 POSTING_READ(SDEIER);
2436 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002437
Oscar Mateo72c90f62014-06-16 16:10:57 +01002438 /* Find, clear, then process each source of interrupt */
2439
Chris Wilson0e434062012-05-09 21:45:44 +01002440 gt_iir = I915_READ(GTIIR);
2441 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002442 I915_WRITE(GTIIR, gt_iir);
2443 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002444 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002445 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002446 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002447 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002448 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002449
2450 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002451 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002452 I915_WRITE(DEIIR, de_iir);
2453 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002454 if (INTEL_GEN(dev_priv) >= 7)
2455 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002456 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002457 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002458 }
2459
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002460 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002461 u32 pm_iir = I915_READ(GEN6_PMIIR);
2462 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002463 I915_WRITE(GEN6_PMIIR, pm_iir);
2464 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002465 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002466 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002467 }
2468
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002469 I915_WRITE(DEIER, de_ier);
2470 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002471 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002472 I915_WRITE(SDEIER, sde_ier);
2473 POSTING_READ(SDEIER);
2474 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002475
Imre Deak1f814da2015-12-16 02:52:19 +02002476 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2477 enable_rpm_wakeref_asserts(dev_priv);
2478
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002479 return ret;
2480}
2481
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002482static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2483 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002484 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302485{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002486 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302487
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002488 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2489 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302490
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002491 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002492 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002493 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002494
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002495 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302496}
2497
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002498static irqreturn_t
2499gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002500{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002501 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002502 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002503 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002504
Ben Widawskyabd58f02013-11-02 21:07:09 -07002505 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002506 iir = I915_READ(GEN8_DE_MISC_IIR);
2507 if (iir) {
2508 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002509 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002510 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002511 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002512 else
2513 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002514 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002515 else
2516 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002517 }
2518
Daniel Vetter6d766f02013-11-07 14:49:55 +01002519 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002520 iir = I915_READ(GEN8_DE_PORT_IIR);
2521 if (iir) {
2522 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302523 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002524
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002525 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002526 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002527
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002528 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002529 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002530 tmp_mask |= GEN9_AUX_CHANNEL_B |
2531 GEN9_AUX_CHANNEL_C |
2532 GEN9_AUX_CHANNEL_D;
2533
2534 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002535 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302536 found = true;
2537 }
2538
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002539 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002540 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2541 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002542 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2543 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002544 found = true;
2545 }
2546 } else if (IS_BROADWELL(dev_priv)) {
2547 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2548 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002549 ilk_hpd_irq_handler(dev_priv,
2550 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002551 found = true;
2552 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302553 }
2554
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002555 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002556 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302557 found = true;
2558 }
2559
Shashank Sharmad04a4922014-08-22 17:40:41 +05302560 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002561 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002562 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002563 else
2564 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002565 }
2566
Damien Lespiau055e3932014-08-18 13:49:10 +01002567 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002568 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002569
Daniel Vetterc42664c2013-11-07 11:05:40 +01002570 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2571 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002572
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002573 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2574 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002575 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002576 continue;
2577 }
2578
2579 ret = IRQ_HANDLED;
2580 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2581
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002582 if (iir & GEN8_PIPE_VBLANK)
2583 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002584
2585 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002586 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002587
2588 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2589 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2590
2591 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002592 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002593 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2594 else
2595 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2596
2597 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002598 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002599 pipe_name(pipe),
2600 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002601 }
2602
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002603 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302604 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002605 /*
2606 * FIXME(BDW): Assume for now that the new interrupt handling
2607 * scheme also closed the SDE interrupt handling race we've seen
2608 * on older pch-split platforms. But this needs testing.
2609 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002610 iir = I915_READ(SDEIIR);
2611 if (iir) {
2612 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002613 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002614
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002615 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2616 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002617 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002618 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002619 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002620 } else {
2621 /*
2622 * Like on previous PCH there seems to be something
2623 * fishy going on with forwarding PCH interrupts.
2624 */
2625 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2626 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002627 }
2628
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002629 return ret;
2630}
2631
2632static irqreturn_t gen8_irq_handler(int irq, void *arg)
2633{
2634 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002635 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002636 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002637 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002638 irqreturn_t ret;
2639
2640 if (!intel_irqs_enabled(dev_priv))
2641 return IRQ_NONE;
2642
2643 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2644 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2645 if (!master_ctl)
2646 return IRQ_NONE;
2647
2648 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2649
2650 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2651 disable_rpm_wakeref_asserts(dev_priv);
2652
2653 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002654 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2655 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002656 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2657
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002658 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2659 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002660
Imre Deak1f814da2015-12-16 02:52:19 +02002661 enable_rpm_wakeref_asserts(dev_priv);
2662
Ben Widawskyabd58f02013-11-02 21:07:09 -07002663 return ret;
2664}
2665
Chris Wilson36703e72017-06-22 11:56:25 +01002666struct wedge_me {
2667 struct delayed_work work;
2668 struct drm_i915_private *i915;
2669 const char *name;
2670};
2671
2672static void wedge_me(struct work_struct *work)
2673{
2674 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2675
2676 dev_err(w->i915->drm.dev,
2677 "%s timed out, cancelling all in-flight rendering.\n",
2678 w->name);
2679 i915_gem_set_wedged(w->i915);
2680}
2681
2682static void __init_wedge(struct wedge_me *w,
2683 struct drm_i915_private *i915,
2684 long timeout,
2685 const char *name)
2686{
2687 w->i915 = i915;
2688 w->name = name;
2689
2690 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2691 schedule_delayed_work(&w->work, timeout);
2692}
2693
2694static void __fini_wedge(struct wedge_me *w)
2695{
2696 cancel_delayed_work_sync(&w->work);
2697 destroy_delayed_work_on_stack(&w->work);
2698 w->i915 = NULL;
2699}
2700
2701#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2702 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2703 (W)->i915; \
2704 __fini_wedge((W)))
2705
Jesse Barnes8a905232009-07-11 16:48:03 -04002706/**
Chris Wilsond5367302017-06-20 10:57:43 +01002707 * i915_reset_device - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002708 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002709 *
2710 * Fire an error uevent so userspace can see that a hang or error
2711 * was detected.
2712 */
Chris Wilsond5367302017-06-20 10:57:43 +01002713static void i915_reset_device(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002714{
Chris Wilson91c8a322016-07-05 10:40:23 +01002715 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002716 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2717 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2718 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002719 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002720
Chris Wilsonc0336662016-05-06 15:40:21 +01002721 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002722
Chris Wilson8af29b02016-09-09 14:11:47 +01002723 DRM_DEBUG_DRIVER("resetting chip\n");
2724 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2725
Chris Wilson36703e72017-06-22 11:56:25 +01002726 /* Use a watchdog to ensure that our reset completes */
2727 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
2728 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002729
Chris Wilson36703e72017-06-22 11:56:25 +01002730 /* Signal that locked waiters should reset the GPU */
2731 set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags);
2732 wake_up_all(&dev_priv->gpu_error.wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00002733
Chris Wilson36703e72017-06-22 11:56:25 +01002734 /* Wait for anyone holding the lock to wakeup, without
2735 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01002736 */
Chris Wilson36703e72017-06-22 11:56:25 +01002737 do {
2738 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilson535275d2017-07-21 13:32:37 +01002739 i915_reset(dev_priv, 0);
Chris Wilson36703e72017-06-22 11:56:25 +01002740 mutex_unlock(&dev_priv->drm.struct_mutex);
2741 }
2742 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2743 I915_RESET_HANDOFF,
2744 TASK_UNINTERRUPTIBLE,
2745 1));
Chris Wilson780f2622016-09-09 14:11:52 +01002746
Chris Wilson36703e72017-06-22 11:56:25 +01002747 intel_finish_reset(dev_priv);
2748 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02002749
Chris Wilson780f2622016-09-09 14:11:52 +01002750 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002751 kobject_uevent_env(kobj,
2752 KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002753}
2754
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002755static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002756{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002757 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04002758
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002759 if (!IS_GEN2(dev_priv))
2760 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04002761
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002762 if (INTEL_GEN(dev_priv) < 4)
2763 I915_WRITE(IPEIR, I915_READ(IPEIR));
2764 else
2765 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002766
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002767 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04002768 eir = I915_READ(EIR);
2769 if (eir) {
2770 /*
2771 * some errors might have become stuck,
2772 * mask them.
2773 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002774 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002775 I915_WRITE(EMR, I915_READ(EMR) | eir);
2776 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2777 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002778}
2779
2780/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002781 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002782 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002783 * @engine_mask: mask representing engines that are hung
Michel Thierry87c390b2017-01-11 20:18:08 -08002784 * @fmt: Error message format string
2785 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002786 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002787 * dump it to the syslog. Also call i915_capture_error_state() to make
2788 * sure we get a record and make it available in debugfs. Fire a uevent
2789 * so userspace knows something bad happened (should trigger collection
2790 * of a ring dump etc.).
2791 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002792void i915_handle_error(struct drm_i915_private *dev_priv,
2793 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002794 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002795{
Michel Thierry142bc7d2017-06-20 10:57:46 +01002796 struct intel_engine_cs *engine;
2797 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02002798 va_list args;
2799 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002800
Mika Kuoppala58174462014-02-25 17:11:26 +02002801 va_start(args, fmt);
2802 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2803 va_end(args);
2804
Chris Wilson1604a862017-03-14 17:18:40 +00002805 /*
2806 * In most cases it's guaranteed that we get here with an RPM
2807 * reference held, for example because there is a pending GPU
2808 * request that won't finish until the reset is done. This
2809 * isn't the case at least when we get here by doing a
2810 * simulated reset via debugfs, so get an RPM reference.
2811 */
2812 intel_runtime_pm_get(dev_priv);
2813
Chris Wilsonc0336662016-05-06 15:40:21 +01002814 i915_capture_error_state(dev_priv, engine_mask, error_msg);
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002815 i915_clear_error_registers(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002816
Michel Thierry142bc7d2017-06-20 10:57:46 +01002817 /*
2818 * Try engine reset when available. We fall back to full reset if
2819 * single reset fails.
2820 */
2821 if (intel_has_reset_engine(dev_priv)) {
2822 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02002823 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01002824 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2825 &dev_priv->gpu_error.flags))
2826 continue;
2827
Chris Wilson535275d2017-07-21 13:32:37 +01002828 if (i915_reset_engine(engine, 0) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01002829 engine_mask &= ~intel_engine_flag(engine);
2830
2831 clear_bit(I915_RESET_ENGINE + engine->id,
2832 &dev_priv->gpu_error.flags);
2833 wake_up_bit(&dev_priv->gpu_error.flags,
2834 I915_RESET_ENGINE + engine->id);
2835 }
2836 }
2837
Chris Wilson8af29b02016-09-09 14:11:47 +01002838 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00002839 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04002840
Michel Thierry142bc7d2017-06-20 10:57:46 +01002841 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01002842 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
2843 wait_event(dev_priv->gpu_error.reset_queue,
2844 !test_bit(I915_RESET_BACKOFF,
2845 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00002846 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01002847 }
Chris Wilson8af29b02016-09-09 14:11:47 +01002848
Michel Thierry142bc7d2017-06-20 10:57:46 +01002849 /* Prevent any other reset-engine attempt. */
2850 for_each_engine(engine, dev_priv, tmp) {
2851 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2852 &dev_priv->gpu_error.flags))
2853 wait_on_bit(&dev_priv->gpu_error.flags,
2854 I915_RESET_ENGINE + engine->id,
2855 TASK_UNINTERRUPTIBLE);
2856 }
2857
Chris Wilsond5367302017-06-20 10:57:43 +01002858 i915_reset_device(dev_priv);
2859
Michel Thierry142bc7d2017-06-20 10:57:46 +01002860 for_each_engine(engine, dev_priv, tmp) {
2861 clear_bit(I915_RESET_ENGINE + engine->id,
2862 &dev_priv->gpu_error.flags);
2863 }
2864
Chris Wilsond5367302017-06-20 10:57:43 +01002865 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
2866 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00002867
2868out:
2869 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002870}
2871
Keith Packard42f52ef2008-10-18 19:39:29 -07002872/* Called from drm generic code, passed 'crtc' which
2873 * we use as a pipe index
2874 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002875static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002876{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002877 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002878 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002879
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002880 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01002881 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2882 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2883
2884 return 0;
2885}
2886
2887static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
2888{
2889 struct drm_i915_private *dev_priv = to_i915(dev);
2890 unsigned long irqflags;
2891
2892 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2893 i915_enable_pipestat(dev_priv, pipe,
2894 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002895 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002896
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002897 return 0;
2898}
2899
Thierry Reding88e72712015-09-24 18:35:31 +02002900static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002901{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002902 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002903 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002904 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002905 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002906
Jesse Barnesf796cf82011-04-07 13:58:17 -07002907 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002908 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002909 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2910
2911 return 0;
2912}
2913
Thierry Reding88e72712015-09-24 18:35:31 +02002914static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002915{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002916 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002917 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002918
Ben Widawskyabd58f02013-11-02 21:07:09 -07002919 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002920 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002921 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002922
Ben Widawskyabd58f02013-11-02 21:07:09 -07002923 return 0;
2924}
2925
Keith Packard42f52ef2008-10-18 19:39:29 -07002926/* Called from drm generic code, passed 'crtc' which
2927 * we use as a pipe index
2928 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002929static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
2930{
2931 struct drm_i915_private *dev_priv = to_i915(dev);
2932 unsigned long irqflags;
2933
2934 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2935 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2936 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2937}
2938
2939static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002940{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002941 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002942 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002943
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002944 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002945 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002946 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002947 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2948}
2949
Thierry Reding88e72712015-09-24 18:35:31 +02002950static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002951{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002952 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002953 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002954 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002955 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002956
2957 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002958 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002959 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2960}
2961
Thierry Reding88e72712015-09-24 18:35:31 +02002962static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002963{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002964 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002965 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002966
Ben Widawskyabd58f02013-11-02 21:07:09 -07002967 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002968 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002969 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2970}
2971
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00002972static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03002973{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002974 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03002975 return;
2976
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03002977 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03002978
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002979 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03002980 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03002981}
Paulo Zanoni105b1222014-04-01 15:37:17 -03002982
Paulo Zanoni622364b2014-04-01 15:37:22 -03002983/*
2984 * SDEIER is also touched by the interrupt handler to work around missed PCH
2985 * interrupts. Hence we can't update it after the interrupt handler is enabled -
2986 * instead we unconditionally enable all PCH interrupt sources here, but then
2987 * only unmask them as needed with SDEIMR.
2988 *
2989 * This function needs to be called before interrupts are enabled.
2990 */
2991static void ibx_irq_pre_postinstall(struct drm_device *dev)
2992{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002993 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03002994
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002995 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03002996 return;
2997
2998 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03002999 I915_WRITE(SDEIER, 0xffffffff);
3000 POSTING_READ(SDEIER);
3001}
3002
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003003static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003004{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003005 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003006 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003007 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003008}
3009
Ville Syrjälä70591a42014-10-30 19:42:58 +02003010static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3011{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003012 if (IS_CHERRYVIEW(dev_priv))
3013 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3014 else
3015 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3016
Ville Syrjäläad22d102016-04-12 18:56:14 +03003017 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003018 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3019
Ville Syrjälä44d92412017-08-18 21:36:51 +03003020 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003021
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003022 GEN3_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003023 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003024}
3025
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003026static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3027{
3028 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003029 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003030 enum pipe pipe;
3031
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003032 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003033
3034 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3035 for_each_pipe(dev_priv, pipe)
3036 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3037
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003038 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3039 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003040 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3041 I915_LPE_PIPE_A_INTERRUPT |
3042 I915_LPE_PIPE_B_INTERRUPT;
3043
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003044 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003045 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3046 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003047
3048 WARN_ON(dev_priv->irq_mask != ~0);
3049
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003050 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003051
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003052 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003053}
3054
3055/* drm_dma.h hooks
3056*/
3057static void ironlake_irq_reset(struct drm_device *dev)
3058{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003059 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003060
Ville Syrjäläd420a502017-08-18 21:37:03 +03003061 if (IS_GEN5(dev_priv))
3062 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003063
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003064 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003065 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003066 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3067
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003068 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003069
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003070 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003071}
3072
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003073static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003074{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003075 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003076
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003077 I915_WRITE(VLV_MASTER_IER, 0);
3078 POSTING_READ(VLV_MASTER_IER);
3079
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003080 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003081
Ville Syrjäläad22d102016-04-12 18:56:14 +03003082 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003083 if (dev_priv->display_irqs_enabled)
3084 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003085 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003086}
3087
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003088static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3089{
3090 GEN8_IRQ_RESET_NDX(GT, 0);
3091 GEN8_IRQ_RESET_NDX(GT, 1);
3092 GEN8_IRQ_RESET_NDX(GT, 2);
3093 GEN8_IRQ_RESET_NDX(GT, 3);
3094}
3095
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003096static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003097{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003098 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003099 int pipe;
3100
Ben Widawskyabd58f02013-11-02 21:07:09 -07003101 I915_WRITE(GEN8_MASTER_IRQ, 0);
3102 POSTING_READ(GEN8_MASTER_IRQ);
3103
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003104 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003105
Damien Lespiau055e3932014-08-18 13:49:10 +01003106 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003107 if (intel_display_power_is_enabled(dev_priv,
3108 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003109 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003110
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003111 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3112 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3113 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003114
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003115 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003116 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003117}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003118
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003119void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003120 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003121{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003122 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003123 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003124
Daniel Vetter13321782014-09-15 14:55:29 +02003125 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003126 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3127 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3128 dev_priv->de_irq_mask[pipe],
3129 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003130 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003131}
3132
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003133void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003134 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003135{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003136 enum pipe pipe;
3137
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003138 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003139 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3140 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003141 spin_unlock_irq(&dev_priv->irq_lock);
3142
3143 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003144 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003145}
3146
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003147static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003148{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003149 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003150
3151 I915_WRITE(GEN8_MASTER_IRQ, 0);
3152 POSTING_READ(GEN8_MASTER_IRQ);
3153
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003154 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003155
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003156 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003157
Ville Syrjäläad22d102016-04-12 18:56:14 +03003158 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003159 if (dev_priv->display_irqs_enabled)
3160 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003161 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003162}
3163
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003164static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003165 const u32 hpd[HPD_NUM_PINS])
3166{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003167 struct intel_encoder *encoder;
3168 u32 enabled_irqs = 0;
3169
Chris Wilson91c8a322016-07-05 10:40:23 +01003170 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003171 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3172 enabled_irqs |= hpd[encoder->hpd_pin];
3173
3174 return enabled_irqs;
3175}
3176
Imre Deak1a56b1a2017-01-27 11:39:21 +02003177static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3178{
3179 u32 hotplug;
3180
3181 /*
3182 * Enable digital hotplug on the PCH, and configure the DP short pulse
3183 * duration to 2ms (which is the minimum in the Display Port spec).
3184 * The pulse duration bits are reserved on LPT+.
3185 */
3186 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3187 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3188 PORTC_PULSE_DURATION_MASK |
3189 PORTD_PULSE_DURATION_MASK);
3190 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3191 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3192 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3193 /*
3194 * When CPU and PCH are on the same package, port A
3195 * HPD must be enabled in both north and south.
3196 */
3197 if (HAS_PCH_LPT_LP(dev_priv))
3198 hotplug |= PORTA_HOTPLUG_ENABLE;
3199 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3200}
3201
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003202static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003203{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003204 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003205
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003206 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003207 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003208 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003209 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003210 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003211 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003212 }
3213
Daniel Vetterfee884e2013-07-04 23:35:21 +02003214 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003215
Imre Deak1a56b1a2017-01-27 11:39:21 +02003216 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003217}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003218
Imre Deak2a57d9c2017-01-27 11:39:18 +02003219static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3220{
3221 u32 hotplug;
3222
3223 /* Enable digital hotplug on the PCH */
3224 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3225 hotplug |= PORTA_HOTPLUG_ENABLE |
3226 PORTB_HOTPLUG_ENABLE |
3227 PORTC_HOTPLUG_ENABLE |
3228 PORTD_HOTPLUG_ENABLE;
3229 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3230
3231 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3232 hotplug |= PORTE_HOTPLUG_ENABLE;
3233 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3234}
3235
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003236static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003237{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003238 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003239
3240 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003241 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003242
3243 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3244
Imre Deak2a57d9c2017-01-27 11:39:18 +02003245 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003246}
3247
Imre Deak1a56b1a2017-01-27 11:39:21 +02003248static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3249{
3250 u32 hotplug;
3251
3252 /*
3253 * Enable digital hotplug on the CPU, and configure the DP short pulse
3254 * duration to 2ms (which is the minimum in the Display Port spec)
3255 * The pulse duration bits are reserved on HSW+.
3256 */
3257 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3258 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3259 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3260 DIGITAL_PORTA_PULSE_DURATION_2ms;
3261 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3262}
3263
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003264static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003265{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003266 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003267
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003268 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003269 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003270 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003271
3272 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003273 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003274 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003275 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003276
3277 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003278 } else {
3279 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003280 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003281
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003282 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3283 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003284
Imre Deak1a56b1a2017-01-27 11:39:21 +02003285 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003286
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003287 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003288}
3289
Imre Deak2a57d9c2017-01-27 11:39:18 +02003290static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3291 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003292{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003293 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003294
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003295 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003296 hotplug |= PORTA_HOTPLUG_ENABLE |
3297 PORTB_HOTPLUG_ENABLE |
3298 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303299
3300 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3301 hotplug, enabled_irqs);
3302 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3303
3304 /*
3305 * For BXT invert bit has to be set based on AOB design
3306 * for HPD detection logic, update it based on VBT fields.
3307 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303308 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3309 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3310 hotplug |= BXT_DDIA_HPD_INVERT;
3311 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3312 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3313 hotplug |= BXT_DDIB_HPD_INVERT;
3314 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3315 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3316 hotplug |= BXT_DDIC_HPD_INVERT;
3317
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003318 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003319}
3320
Imre Deak2a57d9c2017-01-27 11:39:18 +02003321static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3322{
3323 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3324}
3325
3326static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3327{
3328 u32 hotplug_irqs, enabled_irqs;
3329
3330 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3331 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3332
3333 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3334
3335 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3336}
3337
Paulo Zanonid46da432013-02-08 17:35:15 -02003338static void ibx_irq_postinstall(struct drm_device *dev)
3339{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003340 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003341 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003342
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003343 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003344 return;
3345
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003346 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003347 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003348 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003349 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003350 else
3351 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003352
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003353 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003354 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003355
3356 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3357 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003358 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003359 else
3360 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003361}
3362
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003363static void gen5_gt_irq_postinstall(struct drm_device *dev)
3364{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003365 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003366 u32 pm_irqs, gt_irqs;
3367
3368 pm_irqs = gt_irqs = 0;
3369
3370 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003371 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003372 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003373 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3374 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003375 }
3376
3377 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003378 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003379 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003380 } else {
3381 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3382 }
3383
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003384 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003385
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003386 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003387 /*
3388 * RPS interrupts will get enabled/disabled on demand when RPS
3389 * itself is enabled/disabled.
3390 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303391 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003392 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303393 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3394 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003395
Akash Goelf4e9af42016-10-12 21:54:30 +05303396 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003397 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003398 }
3399}
3400
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003401static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003402{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003403 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003404 u32 display_mask, extra_mask;
3405
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003406 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003407 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003408 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003409 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003410 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3411 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003412 } else {
3413 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003414 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3415 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003416 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3417 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3418 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003419 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003420
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003421 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003422
Paulo Zanoni622364b2014-04-01 15:37:22 -03003423 ibx_irq_pre_postinstall(dev);
3424
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003425 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003426
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003427 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003428
Imre Deak1a56b1a2017-01-27 11:39:21 +02003429 ilk_hpd_detection_setup(dev_priv);
3430
Paulo Zanonid46da432013-02-08 17:35:15 -02003431 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003432
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003433 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003434 /* Enable PCU event interrupts
3435 *
3436 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003437 * setup is guaranteed to run in single-threaded context. But we
3438 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003439 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003440 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003441 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003442 }
3443
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003444 return 0;
3445}
3446
Imre Deakf8b79e52014-03-04 19:23:07 +02003447void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3448{
Chris Wilson67520412017-03-02 13:28:01 +00003449 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003450
3451 if (dev_priv->display_irqs_enabled)
3452 return;
3453
3454 dev_priv->display_irqs_enabled = true;
3455
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003456 if (intel_irqs_enabled(dev_priv)) {
3457 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003458 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003459 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003460}
3461
3462void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3463{
Chris Wilson67520412017-03-02 13:28:01 +00003464 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003465
3466 if (!dev_priv->display_irqs_enabled)
3467 return;
3468
3469 dev_priv->display_irqs_enabled = false;
3470
Imre Deak950eaba2014-09-08 15:21:09 +03003471 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003472 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003473}
3474
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003475
3476static int valleyview_irq_postinstall(struct drm_device *dev)
3477{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003478 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003479
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003480 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003481
Ville Syrjäläad22d102016-04-12 18:56:14 +03003482 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003483 if (dev_priv->display_irqs_enabled)
3484 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003485 spin_unlock_irq(&dev_priv->irq_lock);
3486
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003487 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003488 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003489
3490 return 0;
3491}
3492
Ben Widawskyabd58f02013-11-02 21:07:09 -07003493static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3494{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003495 /* These are interrupts we'll toggle with the ring mask register */
3496 uint32_t gt_interrupts[] = {
3497 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003498 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003499 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3500 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003501 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003502 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3503 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3504 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003505 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003506 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3507 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003508 };
3509
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003510 if (HAS_L3_DPF(dev_priv))
3511 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3512
Akash Goelf4e9af42016-10-12 21:54:30 +05303513 dev_priv->pm_ier = 0x0;
3514 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303515 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3516 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003517 /*
3518 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303519 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003520 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303521 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303522 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003523}
3524
3525static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3526{
Damien Lespiau770de832014-03-20 20:45:01 +00003527 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3528 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003529 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3530 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003531 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003532 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003533
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003534 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003535 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003536 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3537 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003538 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003539 de_port_masked |= BXT_DE_PORT_GMBUS;
3540 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003541 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003542 }
Damien Lespiau770de832014-03-20 20:45:01 +00003543
3544 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3545 GEN8_PIPE_FIFO_UNDERRUN;
3546
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003547 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003548 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003549 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3550 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003551 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3552
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003553 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3554 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3555 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003556
Damien Lespiau055e3932014-08-18 13:49:10 +01003557 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003558 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003559 POWER_DOMAIN_PIPE(pipe)))
3560 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3561 dev_priv->de_irq_mask[pipe],
3562 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003563
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003564 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3565 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003566
3567 if (IS_GEN9_LP(dev_priv))
3568 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003569 else if (IS_BROADWELL(dev_priv))
3570 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003571}
3572
3573static int gen8_irq_postinstall(struct drm_device *dev)
3574{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003575 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003576
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003577 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303578 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003579
Ben Widawskyabd58f02013-11-02 21:07:09 -07003580 gen8_gt_irq_postinstall(dev_priv);
3581 gen8_de_irq_postinstall(dev_priv);
3582
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003583 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303584 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003585
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003586 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003587 POSTING_READ(GEN8_MASTER_IRQ);
3588
3589 return 0;
3590}
3591
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003592static int cherryview_irq_postinstall(struct drm_device *dev)
3593{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003594 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003595
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003596 gen8_gt_irq_postinstall(dev_priv);
3597
Ville Syrjäläad22d102016-04-12 18:56:14 +03003598 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003599 if (dev_priv->display_irqs_enabled)
3600 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003601 spin_unlock_irq(&dev_priv->irq_lock);
3602
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003603 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003604 POSTING_READ(GEN8_MASTER_IRQ);
3605
3606 return 0;
3607}
3608
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003609static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003610{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003611 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003612
Ville Syrjälä44d92412017-08-18 21:36:51 +03003613 i9xx_pipestat_irq_reset(dev_priv);
3614
Ville Syrjäläd420a502017-08-18 21:37:03 +03003615 I915_WRITE16(HWSTAM, 0xffff);
3616
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003617 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01003618}
3619
3620static int i8xx_irq_postinstall(struct drm_device *dev)
3621{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003622 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003623 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003624
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003625 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
3626 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01003627
3628 /* Unmask the interrupts that we always want on. */
3629 dev_priv->irq_mask =
3630 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003631 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003632
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003633 enable_mask =
3634 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3635 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3636 I915_USER_INTERRUPT;
3637
3638 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003639
Daniel Vetter379ef822013-10-16 22:55:56 +02003640 /* Interrupt setup is already guaranteed to be single-threaded, this is
3641 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003642 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003643 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3644 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003645 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003646
Chris Wilsonc2798b12012-04-22 21:13:57 +01003647 return 0;
3648}
3649
Daniel Vetterff1f5252012-10-02 15:10:55 +02003650static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003651{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003652 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003653 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003654 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003655
Imre Deak2dd2a882015-02-24 11:14:30 +02003656 if (!intel_irqs_enabled(dev_priv))
3657 return IRQ_NONE;
3658
Imre Deak1f814da2015-12-16 02:52:19 +02003659 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3660 disable_rpm_wakeref_asserts(dev_priv);
3661
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003662 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003663 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003664 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03003665
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003666 iir = I915_READ16(IIR);
3667 if (iir == 0)
3668 break;
3669
3670 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003671
Ville Syrjäläeb643432017-08-18 21:36:59 +03003672 /* Call regardless, as some status bits might not be
3673 * signalled in iir */
3674 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003675
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003676 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003677
Chris Wilsonc2798b12012-04-22 21:13:57 +01003678 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303679 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003680
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003681 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3682 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3683
Ville Syrjäläeb643432017-08-18 21:36:59 +03003684 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003685 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003686
Imre Deak1f814da2015-12-16 02:52:19 +02003687 enable_rpm_wakeref_asserts(dev_priv);
3688
3689 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003690}
3691
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003692static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003693{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003694 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003695
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003696 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003697 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003698 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3699 }
3700
Ville Syrjälä44d92412017-08-18 21:36:51 +03003701 i9xx_pipestat_irq_reset(dev_priv);
3702
Ville Syrjäläd420a502017-08-18 21:37:03 +03003703 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003704
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003705 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003706}
3707
3708static int i915_irq_postinstall(struct drm_device *dev)
3709{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003710 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01003711 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003712
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003713 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
3714 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01003715
3716 /* Unmask the interrupts that we always want on. */
3717 dev_priv->irq_mask =
3718 ~(I915_ASLE_INTERRUPT |
3719 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003720 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003721
3722 enable_mask =
3723 I915_ASLE_INTERRUPT |
3724 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3725 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003726 I915_USER_INTERRUPT;
3727
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003728 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003729 /* Enable in IER... */
3730 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3731 /* and unmask in IMR */
3732 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3733 }
3734
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003735 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003736
Daniel Vetter379ef822013-10-16 22:55:56 +02003737 /* Interrupt setup is already guaranteed to be single-threaded, this is
3738 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003739 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003740 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3741 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003742 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003743
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003744 i915_enable_asle_pipestat(dev_priv);
3745
Daniel Vetter20afbda2012-12-11 14:05:07 +01003746 return 0;
3747}
3748
Daniel Vetterff1f5252012-10-02 15:10:55 +02003749static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003750{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003751 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003752 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003753 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003754
Imre Deak2dd2a882015-02-24 11:14:30 +02003755 if (!intel_irqs_enabled(dev_priv))
3756 return IRQ_NONE;
3757
Imre Deak1f814da2015-12-16 02:52:19 +02003758 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3759 disable_rpm_wakeref_asserts(dev_priv);
3760
Chris Wilson38bde182012-04-24 22:59:50 +01003761 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003762 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003763 u32 hotplug_status = 0;
3764 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003765
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003766 iir = I915_READ(IIR);
3767 if (iir == 0)
3768 break;
3769
3770 ret = IRQ_HANDLED;
3771
3772 if (I915_HAS_HOTPLUG(dev_priv) &&
3773 iir & I915_DISPLAY_PORT_INTERRUPT)
3774 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003775
Ville Syrjäläeb643432017-08-18 21:36:59 +03003776 /* Call regardless, as some status bits might not be
3777 * signalled in iir */
3778 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003779
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003780 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003781
Chris Wilsona266c7d2012-04-24 22:59:44 +01003782 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303783 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003784
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003785 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3786 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003787
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003788 if (hotplug_status)
3789 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3790
3791 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3792 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003793
Imre Deak1f814da2015-12-16 02:52:19 +02003794 enable_rpm_wakeref_asserts(dev_priv);
3795
Chris Wilsona266c7d2012-04-24 22:59:44 +01003796 return ret;
3797}
3798
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003799static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003800{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003801 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003802
Egbert Eich0706f172015-09-23 16:15:27 +02003803 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01003804 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003805
Ville Syrjälä44d92412017-08-18 21:36:51 +03003806 i9xx_pipestat_irq_reset(dev_priv);
3807
Ville Syrjäläd420a502017-08-18 21:37:03 +03003808 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003809
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003810 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003811}
3812
3813static int i965_irq_postinstall(struct drm_device *dev)
3814{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003815 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003816 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003817 u32 error_mask;
3818
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003819 /*
3820 * Enable some error detection, note the instruction error mask
3821 * bit is reserved, so we leave it masked.
3822 */
3823 if (IS_G4X(dev_priv)) {
3824 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3825 GM45_ERROR_MEM_PRIV |
3826 GM45_ERROR_CP_PRIV |
3827 I915_ERROR_MEMORY_REFRESH);
3828 } else {
3829 error_mask = ~(I915_ERROR_PAGE_TABLE |
3830 I915_ERROR_MEMORY_REFRESH);
3831 }
3832 I915_WRITE(EMR, error_mask);
3833
Chris Wilsona266c7d2012-04-24 22:59:44 +01003834 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003835 dev_priv->irq_mask =
3836 ~(I915_ASLE_INTERRUPT |
3837 I915_DISPLAY_PORT_INTERRUPT |
3838 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3839 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3840 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003841
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003842 enable_mask =
3843 I915_ASLE_INTERRUPT |
3844 I915_DISPLAY_PORT_INTERRUPT |
3845 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3846 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3847 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3848 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003849
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003850 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003851 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003852
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003853 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
3854
Daniel Vetterb79480b2013-06-27 17:52:10 +02003855 /* Interrupt setup is already guaranteed to be single-threaded, this is
3856 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003857 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003858 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3859 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3860 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003861 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003862
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003863 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003864
3865 return 0;
3866}
3867
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003868static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003869{
Daniel Vetter20afbda2012-12-11 14:05:07 +01003870 u32 hotplug_en;
3871
Chris Wilson67520412017-03-02 13:28:01 +00003872 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003873
Ville Syrjälä778eb332015-01-09 14:21:13 +02003874 /* Note HDMI and DP share hotplug bits */
3875 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003876 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02003877 /* Programming the CRT detection parameters tends
3878 to generate a spurious hotplug event about three
3879 seconds later. So just do it once.
3880 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003881 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02003882 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02003883 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003884
Ville Syrjälä778eb332015-01-09 14:21:13 +02003885 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02003886 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03003887 HOTPLUG_INT_EN_MASK |
3888 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
3889 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
3890 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003891}
3892
Daniel Vetterff1f5252012-10-02 15:10:55 +02003893static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003894{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003895 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003896 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003897 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003898
Imre Deak2dd2a882015-02-24 11:14:30 +02003899 if (!intel_irqs_enabled(dev_priv))
3900 return IRQ_NONE;
3901
Imre Deak1f814da2015-12-16 02:52:19 +02003902 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3903 disable_rpm_wakeref_asserts(dev_priv);
3904
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003905 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003906 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003907 u32 hotplug_status = 0;
3908 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003909
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003910 iir = I915_READ(IIR);
3911 if (iir == 0)
3912 break;
3913
3914 ret = IRQ_HANDLED;
3915
3916 if (iir & I915_DISPLAY_PORT_INTERRUPT)
3917 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003918
Ville Syrjäläeb643432017-08-18 21:36:59 +03003919 /* Call regardless, as some status bits might not be
3920 * signalled in iir */
3921 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003922
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003923 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003924
Chris Wilsona266c7d2012-04-24 22:59:44 +01003925 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303926 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003927
Chris Wilsona266c7d2012-04-24 22:59:44 +01003928 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303929 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003930
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003931 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3932 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003933
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003934 if (hotplug_status)
3935 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3936
3937 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3938 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003939
Imre Deak1f814da2015-12-16 02:52:19 +02003940 enable_rpm_wakeref_asserts(dev_priv);
3941
Chris Wilsona266c7d2012-04-24 22:59:44 +01003942 return ret;
3943}
3944
Daniel Vetterfca52a52014-09-30 10:56:45 +02003945/**
3946 * intel_irq_init - initializes irq support
3947 * @dev_priv: i915 device instance
3948 *
3949 * This function initializes all the irq support including work items, timers
3950 * and all the vtables. It does not setup the interrupt itself though.
3951 */
Daniel Vetterb9632912014-09-30 10:56:44 +02003952void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003953{
Chris Wilson91c8a322016-07-05 10:40:23 +01003954 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003955 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01003956
Jani Nikula77913b32015-06-18 13:06:16 +03003957 intel_hpd_init_work(dev_priv);
3958
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003959 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003960
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003961 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003962 for (i = 0; i < MAX_L3_SLICES; ++i)
3963 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01003964
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00003965 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303966 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
3967
Deepak Sa6706b42014-03-15 20:23:22 +05303968 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08003969 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03003970 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00003971 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04003972 else
3973 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05303974
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05303975 dev_priv->rps.pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303976
3977 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03003978 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303979 * if GEN6_PM_UP_EI_EXPIRED is masked.
3980 *
3981 * TODO: verify if this can be reproduced on VLV,CHV.
3982 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003983 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05303984 dev_priv->rps.pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303985
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003986 if (INTEL_GEN(dev_priv) >= 8)
Chris Wilson655d49e2017-03-12 13:27:45 +00003987 dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303988
Daniel Vetterb9632912014-09-30 10:56:44 +02003989 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07003990 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03003991 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003992 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003993 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03003994 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03003995 } else {
3996 dev->driver->get_vblank_counter = i915_get_vblank_counter;
3997 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003998 }
3999
Ville Syrjälä21da2702014-08-06 14:49:55 +03004000 /*
4001 * Opt out of the vblank disable timer on everything except gen2.
4002 * Gen2 doesn't have a hardware frame counter and so depends on
4003 * vblank interrupts to produce sane vblank seuquence numbers.
4004 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004005 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004006 dev->vblank_disable_immediate = true;
4007
Chris Wilson262fd482017-02-15 13:15:47 +00004008 /* Most platforms treat the display irq block as an always-on
4009 * power domain. vlv/chv can disable it at runtime and need
4010 * special care to avoid writing any of the display block registers
4011 * outside of the power domain. We defer setting up the display irqs
4012 * in this case to the runtime pm.
4013 */
4014 dev_priv->display_irqs_enabled = true;
4015 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4016 dev_priv->display_irqs_enabled = false;
4017
Lyude317eaa92017-02-03 21:18:25 -05004018 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4019
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004020 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004021 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004022
Daniel Vetterb9632912014-09-30 10:56:44 +02004023 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004024 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004025 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004026 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004027 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004028 dev->driver->enable_vblank = i965_enable_vblank;
4029 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004030 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004031 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004032 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004033 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004034 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004035 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004036 dev->driver->enable_vblank = i965_enable_vblank;
4037 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004038 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004039 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004040 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004041 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004042 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004043 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004044 dev->driver->enable_vblank = gen8_enable_vblank;
4045 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004046 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004047 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004048 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4049 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004050 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4051 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004052 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004053 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004054 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004055 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004056 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004057 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004058 dev->driver->enable_vblank = ironlake_enable_vblank;
4059 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004060 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004061 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004062 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004063 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004064 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4065 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004066 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004067 dev->driver->enable_vblank = i8xx_enable_vblank;
4068 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004069 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004070 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004071 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004072 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004073 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004074 dev->driver->enable_vblank = i8xx_enable_vblank;
4075 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004076 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004077 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004078 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004079 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004080 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004081 dev->driver->enable_vblank = i965_enable_vblank;
4082 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004083 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004084 if (I915_HAS_HOTPLUG(dev_priv))
4085 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004086 }
4087}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004088
Daniel Vetterfca52a52014-09-30 10:56:45 +02004089/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004090 * intel_irq_fini - deinitializes IRQ support
4091 * @i915: i915 device instance
4092 *
4093 * This function deinitializes all the IRQ support.
4094 */
4095void intel_irq_fini(struct drm_i915_private *i915)
4096{
4097 int i;
4098
4099 for (i = 0; i < MAX_L3_SLICES; ++i)
4100 kfree(i915->l3_parity.remap_info[i]);
4101}
4102
4103/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004104 * intel_irq_install - enables the hardware interrupt
4105 * @dev_priv: i915 device instance
4106 *
4107 * This function enables the hardware interrupt handling, but leaves the hotplug
4108 * handling still disabled. It is called after intel_irq_init().
4109 *
4110 * In the driver load and resume code we need working interrupts in a few places
4111 * but don't want to deal with the hassle of concurrent probe and hotplug
4112 * workers. Hence the split into this two-stage approach.
4113 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004114int intel_irq_install(struct drm_i915_private *dev_priv)
4115{
4116 /*
4117 * We enable some interrupt sources in our postinstall hooks, so mark
4118 * interrupts as enabled _before_ actually enabling them to avoid
4119 * special cases in our ordering checks.
4120 */
4121 dev_priv->pm.irqs_enabled = true;
4122
Chris Wilson91c8a322016-07-05 10:40:23 +01004123 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004124}
4125
Daniel Vetterfca52a52014-09-30 10:56:45 +02004126/**
4127 * intel_irq_uninstall - finilizes all irq handling
4128 * @dev_priv: i915 device instance
4129 *
4130 * This stops interrupt and hotplug handling and unregisters and frees all
4131 * resources acquired in the init functions.
4132 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004133void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4134{
Chris Wilson91c8a322016-07-05 10:40:23 +01004135 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004136 intel_hpd_cancel_work(dev_priv);
4137 dev_priv->pm.irqs_enabled = false;
4138}
4139
Daniel Vetterfca52a52014-09-30 10:56:45 +02004140/**
4141 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4142 * @dev_priv: i915 device instance
4143 *
4144 * This function is used to disable interrupts at runtime, both in the runtime
4145 * pm and the system suspend/resume code.
4146 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004147void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004148{
Chris Wilson91c8a322016-07-05 10:40:23 +01004149 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004150 dev_priv->pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004151 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004152}
4153
Daniel Vetterfca52a52014-09-30 10:56:45 +02004154/**
4155 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4156 * @dev_priv: i915 device instance
4157 *
4158 * This function is used to enable interrupts at runtime, both in the runtime
4159 * pm and the system suspend/resume code.
4160 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004161void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004162{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004163 dev_priv->pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004164 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4165 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004166}