blob: 44eef355e12c148557e66deae9b0d25f7d80d117 [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);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100407 dev_priv->gt_pm.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{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100413 struct intel_rps *rps = &dev_priv->gt_pm.rps;
414
415 if (READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100416 return;
417
Mika Kuoppala51951ae2018-02-28 12:11:53 +0200418 if (WARN_ON_ONCE(IS_GEN11(dev_priv)))
419 return;
420
Imre Deakb900b942014-11-05 20:48:48 +0200421 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100422 WARN_ON_ONCE(rps->pm_iir);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100423 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100424 rps->interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200425 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200426
Imre Deakb900b942014-11-05 20:48:48 +0200427 spin_unlock_irq(&dev_priv->irq_lock);
428}
429
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100430void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200431{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100432 struct intel_rps *rps = &dev_priv->gt_pm.rps;
433
434 if (!READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100435 return;
436
Mika Kuoppala51951ae2018-02-28 12:11:53 +0200437 if (WARN_ON_ONCE(IS_GEN11(dev_priv)))
438 return;
439
Imre Deakd4d70aa2014-11-19 15:30:04 +0200440 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100441 rps->interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200442
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100443 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200444
Akash Goelf4e9af42016-10-12 21:54:30 +0530445 gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200446
447 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100448 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100449
450 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700451 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100452 * we will reset the GPU to minimum frequencies, so the current
453 * state of the worker can be discarded.
454 */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100455 cancel_work_sync(&rps->work);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100456 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200457}
458
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530459void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
460{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530461 assert_rpm_wakelock_held(dev_priv);
462
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530463 spin_lock_irq(&dev_priv->irq_lock);
464 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
465 spin_unlock_irq(&dev_priv->irq_lock);
466}
467
468void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
469{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530470 assert_rpm_wakelock_held(dev_priv);
471
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530472 spin_lock_irq(&dev_priv->irq_lock);
473 if (!dev_priv->guc.interrupts_enabled) {
474 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
475 dev_priv->pm_guc_events);
476 dev_priv->guc.interrupts_enabled = true;
477 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
478 }
479 spin_unlock_irq(&dev_priv->irq_lock);
480}
481
482void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
483{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530484 assert_rpm_wakelock_held(dev_priv);
485
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530486 spin_lock_irq(&dev_priv->irq_lock);
487 dev_priv->guc.interrupts_enabled = false;
488
489 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
490
491 spin_unlock_irq(&dev_priv->irq_lock);
492 synchronize_irq(dev_priv->drm.irq);
493
494 gen9_reset_guc_interrupts(dev_priv);
495}
496
Ben Widawsky09610212014-05-15 20:58:08 +0300497/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200498 * bdw_update_port_irq - update DE port interrupt
499 * @dev_priv: driver private
500 * @interrupt_mask: mask of interrupt bits to update
501 * @enabled_irq_mask: mask of interrupt bits to enable
502 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300503static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
504 uint32_t interrupt_mask,
505 uint32_t enabled_irq_mask)
506{
507 uint32_t new_val;
508 uint32_t old_val;
509
Chris Wilson67520412017-03-02 13:28:01 +0000510 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300511
512 WARN_ON(enabled_irq_mask & ~interrupt_mask);
513
514 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
515 return;
516
517 old_val = I915_READ(GEN8_DE_PORT_IMR);
518
519 new_val = old_val;
520 new_val &= ~interrupt_mask;
521 new_val |= (~enabled_irq_mask & interrupt_mask);
522
523 if (new_val != old_val) {
524 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
525 POSTING_READ(GEN8_DE_PORT_IMR);
526 }
527}
528
529/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200530 * bdw_update_pipe_irq - update DE pipe interrupt
531 * @dev_priv: driver private
532 * @pipe: pipe whose interrupt to update
533 * @interrupt_mask: mask of interrupt bits to update
534 * @enabled_irq_mask: mask of interrupt bits to enable
535 */
536void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
537 enum pipe pipe,
538 uint32_t interrupt_mask,
539 uint32_t enabled_irq_mask)
540{
541 uint32_t new_val;
542
Chris Wilson67520412017-03-02 13:28:01 +0000543 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200544
545 WARN_ON(enabled_irq_mask & ~interrupt_mask);
546
547 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
548 return;
549
550 new_val = dev_priv->de_irq_mask[pipe];
551 new_val &= ~interrupt_mask;
552 new_val |= (~enabled_irq_mask & interrupt_mask);
553
554 if (new_val != dev_priv->de_irq_mask[pipe]) {
555 dev_priv->de_irq_mask[pipe] = new_val;
556 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
557 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
558 }
559}
560
561/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200562 * ibx_display_interrupt_update - update SDEIMR
563 * @dev_priv: driver private
564 * @interrupt_mask: mask of interrupt bits to update
565 * @enabled_irq_mask: mask of interrupt bits to enable
566 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200567void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
568 uint32_t interrupt_mask,
569 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200570{
571 uint32_t sdeimr = I915_READ(SDEIMR);
572 sdeimr &= ~interrupt_mask;
573 sdeimr |= (~enabled_irq_mask & interrupt_mask);
574
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100575 WARN_ON(enabled_irq_mask & ~interrupt_mask);
576
Chris Wilson67520412017-03-02 13:28:01 +0000577 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200578
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700579 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300580 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300581
Daniel Vetterfee884e2013-07-04 23:35:21 +0200582 I915_WRITE(SDEIMR, sdeimr);
583 POSTING_READ(SDEIMR);
584}
Paulo Zanoni86642812013-04-12 17:57:57 -0300585
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300586u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
587 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800588{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300589 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200590 u32 enable_mask = status_mask << 16;
591
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300592 lockdep_assert_held(&dev_priv->irq_lock);
593
594 if (INTEL_GEN(dev_priv) < 5)
595 goto out;
596
Imre Deak10c59c52014-02-10 18:42:48 +0200597 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300598 * On pipe A we don't support the PSR interrupt yet,
599 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200600 */
601 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
602 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300603 /*
604 * On pipe B and C we don't support the PSR interrupt yet, on pipe
605 * A the same bit is for perf counters which we don't use either.
606 */
607 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
608 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200609
610 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
611 SPRITE0_FLIP_DONE_INT_EN_VLV |
612 SPRITE1_FLIP_DONE_INT_EN_VLV);
613 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
614 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
615 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
616 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
617
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300618out:
619 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
620 status_mask & ~PIPESTAT_INT_STATUS_MASK,
621 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
622 pipe_name(pipe), enable_mask, status_mask);
623
Imre Deak10c59c52014-02-10 18:42:48 +0200624 return enable_mask;
625}
626
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300627void i915_enable_pipestat(struct drm_i915_private *dev_priv,
628 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200629{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300630 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200631 u32 enable_mask;
632
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300633 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
634 "pipe %c: status_mask=0x%x\n",
635 pipe_name(pipe), status_mask);
636
637 lockdep_assert_held(&dev_priv->irq_lock);
638 WARN_ON(!intel_irqs_enabled(dev_priv));
639
640 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
641 return;
642
643 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
644 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
645
646 I915_WRITE(reg, enable_mask | status_mask);
647 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200648}
649
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300650void i915_disable_pipestat(struct drm_i915_private *dev_priv,
651 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200652{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300653 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200654 u32 enable_mask;
655
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300656 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
657 "pipe %c: status_mask=0x%x\n",
658 pipe_name(pipe), status_mask);
659
660 lockdep_assert_held(&dev_priv->irq_lock);
661 WARN_ON(!intel_irqs_enabled(dev_priv));
662
663 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
664 return;
665
666 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
667 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
668
669 I915_WRITE(reg, enable_mask | status_mask);
670 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200671}
672
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000673/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300674 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100675 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000676 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100677static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000678{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100679 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300680 return;
681
Daniel Vetter13321782014-09-15 14:55:29 +0200682 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000683
Imre Deak755e9012014-02-10 18:42:47 +0200684 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100685 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200686 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200687 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000688
Daniel Vetter13321782014-09-15 14:55:29 +0200689 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000690}
691
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300692/*
693 * This timing diagram depicts the video signal in and
694 * around the vertical blanking period.
695 *
696 * Assumptions about the fictitious mode used in this example:
697 * vblank_start >= 3
698 * vsync_start = vblank_start + 1
699 * vsync_end = vblank_start + 2
700 * vtotal = vblank_start + 3
701 *
702 * start of vblank:
703 * latch double buffered registers
704 * increment frame counter (ctg+)
705 * generate start of vblank interrupt (gen4+)
706 * |
707 * | frame start:
708 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
709 * | may be shifted forward 1-3 extra lines via PIPECONF
710 * | |
711 * | | start of vsync:
712 * | | generate vsync interrupt
713 * | | |
714 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
715 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
716 * ----va---> <-----------------vb--------------------> <--------va-------------
717 * | | <----vs-----> |
718 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
719 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
720 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
721 * | | |
722 * last visible pixel first visible pixel
723 * | increment frame counter (gen3/4)
724 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
725 *
726 * x = horizontal active
727 * _ = horizontal blanking
728 * hs = horizontal sync
729 * va = vertical active
730 * vb = vertical blanking
731 * vs = vertical sync
732 * vbs = vblank_start (number)
733 *
734 * Summary:
735 * - most events happen at the start of horizontal sync
736 * - frame start happens at the start of horizontal blank, 1-4 lines
737 * (depending on PIPECONF settings) after the start of vblank
738 * - gen3/4 pixel and frame counter are synchronized with the start
739 * of horizontal active on the first line of vertical active
740 */
741
Keith Packard42f52ef2008-10-18 19:39:29 -0700742/* Called from drm generic code, passed a 'crtc', which
743 * we use as a pipe index
744 */
Thierry Reding88e72712015-09-24 18:35:31 +0200745static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700746{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100747 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200748 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300749 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200750 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200751 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700752
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100753 htotal = mode->crtc_htotal;
754 hsync_start = mode->crtc_hsync_start;
755 vbl_start = mode->crtc_vblank_start;
756 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
757 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300758
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300759 /* Convert to pixel count */
760 vbl_start *= htotal;
761
762 /* Start of vblank event occurs at start of hsync */
763 vbl_start -= htotal - hsync_start;
764
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800765 high_frame = PIPEFRAME(pipe);
766 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100767
Ville Syrjälä694e4092017-03-09 17:44:30 +0200768 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
769
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700770 /*
771 * High & low register fields aren't synchronized, so make sure
772 * we get a low value that's stable across two reads of the high
773 * register.
774 */
775 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200776 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
777 low = I915_READ_FW(low_frame);
778 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700779 } while (high1 != high2);
780
Ville Syrjälä694e4092017-03-09 17:44:30 +0200781 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
782
Chris Wilson5eddb702010-09-11 13:48:45 +0100783 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300784 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100785 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300786
787 /*
788 * The frame counter increments at beginning of active.
789 * Cook up a vblank counter by also checking the pixel
790 * counter against vblank start.
791 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200792 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700793}
794
Dave Airlie974e59b2015-10-30 09:45:33 +1000795static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800796{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100797 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800798
Ville Syrjälä649636e2015-09-22 19:50:01 +0300799 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800800}
801
Uma Shankaraec02462017-09-25 19:26:01 +0530802/*
803 * On certain encoders on certain platforms, pipe
804 * scanline register will not work to get the scanline,
805 * since the timings are driven from the PORT or issues
806 * with scanline register updates.
807 * This function will use Framestamp and current
808 * timestamp registers to calculate the scanline.
809 */
810static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
811{
812 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
813 struct drm_vblank_crtc *vblank =
814 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
815 const struct drm_display_mode *mode = &vblank->hwmode;
816 u32 vblank_start = mode->crtc_vblank_start;
817 u32 vtotal = mode->crtc_vtotal;
818 u32 htotal = mode->crtc_htotal;
819 u32 clock = mode->crtc_clock;
820 u32 scanline, scan_prev_time, scan_curr_time, scan_post_time;
821
822 /*
823 * To avoid the race condition where we might cross into the
824 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
825 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
826 * during the same frame.
827 */
828 do {
829 /*
830 * This field provides read back of the display
831 * pipe frame time stamp. The time stamp value
832 * is sampled at every start of vertical blank.
833 */
834 scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
835
836 /*
837 * The TIMESTAMP_CTR register has the current
838 * time stamp value.
839 */
840 scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR);
841
842 scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
843 } while (scan_post_time != scan_prev_time);
844
845 scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
846 clock), 1000 * htotal);
847 scanline = min(scanline, vtotal - 1);
848 scanline = (scanline + vblank_start) % vtotal;
849
850 return scanline;
851}
852
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300853/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300854static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
855{
856 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100857 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200858 const struct drm_display_mode *mode;
859 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300860 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300861 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300862
Ville Syrjälä72259532017-03-02 19:15:05 +0200863 if (!crtc->active)
864 return -1;
865
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200866 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
867 mode = &vblank->hwmode;
868
Uma Shankaraec02462017-09-25 19:26:01 +0530869 if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
870 return __intel_get_crtc_scanline_from_timestamp(crtc);
871
Ville Syrjälä80715b22014-05-15 20:23:23 +0300872 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300873 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
874 vtotal /= 2;
875
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100876 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300877 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300878 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300879 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300880
881 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700882 * On HSW, the DSL reg (0x70000) appears to return 0 if we
883 * read it just before the start of vblank. So try it again
884 * so we don't accidentally end up spanning a vblank frame
885 * increment, causing the pipe_update_end() code to squak at us.
886 *
887 * The nature of this problem means we can't simply check the ISR
888 * bit and return the vblank start value; nor can we use the scanline
889 * debug register in the transcoder as it appears to have the same
890 * problem. We may need to extend this to include other platforms,
891 * but so far testing only shows the problem on HSW.
892 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100893 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700894 int i, temp;
895
896 for (i = 0; i < 100; i++) {
897 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200898 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700899 if (temp != position) {
900 position = temp;
901 break;
902 }
903 }
904 }
905
906 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300907 * See update_scanline_offset() for the details on the
908 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300909 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300910 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300911}
912
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200913static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
914 bool in_vblank_irq, int *vpos, int *hpos,
915 ktime_t *stime, ktime_t *etime,
916 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100917{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100918 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200919 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
920 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300921 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300922 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100923 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100924
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200925 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100926 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800927 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200928 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100929 }
930
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300931 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300932 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300933 vtotal = mode->crtc_vtotal;
934 vbl_start = mode->crtc_vblank_start;
935 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100936
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200937 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
938 vbl_start = DIV_ROUND_UP(vbl_start, 2);
939 vbl_end /= 2;
940 vtotal /= 2;
941 }
942
Mario Kleinerad3543e2013-10-30 05:13:08 +0100943 /*
944 * Lock uncore.lock, as we will do multiple timing critical raw
945 * register reads, potentially with preemption disabled, so the
946 * following code must not block on uncore.lock.
947 */
948 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300949
Mario Kleinerad3543e2013-10-30 05:13:08 +0100950 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
951
952 /* Get optional system timestamp before query. */
953 if (stime)
954 *stime = ktime_get();
955
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100956 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100957 /* No obvious pixelcount register. Only query vertical
958 * scanout position from Display scan line register.
959 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300960 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100961 } else {
962 /* Have access to pixelcount since start of frame.
963 * We can split this into vertical and horizontal
964 * scanout position.
965 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300966 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100967
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300968 /* convert to pixel counts */
969 vbl_start *= htotal;
970 vbl_end *= htotal;
971 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300972
973 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300974 * In interlaced modes, the pixel counter counts all pixels,
975 * so one field will have htotal more pixels. In order to avoid
976 * the reported position from jumping backwards when the pixel
977 * counter is beyond the length of the shorter field, just
978 * clamp the position the length of the shorter field. This
979 * matches how the scanline counter based position works since
980 * the scanline counter doesn't count the two half lines.
981 */
982 if (position >= vtotal)
983 position = vtotal - 1;
984
985 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300986 * Start of vblank interrupt is triggered at start of hsync,
987 * just prior to the first active line of vblank. However we
988 * consider lines to start at the leading edge of horizontal
989 * active. So, should we get here before we've crossed into
990 * the horizontal active of the first line in vblank, we would
991 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
992 * always add htotal-hsync_start to the current pixel position.
993 */
994 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300995 }
996
Mario Kleinerad3543e2013-10-30 05:13:08 +0100997 /* Get optional system timestamp after query. */
998 if (etime)
999 *etime = ktime_get();
1000
1001 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1002
1003 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1004
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001005 /*
1006 * While in vblank, position will be negative
1007 * counting up towards 0 at vbl_end. And outside
1008 * vblank, position will be positive counting
1009 * up since vbl_end.
1010 */
1011 if (position >= vbl_start)
1012 position -= vbl_end;
1013 else
1014 position += vtotal - vbl_end;
1015
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001016 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001017 *vpos = position;
1018 *hpos = 0;
1019 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001020 *vpos = position / htotal;
1021 *hpos = position - (*vpos * htotal);
1022 }
1023
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001024 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001025}
1026
Ville Syrjäläa225f072014-04-29 13:35:45 +03001027int intel_get_crtc_scanline(struct intel_crtc *crtc)
1028{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001029 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +03001030 unsigned long irqflags;
1031 int position;
1032
1033 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1034 position = __intel_get_crtc_scanline(crtc);
1035 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1036
1037 return position;
1038}
1039
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001040static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001041{
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001042 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001043 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001044
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001045 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001046
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001047 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1048
Daniel Vetter20e4d402012-08-08 23:35:39 +02001049 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001050
Jesse Barnes7648fa92010-05-20 14:28:11 -07001051 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001052 busy_up = I915_READ(RCPREVBSYTUPAVG);
1053 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001054 max_avg = I915_READ(RCBMAXAVG);
1055 min_avg = I915_READ(RCBMINAVG);
1056
1057 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001058 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001059 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1060 new_delay = dev_priv->ips.cur_delay - 1;
1061 if (new_delay < dev_priv->ips.max_delay)
1062 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001063 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001064 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1065 new_delay = dev_priv->ips.cur_delay + 1;
1066 if (new_delay > dev_priv->ips.min_delay)
1067 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001068 }
1069
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001070 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001071 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001072
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001073 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001074
Jesse Barnesf97108d2010-01-29 11:27:07 -08001075 return;
1076}
1077
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001078static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001079{
Chris Wilsone61e0f52018-02-21 09:56:36 +00001080 struct i915_request *rq = NULL;
Chris Wilson56299fb2017-02-27 20:58:48 +00001081 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001082
Chris Wilsonbcbd5c32017-10-25 15:39:42 +01001083 if (!engine->breadcrumbs.irq_armed)
1084 return;
1085
Chris Wilson2246bea2017-02-17 15:13:00 +00001086 atomic_inc(&engine->irq_count);
Chris Wilson538b2572017-01-24 15:18:05 +00001087 set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson56299fb2017-02-27 20:58:48 +00001088
Chris Wilson61d3dc72017-03-03 19:08:24 +00001089 spin_lock(&engine->breadcrumbs.irq_lock);
1090 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001091 if (wait) {
Chris Wilson17b51ad2017-09-18 17:27:33 +01001092 bool wakeup = engine->irq_seqno_barrier;
1093
Chris Wilson56299fb2017-02-27 20:58:48 +00001094 /* We use a callback from the dma-fence to submit
1095 * requests after waiting on our own requests. To
1096 * ensure minimum delay in queuing the next request to
1097 * hardware, signal the fence now rather than wait for
1098 * the signaler to be woken up. We still wake up the
1099 * waiter in order to handle the irq-seqno coherency
1100 * issues (we may receive the interrupt before the
1101 * seqno is written, see __i915_request_irq_complete())
1102 * and to handle coalescing of multiple seqno updates
1103 * and many waiters.
1104 */
1105 if (i915_seqno_passed(intel_engine_get_seqno(engine),
Chris Wilson17b51ad2017-09-18 17:27:33 +01001106 wait->seqno)) {
Chris Wilsone61e0f52018-02-21 09:56:36 +00001107 struct i915_request *waiter = wait->request;
Chris Wilsonde4d2102017-09-18 17:27:34 +01001108
Chris Wilson17b51ad2017-09-18 17:27:33 +01001109 wakeup = true;
1110 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Chris Wilsonde4d2102017-09-18 17:27:34 +01001111 &waiter->fence.flags) &&
1112 intel_wait_check_request(wait, waiter))
Chris Wilsone61e0f52018-02-21 09:56:36 +00001113 rq = i915_request_get(waiter);
Chris Wilson17b51ad2017-09-18 17:27:33 +01001114 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001115
Chris Wilson17b51ad2017-09-18 17:27:33 +01001116 if (wakeup)
1117 wake_up_process(wait->tsk);
Chris Wilson67b807a82017-02-27 20:58:50 +00001118 } else {
Chris Wilsonbcbd5c32017-10-25 15:39:42 +01001119 if (engine->breadcrumbs.irq_armed)
1120 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001121 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001122 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001123
Chris Wilson24754d72017-03-03 14:45:57 +00001124 if (rq) {
Chris Wilson56299fb2017-02-27 20:58:48 +00001125 dma_fence_signal(&rq->fence);
Chris Wilson4e9a8be2018-03-05 10:41:05 +00001126 GEM_BUG_ON(!i915_request_completed(rq));
Chris Wilsone61e0f52018-02-21 09:56:36 +00001127 i915_request_put(rq);
Chris Wilson24754d72017-03-03 14:45:57 +00001128 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001129
1130 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001131}
1132
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001133static void vlv_c0_read(struct drm_i915_private *dev_priv,
1134 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001135{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001136 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001137 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1138 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001139}
1140
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001141void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1142{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001143 memset(&dev_priv->gt_pm.rps.ei, 0, sizeof(dev_priv->gt_pm.rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001144}
1145
1146static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1147{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001148 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1149 const struct intel_rps_ei *prev = &rps->ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001150 struct intel_rps_ei now;
1151 u32 events = 0;
1152
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001153 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001154 return 0;
1155
1156 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001157
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001158 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001159 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001160 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001161
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001162 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001163
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001164 time *= dev_priv->czclk_freq;
1165
1166 /* Workload can be split between render + media,
1167 * e.g. SwapBuffers being blitted in X after being rendered in
1168 * mesa. To account for this we need to combine both engines
1169 * into our activity counter.
1170 */
Chris Wilson569884e2017-03-09 21:12:31 +00001171 render = now.render_c0 - prev->render_c0;
1172 media = now.media_c0 - prev->media_c0;
1173 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001174 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001175
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001176 if (c0 > time * rps->up_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001177 events = GEN6_PM_RP_UP_THRESHOLD;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001178 else if (c0 < time * rps->down_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001179 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001180 }
1181
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001182 rps->ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001183 return events;
Deepak S31685c22014-07-03 17:33:01 -04001184}
1185
Ben Widawsky4912d042011-04-25 11:25:20 -07001186static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001187{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001188 struct drm_i915_private *dev_priv =
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001189 container_of(work, struct drm_i915_private, gt_pm.rps.work);
1190 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001191 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001192 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001193 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001194
Daniel Vetter59cdb632013-07-04 23:35:28 +02001195 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001196 if (rps->interrupts_enabled) {
1197 pm_iir = fetch_and_zero(&rps->pm_iir);
1198 client_boost = atomic_read(&rps->num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001199 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001200 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001201
Paulo Zanoni60611c12013-08-15 11:50:01 -03001202 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301203 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001204 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001205 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001206
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001207 mutex_lock(&dev_priv->pcu_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001208
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001209 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1210
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001211 adj = rps->last_adj;
1212 new_delay = rps->cur_freq;
1213 min = rps->min_freq_softlimit;
1214 max = rps->max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001215 if (client_boost)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001216 max = rps->max_freq;
1217 if (client_boost && new_delay < rps->boost_freq) {
1218 new_delay = rps->boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001219 adj = 0;
1220 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001221 if (adj > 0)
1222 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001223 else /* CHV needs even encode values */
1224 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301225
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001226 if (new_delay >= rps->max_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301227 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001228 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001229 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001230 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001231 if (rps->cur_freq > rps->efficient_freq)
1232 new_delay = rps->efficient_freq;
1233 else if (rps->cur_freq > rps->min_freq_softlimit)
1234 new_delay = rps->min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001235 adj = 0;
1236 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1237 if (adj < 0)
1238 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001239 else /* CHV needs even encode values */
1240 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301241
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001242 if (new_delay <= rps->min_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301243 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001244 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001245 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001246 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001247
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001248 rps->last_adj = adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001249
Ben Widawsky79249632012-09-07 19:43:42 -07001250 /* sysfs frequency interfaces may have snuck in while servicing the
1251 * interrupt
1252 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001253 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001254 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301255
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001256 if (intel_set_rps(dev_priv, new_delay)) {
1257 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001258 rps->last_adj = 0;
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001259 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001260
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001261 mutex_unlock(&dev_priv->pcu_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001262
1263out:
1264 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1265 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001266 if (rps->interrupts_enabled)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001267 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1268 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001269}
1270
Ben Widawskye3689192012-05-25 16:56:22 -07001271
1272/**
1273 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1274 * occurred.
1275 * @work: workqueue struct
1276 *
1277 * Doesn't actually do anything except notify userspace. As a consequence of
1278 * this event, userspace should try to remap the bad rows since statistically
1279 * it is likely the same row is more likely to go bad again.
1280 */
1281static void ivybridge_parity_work(struct work_struct *work)
1282{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001283 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001284 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001285 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001286 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001287 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001288 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001289
1290 /* We must turn off DOP level clock gating to access the L3 registers.
1291 * In order to prevent a get/put style interface, acquire struct mutex
1292 * any time we access those registers.
1293 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001294 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001295
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001296 /* If we've screwed up tracking, just let the interrupt fire again */
1297 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1298 goto out;
1299
Ben Widawskye3689192012-05-25 16:56:22 -07001300 misccpctl = I915_READ(GEN7_MISCCPCTL);
1301 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1302 POSTING_READ(GEN7_MISCCPCTL);
1303
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001304 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001305 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001306
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001307 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001308 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001309 break;
1310
1311 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1312
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001313 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001314
1315 error_status = I915_READ(reg);
1316 row = GEN7_PARITY_ERROR_ROW(error_status);
1317 bank = GEN7_PARITY_ERROR_BANK(error_status);
1318 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1319
1320 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1321 POSTING_READ(reg);
1322
1323 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1324 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1325 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1326 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1327 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1328 parity_event[5] = NULL;
1329
Chris Wilson91c8a322016-07-05 10:40:23 +01001330 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001331 KOBJ_CHANGE, parity_event);
1332
1333 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1334 slice, row, bank, subbank);
1335
1336 kfree(parity_event[4]);
1337 kfree(parity_event[3]);
1338 kfree(parity_event[2]);
1339 kfree(parity_event[1]);
1340 }
Ben Widawskye3689192012-05-25 16:56:22 -07001341
1342 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1343
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001344out:
1345 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001346 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001347 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001348 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001349
Chris Wilson91c8a322016-07-05 10:40:23 +01001350 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001351}
1352
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001353static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1354 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001355{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001356 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001357 return;
1358
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001359 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001360 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001361 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001362
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001363 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001364 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1365 dev_priv->l3_parity.which_slice |= 1 << 1;
1366
1367 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1368 dev_priv->l3_parity.which_slice |= 1 << 0;
1369
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001370 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001371}
1372
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001373static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001374 u32 gt_iir)
1375{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001376 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301377 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001378 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301379 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001380}
1381
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001382static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001383 u32 gt_iir)
1384{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001385 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301386 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001387 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301388 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001389 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301390 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001391
Ben Widawskycc609d52013-05-28 19:22:29 -07001392 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1393 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001394 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1395 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001396
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001397 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1398 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001399}
1400
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001401static void
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001402gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001403{
Mika Kuoppalab620e872017-09-22 15:43:03 +03001404 struct intel_engine_execlists * const execlists = &engine->execlists;
Chris Wilson31de7352017-03-16 12:56:18 +00001405 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001406
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001407 if (iir & GT_CONTEXT_SWITCH_INTERRUPT) {
Chris Wilson4a118ec2017-10-23 22:32:36 +01001408 if (READ_ONCE(engine->execlists.active)) {
1409 __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted);
1410 tasklet = true;
1411 }
Chris Wilsonf7470262017-01-24 15:20:21 +00001412 }
Chris Wilson31de7352017-03-16 12:56:18 +00001413
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001414 if (iir & GT_RENDER_USER_INTERRUPT) {
Chris Wilson31de7352017-03-16 12:56:18 +00001415 notify_ring(engine);
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +00001416 tasklet |= USES_GUC_SUBMISSION(engine->i915);
Chris Wilson31de7352017-03-16 12:56:18 +00001417 }
1418
1419 if (tasklet)
Sagar Arun Kamblec6dce8f2017-11-16 19:02:37 +05301420 tasklet_hi_schedule(&execlists->tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001421}
1422
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001423static void gen8_gt_irq_ack(struct drm_i915_private *i915,
Chris Wilson55ef72f2018-02-02 15:34:48 +00001424 u32 master_ctl, u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001425{
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001426 void __iomem * const regs = i915->regs;
1427
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001428#define GEN8_GT_IRQS (GEN8_GT_RCS_IRQ | \
1429 GEN8_GT_BCS_IRQ | \
1430 GEN8_GT_VCS1_IRQ | \
1431 GEN8_GT_VCS2_IRQ | \
1432 GEN8_GT_VECS_IRQ | \
1433 GEN8_GT_PM_IRQ | \
1434 GEN8_GT_GUC_IRQ)
1435
Ben Widawskyabd58f02013-11-02 21:07:09 -07001436 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001437 gt_iir[0] = raw_reg_read(regs, GEN8_GT_IIR(0));
1438 if (likely(gt_iir[0]))
1439 raw_reg_write(regs, GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001440 }
1441
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001442 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001443 gt_iir[1] = raw_reg_read(regs, GEN8_GT_IIR(1));
1444 if (likely(gt_iir[1]))
1445 raw_reg_write(regs, GEN8_GT_IIR(1), gt_iir[1]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001446 }
1447
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301448 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001449 gt_iir[2] = raw_reg_read(regs, GEN8_GT_IIR(2));
1450 if (likely(gt_iir[2] & (i915->pm_rps_events |
1451 i915->pm_guc_events)))
1452 raw_reg_write(regs, GEN8_GT_IIR(2),
1453 gt_iir[2] & (i915->pm_rps_events |
1454 i915->pm_guc_events));
1455 }
1456
1457 if (master_ctl & GEN8_GT_VECS_IRQ) {
1458 gt_iir[3] = raw_reg_read(regs, GEN8_GT_IIR(3));
1459 if (likely(gt_iir[3]))
1460 raw_reg_write(regs, GEN8_GT_IIR(3), gt_iir[3]);
Ben Widawsky09610212014-05-15 20:58:08 +03001461 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07001462}
1463
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001464static void gen8_gt_irq_handler(struct drm_i915_private *i915,
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001465 u32 master_ctl, u32 gt_iir[4])
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001466{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001467 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001468 gen8_cs_irq_handler(i915->engine[RCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001469 gt_iir[0] >> GEN8_RCS_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001470 gen8_cs_irq_handler(i915->engine[BCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001471 gt_iir[0] >> GEN8_BCS_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001472 }
1473
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001474 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001475 gen8_cs_irq_handler(i915->engine[VCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001476 gt_iir[1] >> GEN8_VCS1_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001477 gen8_cs_irq_handler(i915->engine[VCS2],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001478 gt_iir[1] >> GEN8_VCS2_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001479 }
1480
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001481 if (master_ctl & GEN8_GT_VECS_IRQ) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001482 gen8_cs_irq_handler(i915->engine[VECS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001483 gt_iir[3] >> GEN8_VECS_IRQ_SHIFT);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001484 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001485
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001486 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001487 gen6_rps_irq_handler(i915, gt_iir[2]);
1488 gen9_guc_irq_handler(i915, gt_iir[2]);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001489 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001490}
1491
Imre Deak63c88d22015-07-20 14:43:39 -07001492static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1493{
1494 switch (port) {
1495 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001496 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001497 case PORT_B:
1498 return val & PORTB_HOTPLUG_LONG_DETECT;
1499 case PORT_C:
1500 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001501 default:
1502 return false;
1503 }
1504}
1505
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001506static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1507{
1508 switch (port) {
1509 case PORT_E:
1510 return val & PORTE_HOTPLUG_LONG_DETECT;
1511 default:
1512 return false;
1513 }
1514}
1515
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001516static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1517{
1518 switch (port) {
1519 case PORT_A:
1520 return val & PORTA_HOTPLUG_LONG_DETECT;
1521 case PORT_B:
1522 return val & PORTB_HOTPLUG_LONG_DETECT;
1523 case PORT_C:
1524 return val & PORTC_HOTPLUG_LONG_DETECT;
1525 case PORT_D:
1526 return val & PORTD_HOTPLUG_LONG_DETECT;
1527 default:
1528 return false;
1529 }
1530}
1531
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001532static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1533{
1534 switch (port) {
1535 case PORT_A:
1536 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1537 default:
1538 return false;
1539 }
1540}
1541
Jani Nikula676574d2015-05-28 15:43:53 +03001542static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001543{
1544 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001545 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001546 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001547 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001548 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001549 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001550 return val & PORTD_HOTPLUG_LONG_DETECT;
1551 default:
1552 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001553 }
1554}
1555
Jani Nikula676574d2015-05-28 15:43:53 +03001556static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001557{
1558 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001559 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001560 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001561 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001562 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001563 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001564 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1565 default:
1566 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001567 }
1568}
1569
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001570/*
1571 * Get a bit mask of pins that have triggered, and which ones may be long.
1572 * This can be called multiple times with the same masks to accumulate
1573 * hotplug detection results from several registers.
1574 *
1575 * Note that the caller is expected to zero out the masks initially.
1576 */
Rodrigo Vivicf539022018-01-29 15:22:21 -08001577static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1578 u32 *pin_mask, u32 *long_mask,
1579 u32 hotplug_trigger, u32 dig_hotplug_reg,
1580 const u32 hpd[HPD_NUM_PINS],
1581 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001582{
Jani Nikula8c841e52015-06-18 13:06:17 +03001583 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001584 int i;
1585
Jani Nikula676574d2015-05-28 15:43:53 +03001586 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001587 if ((hpd[i] & hotplug_trigger) == 0)
1588 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001589
Jani Nikula8c841e52015-06-18 13:06:17 +03001590 *pin_mask |= BIT(i);
1591
Rodrigo Vivicf539022018-01-29 15:22:21 -08001592 port = intel_hpd_pin_to_port(dev_priv, i);
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07001593 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001594 continue;
1595
Imre Deakfd63e2a2015-07-21 15:32:44 -07001596 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001597 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001598 }
1599
1600 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1601 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1602
1603}
1604
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001605static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001606{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001607 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001608}
1609
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001610static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001611{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001612 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001613}
1614
Shuang He8bf1e9f2013-10-15 18:55:27 +01001615#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001616static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1617 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001618 uint32_t crc0, uint32_t crc1,
1619 uint32_t crc2, uint32_t crc3,
1620 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001621{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001622 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1623 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001624 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1625 struct drm_driver *driver = dev_priv->drm.driver;
1626 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001627 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001628
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001629 spin_lock(&pipe_crc->lock);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +01001630 if (pipe_crc->source && !crtc->base.crc.opened) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001631 if (!pipe_crc->entries) {
1632 spin_unlock(&pipe_crc->lock);
1633 DRM_DEBUG_KMS("spurious interrupt\n");
1634 return;
1635 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001636
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001637 head = pipe_crc->head;
1638 tail = pipe_crc->tail;
1639
1640 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1641 spin_unlock(&pipe_crc->lock);
1642 DRM_ERROR("CRC buffer overflowing\n");
1643 return;
1644 }
1645
1646 entry = &pipe_crc->entries[head];
1647
1648 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1649 entry->crc[0] = crc0;
1650 entry->crc[1] = crc1;
1651 entry->crc[2] = crc2;
1652 entry->crc[3] = crc3;
1653 entry->crc[4] = crc4;
1654
1655 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1656 pipe_crc->head = head;
1657
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001658 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001659
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001660 wake_up_interruptible(&pipe_crc->wq);
1661 } else {
1662 /*
1663 * For some not yet identified reason, the first CRC is
1664 * bonkers. So let's just wait for the next vblank and read
1665 * out the buggy result.
1666 *
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001667 * On GEN8+ sometimes the second CRC is bonkers as well, so
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001668 * don't trust that one either.
1669 */
Maarten Lankhorst033b7a22018-03-08 13:02:02 +01001670 if (pipe_crc->skipped <= 0 ||
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001671 (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001672 pipe_crc->skipped++;
1673 spin_unlock(&pipe_crc->lock);
1674 return;
1675 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001676 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001677 crcs[0] = crc0;
1678 crcs[1] = crc1;
1679 crcs[2] = crc2;
1680 crcs[3] = crc3;
1681 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001682 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001683 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001684 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001685 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001686}
Daniel Vetter277de952013-10-18 16:37:07 +02001687#else
1688static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001689display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1690 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001691 uint32_t crc0, uint32_t crc1,
1692 uint32_t crc2, uint32_t crc3,
1693 uint32_t crc4) {}
1694#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001695
Daniel Vetter277de952013-10-18 16:37:07 +02001696
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001697static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1698 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001699{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001700 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001701 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1702 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001703}
1704
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001705static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1706 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001707{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001708 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001709 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1710 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1711 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1712 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1713 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001714}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001715
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001716static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1717 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001718{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001719 uint32_t res1, res2;
1720
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001721 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001722 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1723 else
1724 res1 = 0;
1725
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001726 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001727 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1728 else
1729 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001730
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001731 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001732 I915_READ(PIPE_CRC_RES_RED(pipe)),
1733 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1734 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1735 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001736}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001737
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001738/* The RPS events need forcewake, so we add them to a work queue and mask their
1739 * IMR bits until the work is done. Other interrupts can be processed without
1740 * the work queue. */
1741static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001742{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001743 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1744
Deepak Sa6706b42014-03-15 20:23:22 +05301745 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001746 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301747 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001748 if (rps->interrupts_enabled) {
1749 rps->pm_iir |= pm_iir & dev_priv->pm_rps_events;
1750 schedule_work(&rps->work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001751 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001752 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001753 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001754
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001755 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001756 return;
1757
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001758 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001759 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301760 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001761
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001762 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1763 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001764 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001765}
1766
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301767static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1768{
Michal Wajdeczko93bf8092018-03-08 16:46:55 +01001769 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT)
1770 intel_guc_to_host_event_handler(&dev_priv->guc);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301771}
1772
Ville Syrjälä44d92412017-08-18 21:36:51 +03001773static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1774{
1775 enum pipe pipe;
1776
1777 for_each_pipe(dev_priv, pipe) {
1778 I915_WRITE(PIPESTAT(pipe),
1779 PIPESTAT_INT_STATUS_MASK |
1780 PIPE_FIFO_UNDERRUN_STATUS);
1781
1782 dev_priv->pipestat_irq_mask[pipe] = 0;
1783 }
1784}
1785
Ville Syrjäläeb643432017-08-18 21:36:59 +03001786static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1787 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001788{
Imre Deakc1874ed2014-02-04 21:35:46 +02001789 int pipe;
1790
Imre Deak58ead0d2014-02-04 21:35:47 +02001791 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001792
1793 if (!dev_priv->display_irqs_enabled) {
1794 spin_unlock(&dev_priv->irq_lock);
1795 return;
1796 }
1797
Damien Lespiau055e3932014-08-18 13:49:10 +01001798 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001799 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001800 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001801
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001802 /*
1803 * PIPESTAT bits get signalled even when the interrupt is
1804 * disabled with the mask bits, and some of the status bits do
1805 * not generate interrupts at all (like the underrun bit). Hence
1806 * we need to be careful that we only handle what we want to
1807 * handle.
1808 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001809
1810 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001811 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001812
1813 switch (pipe) {
1814 case PIPE_A:
1815 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1816 break;
1817 case PIPE_B:
1818 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1819 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001820 case PIPE_C:
1821 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1822 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001823 }
1824 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001825 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001826
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001827 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001828 continue;
1829
1830 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001831 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1832 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001833
1834 /*
1835 * Clear the PIPE*STAT regs before the IIR
1836 */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001837 if (pipe_stats[pipe])
1838 I915_WRITE(reg, enable_mask | pipe_stats[pipe]);
Imre Deakc1874ed2014-02-04 21:35:46 +02001839 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001840 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001841}
1842
Ville Syrjäläeb643432017-08-18 21:36:59 +03001843static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1844 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1845{
1846 enum pipe pipe;
1847
1848 for_each_pipe(dev_priv, pipe) {
1849 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1850 drm_handle_vblank(&dev_priv->drm, pipe);
1851
1852 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1853 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1854
1855 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1856 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1857 }
1858}
1859
1860static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1861 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1862{
1863 bool blc_event = false;
1864 enum pipe pipe;
1865
1866 for_each_pipe(dev_priv, pipe) {
1867 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1868 drm_handle_vblank(&dev_priv->drm, pipe);
1869
1870 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1871 blc_event = true;
1872
1873 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1874 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1875
1876 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1877 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1878 }
1879
1880 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1881 intel_opregion_asle_intr(dev_priv);
1882}
1883
1884static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1885 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1886{
1887 bool blc_event = false;
1888 enum pipe pipe;
1889
1890 for_each_pipe(dev_priv, pipe) {
1891 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1892 drm_handle_vblank(&dev_priv->drm, pipe);
1893
1894 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1895 blc_event = true;
1896
1897 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1898 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1899
1900 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1901 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1902 }
1903
1904 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1905 intel_opregion_asle_intr(dev_priv);
1906
1907 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1908 gmbus_irq_handler(dev_priv);
1909}
1910
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001911static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001912 u32 pipe_stats[I915_MAX_PIPES])
1913{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001914 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001915
Damien Lespiau055e3932014-08-18 13:49:10 +01001916 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001917 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1918 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001919
1920 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001921 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001922
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001923 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1924 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001925 }
1926
1927 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001928 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001929}
1930
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001931static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001932{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001933 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001934
1935 if (hotplug_status)
1936 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1937
1938 return hotplug_status;
1939}
1940
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001941static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001942 u32 hotplug_status)
1943{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001944 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001945
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001946 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1947 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001948 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001949
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001950 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08001951 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1952 hotplug_trigger, hotplug_trigger,
1953 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001954 i9xx_port_hotplug_long_detect);
1955
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001956 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001957 }
Jani Nikula369712e2015-05-27 15:03:40 +03001958
1959 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001960 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001961 } else {
1962 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001963
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001964 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08001965 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1966 hotplug_trigger, hotplug_trigger,
1967 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001968 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001969 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001970 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001971 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001972}
1973
Daniel Vetterff1f5252012-10-02 15:10:55 +02001974static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001975{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001976 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001977 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001978 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001979
Imre Deak2dd2a882015-02-24 11:14:30 +02001980 if (!intel_irqs_enabled(dev_priv))
1981 return IRQ_NONE;
1982
Imre Deak1f814da2015-12-16 02:52:19 +02001983 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1984 disable_rpm_wakeref_asserts(dev_priv);
1985
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001986 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001987 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001988 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001989 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001990 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001991
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001992 gt_iir = I915_READ(GTIIR);
1993 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001994 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001995
1996 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001997 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001998
1999 ret = IRQ_HANDLED;
2000
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002001 /*
2002 * Theory on interrupt generation, based on empirical evidence:
2003 *
2004 * x = ((VLV_IIR & VLV_IER) ||
2005 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2006 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2007 *
2008 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2009 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2010 * guarantee the CPU interrupt will be raised again even if we
2011 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2012 * bits this time around.
2013 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002014 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002015 ier = I915_READ(VLV_IER);
2016 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002017
2018 if (gt_iir)
2019 I915_WRITE(GTIIR, gt_iir);
2020 if (pm_iir)
2021 I915_WRITE(GEN6_PMIIR, pm_iir);
2022
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002023 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002024 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002025
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002026 /* Call regardless, as some status bits might not be
2027 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002028 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002029
Jerome Anandeef57322017-01-25 04:27:49 +05302030 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2031 I915_LPE_PIPE_B_INTERRUPT))
2032 intel_lpe_audio_irq_handler(dev_priv);
2033
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002034 /*
2035 * VLV_IIR is single buffered, and reflects the level
2036 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2037 */
2038 if (iir)
2039 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002040
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002041 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002042 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2043 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002044
Ville Syrjälä52894872016-04-13 21:19:56 +03002045 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002046 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002047 if (pm_iir)
2048 gen6_rps_irq_handler(dev_priv, pm_iir);
2049
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002050 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002051 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002052
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002053 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002054 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002055
Imre Deak1f814da2015-12-16 02:52:19 +02002056 enable_rpm_wakeref_asserts(dev_priv);
2057
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002058 return ret;
2059}
2060
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002061static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2062{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002063 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002064 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002065 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002066
Imre Deak2dd2a882015-02-24 11:14:30 +02002067 if (!intel_irqs_enabled(dev_priv))
2068 return IRQ_NONE;
2069
Imre Deak1f814da2015-12-16 02:52:19 +02002070 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2071 disable_rpm_wakeref_asserts(dev_priv);
2072
Chris Wilson579de732016-03-14 09:01:57 +00002073 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002074 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002075 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002076 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002077 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002078 u32 ier = 0;
2079
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002080 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2081 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002082
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002083 if (master_ctl == 0 && iir == 0)
2084 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002085
Oscar Mateo27b6c122014-06-16 16:11:00 +01002086 ret = IRQ_HANDLED;
2087
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002088 /*
2089 * Theory on interrupt generation, based on empirical evidence:
2090 *
2091 * x = ((VLV_IIR & VLV_IER) ||
2092 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2093 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2094 *
2095 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2096 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2097 * guarantee the CPU interrupt will be raised again even if we
2098 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2099 * bits this time around.
2100 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002101 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002102 ier = I915_READ(VLV_IER);
2103 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002104
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002105 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002106
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002107 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002108 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002109
Oscar Mateo27b6c122014-06-16 16:11:00 +01002110 /* Call regardless, as some status bits might not be
2111 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002112 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002113
Jerome Anandeef57322017-01-25 04:27:49 +05302114 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2115 I915_LPE_PIPE_B_INTERRUPT |
2116 I915_LPE_PIPE_C_INTERRUPT))
2117 intel_lpe_audio_irq_handler(dev_priv);
2118
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002119 /*
2120 * VLV_IIR is single buffered, and reflects the level
2121 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2122 */
2123 if (iir)
2124 I915_WRITE(VLV_IIR, iir);
2125
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002126 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002127 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002128 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002129
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002130 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002131
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002132 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002133 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002134
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002135 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002136 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002137
Imre Deak1f814da2015-12-16 02:52:19 +02002138 enable_rpm_wakeref_asserts(dev_priv);
2139
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002140 return ret;
2141}
2142
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002143static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2144 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002145 const u32 hpd[HPD_NUM_PINS])
2146{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002147 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2148
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002149 /*
2150 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2151 * unless we touch the hotplug register, even if hotplug_trigger is
2152 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2153 * errors.
2154 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002155 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002156 if (!hotplug_trigger) {
2157 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2158 PORTD_HOTPLUG_STATUS_MASK |
2159 PORTC_HOTPLUG_STATUS_MASK |
2160 PORTB_HOTPLUG_STATUS_MASK;
2161 dig_hotplug_reg &= ~mask;
2162 }
2163
Ville Syrjälä40e56412015-08-27 23:56:10 +03002164 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002165 if (!hotplug_trigger)
2166 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002167
Rodrigo Vivicf539022018-01-29 15:22:21 -08002168 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002169 dig_hotplug_reg, hpd,
2170 pch_port_hotplug_long_detect);
2171
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002172 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002173}
2174
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002175static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002176{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002177 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002178 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002179
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002180 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002181
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002182 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2183 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2184 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002185 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002186 port_name(port));
2187 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002188
Daniel Vetterce99c252012-12-01 13:53:47 +01002189 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002190 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002191
Jesse Barnes776ad802011-01-04 15:09:39 -08002192 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002193 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002194
2195 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2196 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2197
2198 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2199 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2200
2201 if (pch_iir & SDE_POISON)
2202 DRM_ERROR("PCH poison interrupt\n");
2203
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002204 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002205 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002206 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2207 pipe_name(pipe),
2208 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002209
2210 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2211 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2212
2213 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2214 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2215
Jesse Barnes776ad802011-01-04 15:09:39 -08002216 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002217 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002218
2219 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002220 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002221}
2222
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002223static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002224{
Paulo Zanoni86642812013-04-12 17:57:57 -03002225 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002226 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002227
Paulo Zanonide032bf2013-04-12 17:57:58 -03002228 if (err_int & ERR_INT_POISON)
2229 DRM_ERROR("Poison interrupt\n");
2230
Damien Lespiau055e3932014-08-18 13:49:10 +01002231 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002232 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2233 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002234
Daniel Vetter5a69b892013-10-16 22:55:52 +02002235 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002236 if (IS_IVYBRIDGE(dev_priv))
2237 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002238 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002239 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002240 }
2241 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002242
Paulo Zanoni86642812013-04-12 17:57:57 -03002243 I915_WRITE(GEN7_ERR_INT, err_int);
2244}
2245
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002246static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002247{
Paulo Zanoni86642812013-04-12 17:57:57 -03002248 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002249 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002250
Paulo Zanonide032bf2013-04-12 17:57:58 -03002251 if (serr_int & SERR_INT_POISON)
2252 DRM_ERROR("PCH poison interrupt\n");
2253
Mika Kahola45c1cd82017-10-10 13:17:06 +03002254 for_each_pipe(dev_priv, pipe)
2255 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2256 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002257
2258 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002259}
2260
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002261static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002262{
Adam Jackson23e81d62012-06-06 15:45:44 -04002263 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002264 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002265
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002266 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002267
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002268 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2269 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2270 SDE_AUDIO_POWER_SHIFT_CPT);
2271 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2272 port_name(port));
2273 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002274
2275 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002276 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002277
2278 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002279 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002280
2281 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2282 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2283
2284 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2285 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2286
2287 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002288 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002289 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2290 pipe_name(pipe),
2291 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002292
2293 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002294 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002295}
2296
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002297static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002298{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002299 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2300 ~SDE_PORTE_HOTPLUG_SPT;
2301 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2302 u32 pin_mask = 0, long_mask = 0;
2303
2304 if (hotplug_trigger) {
2305 u32 dig_hotplug_reg;
2306
2307 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2308 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2309
Rodrigo Vivicf539022018-01-29 15:22:21 -08002310 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2311 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002312 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002313 }
2314
2315 if (hotplug2_trigger) {
2316 u32 dig_hotplug_reg;
2317
2318 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2319 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2320
Rodrigo Vivicf539022018-01-29 15:22:21 -08002321 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2322 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002323 spt_port_hotplug2_long_detect);
2324 }
2325
2326 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002327 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002328
2329 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002330 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002331}
2332
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002333static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2334 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002335 const u32 hpd[HPD_NUM_PINS])
2336{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002337 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2338
2339 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2340 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2341
Rodrigo Vivicf539022018-01-29 15:22:21 -08002342 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002343 dig_hotplug_reg, hpd,
2344 ilk_port_hotplug_long_detect);
2345
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002346 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002347}
2348
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002349static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2350 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002351{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002352 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002353 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2354
Ville Syrjälä40e56412015-08-27 23:56:10 +03002355 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002356 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002357
2358 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002359 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002360
2361 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002362 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002363
Paulo Zanonic008bc62013-07-12 16:35:10 -03002364 if (de_iir & DE_POISON)
2365 DRM_ERROR("Poison interrupt\n");
2366
Damien Lespiau055e3932014-08-18 13:49:10 +01002367 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002368 if (de_iir & DE_PIPE_VBLANK(pipe))
2369 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002370
Daniel Vetter40da17c22013-10-21 18:04:36 +02002371 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002372 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002373
Daniel Vetter40da17c22013-10-21 18:04:36 +02002374 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002375 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002376 }
2377
2378 /* check event from PCH */
2379 if (de_iir & DE_PCH_EVENT) {
2380 u32 pch_iir = I915_READ(SDEIIR);
2381
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002382 if (HAS_PCH_CPT(dev_priv))
2383 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002384 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002385 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002386
2387 /* should clear PCH hotplug event before clear CPU irq */
2388 I915_WRITE(SDEIIR, pch_iir);
2389 }
2390
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002391 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2392 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002393}
2394
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002395static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2396 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002397{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002398 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002399 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2400
Ville Syrjälä40e56412015-08-27 23:56:10 +03002401 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002402 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002403
2404 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002405 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002406
2407 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002408 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002409
2410 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002411 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002412
Damien Lespiau055e3932014-08-18 13:49:10 +01002413 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002414 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2415 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002416 }
2417
2418 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002419 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002420 u32 pch_iir = I915_READ(SDEIIR);
2421
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002422 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002423
2424 /* clear PCH hotplug event before clear CPU irq */
2425 I915_WRITE(SDEIIR, pch_iir);
2426 }
2427}
2428
Oscar Mateo72c90f62014-06-16 16:10:57 +01002429/*
2430 * To handle irqs with the minimum potential races with fresh interrupts, we:
2431 * 1 - Disable Master Interrupt Control.
2432 * 2 - Find the source(s) of the interrupt.
2433 * 3 - Clear the Interrupt Identity bits (IIR).
2434 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2435 * 5 - Re-enable Master Interrupt Control.
2436 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002437static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002438{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002439 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002440 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002441 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002442 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002443
Imre Deak2dd2a882015-02-24 11:14:30 +02002444 if (!intel_irqs_enabled(dev_priv))
2445 return IRQ_NONE;
2446
Imre Deak1f814da2015-12-16 02:52:19 +02002447 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2448 disable_rpm_wakeref_asserts(dev_priv);
2449
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002450 /* disable master interrupt before clearing iir */
2451 de_ier = I915_READ(DEIER);
2452 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002453 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002454
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002455 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2456 * interrupts will will be stored on its back queue, and then we'll be
2457 * able to process them after we restore SDEIER (as soon as we restore
2458 * it, we'll get an interrupt if SDEIIR still has something to process
2459 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002460 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002461 sde_ier = I915_READ(SDEIER);
2462 I915_WRITE(SDEIER, 0);
2463 POSTING_READ(SDEIER);
2464 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002465
Oscar Mateo72c90f62014-06-16 16:10:57 +01002466 /* Find, clear, then process each source of interrupt */
2467
Chris Wilson0e434062012-05-09 21:45:44 +01002468 gt_iir = I915_READ(GTIIR);
2469 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002470 I915_WRITE(GTIIR, gt_iir);
2471 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002472 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002473 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002474 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002475 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002476 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002477
2478 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002479 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002480 I915_WRITE(DEIIR, de_iir);
2481 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002482 if (INTEL_GEN(dev_priv) >= 7)
2483 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002484 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002485 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002486 }
2487
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002488 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002489 u32 pm_iir = I915_READ(GEN6_PMIIR);
2490 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002491 I915_WRITE(GEN6_PMIIR, pm_iir);
2492 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002493 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002494 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002495 }
2496
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002497 I915_WRITE(DEIER, de_ier);
2498 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002499 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002500 I915_WRITE(SDEIER, sde_ier);
2501 POSTING_READ(SDEIER);
2502 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002503
Imre Deak1f814da2015-12-16 02:52:19 +02002504 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2505 enable_rpm_wakeref_asserts(dev_priv);
2506
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002507 return ret;
2508}
2509
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002510static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2511 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002512 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302513{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002514 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302515
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002516 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2517 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302518
Rodrigo Vivicf539022018-01-29 15:22:21 -08002519 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002520 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002521 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002522
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002523 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302524}
2525
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002526static irqreturn_t
2527gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002528{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002529 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002530 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002531 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002532
Ben Widawskyabd58f02013-11-02 21:07:09 -07002533 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002534 iir = I915_READ(GEN8_DE_MISC_IIR);
2535 if (iir) {
2536 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002537 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002538 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002539 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002540 else
2541 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002542 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002543 else
2544 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002545 }
2546
Daniel Vetter6d766f02013-11-07 14:49:55 +01002547 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002548 iir = I915_READ(GEN8_DE_PORT_IIR);
2549 if (iir) {
2550 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302551 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002552
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002553 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002554 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002555
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002556 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002557 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002558 tmp_mask |= GEN9_AUX_CHANNEL_B |
2559 GEN9_AUX_CHANNEL_C |
2560 GEN9_AUX_CHANNEL_D;
2561
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002562 if (IS_CNL_WITH_PORT_F(dev_priv))
2563 tmp_mask |= CNL_AUX_CHANNEL_F;
2564
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002565 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002566 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302567 found = true;
2568 }
2569
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002570 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002571 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2572 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002573 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2574 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002575 found = true;
2576 }
2577 } else if (IS_BROADWELL(dev_priv)) {
2578 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2579 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002580 ilk_hpd_irq_handler(dev_priv,
2581 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002582 found = true;
2583 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302584 }
2585
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002586 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002587 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302588 found = true;
2589 }
2590
Shashank Sharmad04a4922014-08-22 17:40:41 +05302591 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002592 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002593 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002594 else
2595 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002596 }
2597
Damien Lespiau055e3932014-08-18 13:49:10 +01002598 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002599 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002600
Daniel Vetterc42664c2013-11-07 11:05:40 +01002601 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2602 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002603
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002604 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2605 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002606 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002607 continue;
2608 }
2609
2610 ret = IRQ_HANDLED;
2611 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2612
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002613 if (iir & GEN8_PIPE_VBLANK)
2614 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002615
2616 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002617 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002618
2619 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2620 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2621
2622 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002623 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002624 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2625 else
2626 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2627
2628 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002629 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002630 pipe_name(pipe),
2631 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002632 }
2633
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002634 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302635 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002636 /*
2637 * FIXME(BDW): Assume for now that the new interrupt handling
2638 * scheme also closed the SDE interrupt handling race we've seen
2639 * on older pch-split platforms. But this needs testing.
2640 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002641 iir = I915_READ(SDEIIR);
2642 if (iir) {
2643 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002644 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002645
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002646 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2647 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002648 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002649 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002650 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002651 } else {
2652 /*
2653 * Like on previous PCH there seems to be something
2654 * fishy going on with forwarding PCH interrupts.
2655 */
2656 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2657 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002658 }
2659
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002660 return ret;
2661}
2662
2663static irqreturn_t gen8_irq_handler(int irq, void *arg)
2664{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002665 struct drm_i915_private *dev_priv = to_i915(arg);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002666 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002667 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002668
2669 if (!intel_irqs_enabled(dev_priv))
2670 return IRQ_NONE;
2671
2672 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2673 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2674 if (!master_ctl)
2675 return IRQ_NONE;
2676
2677 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2678
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002679 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002680 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002681
2682 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2683 if (master_ctl & ~GEN8_GT_IRQS) {
2684 disable_rpm_wakeref_asserts(dev_priv);
2685 gen8_de_irq_handler(dev_priv, master_ctl);
2686 enable_rpm_wakeref_asserts(dev_priv);
2687 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002688
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002689 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002690
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002691 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002692
Chris Wilson55ef72f2018-02-02 15:34:48 +00002693 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002694}
2695
Chris Wilson36703e72017-06-22 11:56:25 +01002696struct wedge_me {
2697 struct delayed_work work;
2698 struct drm_i915_private *i915;
2699 const char *name;
2700};
2701
2702static void wedge_me(struct work_struct *work)
2703{
2704 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2705
2706 dev_err(w->i915->drm.dev,
2707 "%s timed out, cancelling all in-flight rendering.\n",
2708 w->name);
2709 i915_gem_set_wedged(w->i915);
2710}
2711
2712static void __init_wedge(struct wedge_me *w,
2713 struct drm_i915_private *i915,
2714 long timeout,
2715 const char *name)
2716{
2717 w->i915 = i915;
2718 w->name = name;
2719
2720 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2721 schedule_delayed_work(&w->work, timeout);
2722}
2723
2724static void __fini_wedge(struct wedge_me *w)
2725{
2726 cancel_delayed_work_sync(&w->work);
2727 destroy_delayed_work_on_stack(&w->work);
2728 w->i915 = NULL;
2729}
2730
2731#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2732 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2733 (W)->i915; \
2734 __fini_wedge((W)))
2735
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002736static void
2737gen11_gt_engine_irq_handler(struct drm_i915_private * const i915,
2738 const unsigned int bank,
2739 const unsigned int engine_n,
2740 const u16 iir)
2741{
2742 struct intel_engine_cs ** const engine = i915->engine;
2743
2744 switch (bank) {
2745 case 0:
2746 switch (engine_n) {
2747
2748 case GEN11_RCS0:
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002749 return gen8_cs_irq_handler(engine[RCS], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002750
2751 case GEN11_BCS:
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002752 return gen8_cs_irq_handler(engine[BCS], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002753 }
2754 case 1:
2755 switch (engine_n) {
2756
2757 case GEN11_VCS(0):
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002758 return gen8_cs_irq_handler(engine[_VCS(0)], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002759 case GEN11_VCS(1):
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002760 return gen8_cs_irq_handler(engine[_VCS(1)], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002761 case GEN11_VCS(2):
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002762 return gen8_cs_irq_handler(engine[_VCS(2)], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002763 case GEN11_VCS(3):
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002764 return gen8_cs_irq_handler(engine[_VCS(3)], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002765
2766 case GEN11_VECS(0):
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002767 return gen8_cs_irq_handler(engine[_VECS(0)], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002768 case GEN11_VECS(1):
Chris Wilson51f6b0f2018-03-09 01:08:08 +00002769 return gen8_cs_irq_handler(engine[_VECS(1)], iir);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002770 }
2771 }
2772}
2773
2774static u32
2775gen11_gt_engine_intr(struct drm_i915_private * const i915,
2776 const unsigned int bank, const unsigned int bit)
2777{
2778 void __iomem * const regs = i915->regs;
2779 u32 timeout_ts;
2780 u32 ident;
2781
2782 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
2783
2784 /*
2785 * NB: Specs do not specify how long to spin wait,
2786 * so we do ~100us as an educated guess.
2787 */
2788 timeout_ts = (local_clock() >> 10) + 100;
2789 do {
2790 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
2791 } while (!(ident & GEN11_INTR_DATA_VALID) &&
2792 !time_after32(local_clock() >> 10, timeout_ts));
2793
2794 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
2795 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
2796 bank, bit, ident);
2797 return 0;
2798 }
2799
2800 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
2801 GEN11_INTR_DATA_VALID);
2802
2803 return ident & GEN11_INTR_ENGINE_MASK;
2804}
2805
2806static void
2807gen11_gt_irq_handler(struct drm_i915_private * const i915,
2808 const u32 master_ctl)
2809{
2810 void __iomem * const regs = i915->regs;
2811 unsigned int bank;
2812
2813 for (bank = 0; bank < 2; bank++) {
2814 unsigned long intr_dw;
2815 unsigned int bit;
2816
2817 if (!(master_ctl & GEN11_GT_DW_IRQ(bank)))
2818 continue;
2819
2820 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
2821
2822 if (unlikely(!intr_dw)) {
2823 DRM_ERROR("GT_INTR_DW%u blank!\n", bank);
2824 continue;
2825 }
2826
2827 for_each_set_bit(bit, &intr_dw, 32) {
2828 const u16 iir = gen11_gt_engine_intr(i915, bank, bit);
2829
2830 if (unlikely(!iir))
2831 continue;
2832
2833 gen11_gt_engine_irq_handler(i915, bank, bit, iir);
2834 }
2835
2836 /* Clear must be after shared has been served for engine */
2837 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
2838 }
2839}
2840
2841static irqreturn_t gen11_irq_handler(int irq, void *arg)
2842{
2843 struct drm_i915_private * const i915 = to_i915(arg);
2844 void __iomem * const regs = i915->regs;
2845 u32 master_ctl;
2846
2847 if (!intel_irqs_enabled(i915))
2848 return IRQ_NONE;
2849
2850 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2851 master_ctl &= ~GEN11_MASTER_IRQ;
2852 if (!master_ctl)
2853 return IRQ_NONE;
2854
2855 /* Disable interrupts. */
2856 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2857
2858 /* Find, clear, then process each source of interrupt. */
2859 gen11_gt_irq_handler(i915, master_ctl);
2860
2861 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2862 if (master_ctl & GEN11_DISPLAY_IRQ) {
2863 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2864
2865 disable_rpm_wakeref_asserts(i915);
2866 /*
2867 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2868 * for the display related bits.
2869 */
2870 gen8_de_irq_handler(i915, disp_ctl);
2871 enable_rpm_wakeref_asserts(i915);
2872 }
2873
2874 /* Acknowledge and enable interrupts. */
2875 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ | master_ctl);
2876
2877 return IRQ_HANDLED;
2878}
2879
Jesse Barnes8a905232009-07-11 16:48:03 -04002880/**
Chris Wilsond5367302017-06-20 10:57:43 +01002881 * i915_reset_device - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002882 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002883 *
2884 * Fire an error uevent so userspace can see that a hang or error
2885 * was detected.
2886 */
Chris Wilsond5367302017-06-20 10:57:43 +01002887static void i915_reset_device(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002888{
Chris Wilson91c8a322016-07-05 10:40:23 +01002889 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002890 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2891 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2892 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002893 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002894
Chris Wilsonc0336662016-05-06 15:40:21 +01002895 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002896
Chris Wilson8af29b02016-09-09 14:11:47 +01002897 DRM_DEBUG_DRIVER("resetting chip\n");
2898 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2899
Chris Wilson36703e72017-06-22 11:56:25 +01002900 /* Use a watchdog to ensure that our reset completes */
2901 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
2902 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002903
Chris Wilson36703e72017-06-22 11:56:25 +01002904 /* Signal that locked waiters should reset the GPU */
2905 set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags);
2906 wake_up_all(&dev_priv->gpu_error.wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00002907
Chris Wilson36703e72017-06-22 11:56:25 +01002908 /* Wait for anyone holding the lock to wakeup, without
2909 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01002910 */
Chris Wilson36703e72017-06-22 11:56:25 +01002911 do {
2912 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilson535275d2017-07-21 13:32:37 +01002913 i915_reset(dev_priv, 0);
Chris Wilson36703e72017-06-22 11:56:25 +01002914 mutex_unlock(&dev_priv->drm.struct_mutex);
2915 }
2916 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2917 I915_RESET_HANDOFF,
2918 TASK_UNINTERRUPTIBLE,
2919 1));
Chris Wilson780f2622016-09-09 14:11:52 +01002920
Chris Wilson36703e72017-06-22 11:56:25 +01002921 intel_finish_reset(dev_priv);
2922 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02002923
Chris Wilson780f2622016-09-09 14:11:52 +01002924 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002925 kobject_uevent_env(kobj,
2926 KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002927}
2928
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002929static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002930{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002931 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04002932
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002933 if (!IS_GEN2(dev_priv))
2934 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04002935
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002936 if (INTEL_GEN(dev_priv) < 4)
2937 I915_WRITE(IPEIR, I915_READ(IPEIR));
2938 else
2939 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002940
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002941 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04002942 eir = I915_READ(EIR);
2943 if (eir) {
2944 /*
2945 * some errors might have become stuck,
2946 * mask them.
2947 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002948 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002949 I915_WRITE(EMR, I915_READ(EMR) | eir);
2950 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2951 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002952}
2953
2954/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002955 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002956 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002957 * @engine_mask: mask representing engines that are hung
Michel Thierry87c390b2017-01-11 20:18:08 -08002958 * @fmt: Error message format string
2959 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002960 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002961 * dump it to the syslog. Also call i915_capture_error_state() to make
2962 * sure we get a record and make it available in debugfs. Fire a uevent
2963 * so userspace knows something bad happened (should trigger collection
2964 * of a ring dump etc.).
2965 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002966void i915_handle_error(struct drm_i915_private *dev_priv,
2967 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002968 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002969{
Michel Thierry142bc7d2017-06-20 10:57:46 +01002970 struct intel_engine_cs *engine;
2971 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02002972 va_list args;
2973 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002974
Mika Kuoppala58174462014-02-25 17:11:26 +02002975 va_start(args, fmt);
2976 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2977 va_end(args);
2978
Chris Wilson1604a862017-03-14 17:18:40 +00002979 /*
2980 * In most cases it's guaranteed that we get here with an RPM
2981 * reference held, for example because there is a pending GPU
2982 * request that won't finish until the reset is done. This
2983 * isn't the case at least when we get here by doing a
2984 * simulated reset via debugfs, so get an RPM reference.
2985 */
2986 intel_runtime_pm_get(dev_priv);
2987
Chris Wilson873d66f2018-03-16 21:49:59 +00002988 engine_mask &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilsonc0336662016-05-06 15:40:21 +01002989 i915_capture_error_state(dev_priv, engine_mask, error_msg);
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002990 i915_clear_error_registers(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002991
Michel Thierry142bc7d2017-06-20 10:57:46 +01002992 /*
2993 * Try engine reset when available. We fall back to full reset if
2994 * single reset fails.
2995 */
2996 if (intel_has_reset_engine(dev_priv)) {
2997 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02002998 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01002999 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3000 &dev_priv->gpu_error.flags))
3001 continue;
3002
Chris Wilson535275d2017-07-21 13:32:37 +01003003 if (i915_reset_engine(engine, 0) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01003004 engine_mask &= ~intel_engine_flag(engine);
3005
3006 clear_bit(I915_RESET_ENGINE + engine->id,
3007 &dev_priv->gpu_error.flags);
3008 wake_up_bit(&dev_priv->gpu_error.flags,
3009 I915_RESET_ENGINE + engine->id);
3010 }
3011 }
3012
Chris Wilson8af29b02016-09-09 14:11:47 +01003013 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00003014 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04003015
Michel Thierry142bc7d2017-06-20 10:57:46 +01003016 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01003017 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
3018 wait_event(dev_priv->gpu_error.reset_queue,
3019 !test_bit(I915_RESET_BACKOFF,
3020 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00003021 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01003022 }
Chris Wilson8af29b02016-09-09 14:11:47 +01003023
Michel Thierry142bc7d2017-06-20 10:57:46 +01003024 /* Prevent any other reset-engine attempt. */
3025 for_each_engine(engine, dev_priv, tmp) {
3026 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3027 &dev_priv->gpu_error.flags))
3028 wait_on_bit(&dev_priv->gpu_error.flags,
3029 I915_RESET_ENGINE + engine->id,
3030 TASK_UNINTERRUPTIBLE);
3031 }
3032
Chris Wilsond5367302017-06-20 10:57:43 +01003033 i915_reset_device(dev_priv);
3034
Michel Thierry142bc7d2017-06-20 10:57:46 +01003035 for_each_engine(engine, dev_priv, tmp) {
3036 clear_bit(I915_RESET_ENGINE + engine->id,
3037 &dev_priv->gpu_error.flags);
3038 }
3039
Chris Wilsond5367302017-06-20 10:57:43 +01003040 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
3041 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00003042
3043out:
3044 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04003045}
3046
Keith Packard42f52ef2008-10-18 19:39:29 -07003047/* Called from drm generic code, passed 'crtc' which
3048 * we use as a pipe index
3049 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003050static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003051{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003052 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003053 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003054
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003055 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003056 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3057 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3058
3059 return 0;
3060}
3061
3062static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3063{
3064 struct drm_i915_private *dev_priv = to_i915(dev);
3065 unsigned long irqflags;
3066
3067 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3068 i915_enable_pipestat(dev_priv, pipe,
3069 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003070 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003071
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003072 return 0;
3073}
3074
Thierry Reding88e72712015-09-24 18:35:31 +02003075static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003076{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003077 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003078 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003079 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003080 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003081
Jesse Barnesf796cf82011-04-07 13:58:17 -07003082 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003083 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003084 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3085
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003086 /* Even though there is no DMC, frame counter can get stuck when
3087 * PSR is active as no frames are generated.
3088 */
3089 if (HAS_PSR(dev_priv))
3090 drm_vblank_restore(dev, pipe);
3091
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003092 return 0;
3093}
3094
Thierry Reding88e72712015-09-24 18:35:31 +02003095static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003096{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003097 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003098 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003099
Ben Widawskyabd58f02013-11-02 21:07:09 -07003100 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003101 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003102 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003103
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003104 /* Even if there is no DMC, frame counter can get stuck when
3105 * PSR is active as no frames are generated, so check only for PSR.
3106 */
3107 if (HAS_PSR(dev_priv))
3108 drm_vblank_restore(dev, pipe);
3109
Ben Widawskyabd58f02013-11-02 21:07:09 -07003110 return 0;
3111}
3112
Keith Packard42f52ef2008-10-18 19:39:29 -07003113/* Called from drm generic code, passed 'crtc' which
3114 * we use as a pipe index
3115 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003116static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3117{
3118 struct drm_i915_private *dev_priv = to_i915(dev);
3119 unsigned long irqflags;
3120
3121 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3122 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3123 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3124}
3125
3126static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003127{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003128 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003129 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003130
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003131 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003132 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003133 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003134 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3135}
3136
Thierry Reding88e72712015-09-24 18:35:31 +02003137static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003138{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003139 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003140 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003141 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003142 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003143
3144 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003145 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003146 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3147}
3148
Thierry Reding88e72712015-09-24 18:35:31 +02003149static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003150{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003151 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003152 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003153
Ben Widawskyabd58f02013-11-02 21:07:09 -07003154 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003155 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003156 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3157}
3158
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003159static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003160{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003161 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003162 return;
3163
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003164 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003165
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003166 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003167 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003168}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003169
Paulo Zanoni622364b2014-04-01 15:37:22 -03003170/*
3171 * SDEIER is also touched by the interrupt handler to work around missed PCH
3172 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3173 * instead we unconditionally enable all PCH interrupt sources here, but then
3174 * only unmask them as needed with SDEIMR.
3175 *
3176 * This function needs to be called before interrupts are enabled.
3177 */
3178static void ibx_irq_pre_postinstall(struct drm_device *dev)
3179{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003180 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003181
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003182 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003183 return;
3184
3185 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003186 I915_WRITE(SDEIER, 0xffffffff);
3187 POSTING_READ(SDEIER);
3188}
3189
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003190static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003191{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003192 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003193 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003194 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003195}
3196
Ville Syrjälä70591a42014-10-30 19:42:58 +02003197static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3198{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003199 if (IS_CHERRYVIEW(dev_priv))
3200 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3201 else
3202 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3203
Ville Syrjäläad22d102016-04-12 18:56:14 +03003204 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003205 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3206
Ville Syrjälä44d92412017-08-18 21:36:51 +03003207 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003208
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003209 GEN3_IRQ_RESET(VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003210 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003211}
3212
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003213static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3214{
3215 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003216 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003217 enum pipe pipe;
3218
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003219 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003220
3221 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3222 for_each_pipe(dev_priv, pipe)
3223 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3224
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003225 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3226 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003227 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3228 I915_LPE_PIPE_A_INTERRUPT |
3229 I915_LPE_PIPE_B_INTERRUPT;
3230
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003231 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003232 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3233 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003234
Chris Wilson8bd099a2017-11-30 12:52:53 +00003235 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003236
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003237 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003238
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003239 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003240}
3241
3242/* drm_dma.h hooks
3243*/
3244static void ironlake_irq_reset(struct drm_device *dev)
3245{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003246 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003247
Ville Syrjäläd420a502017-08-18 21:37:03 +03003248 if (IS_GEN5(dev_priv))
3249 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003250
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003251 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003252 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003253 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3254
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003255 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003256
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003257 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003258}
3259
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003260static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003261{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003262 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003263
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003264 I915_WRITE(VLV_MASTER_IER, 0);
3265 POSTING_READ(VLV_MASTER_IER);
3266
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003267 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003268
Ville Syrjäläad22d102016-04-12 18:56:14 +03003269 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003270 if (dev_priv->display_irqs_enabled)
3271 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003272 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003273}
3274
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003275static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3276{
3277 GEN8_IRQ_RESET_NDX(GT, 0);
3278 GEN8_IRQ_RESET_NDX(GT, 1);
3279 GEN8_IRQ_RESET_NDX(GT, 2);
3280 GEN8_IRQ_RESET_NDX(GT, 3);
3281}
3282
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003283static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003284{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003285 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003286 int pipe;
3287
Ben Widawskyabd58f02013-11-02 21:07:09 -07003288 I915_WRITE(GEN8_MASTER_IRQ, 0);
3289 POSTING_READ(GEN8_MASTER_IRQ);
3290
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003291 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003292
Damien Lespiau055e3932014-08-18 13:49:10 +01003293 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003294 if (intel_display_power_is_enabled(dev_priv,
3295 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003296 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003297
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003298 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3299 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3300 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003301
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003302 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003303 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003304}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003305
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003306static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3307{
3308 /* Disable RCS, BCS, VCS and VECS class engines. */
3309 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3310 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3311
3312 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3313 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3314 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3315 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3316 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3317 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
3318}
3319
3320static void gen11_irq_reset(struct drm_device *dev)
3321{
3322 struct drm_i915_private *dev_priv = dev->dev_private;
3323 int pipe;
3324
3325 I915_WRITE(GEN11_GFX_MSTR_IRQ, 0);
3326 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3327
3328 gen11_gt_irq_reset(dev_priv);
3329
3330 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3331
3332 for_each_pipe(dev_priv, pipe)
3333 if (intel_display_power_is_enabled(dev_priv,
3334 POWER_DOMAIN_PIPE(pipe)))
3335 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3336
3337 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3338 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3339 GEN3_IRQ_RESET(GEN8_PCU_);
3340}
3341
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003342void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003343 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003344{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003345 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003346 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003347
Daniel Vetter13321782014-09-15 14:55:29 +02003348 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003349
3350 if (!intel_irqs_enabled(dev_priv)) {
3351 spin_unlock_irq(&dev_priv->irq_lock);
3352 return;
3353 }
3354
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003355 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3356 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3357 dev_priv->de_irq_mask[pipe],
3358 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003359
Daniel Vetter13321782014-09-15 14:55:29 +02003360 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003361}
3362
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003363void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003364 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003365{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003366 enum pipe pipe;
3367
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003368 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003369
3370 if (!intel_irqs_enabled(dev_priv)) {
3371 spin_unlock_irq(&dev_priv->irq_lock);
3372 return;
3373 }
3374
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003375 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3376 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003377
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003378 spin_unlock_irq(&dev_priv->irq_lock);
3379
3380 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003381 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003382}
3383
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003384static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003385{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003386 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003387
3388 I915_WRITE(GEN8_MASTER_IRQ, 0);
3389 POSTING_READ(GEN8_MASTER_IRQ);
3390
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003391 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003392
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003393 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003394
Ville Syrjäläad22d102016-04-12 18:56:14 +03003395 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003396 if (dev_priv->display_irqs_enabled)
3397 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003398 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003399}
3400
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003401static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003402 const u32 hpd[HPD_NUM_PINS])
3403{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003404 struct intel_encoder *encoder;
3405 u32 enabled_irqs = 0;
3406
Chris Wilson91c8a322016-07-05 10:40:23 +01003407 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003408 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3409 enabled_irqs |= hpd[encoder->hpd_pin];
3410
3411 return enabled_irqs;
3412}
3413
Imre Deak1a56b1a2017-01-27 11:39:21 +02003414static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3415{
3416 u32 hotplug;
3417
3418 /*
3419 * Enable digital hotplug on the PCH, and configure the DP short pulse
3420 * duration to 2ms (which is the minimum in the Display Port spec).
3421 * The pulse duration bits are reserved on LPT+.
3422 */
3423 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3424 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3425 PORTC_PULSE_DURATION_MASK |
3426 PORTD_PULSE_DURATION_MASK);
3427 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3428 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3429 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3430 /*
3431 * When CPU and PCH are on the same package, port A
3432 * HPD must be enabled in both north and south.
3433 */
3434 if (HAS_PCH_LPT_LP(dev_priv))
3435 hotplug |= PORTA_HOTPLUG_ENABLE;
3436 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3437}
3438
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003439static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003440{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003441 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003442
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003443 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003444 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003445 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003446 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003447 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003448 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003449 }
3450
Daniel Vetterfee884e2013-07-04 23:35:21 +02003451 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003452
Imre Deak1a56b1a2017-01-27 11:39:21 +02003453 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003454}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003455
Imre Deak2a57d9c2017-01-27 11:39:18 +02003456static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3457{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003458 u32 val, hotplug;
3459
3460 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3461 if (HAS_PCH_CNP(dev_priv)) {
3462 val = I915_READ(SOUTH_CHICKEN1);
3463 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3464 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3465 I915_WRITE(SOUTH_CHICKEN1, val);
3466 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003467
3468 /* Enable digital hotplug on the PCH */
3469 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3470 hotplug |= PORTA_HOTPLUG_ENABLE |
3471 PORTB_HOTPLUG_ENABLE |
3472 PORTC_HOTPLUG_ENABLE |
3473 PORTD_HOTPLUG_ENABLE;
3474 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3475
3476 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3477 hotplug |= PORTE_HOTPLUG_ENABLE;
3478 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3479}
3480
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003481static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003482{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003483 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003484
3485 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003486 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003487
3488 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3489
Imre Deak2a57d9c2017-01-27 11:39:18 +02003490 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003491}
3492
Imre Deak1a56b1a2017-01-27 11:39:21 +02003493static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3494{
3495 u32 hotplug;
3496
3497 /*
3498 * Enable digital hotplug on the CPU, and configure the DP short pulse
3499 * duration to 2ms (which is the minimum in the Display Port spec)
3500 * The pulse duration bits are reserved on HSW+.
3501 */
3502 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3503 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3504 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3505 DIGITAL_PORTA_PULSE_DURATION_2ms;
3506 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3507}
3508
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003509static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003510{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003511 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003512
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003513 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003514 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003515 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003516
3517 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003518 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003519 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003520 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003521
3522 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003523 } else {
3524 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003525 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003526
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003527 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3528 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003529
Imre Deak1a56b1a2017-01-27 11:39:21 +02003530 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003531
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003532 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003533}
3534
Imre Deak2a57d9c2017-01-27 11:39:18 +02003535static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3536 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003537{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003538 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003539
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003540 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003541 hotplug |= PORTA_HOTPLUG_ENABLE |
3542 PORTB_HOTPLUG_ENABLE |
3543 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303544
3545 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3546 hotplug, enabled_irqs);
3547 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3548
3549 /*
3550 * For BXT invert bit has to be set based on AOB design
3551 * for HPD detection logic, update it based on VBT fields.
3552 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303553 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3554 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3555 hotplug |= BXT_DDIA_HPD_INVERT;
3556 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3557 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3558 hotplug |= BXT_DDIB_HPD_INVERT;
3559 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3560 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3561 hotplug |= BXT_DDIC_HPD_INVERT;
3562
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003563 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003564}
3565
Imre Deak2a57d9c2017-01-27 11:39:18 +02003566static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3567{
3568 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3569}
3570
3571static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3572{
3573 u32 hotplug_irqs, enabled_irqs;
3574
3575 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3576 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3577
3578 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3579
3580 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3581}
3582
Paulo Zanonid46da432013-02-08 17:35:15 -02003583static void ibx_irq_postinstall(struct drm_device *dev)
3584{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003585 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003586 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003587
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003588 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003589 return;
3590
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003591 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003592 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003593 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003594 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003595 else
3596 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003597
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003598 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003599 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003600
3601 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3602 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003603 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003604 else
3605 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003606}
3607
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003608static void gen5_gt_irq_postinstall(struct drm_device *dev)
3609{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003610 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003611 u32 pm_irqs, gt_irqs;
3612
3613 pm_irqs = gt_irqs = 0;
3614
3615 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003616 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003617 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003618 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3619 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003620 }
3621
3622 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003623 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003624 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003625 } else {
3626 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3627 }
3628
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003629 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003630
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003631 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003632 /*
3633 * RPS interrupts will get enabled/disabled on demand when RPS
3634 * itself is enabled/disabled.
3635 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303636 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003637 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303638 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3639 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003640
Akash Goelf4e9af42016-10-12 21:54:30 +05303641 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003642 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003643 }
3644}
3645
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003646static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003647{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003648 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003649 u32 display_mask, extra_mask;
3650
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003651 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003652 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003653 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003654 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003655 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3656 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003657 } else {
3658 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003659 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3660 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003661 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3662 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3663 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003664 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003665
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003666 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003667
Paulo Zanoni622364b2014-04-01 15:37:22 -03003668 ibx_irq_pre_postinstall(dev);
3669
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003670 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003671
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003672 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003673
Imre Deak1a56b1a2017-01-27 11:39:21 +02003674 ilk_hpd_detection_setup(dev_priv);
3675
Paulo Zanonid46da432013-02-08 17:35:15 -02003676 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003677
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003678 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003679 /* Enable PCU event interrupts
3680 *
3681 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003682 * setup is guaranteed to run in single-threaded context. But we
3683 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003684 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003685 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003686 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003687 }
3688
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003689 return 0;
3690}
3691
Imre Deakf8b79e52014-03-04 19:23:07 +02003692void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3693{
Chris Wilson67520412017-03-02 13:28:01 +00003694 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003695
3696 if (dev_priv->display_irqs_enabled)
3697 return;
3698
3699 dev_priv->display_irqs_enabled = true;
3700
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003701 if (intel_irqs_enabled(dev_priv)) {
3702 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003703 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003704 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003705}
3706
3707void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3708{
Chris Wilson67520412017-03-02 13:28:01 +00003709 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003710
3711 if (!dev_priv->display_irqs_enabled)
3712 return;
3713
3714 dev_priv->display_irqs_enabled = false;
3715
Imre Deak950eaba2014-09-08 15:21:09 +03003716 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003717 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003718}
3719
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003720
3721static int valleyview_irq_postinstall(struct drm_device *dev)
3722{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003723 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003724
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003725 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003726
Ville Syrjäläad22d102016-04-12 18:56:14 +03003727 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003728 if (dev_priv->display_irqs_enabled)
3729 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003730 spin_unlock_irq(&dev_priv->irq_lock);
3731
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003732 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003733 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003734
3735 return 0;
3736}
3737
Ben Widawskyabd58f02013-11-02 21:07:09 -07003738static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3739{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003740 /* These are interrupts we'll toggle with the ring mask register */
3741 uint32_t gt_interrupts[] = {
3742 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003743 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003744 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3745 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003746 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003747 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3748 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3749 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003750 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003751 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3752 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003753 };
3754
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003755 if (HAS_L3_DPF(dev_priv))
3756 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3757
Akash Goelf4e9af42016-10-12 21:54:30 +05303758 dev_priv->pm_ier = 0x0;
3759 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303760 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3761 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003762 /*
3763 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303764 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003765 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303766 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303767 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003768}
3769
3770static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3771{
Damien Lespiau770de832014-03-20 20:45:01 +00003772 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3773 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003774 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3775 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003776 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003777 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003778
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003779 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003780 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003781 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3782 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003783 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003784 de_port_masked |= BXT_DE_PORT_GMBUS;
3785 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003786 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003787 }
Damien Lespiau770de832014-03-20 20:45:01 +00003788
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003789 if (IS_CNL_WITH_PORT_F(dev_priv))
3790 de_port_masked |= CNL_AUX_CHANNEL_F;
3791
Damien Lespiau770de832014-03-20 20:45:01 +00003792 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3793 GEN8_PIPE_FIFO_UNDERRUN;
3794
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003795 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003796 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003797 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3798 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003799 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3800
Mika Kahola0a195c02017-10-10 13:17:04 +03003801 for_each_pipe(dev_priv, pipe) {
3802 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003803
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003804 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003805 POWER_DOMAIN_PIPE(pipe)))
3806 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3807 dev_priv->de_irq_mask[pipe],
3808 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03003809 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07003810
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003811 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3812 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003813
3814 if (IS_GEN9_LP(dev_priv))
3815 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003816 else if (IS_BROADWELL(dev_priv))
3817 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003818}
3819
3820static int gen8_irq_postinstall(struct drm_device *dev)
3821{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003822 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003823
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003824 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303825 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003826
Ben Widawskyabd58f02013-11-02 21:07:09 -07003827 gen8_gt_irq_postinstall(dev_priv);
3828 gen8_de_irq_postinstall(dev_priv);
3829
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003830 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303831 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003832
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003833 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003834 POSTING_READ(GEN8_MASTER_IRQ);
3835
3836 return 0;
3837}
3838
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003839static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3840{
3841 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
3842
3843 BUILD_BUG_ON(irqs & 0xffff0000);
3844
3845 /* Enable RCS, BCS, VCS and VECS class interrupts. */
3846 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
3847 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
3848
3849 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
3850 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
3851 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
3852 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
3853 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
3854 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
3855
3856 dev_priv->pm_imr = 0xffffffff; /* TODO */
3857}
3858
3859static int gen11_irq_postinstall(struct drm_device *dev)
3860{
3861 struct drm_i915_private *dev_priv = dev->dev_private;
3862
3863 gen11_gt_irq_postinstall(dev_priv);
3864 gen8_de_irq_postinstall(dev_priv);
3865
3866 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
3867
3868 I915_WRITE(GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
3869 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3870
3871 return 0;
3872}
3873
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003874static int cherryview_irq_postinstall(struct drm_device *dev)
3875{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003876 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003877
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003878 gen8_gt_irq_postinstall(dev_priv);
3879
Ville Syrjäläad22d102016-04-12 18:56:14 +03003880 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003881 if (dev_priv->display_irqs_enabled)
3882 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003883 spin_unlock_irq(&dev_priv->irq_lock);
3884
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003885 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003886 POSTING_READ(GEN8_MASTER_IRQ);
3887
3888 return 0;
3889}
3890
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003891static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003892{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003893 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003894
Ville Syrjälä44d92412017-08-18 21:36:51 +03003895 i9xx_pipestat_irq_reset(dev_priv);
3896
Ville Syrjäläd420a502017-08-18 21:37:03 +03003897 I915_WRITE16(HWSTAM, 0xffff);
3898
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003899 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01003900}
3901
3902static int i8xx_irq_postinstall(struct drm_device *dev)
3903{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003904 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003905 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003906
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003907 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
3908 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01003909
3910 /* Unmask the interrupts that we always want on. */
3911 dev_priv->irq_mask =
3912 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003913 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003914
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003915 enable_mask =
3916 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3917 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3918 I915_USER_INTERRUPT;
3919
3920 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003921
Daniel Vetter379ef822013-10-16 22:55:56 +02003922 /* Interrupt setup is already guaranteed to be single-threaded, this is
3923 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003924 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003925 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3926 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003927 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003928
Chris Wilsonc2798b12012-04-22 21:13:57 +01003929 return 0;
3930}
3931
Daniel Vetterff1f5252012-10-02 15:10:55 +02003932static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003933{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003934 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003935 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003936 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003937
Imre Deak2dd2a882015-02-24 11:14:30 +02003938 if (!intel_irqs_enabled(dev_priv))
3939 return IRQ_NONE;
3940
Imre Deak1f814da2015-12-16 02:52:19 +02003941 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3942 disable_rpm_wakeref_asserts(dev_priv);
3943
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003944 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003945 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003946 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03003947
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003948 iir = I915_READ16(IIR);
3949 if (iir == 0)
3950 break;
3951
3952 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003953
Ville Syrjäläeb643432017-08-18 21:36:59 +03003954 /* Call regardless, as some status bits might not be
3955 * signalled in iir */
3956 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003957
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003958 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003959
Chris Wilsonc2798b12012-04-22 21:13:57 +01003960 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303961 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003962
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003963 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3964 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3965
Ville Syrjäläeb643432017-08-18 21:36:59 +03003966 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003967 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003968
Imre Deak1f814da2015-12-16 02:52:19 +02003969 enable_rpm_wakeref_asserts(dev_priv);
3970
3971 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003972}
3973
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003974static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003975{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003976 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003977
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003978 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003979 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003980 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3981 }
3982
Ville Syrjälä44d92412017-08-18 21:36:51 +03003983 i9xx_pipestat_irq_reset(dev_priv);
3984
Ville Syrjäläd420a502017-08-18 21:37:03 +03003985 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003986
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003987 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003988}
3989
3990static int i915_irq_postinstall(struct drm_device *dev)
3991{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003992 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01003993 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003994
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003995 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
3996 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01003997
3998 /* Unmask the interrupts that we always want on. */
3999 dev_priv->irq_mask =
4000 ~(I915_ASLE_INTERRUPT |
4001 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004002 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004003
4004 enable_mask =
4005 I915_ASLE_INTERRUPT |
4006 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4007 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004008 I915_USER_INTERRUPT;
4009
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004010 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004011 /* Enable in IER... */
4012 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4013 /* and unmask in IMR */
4014 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4015 }
4016
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004017 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004018
Daniel Vetter379ef822013-10-16 22:55:56 +02004019 /* Interrupt setup is already guaranteed to be single-threaded, this is
4020 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004021 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004022 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4023 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004024 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004025
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004026 i915_enable_asle_pipestat(dev_priv);
4027
Daniel Vetter20afbda2012-12-11 14:05:07 +01004028 return 0;
4029}
4030
Daniel Vetterff1f5252012-10-02 15:10:55 +02004031static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004032{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004033 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004034 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004035 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004036
Imre Deak2dd2a882015-02-24 11:14:30 +02004037 if (!intel_irqs_enabled(dev_priv))
4038 return IRQ_NONE;
4039
Imre Deak1f814da2015-12-16 02:52:19 +02004040 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4041 disable_rpm_wakeref_asserts(dev_priv);
4042
Chris Wilson38bde182012-04-24 22:59:50 +01004043 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004044 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004045 u32 hotplug_status = 0;
4046 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004047
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004048 iir = I915_READ(IIR);
4049 if (iir == 0)
4050 break;
4051
4052 ret = IRQ_HANDLED;
4053
4054 if (I915_HAS_HOTPLUG(dev_priv) &&
4055 iir & I915_DISPLAY_PORT_INTERRUPT)
4056 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004057
Ville Syrjäläeb643432017-08-18 21:36:59 +03004058 /* Call regardless, as some status bits might not be
4059 * signalled in iir */
4060 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004061
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004062 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004063
Chris Wilsona266c7d2012-04-24 22:59:44 +01004064 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304065 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004066
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004067 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4068 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004069
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004070 if (hotplug_status)
4071 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4072
4073 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4074 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004075
Imre Deak1f814da2015-12-16 02:52:19 +02004076 enable_rpm_wakeref_asserts(dev_priv);
4077
Chris Wilsona266c7d2012-04-24 22:59:44 +01004078 return ret;
4079}
4080
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004081static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004082{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004083 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004084
Egbert Eich0706f172015-09-23 16:15:27 +02004085 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004086 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004087
Ville Syrjälä44d92412017-08-18 21:36:51 +03004088 i9xx_pipestat_irq_reset(dev_priv);
4089
Ville Syrjäläd420a502017-08-18 21:37:03 +03004090 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004091
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004092 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004093}
4094
4095static int i965_irq_postinstall(struct drm_device *dev)
4096{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004097 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004098 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004099 u32 error_mask;
4100
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004101 /*
4102 * Enable some error detection, note the instruction error mask
4103 * bit is reserved, so we leave it masked.
4104 */
4105 if (IS_G4X(dev_priv)) {
4106 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4107 GM45_ERROR_MEM_PRIV |
4108 GM45_ERROR_CP_PRIV |
4109 I915_ERROR_MEMORY_REFRESH);
4110 } else {
4111 error_mask = ~(I915_ERROR_PAGE_TABLE |
4112 I915_ERROR_MEMORY_REFRESH);
4113 }
4114 I915_WRITE(EMR, error_mask);
4115
Chris Wilsona266c7d2012-04-24 22:59:44 +01004116 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004117 dev_priv->irq_mask =
4118 ~(I915_ASLE_INTERRUPT |
4119 I915_DISPLAY_PORT_INTERRUPT |
4120 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4121 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4122 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004123
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004124 enable_mask =
4125 I915_ASLE_INTERRUPT |
4126 I915_DISPLAY_PORT_INTERRUPT |
4127 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4128 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4129 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4130 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004131
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004132 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004133 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004134
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004135 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
4136
Daniel Vetterb79480b2013-06-27 17:52:10 +02004137 /* Interrupt setup is already guaranteed to be single-threaded, this is
4138 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004139 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004140 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4141 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4142 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004143 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004144
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004145 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004146
4147 return 0;
4148}
4149
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004150static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004151{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004152 u32 hotplug_en;
4153
Chris Wilson67520412017-03-02 13:28:01 +00004154 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004155
Ville Syrjälä778eb332015-01-09 14:21:13 +02004156 /* Note HDMI and DP share hotplug bits */
4157 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004158 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004159 /* Programming the CRT detection parameters tends
4160 to generate a spurious hotplug event about three
4161 seconds later. So just do it once.
4162 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004163 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004164 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004165 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004166
Ville Syrjälä778eb332015-01-09 14:21:13 +02004167 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004168 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004169 HOTPLUG_INT_EN_MASK |
4170 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4171 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4172 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004173}
4174
Daniel Vetterff1f5252012-10-02 15:10:55 +02004175static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004176{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004177 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004178 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004179 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180
Imre Deak2dd2a882015-02-24 11:14:30 +02004181 if (!intel_irqs_enabled(dev_priv))
4182 return IRQ_NONE;
4183
Imre Deak1f814da2015-12-16 02:52:19 +02004184 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4185 disable_rpm_wakeref_asserts(dev_priv);
4186
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004187 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004188 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004189 u32 hotplug_status = 0;
4190 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004191
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004192 iir = I915_READ(IIR);
4193 if (iir == 0)
4194 break;
4195
4196 ret = IRQ_HANDLED;
4197
4198 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4199 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004200
Ville Syrjäläeb643432017-08-18 21:36:59 +03004201 /* Call regardless, as some status bits might not be
4202 * signalled in iir */
4203 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004204
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004205 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004206
Chris Wilsona266c7d2012-04-24 22:59:44 +01004207 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304208 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004209
Chris Wilsona266c7d2012-04-24 22:59:44 +01004210 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304211 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004212
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004213 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4214 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004215
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004216 if (hotplug_status)
4217 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4218
4219 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4220 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004221
Imre Deak1f814da2015-12-16 02:52:19 +02004222 enable_rpm_wakeref_asserts(dev_priv);
4223
Chris Wilsona266c7d2012-04-24 22:59:44 +01004224 return ret;
4225}
4226
Daniel Vetterfca52a52014-09-30 10:56:45 +02004227/**
4228 * intel_irq_init - initializes irq support
4229 * @dev_priv: i915 device instance
4230 *
4231 * This function initializes all the irq support including work items, timers
4232 * and all the vtables. It does not setup the interrupt itself though.
4233 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004234void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004235{
Chris Wilson91c8a322016-07-05 10:40:23 +01004236 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004237 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004238 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004239
Jani Nikula77913b32015-06-18 13:06:16 +03004240 intel_hpd_init_work(dev_priv);
4241
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004242 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004243
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004244 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004245 for (i = 0; i < MAX_L3_SLICES; ++i)
4246 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004247
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004248 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304249 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4250
Deepak Sa6706b42014-03-15 20:23:22 +05304251 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004252 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004253 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004254 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004255 else
4256 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304257
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004258 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304259
4260 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004261 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304262 * if GEN6_PM_UP_EI_EXPIRED is masked.
4263 *
4264 * TODO: verify if this can be reproduced on VLV,CHV.
4265 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004266 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004267 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304268
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004269 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004270 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304271
Daniel Vetterb9632912014-09-30 10:56:44 +02004272 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004273 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004274 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004275 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004276 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004277 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004278 } else {
4279 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4280 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004281 }
4282
Ville Syrjälä21da2702014-08-06 14:49:55 +03004283 /*
4284 * Opt out of the vblank disable timer on everything except gen2.
4285 * Gen2 doesn't have a hardware frame counter and so depends on
4286 * vblank interrupts to produce sane vblank seuquence numbers.
4287 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004288 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004289 dev->vblank_disable_immediate = true;
4290
Chris Wilson262fd482017-02-15 13:15:47 +00004291 /* Most platforms treat the display irq block as an always-on
4292 * power domain. vlv/chv can disable it at runtime and need
4293 * special care to avoid writing any of the display block registers
4294 * outside of the power domain. We defer setting up the display irqs
4295 * in this case to the runtime pm.
4296 */
4297 dev_priv->display_irqs_enabled = true;
4298 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4299 dev_priv->display_irqs_enabled = false;
4300
Lyude317eaa92017-02-03 21:18:25 -05004301 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4302
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004303 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004304 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004305
Daniel Vetterb9632912014-09-30 10:56:44 +02004306 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004307 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004308 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004309 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004310 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004311 dev->driver->enable_vblank = i965_enable_vblank;
4312 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004313 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004314 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004315 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004316 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004317 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004318 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004319 dev->driver->enable_vblank = i965_enable_vblank;
4320 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004321 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004322 } else if (INTEL_GEN(dev_priv) >= 11) {
4323 dev->driver->irq_handler = gen11_irq_handler;
4324 dev->driver->irq_preinstall = gen11_irq_reset;
4325 dev->driver->irq_postinstall = gen11_irq_postinstall;
4326 dev->driver->irq_uninstall = gen11_irq_reset;
4327 dev->driver->enable_vblank = gen8_enable_vblank;
4328 dev->driver->disable_vblank = gen8_disable_vblank;
4329 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004330 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004331 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004332 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004333 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004334 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004335 dev->driver->enable_vblank = gen8_enable_vblank;
4336 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004337 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004338 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004339 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4340 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004341 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4342 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004343 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004344 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004345 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004346 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004347 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004348 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004349 dev->driver->enable_vblank = ironlake_enable_vblank;
4350 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004351 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004352 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004353 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004354 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004355 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4356 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004357 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004358 dev->driver->enable_vblank = i8xx_enable_vblank;
4359 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004360 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004361 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004362 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004363 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004364 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004365 dev->driver->enable_vblank = i8xx_enable_vblank;
4366 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004367 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004368 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004369 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004370 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004371 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004372 dev->driver->enable_vblank = i965_enable_vblank;
4373 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004374 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004375 if (I915_HAS_HOTPLUG(dev_priv))
4376 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004377 }
4378}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004379
Daniel Vetterfca52a52014-09-30 10:56:45 +02004380/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004381 * intel_irq_fini - deinitializes IRQ support
4382 * @i915: i915 device instance
4383 *
4384 * This function deinitializes all the IRQ support.
4385 */
4386void intel_irq_fini(struct drm_i915_private *i915)
4387{
4388 int i;
4389
4390 for (i = 0; i < MAX_L3_SLICES; ++i)
4391 kfree(i915->l3_parity.remap_info[i]);
4392}
4393
4394/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004395 * intel_irq_install - enables the hardware interrupt
4396 * @dev_priv: i915 device instance
4397 *
4398 * This function enables the hardware interrupt handling, but leaves the hotplug
4399 * handling still disabled. It is called after intel_irq_init().
4400 *
4401 * In the driver load and resume code we need working interrupts in a few places
4402 * but don't want to deal with the hassle of concurrent probe and hotplug
4403 * workers. Hence the split into this two-stage approach.
4404 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004405int intel_irq_install(struct drm_i915_private *dev_priv)
4406{
4407 /*
4408 * We enable some interrupt sources in our postinstall hooks, so mark
4409 * interrupts as enabled _before_ actually enabling them to avoid
4410 * special cases in our ordering checks.
4411 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004412 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004413
Chris Wilson91c8a322016-07-05 10:40:23 +01004414 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004415}
4416
Daniel Vetterfca52a52014-09-30 10:56:45 +02004417/**
4418 * intel_irq_uninstall - finilizes all irq handling
4419 * @dev_priv: i915 device instance
4420 *
4421 * This stops interrupt and hotplug handling and unregisters and frees all
4422 * resources acquired in the init functions.
4423 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004424void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4425{
Chris Wilson91c8a322016-07-05 10:40:23 +01004426 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004427 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004428 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004429}
4430
Daniel Vetterfca52a52014-09-30 10:56:45 +02004431/**
4432 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4433 * @dev_priv: i915 device instance
4434 *
4435 * This function is used to disable interrupts at runtime, both in the runtime
4436 * pm and the system suspend/resume code.
4437 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004438void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004439{
Chris Wilson91c8a322016-07-05 10:40:23 +01004440 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004441 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004442 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004443}
4444
Daniel Vetterfca52a52014-09-30 10:56:45 +02004445/**
4446 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4447 * @dev_priv: i915 device instance
4448 *
4449 * This function is used to enable interrupts at runtime, both in the runtime
4450 * pm and the system suspend/resume code.
4451 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004452void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004453{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004454 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004455 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4456 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004457}