blob: babf81cf668b31a00318a5509638048a8fae10f4 [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
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001402gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
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
1407 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) {
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
1414 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) {
1415 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],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001469 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001470 gen8_cs_irq_handler(i915->engine[BCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001471 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1472 }
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],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001476 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001477 gen8_cs_irq_handler(i915->engine[VCS2],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001478 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1479 }
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],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001483 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 Vivi256cfdde2017-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{
1769 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) {
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301770 /* Sample the log buffer flush related bits & clear them out now
1771 * itself from the message identity register to minimize the
1772 * probability of losing a flush interrupt, when there are back
1773 * to back flush interrupts.
1774 * There can be a new flush interrupt, for different log buffer
1775 * type (like for ISR), whilst Host is handling one (for DPC).
1776 * Since same bit is used in message register for ISR & DPC, it
1777 * could happen that GuC sets the bit for 2nd interrupt but Host
1778 * clears out the bit on handling the 1st interrupt.
1779 */
1780 u32 msg, flush;
1781
1782 msg = I915_READ(SOFT_SCRATCH(15));
Arkadiusz Hilera80bc452016-11-25 18:59:34 +01001783 flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED |
1784 INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER);
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301785 if (flush) {
1786 /* Clear the message bits that are handled */
1787 I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
1788
1789 /* Handle flush interrupt in bottom half */
Oscar Mateoe7465472017-03-22 10:39:48 -07001790 queue_work(dev_priv->guc.log.runtime.flush_wq,
1791 &dev_priv->guc.log.runtime.flush_work);
Akash Goel5aa1ee42016-10-12 21:54:36 +05301792
1793 dev_priv->guc.log.flush_interrupt_count++;
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301794 } else {
1795 /* Not clearing of unhandled event bits won't result in
1796 * re-triggering of the interrupt.
1797 */
1798 }
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301799 }
1800}
1801
Ville Syrjälä44d92412017-08-18 21:36:51 +03001802static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1803{
1804 enum pipe pipe;
1805
1806 for_each_pipe(dev_priv, pipe) {
1807 I915_WRITE(PIPESTAT(pipe),
1808 PIPESTAT_INT_STATUS_MASK |
1809 PIPE_FIFO_UNDERRUN_STATUS);
1810
1811 dev_priv->pipestat_irq_mask[pipe] = 0;
1812 }
1813}
1814
Ville Syrjäläeb643432017-08-18 21:36:59 +03001815static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1816 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001817{
Imre Deakc1874ed2014-02-04 21:35:46 +02001818 int pipe;
1819
Imre Deak58ead0d2014-02-04 21:35:47 +02001820 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001821
1822 if (!dev_priv->display_irqs_enabled) {
1823 spin_unlock(&dev_priv->irq_lock);
1824 return;
1825 }
1826
Damien Lespiau055e3932014-08-18 13:49:10 +01001827 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001828 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001829 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001830
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001831 /*
1832 * PIPESTAT bits get signalled even when the interrupt is
1833 * disabled with the mask bits, and some of the status bits do
1834 * not generate interrupts at all (like the underrun bit). Hence
1835 * we need to be careful that we only handle what we want to
1836 * handle.
1837 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001838
1839 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001840 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001841
1842 switch (pipe) {
1843 case PIPE_A:
1844 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1845 break;
1846 case PIPE_B:
1847 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1848 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001849 case PIPE_C:
1850 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1851 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001852 }
1853 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001854 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001855
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001856 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001857 continue;
1858
1859 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001860 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1861 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001862
1863 /*
1864 * Clear the PIPE*STAT regs before the IIR
1865 */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001866 if (pipe_stats[pipe])
1867 I915_WRITE(reg, enable_mask | pipe_stats[pipe]);
Imre Deakc1874ed2014-02-04 21:35:46 +02001868 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001869 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001870}
1871
Ville Syrjäläeb643432017-08-18 21:36:59 +03001872static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1873 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1874{
1875 enum pipe pipe;
1876
1877 for_each_pipe(dev_priv, pipe) {
1878 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1879 drm_handle_vblank(&dev_priv->drm, pipe);
1880
1881 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1882 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1883
1884 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1885 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1886 }
1887}
1888
1889static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1890 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1891{
1892 bool blc_event = false;
1893 enum pipe pipe;
1894
1895 for_each_pipe(dev_priv, pipe) {
1896 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1897 drm_handle_vblank(&dev_priv->drm, pipe);
1898
1899 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1900 blc_event = true;
1901
1902 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1903 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1904
1905 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1906 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1907 }
1908
1909 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1910 intel_opregion_asle_intr(dev_priv);
1911}
1912
1913static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1914 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1915{
1916 bool blc_event = false;
1917 enum pipe pipe;
1918
1919 for_each_pipe(dev_priv, pipe) {
1920 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1921 drm_handle_vblank(&dev_priv->drm, pipe);
1922
1923 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1924 blc_event = true;
1925
1926 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1927 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1928
1929 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1930 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1931 }
1932
1933 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1934 intel_opregion_asle_intr(dev_priv);
1935
1936 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1937 gmbus_irq_handler(dev_priv);
1938}
1939
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001940static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001941 u32 pipe_stats[I915_MAX_PIPES])
1942{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001943 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001944
Damien Lespiau055e3932014-08-18 13:49:10 +01001945 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001946 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1947 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001948
1949 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001950 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001951
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001952 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1953 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001954 }
1955
1956 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001957 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001958}
1959
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001960static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001961{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001962 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001963
1964 if (hotplug_status)
1965 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1966
1967 return hotplug_status;
1968}
1969
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001970static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001971 u32 hotplug_status)
1972{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001973 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001974
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001975 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1976 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001977 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001978
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001979 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08001980 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1981 hotplug_trigger, hotplug_trigger,
1982 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001983 i9xx_port_hotplug_long_detect);
1984
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001985 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001986 }
Jani Nikula369712e2015-05-27 15:03:40 +03001987
1988 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001989 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001990 } else {
1991 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001992
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001993 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08001994 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
1995 hotplug_trigger, hotplug_trigger,
1996 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001997 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001998 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001999 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002000 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002001}
2002
Daniel Vetterff1f5252012-10-02 15:10:55 +02002003static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002004{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002005 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002006 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002007 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002008
Imre Deak2dd2a882015-02-24 11:14:30 +02002009 if (!intel_irqs_enabled(dev_priv))
2010 return IRQ_NONE;
2011
Imre Deak1f814da2015-12-16 02:52:19 +02002012 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2013 disable_rpm_wakeref_asserts(dev_priv);
2014
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002015 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002016 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002017 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002018 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002019 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002020
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002021 gt_iir = I915_READ(GTIIR);
2022 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002023 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002024
2025 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002026 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002027
2028 ret = IRQ_HANDLED;
2029
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002030 /*
2031 * Theory on interrupt generation, based on empirical evidence:
2032 *
2033 * x = ((VLV_IIR & VLV_IER) ||
2034 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2035 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2036 *
2037 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2038 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2039 * guarantee the CPU interrupt will be raised again even if we
2040 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2041 * bits this time around.
2042 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002043 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002044 ier = I915_READ(VLV_IER);
2045 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002046
2047 if (gt_iir)
2048 I915_WRITE(GTIIR, gt_iir);
2049 if (pm_iir)
2050 I915_WRITE(GEN6_PMIIR, pm_iir);
2051
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002052 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002053 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002054
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002055 /* Call regardless, as some status bits might not be
2056 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002057 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002058
Jerome Anandeef57322017-01-25 04:27:49 +05302059 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2060 I915_LPE_PIPE_B_INTERRUPT))
2061 intel_lpe_audio_irq_handler(dev_priv);
2062
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002063 /*
2064 * VLV_IIR is single buffered, and reflects the level
2065 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2066 */
2067 if (iir)
2068 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002069
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002070 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002071 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2072 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002073
Ville Syrjälä52894872016-04-13 21:19:56 +03002074 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002075 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002076 if (pm_iir)
2077 gen6_rps_irq_handler(dev_priv, pm_iir);
2078
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002079 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002080 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002081
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002082 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002083 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002084
Imre Deak1f814da2015-12-16 02:52:19 +02002085 enable_rpm_wakeref_asserts(dev_priv);
2086
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002087 return ret;
2088}
2089
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002090static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2091{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002092 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002093 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002094 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002095
Imre Deak2dd2a882015-02-24 11:14:30 +02002096 if (!intel_irqs_enabled(dev_priv))
2097 return IRQ_NONE;
2098
Imre Deak1f814da2015-12-16 02:52:19 +02002099 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2100 disable_rpm_wakeref_asserts(dev_priv);
2101
Chris Wilson579de732016-03-14 09:01:57 +00002102 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002103 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002104 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002105 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002106 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002107 u32 ier = 0;
2108
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002109 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2110 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002111
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002112 if (master_ctl == 0 && iir == 0)
2113 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002114
Oscar Mateo27b6c122014-06-16 16:11:00 +01002115 ret = IRQ_HANDLED;
2116
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002117 /*
2118 * Theory on interrupt generation, based on empirical evidence:
2119 *
2120 * x = ((VLV_IIR & VLV_IER) ||
2121 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2122 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2123 *
2124 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2125 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2126 * guarantee the CPU interrupt will be raised again even if we
2127 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2128 * bits this time around.
2129 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002130 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002131 ier = I915_READ(VLV_IER);
2132 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002133
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002134 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002135
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002136 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002137 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002138
Oscar Mateo27b6c122014-06-16 16:11:00 +01002139 /* Call regardless, as some status bits might not be
2140 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002141 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002142
Jerome Anandeef57322017-01-25 04:27:49 +05302143 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2144 I915_LPE_PIPE_B_INTERRUPT |
2145 I915_LPE_PIPE_C_INTERRUPT))
2146 intel_lpe_audio_irq_handler(dev_priv);
2147
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002148 /*
2149 * VLV_IIR is single buffered, and reflects the level
2150 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2151 */
2152 if (iir)
2153 I915_WRITE(VLV_IIR, iir);
2154
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002155 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002156 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002157 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002158
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002159 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002160
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002161 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002162 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002163
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002164 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002165 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002166
Imre Deak1f814da2015-12-16 02:52:19 +02002167 enable_rpm_wakeref_asserts(dev_priv);
2168
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002169 return ret;
2170}
2171
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002172static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2173 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002174 const u32 hpd[HPD_NUM_PINS])
2175{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002176 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2177
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002178 /*
2179 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2180 * unless we touch the hotplug register, even if hotplug_trigger is
2181 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2182 * errors.
2183 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002184 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002185 if (!hotplug_trigger) {
2186 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2187 PORTD_HOTPLUG_STATUS_MASK |
2188 PORTC_HOTPLUG_STATUS_MASK |
2189 PORTB_HOTPLUG_STATUS_MASK;
2190 dig_hotplug_reg &= ~mask;
2191 }
2192
Ville Syrjälä40e56412015-08-27 23:56:10 +03002193 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002194 if (!hotplug_trigger)
2195 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002196
Rodrigo Vivicf539022018-01-29 15:22:21 -08002197 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002198 dig_hotplug_reg, hpd,
2199 pch_port_hotplug_long_detect);
2200
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002201 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002202}
2203
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002204static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002205{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002206 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002207 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002208
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002209 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002210
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002211 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2212 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2213 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002214 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002215 port_name(port));
2216 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002217
Daniel Vetterce99c252012-12-01 13:53:47 +01002218 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002219 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002220
Jesse Barnes776ad802011-01-04 15:09:39 -08002221 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002222 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002223
2224 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2225 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2226
2227 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2228 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2229
2230 if (pch_iir & SDE_POISON)
2231 DRM_ERROR("PCH poison interrupt\n");
2232
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002233 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002234 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002235 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2236 pipe_name(pipe),
2237 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002238
2239 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2240 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2241
2242 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2243 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2244
Jesse Barnes776ad802011-01-04 15:09:39 -08002245 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002246 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002247
2248 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002249 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002250}
2251
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002252static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002253{
Paulo Zanoni86642812013-04-12 17:57:57 -03002254 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002255 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002256
Paulo Zanonide032bf2013-04-12 17:57:58 -03002257 if (err_int & ERR_INT_POISON)
2258 DRM_ERROR("Poison interrupt\n");
2259
Damien Lespiau055e3932014-08-18 13:49:10 +01002260 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002261 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2262 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002263
Daniel Vetter5a69b892013-10-16 22:55:52 +02002264 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002265 if (IS_IVYBRIDGE(dev_priv))
2266 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002267 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002268 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002269 }
2270 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002271
Paulo Zanoni86642812013-04-12 17:57:57 -03002272 I915_WRITE(GEN7_ERR_INT, err_int);
2273}
2274
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002275static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002276{
Paulo Zanoni86642812013-04-12 17:57:57 -03002277 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002278 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002279
Paulo Zanonide032bf2013-04-12 17:57:58 -03002280 if (serr_int & SERR_INT_POISON)
2281 DRM_ERROR("PCH poison interrupt\n");
2282
Mika Kahola45c1cd82017-10-10 13:17:06 +03002283 for_each_pipe(dev_priv, pipe)
2284 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2285 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002286
2287 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002288}
2289
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002290static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002291{
Adam Jackson23e81d62012-06-06 15:45:44 -04002292 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002293 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002294
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002295 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002296
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002297 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2298 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2299 SDE_AUDIO_POWER_SHIFT_CPT);
2300 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2301 port_name(port));
2302 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002303
2304 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002305 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002306
2307 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002308 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002309
2310 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2311 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2312
2313 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2314 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2315
2316 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002317 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002318 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2319 pipe_name(pipe),
2320 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002321
2322 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002323 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002324}
2325
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002326static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002327{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002328 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2329 ~SDE_PORTE_HOTPLUG_SPT;
2330 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2331 u32 pin_mask = 0, long_mask = 0;
2332
2333 if (hotplug_trigger) {
2334 u32 dig_hotplug_reg;
2335
2336 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2337 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2338
Rodrigo Vivicf539022018-01-29 15:22:21 -08002339 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2340 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002341 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002342 }
2343
2344 if (hotplug2_trigger) {
2345 u32 dig_hotplug_reg;
2346
2347 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2348 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2349
Rodrigo Vivicf539022018-01-29 15:22:21 -08002350 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2351 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002352 spt_port_hotplug2_long_detect);
2353 }
2354
2355 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002356 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002357
2358 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002359 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002360}
2361
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002362static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2363 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002364 const u32 hpd[HPD_NUM_PINS])
2365{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002366 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2367
2368 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2369 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2370
Rodrigo Vivicf539022018-01-29 15:22:21 -08002371 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002372 dig_hotplug_reg, hpd,
2373 ilk_port_hotplug_long_detect);
2374
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002375 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002376}
2377
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002378static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2379 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002380{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002381 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002382 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2383
Ville Syrjälä40e56412015-08-27 23:56:10 +03002384 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002385 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002386
2387 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002388 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002389
2390 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002391 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002392
Paulo Zanonic008bc62013-07-12 16:35:10 -03002393 if (de_iir & DE_POISON)
2394 DRM_ERROR("Poison interrupt\n");
2395
Damien Lespiau055e3932014-08-18 13:49:10 +01002396 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002397 if (de_iir & DE_PIPE_VBLANK(pipe))
2398 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002399
Daniel Vetter40da17c22013-10-21 18:04:36 +02002400 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002401 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002402
Daniel Vetter40da17c22013-10-21 18:04:36 +02002403 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002404 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002405 }
2406
2407 /* check event from PCH */
2408 if (de_iir & DE_PCH_EVENT) {
2409 u32 pch_iir = I915_READ(SDEIIR);
2410
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002411 if (HAS_PCH_CPT(dev_priv))
2412 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002413 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002414 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002415
2416 /* should clear PCH hotplug event before clear CPU irq */
2417 I915_WRITE(SDEIIR, pch_iir);
2418 }
2419
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002420 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2421 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002422}
2423
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002424static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2425 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002426{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002427 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002428 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2429
Ville Syrjälä40e56412015-08-27 23:56:10 +03002430 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002431 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002432
2433 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002434 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002435
2436 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002437 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002438
2439 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002440 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002441
Damien Lespiau055e3932014-08-18 13:49:10 +01002442 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002443 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2444 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002445 }
2446
2447 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002448 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002449 u32 pch_iir = I915_READ(SDEIIR);
2450
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002451 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002452
2453 /* clear PCH hotplug event before clear CPU irq */
2454 I915_WRITE(SDEIIR, pch_iir);
2455 }
2456}
2457
Oscar Mateo72c90f62014-06-16 16:10:57 +01002458/*
2459 * To handle irqs with the minimum potential races with fresh interrupts, we:
2460 * 1 - Disable Master Interrupt Control.
2461 * 2 - Find the source(s) of the interrupt.
2462 * 3 - Clear the Interrupt Identity bits (IIR).
2463 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2464 * 5 - Re-enable Master Interrupt Control.
2465 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002466static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002467{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002468 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002469 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002470 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002471 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002472
Imre Deak2dd2a882015-02-24 11:14:30 +02002473 if (!intel_irqs_enabled(dev_priv))
2474 return IRQ_NONE;
2475
Imre Deak1f814da2015-12-16 02:52:19 +02002476 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2477 disable_rpm_wakeref_asserts(dev_priv);
2478
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002479 /* disable master interrupt before clearing iir */
2480 de_ier = I915_READ(DEIER);
2481 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002482 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002483
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002484 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2485 * interrupts will will be stored on its back queue, and then we'll be
2486 * able to process them after we restore SDEIER (as soon as we restore
2487 * it, we'll get an interrupt if SDEIIR still has something to process
2488 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002489 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002490 sde_ier = I915_READ(SDEIER);
2491 I915_WRITE(SDEIER, 0);
2492 POSTING_READ(SDEIER);
2493 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002494
Oscar Mateo72c90f62014-06-16 16:10:57 +01002495 /* Find, clear, then process each source of interrupt */
2496
Chris Wilson0e434062012-05-09 21:45:44 +01002497 gt_iir = I915_READ(GTIIR);
2498 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002499 I915_WRITE(GTIIR, gt_iir);
2500 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002501 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002502 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002503 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002504 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002505 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002506
2507 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002508 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002509 I915_WRITE(DEIIR, de_iir);
2510 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002511 if (INTEL_GEN(dev_priv) >= 7)
2512 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002513 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002514 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002515 }
2516
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002517 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002518 u32 pm_iir = I915_READ(GEN6_PMIIR);
2519 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002520 I915_WRITE(GEN6_PMIIR, pm_iir);
2521 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002522 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002523 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002524 }
2525
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002526 I915_WRITE(DEIER, de_ier);
2527 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002528 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002529 I915_WRITE(SDEIER, sde_ier);
2530 POSTING_READ(SDEIER);
2531 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002532
Imre Deak1f814da2015-12-16 02:52:19 +02002533 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2534 enable_rpm_wakeref_asserts(dev_priv);
2535
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002536 return ret;
2537}
2538
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002539static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2540 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002541 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302542{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002543 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302544
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002545 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2546 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302547
Rodrigo Vivicf539022018-01-29 15:22:21 -08002548 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002549 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002550 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002551
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002552 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302553}
2554
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002555static irqreturn_t
2556gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002557{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002558 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002559 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002560 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002561
Ben Widawskyabd58f02013-11-02 21:07:09 -07002562 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002563 iir = I915_READ(GEN8_DE_MISC_IIR);
2564 if (iir) {
2565 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002566 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002567 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002568 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002569 else
2570 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002571 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002572 else
2573 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002574 }
2575
Daniel Vetter6d766f02013-11-07 14:49:55 +01002576 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002577 iir = I915_READ(GEN8_DE_PORT_IIR);
2578 if (iir) {
2579 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302580 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002581
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002582 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002583 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002584
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002585 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002586 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002587 tmp_mask |= GEN9_AUX_CHANNEL_B |
2588 GEN9_AUX_CHANNEL_C |
2589 GEN9_AUX_CHANNEL_D;
2590
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002591 if (IS_CNL_WITH_PORT_F(dev_priv))
2592 tmp_mask |= CNL_AUX_CHANNEL_F;
2593
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002594 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002595 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302596 found = true;
2597 }
2598
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002599 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002600 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2601 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002602 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2603 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002604 found = true;
2605 }
2606 } else if (IS_BROADWELL(dev_priv)) {
2607 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2608 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002609 ilk_hpd_irq_handler(dev_priv,
2610 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002611 found = true;
2612 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302613 }
2614
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002615 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002616 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302617 found = true;
2618 }
2619
Shashank Sharmad04a4922014-08-22 17:40:41 +05302620 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002621 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002622 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002623 else
2624 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002625 }
2626
Damien Lespiau055e3932014-08-18 13:49:10 +01002627 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002628 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002629
Daniel Vetterc42664c2013-11-07 11:05:40 +01002630 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2631 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002632
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002633 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2634 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002635 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002636 continue;
2637 }
2638
2639 ret = IRQ_HANDLED;
2640 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2641
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002642 if (iir & GEN8_PIPE_VBLANK)
2643 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002644
2645 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002646 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002647
2648 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2649 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2650
2651 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002652 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002653 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2654 else
2655 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2656
2657 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002658 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002659 pipe_name(pipe),
2660 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002661 }
2662
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002663 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302664 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002665 /*
2666 * FIXME(BDW): Assume for now that the new interrupt handling
2667 * scheme also closed the SDE interrupt handling race we've seen
2668 * on older pch-split platforms. But this needs testing.
2669 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002670 iir = I915_READ(SDEIIR);
2671 if (iir) {
2672 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002673 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002674
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002675 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2676 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002677 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002678 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002679 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002680 } else {
2681 /*
2682 * Like on previous PCH there seems to be something
2683 * fishy going on with forwarding PCH interrupts.
2684 */
2685 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2686 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002687 }
2688
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002689 return ret;
2690}
2691
2692static irqreturn_t gen8_irq_handler(int irq, void *arg)
2693{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002694 struct drm_i915_private *dev_priv = to_i915(arg);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002695 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002696 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002697
2698 if (!intel_irqs_enabled(dev_priv))
2699 return IRQ_NONE;
2700
2701 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2702 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2703 if (!master_ctl)
2704 return IRQ_NONE;
2705
2706 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2707
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002708 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002709 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002710
2711 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2712 if (master_ctl & ~GEN8_GT_IRQS) {
2713 disable_rpm_wakeref_asserts(dev_priv);
2714 gen8_de_irq_handler(dev_priv, master_ctl);
2715 enable_rpm_wakeref_asserts(dev_priv);
2716 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002717
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002718 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002719
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002720 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002721
Chris Wilson55ef72f2018-02-02 15:34:48 +00002722 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002723}
2724
Chris Wilson36703e72017-06-22 11:56:25 +01002725struct wedge_me {
2726 struct delayed_work work;
2727 struct drm_i915_private *i915;
2728 const char *name;
2729};
2730
2731static void wedge_me(struct work_struct *work)
2732{
2733 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2734
2735 dev_err(w->i915->drm.dev,
2736 "%s timed out, cancelling all in-flight rendering.\n",
2737 w->name);
2738 i915_gem_set_wedged(w->i915);
2739}
2740
2741static void __init_wedge(struct wedge_me *w,
2742 struct drm_i915_private *i915,
2743 long timeout,
2744 const char *name)
2745{
2746 w->i915 = i915;
2747 w->name = name;
2748
2749 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2750 schedule_delayed_work(&w->work, timeout);
2751}
2752
2753static void __fini_wedge(struct wedge_me *w)
2754{
2755 cancel_delayed_work_sync(&w->work);
2756 destroy_delayed_work_on_stack(&w->work);
2757 w->i915 = NULL;
2758}
2759
2760#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2761 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2762 (W)->i915; \
2763 __fini_wedge((W)))
2764
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002765static __always_inline void
2766gen11_cs_irq_handler(struct intel_engine_cs * const engine, const u32 iir)
2767{
2768 gen8_cs_irq_handler(engine, iir, 0);
2769}
2770
2771static void
2772gen11_gt_engine_irq_handler(struct drm_i915_private * const i915,
2773 const unsigned int bank,
2774 const unsigned int engine_n,
2775 const u16 iir)
2776{
2777 struct intel_engine_cs ** const engine = i915->engine;
2778
2779 switch (bank) {
2780 case 0:
2781 switch (engine_n) {
2782
2783 case GEN11_RCS0:
2784 return gen11_cs_irq_handler(engine[RCS], iir);
2785
2786 case GEN11_BCS:
2787 return gen11_cs_irq_handler(engine[BCS], iir);
2788 }
2789 case 1:
2790 switch (engine_n) {
2791
2792 case GEN11_VCS(0):
2793 return gen11_cs_irq_handler(engine[_VCS(0)], iir);
2794 case GEN11_VCS(1):
2795 return gen11_cs_irq_handler(engine[_VCS(1)], iir);
2796 case GEN11_VCS(2):
2797 return gen11_cs_irq_handler(engine[_VCS(2)], iir);
2798 case GEN11_VCS(3):
2799 return gen11_cs_irq_handler(engine[_VCS(3)], iir);
2800
2801 case GEN11_VECS(0):
2802 return gen11_cs_irq_handler(engine[_VECS(0)], iir);
2803 case GEN11_VECS(1):
2804 return gen11_cs_irq_handler(engine[_VECS(1)], iir);
2805 }
2806 }
2807}
2808
2809static u32
2810gen11_gt_engine_intr(struct drm_i915_private * const i915,
2811 const unsigned int bank, const unsigned int bit)
2812{
2813 void __iomem * const regs = i915->regs;
2814 u32 timeout_ts;
2815 u32 ident;
2816
2817 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
2818
2819 /*
2820 * NB: Specs do not specify how long to spin wait,
2821 * so we do ~100us as an educated guess.
2822 */
2823 timeout_ts = (local_clock() >> 10) + 100;
2824 do {
2825 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
2826 } while (!(ident & GEN11_INTR_DATA_VALID) &&
2827 !time_after32(local_clock() >> 10, timeout_ts));
2828
2829 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
2830 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
2831 bank, bit, ident);
2832 return 0;
2833 }
2834
2835 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
2836 GEN11_INTR_DATA_VALID);
2837
2838 return ident & GEN11_INTR_ENGINE_MASK;
2839}
2840
2841static void
2842gen11_gt_irq_handler(struct drm_i915_private * const i915,
2843 const u32 master_ctl)
2844{
2845 void __iomem * const regs = i915->regs;
2846 unsigned int bank;
2847
2848 for (bank = 0; bank < 2; bank++) {
2849 unsigned long intr_dw;
2850 unsigned int bit;
2851
2852 if (!(master_ctl & GEN11_GT_DW_IRQ(bank)))
2853 continue;
2854
2855 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
2856
2857 if (unlikely(!intr_dw)) {
2858 DRM_ERROR("GT_INTR_DW%u blank!\n", bank);
2859 continue;
2860 }
2861
2862 for_each_set_bit(bit, &intr_dw, 32) {
2863 const u16 iir = gen11_gt_engine_intr(i915, bank, bit);
2864
2865 if (unlikely(!iir))
2866 continue;
2867
2868 gen11_gt_engine_irq_handler(i915, bank, bit, iir);
2869 }
2870
2871 /* Clear must be after shared has been served for engine */
2872 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
2873 }
2874}
2875
2876static irqreturn_t gen11_irq_handler(int irq, void *arg)
2877{
2878 struct drm_i915_private * const i915 = to_i915(arg);
2879 void __iomem * const regs = i915->regs;
2880 u32 master_ctl;
2881
2882 if (!intel_irqs_enabled(i915))
2883 return IRQ_NONE;
2884
2885 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2886 master_ctl &= ~GEN11_MASTER_IRQ;
2887 if (!master_ctl)
2888 return IRQ_NONE;
2889
2890 /* Disable interrupts. */
2891 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2892
2893 /* Find, clear, then process each source of interrupt. */
2894 gen11_gt_irq_handler(i915, master_ctl);
2895
2896 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2897 if (master_ctl & GEN11_DISPLAY_IRQ) {
2898 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2899
2900 disable_rpm_wakeref_asserts(i915);
2901 /*
2902 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2903 * for the display related bits.
2904 */
2905 gen8_de_irq_handler(i915, disp_ctl);
2906 enable_rpm_wakeref_asserts(i915);
2907 }
2908
2909 /* Acknowledge and enable interrupts. */
2910 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ | master_ctl);
2911
2912 return IRQ_HANDLED;
2913}
2914
Jesse Barnes8a905232009-07-11 16:48:03 -04002915/**
Chris Wilsond5367302017-06-20 10:57:43 +01002916 * i915_reset_device - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002917 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002918 *
2919 * Fire an error uevent so userspace can see that a hang or error
2920 * was detected.
2921 */
Chris Wilsond5367302017-06-20 10:57:43 +01002922static void i915_reset_device(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002923{
Chris Wilson91c8a322016-07-05 10:40:23 +01002924 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002925 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2926 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2927 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002928 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002929
Chris Wilsonc0336662016-05-06 15:40:21 +01002930 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002931
Chris Wilson8af29b02016-09-09 14:11:47 +01002932 DRM_DEBUG_DRIVER("resetting chip\n");
2933 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2934
Chris Wilson36703e72017-06-22 11:56:25 +01002935 /* Use a watchdog to ensure that our reset completes */
2936 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
2937 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002938
Chris Wilson36703e72017-06-22 11:56:25 +01002939 /* Signal that locked waiters should reset the GPU */
2940 set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags);
2941 wake_up_all(&dev_priv->gpu_error.wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00002942
Chris Wilson36703e72017-06-22 11:56:25 +01002943 /* Wait for anyone holding the lock to wakeup, without
2944 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01002945 */
Chris Wilson36703e72017-06-22 11:56:25 +01002946 do {
2947 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilson535275d2017-07-21 13:32:37 +01002948 i915_reset(dev_priv, 0);
Chris Wilson36703e72017-06-22 11:56:25 +01002949 mutex_unlock(&dev_priv->drm.struct_mutex);
2950 }
2951 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2952 I915_RESET_HANDOFF,
2953 TASK_UNINTERRUPTIBLE,
2954 1));
Chris Wilson780f2622016-09-09 14:11:52 +01002955
Chris Wilson36703e72017-06-22 11:56:25 +01002956 intel_finish_reset(dev_priv);
2957 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02002958
Chris Wilson780f2622016-09-09 14:11:52 +01002959 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002960 kobject_uevent_env(kobj,
2961 KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002962}
2963
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002964static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002965{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002966 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04002967
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002968 if (!IS_GEN2(dev_priv))
2969 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04002970
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002971 if (INTEL_GEN(dev_priv) < 4)
2972 I915_WRITE(IPEIR, I915_READ(IPEIR));
2973 else
2974 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002975
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002976 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04002977 eir = I915_READ(EIR);
2978 if (eir) {
2979 /*
2980 * some errors might have become stuck,
2981 * mask them.
2982 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002983 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002984 I915_WRITE(EMR, I915_READ(EMR) | eir);
2985 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2986 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002987}
2988
2989/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002990 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002991 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002992 * @engine_mask: mask representing engines that are hung
Michel Thierry87c390b2017-01-11 20:18:08 -08002993 * @fmt: Error message format string
2994 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002995 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002996 * dump it to the syslog. Also call i915_capture_error_state() to make
2997 * sure we get a record and make it available in debugfs. Fire a uevent
2998 * so userspace knows something bad happened (should trigger collection
2999 * of a ring dump etc.).
3000 */
Chris Wilsonc0336662016-05-06 15:40:21 +01003001void i915_handle_error(struct drm_i915_private *dev_priv,
3002 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02003003 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01003004{
Michel Thierry142bc7d2017-06-20 10:57:46 +01003005 struct intel_engine_cs *engine;
3006 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02003007 va_list args;
3008 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01003009
Mika Kuoppala58174462014-02-25 17:11:26 +02003010 va_start(args, fmt);
3011 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
3012 va_end(args);
3013
Chris Wilson1604a862017-03-14 17:18:40 +00003014 /*
3015 * In most cases it's guaranteed that we get here with an RPM
3016 * reference held, for example because there is a pending GPU
3017 * request that won't finish until the reset is done. This
3018 * isn't the case at least when we get here by doing a
3019 * simulated reset via debugfs, so get an RPM reference.
3020 */
3021 intel_runtime_pm_get(dev_priv);
3022
Chris Wilsonc0336662016-05-06 15:40:21 +01003023 i915_capture_error_state(dev_priv, engine_mask, error_msg);
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003024 i915_clear_error_registers(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04003025
Michel Thierry142bc7d2017-06-20 10:57:46 +01003026 /*
3027 * Try engine reset when available. We fall back to full reset if
3028 * single reset fails.
3029 */
3030 if (intel_has_reset_engine(dev_priv)) {
3031 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02003032 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01003033 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3034 &dev_priv->gpu_error.flags))
3035 continue;
3036
Chris Wilson535275d2017-07-21 13:32:37 +01003037 if (i915_reset_engine(engine, 0) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01003038 engine_mask &= ~intel_engine_flag(engine);
3039
3040 clear_bit(I915_RESET_ENGINE + engine->id,
3041 &dev_priv->gpu_error.flags);
3042 wake_up_bit(&dev_priv->gpu_error.flags,
3043 I915_RESET_ENGINE + engine->id);
3044 }
3045 }
3046
Chris Wilson8af29b02016-09-09 14:11:47 +01003047 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00003048 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04003049
Michel Thierry142bc7d2017-06-20 10:57:46 +01003050 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01003051 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
3052 wait_event(dev_priv->gpu_error.reset_queue,
3053 !test_bit(I915_RESET_BACKOFF,
3054 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00003055 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01003056 }
Chris Wilson8af29b02016-09-09 14:11:47 +01003057
Michel Thierry142bc7d2017-06-20 10:57:46 +01003058 /* Prevent any other reset-engine attempt. */
3059 for_each_engine(engine, dev_priv, tmp) {
3060 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3061 &dev_priv->gpu_error.flags))
3062 wait_on_bit(&dev_priv->gpu_error.flags,
3063 I915_RESET_ENGINE + engine->id,
3064 TASK_UNINTERRUPTIBLE);
3065 }
3066
Chris Wilsond5367302017-06-20 10:57:43 +01003067 i915_reset_device(dev_priv);
3068
Michel Thierry142bc7d2017-06-20 10:57:46 +01003069 for_each_engine(engine, dev_priv, tmp) {
3070 clear_bit(I915_RESET_ENGINE + engine->id,
3071 &dev_priv->gpu_error.flags);
3072 }
3073
Chris Wilsond5367302017-06-20 10:57:43 +01003074 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
3075 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00003076
3077out:
3078 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04003079}
3080
Keith Packard42f52ef2008-10-18 19:39:29 -07003081/* Called from drm generic code, passed 'crtc' which
3082 * we use as a pipe index
3083 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003084static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003085{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003086 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003087 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003088
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003089 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003090 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3091 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3092
3093 return 0;
3094}
3095
3096static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3097{
3098 struct drm_i915_private *dev_priv = to_i915(dev);
3099 unsigned long irqflags;
3100
3101 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3102 i915_enable_pipestat(dev_priv, pipe,
3103 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003104 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003105
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003106 return 0;
3107}
3108
Thierry Reding88e72712015-09-24 18:35:31 +02003109static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003110{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003111 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003112 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003113 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003114 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003115
Jesse Barnesf796cf82011-04-07 13:58:17 -07003116 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003117 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003118 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3119
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003120 /* Even though there is no DMC, frame counter can get stuck when
3121 * PSR is active as no frames are generated.
3122 */
3123 if (HAS_PSR(dev_priv))
3124 drm_vblank_restore(dev, pipe);
3125
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003126 return 0;
3127}
3128
Thierry Reding88e72712015-09-24 18:35:31 +02003129static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003130{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003131 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003132 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003133
Ben Widawskyabd58f02013-11-02 21:07:09 -07003134 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003135 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003136 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003137
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003138 /* Even if there is no DMC, frame counter can get stuck when
3139 * PSR is active as no frames are generated, so check only for PSR.
3140 */
3141 if (HAS_PSR(dev_priv))
3142 drm_vblank_restore(dev, pipe);
3143
Ben Widawskyabd58f02013-11-02 21:07:09 -07003144 return 0;
3145}
3146
Keith Packard42f52ef2008-10-18 19:39:29 -07003147/* Called from drm generic code, passed 'crtc' which
3148 * we use as a pipe index
3149 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003150static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3151{
3152 struct drm_i915_private *dev_priv = to_i915(dev);
3153 unsigned long irqflags;
3154
3155 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3156 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3157 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3158}
3159
3160static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003161{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003162 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003163 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003164
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003165 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003166 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003167 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003168 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3169}
3170
Thierry Reding88e72712015-09-24 18:35:31 +02003171static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003172{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003173 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003174 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003175 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003176 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003177
3178 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003179 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003180 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3181}
3182
Thierry Reding88e72712015-09-24 18:35:31 +02003183static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003184{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003185 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003186 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003187
Ben Widawskyabd58f02013-11-02 21:07:09 -07003188 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003189 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003190 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3191}
3192
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003193static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003194{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003195 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003196 return;
3197
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003198 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003199
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003200 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003201 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003202}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003203
Paulo Zanoni622364b2014-04-01 15:37:22 -03003204/*
3205 * SDEIER is also touched by the interrupt handler to work around missed PCH
3206 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3207 * instead we unconditionally enable all PCH interrupt sources here, but then
3208 * only unmask them as needed with SDEIMR.
3209 *
3210 * This function needs to be called before interrupts are enabled.
3211 */
3212static void ibx_irq_pre_postinstall(struct drm_device *dev)
3213{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003214 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003215
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003216 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003217 return;
3218
3219 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003220 I915_WRITE(SDEIER, 0xffffffff);
3221 POSTING_READ(SDEIER);
3222}
3223
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003224static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003225{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003226 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003227 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003228 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003229}
3230
Ville Syrjälä70591a42014-10-30 19:42:58 +02003231static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3232{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003233 if (IS_CHERRYVIEW(dev_priv))
3234 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3235 else
3236 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3237
Ville Syrjäläad22d102016-04-12 18:56:14 +03003238 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003239 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3240
Ville Syrjälä44d92412017-08-18 21:36:51 +03003241 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003242
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003243 GEN3_IRQ_RESET(VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003244 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003245}
3246
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003247static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3248{
3249 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003250 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003251 enum pipe pipe;
3252
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003253 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003254
3255 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3256 for_each_pipe(dev_priv, pipe)
3257 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3258
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003259 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3260 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003261 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3262 I915_LPE_PIPE_A_INTERRUPT |
3263 I915_LPE_PIPE_B_INTERRUPT;
3264
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003265 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003266 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3267 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003268
Chris Wilson8bd099a2017-11-30 12:52:53 +00003269 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003270
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003271 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003272
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003273 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003274}
3275
3276/* drm_dma.h hooks
3277*/
3278static void ironlake_irq_reset(struct drm_device *dev)
3279{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003280 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003281
Ville Syrjäläd420a502017-08-18 21:37:03 +03003282 if (IS_GEN5(dev_priv))
3283 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003284
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003285 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003286 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003287 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3288
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003289 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003290
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003291 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003292}
3293
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003294static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003295{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003296 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003297
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003298 I915_WRITE(VLV_MASTER_IER, 0);
3299 POSTING_READ(VLV_MASTER_IER);
3300
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003301 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003302
Ville Syrjäläad22d102016-04-12 18:56:14 +03003303 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003304 if (dev_priv->display_irqs_enabled)
3305 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003306 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003307}
3308
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003309static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3310{
3311 GEN8_IRQ_RESET_NDX(GT, 0);
3312 GEN8_IRQ_RESET_NDX(GT, 1);
3313 GEN8_IRQ_RESET_NDX(GT, 2);
3314 GEN8_IRQ_RESET_NDX(GT, 3);
3315}
3316
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003317static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003318{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003319 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003320 int pipe;
3321
Ben Widawskyabd58f02013-11-02 21:07:09 -07003322 I915_WRITE(GEN8_MASTER_IRQ, 0);
3323 POSTING_READ(GEN8_MASTER_IRQ);
3324
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003325 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003326
Damien Lespiau055e3932014-08-18 13:49:10 +01003327 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003328 if (intel_display_power_is_enabled(dev_priv,
3329 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003330 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003331
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003332 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3333 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3334 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003335
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003336 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003337 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003338}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003339
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003340static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3341{
3342 /* Disable RCS, BCS, VCS and VECS class engines. */
3343 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3344 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3345
3346 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3347 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3348 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3349 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3350 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3351 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
3352}
3353
3354static void gen11_irq_reset(struct drm_device *dev)
3355{
3356 struct drm_i915_private *dev_priv = dev->dev_private;
3357 int pipe;
3358
3359 I915_WRITE(GEN11_GFX_MSTR_IRQ, 0);
3360 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3361
3362 gen11_gt_irq_reset(dev_priv);
3363
3364 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3365
3366 for_each_pipe(dev_priv, pipe)
3367 if (intel_display_power_is_enabled(dev_priv,
3368 POWER_DOMAIN_PIPE(pipe)))
3369 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3370
3371 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3372 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3373 GEN3_IRQ_RESET(GEN8_PCU_);
3374}
3375
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003376void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003377 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003378{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003379 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003380 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003381
Daniel Vetter13321782014-09-15 14:55:29 +02003382 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003383
3384 if (!intel_irqs_enabled(dev_priv)) {
3385 spin_unlock_irq(&dev_priv->irq_lock);
3386 return;
3387 }
3388
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003389 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3390 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3391 dev_priv->de_irq_mask[pipe],
3392 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003393
Daniel Vetter13321782014-09-15 14:55:29 +02003394 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003395}
3396
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003397void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003398 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003399{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003400 enum pipe pipe;
3401
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003402 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003403
3404 if (!intel_irqs_enabled(dev_priv)) {
3405 spin_unlock_irq(&dev_priv->irq_lock);
3406 return;
3407 }
3408
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003409 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3410 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003411
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003412 spin_unlock_irq(&dev_priv->irq_lock);
3413
3414 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003415 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003416}
3417
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003418static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003419{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003420 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003421
3422 I915_WRITE(GEN8_MASTER_IRQ, 0);
3423 POSTING_READ(GEN8_MASTER_IRQ);
3424
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003425 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003426
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003427 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003428
Ville Syrjäläad22d102016-04-12 18:56:14 +03003429 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003430 if (dev_priv->display_irqs_enabled)
3431 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003432 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003433}
3434
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003435static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003436 const u32 hpd[HPD_NUM_PINS])
3437{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003438 struct intel_encoder *encoder;
3439 u32 enabled_irqs = 0;
3440
Chris Wilson91c8a322016-07-05 10:40:23 +01003441 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003442 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3443 enabled_irqs |= hpd[encoder->hpd_pin];
3444
3445 return enabled_irqs;
3446}
3447
Imre Deak1a56b1a2017-01-27 11:39:21 +02003448static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3449{
3450 u32 hotplug;
3451
3452 /*
3453 * Enable digital hotplug on the PCH, and configure the DP short pulse
3454 * duration to 2ms (which is the minimum in the Display Port spec).
3455 * The pulse duration bits are reserved on LPT+.
3456 */
3457 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3458 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3459 PORTC_PULSE_DURATION_MASK |
3460 PORTD_PULSE_DURATION_MASK);
3461 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3462 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3463 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3464 /*
3465 * When CPU and PCH are on the same package, port A
3466 * HPD must be enabled in both north and south.
3467 */
3468 if (HAS_PCH_LPT_LP(dev_priv))
3469 hotplug |= PORTA_HOTPLUG_ENABLE;
3470 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3471}
3472
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003473static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003474{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003475 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003476
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003477 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003478 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003479 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003480 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003481 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003482 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003483 }
3484
Daniel Vetterfee884e2013-07-04 23:35:21 +02003485 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003486
Imre Deak1a56b1a2017-01-27 11:39:21 +02003487 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003488}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003489
Imre Deak2a57d9c2017-01-27 11:39:18 +02003490static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3491{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003492 u32 val, hotplug;
3493
3494 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3495 if (HAS_PCH_CNP(dev_priv)) {
3496 val = I915_READ(SOUTH_CHICKEN1);
3497 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3498 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3499 I915_WRITE(SOUTH_CHICKEN1, val);
3500 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003501
3502 /* Enable digital hotplug on the PCH */
3503 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3504 hotplug |= PORTA_HOTPLUG_ENABLE |
3505 PORTB_HOTPLUG_ENABLE |
3506 PORTC_HOTPLUG_ENABLE |
3507 PORTD_HOTPLUG_ENABLE;
3508 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3509
3510 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3511 hotplug |= PORTE_HOTPLUG_ENABLE;
3512 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3513}
3514
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003515static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003516{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003517 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003518
3519 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003520 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003521
3522 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3523
Imre Deak2a57d9c2017-01-27 11:39:18 +02003524 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003525}
3526
Imre Deak1a56b1a2017-01-27 11:39:21 +02003527static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3528{
3529 u32 hotplug;
3530
3531 /*
3532 * Enable digital hotplug on the CPU, and configure the DP short pulse
3533 * duration to 2ms (which is the minimum in the Display Port spec)
3534 * The pulse duration bits are reserved on HSW+.
3535 */
3536 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3537 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3538 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3539 DIGITAL_PORTA_PULSE_DURATION_2ms;
3540 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3541}
3542
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003543static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003544{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003545 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003546
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003547 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003548 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003549 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003550
3551 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003552 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003553 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003554 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003555
3556 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003557 } else {
3558 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003559 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003560
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003561 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3562 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003563
Imre Deak1a56b1a2017-01-27 11:39:21 +02003564 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003565
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003566 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003567}
3568
Imre Deak2a57d9c2017-01-27 11:39:18 +02003569static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3570 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003571{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003572 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003573
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003574 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003575 hotplug |= PORTA_HOTPLUG_ENABLE |
3576 PORTB_HOTPLUG_ENABLE |
3577 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303578
3579 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3580 hotplug, enabled_irqs);
3581 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3582
3583 /*
3584 * For BXT invert bit has to be set based on AOB design
3585 * for HPD detection logic, update it based on VBT fields.
3586 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303587 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3588 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3589 hotplug |= BXT_DDIA_HPD_INVERT;
3590 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3591 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3592 hotplug |= BXT_DDIB_HPD_INVERT;
3593 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3594 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3595 hotplug |= BXT_DDIC_HPD_INVERT;
3596
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003597 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003598}
3599
Imre Deak2a57d9c2017-01-27 11:39:18 +02003600static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3601{
3602 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3603}
3604
3605static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3606{
3607 u32 hotplug_irqs, enabled_irqs;
3608
3609 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3610 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3611
3612 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3613
3614 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3615}
3616
Paulo Zanonid46da432013-02-08 17:35:15 -02003617static void ibx_irq_postinstall(struct drm_device *dev)
3618{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003619 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003620 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003621
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003622 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003623 return;
3624
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003625 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003626 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003627 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003628 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003629 else
3630 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003631
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003632 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003633 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003634
3635 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3636 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003637 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003638 else
3639 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003640}
3641
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003642static void gen5_gt_irq_postinstall(struct drm_device *dev)
3643{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003644 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003645 u32 pm_irqs, gt_irqs;
3646
3647 pm_irqs = gt_irqs = 0;
3648
3649 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003650 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003651 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003652 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3653 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003654 }
3655
3656 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003657 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003658 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003659 } else {
3660 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3661 }
3662
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003663 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003664
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003665 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003666 /*
3667 * RPS interrupts will get enabled/disabled on demand when RPS
3668 * itself is enabled/disabled.
3669 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303670 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003671 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303672 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3673 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003674
Akash Goelf4e9af42016-10-12 21:54:30 +05303675 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003676 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003677 }
3678}
3679
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003680static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003681{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003682 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003683 u32 display_mask, extra_mask;
3684
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003685 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003686 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003687 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003688 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003689 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3690 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003691 } else {
3692 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003693 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3694 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003695 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3696 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3697 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003698 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003699
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003700 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003701
Paulo Zanoni622364b2014-04-01 15:37:22 -03003702 ibx_irq_pre_postinstall(dev);
3703
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003704 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003705
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003706 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003707
Imre Deak1a56b1a2017-01-27 11:39:21 +02003708 ilk_hpd_detection_setup(dev_priv);
3709
Paulo Zanonid46da432013-02-08 17:35:15 -02003710 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003711
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003712 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003713 /* Enable PCU event interrupts
3714 *
3715 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003716 * setup is guaranteed to run in single-threaded context. But we
3717 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003718 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003719 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003720 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003721 }
3722
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003723 return 0;
3724}
3725
Imre Deakf8b79e52014-03-04 19:23:07 +02003726void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3727{
Chris Wilson67520412017-03-02 13:28:01 +00003728 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003729
3730 if (dev_priv->display_irqs_enabled)
3731 return;
3732
3733 dev_priv->display_irqs_enabled = true;
3734
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003735 if (intel_irqs_enabled(dev_priv)) {
3736 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003737 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003738 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003739}
3740
3741void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3742{
Chris Wilson67520412017-03-02 13:28:01 +00003743 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003744
3745 if (!dev_priv->display_irqs_enabled)
3746 return;
3747
3748 dev_priv->display_irqs_enabled = false;
3749
Imre Deak950eaba2014-09-08 15:21:09 +03003750 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003751 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003752}
3753
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003754
3755static int valleyview_irq_postinstall(struct drm_device *dev)
3756{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003757 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003758
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003759 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003760
Ville Syrjäläad22d102016-04-12 18:56:14 +03003761 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003762 if (dev_priv->display_irqs_enabled)
3763 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003764 spin_unlock_irq(&dev_priv->irq_lock);
3765
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003766 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003767 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003768
3769 return 0;
3770}
3771
Ben Widawskyabd58f02013-11-02 21:07:09 -07003772static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3773{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003774 /* These are interrupts we'll toggle with the ring mask register */
3775 uint32_t gt_interrupts[] = {
3776 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003777 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003778 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3779 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003780 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003781 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3782 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3783 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003784 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003785 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3786 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003787 };
3788
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003789 if (HAS_L3_DPF(dev_priv))
3790 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3791
Akash Goelf4e9af42016-10-12 21:54:30 +05303792 dev_priv->pm_ier = 0x0;
3793 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303794 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3795 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003796 /*
3797 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303798 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003799 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303800 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303801 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003802}
3803
3804static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3805{
Damien Lespiau770de83d2014-03-20 20:45:01 +00003806 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3807 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003808 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3809 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003810 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003811 enum pipe pipe;
Damien Lespiau770de83d2014-03-20 20:45:01 +00003812
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003813 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003814 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003815 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3816 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003817 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003818 de_port_masked |= BXT_DE_PORT_GMBUS;
3819 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003820 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003821 }
Damien Lespiau770de83d2014-03-20 20:45:01 +00003822
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003823 if (IS_CNL_WITH_PORT_F(dev_priv))
3824 de_port_masked |= CNL_AUX_CHANNEL_F;
3825
Damien Lespiau770de83d2014-03-20 20:45:01 +00003826 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3827 GEN8_PIPE_FIFO_UNDERRUN;
3828
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003829 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003830 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003831 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3832 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003833 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3834
Mika Kahola0a195c02017-10-10 13:17:04 +03003835 for_each_pipe(dev_priv, pipe) {
3836 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003837
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003838 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003839 POWER_DOMAIN_PIPE(pipe)))
3840 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3841 dev_priv->de_irq_mask[pipe],
3842 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03003843 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07003844
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003845 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3846 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003847
3848 if (IS_GEN9_LP(dev_priv))
3849 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003850 else if (IS_BROADWELL(dev_priv))
3851 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003852}
3853
3854static int gen8_irq_postinstall(struct drm_device *dev)
3855{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003856 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003857
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003858 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303859 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003860
Ben Widawskyabd58f02013-11-02 21:07:09 -07003861 gen8_gt_irq_postinstall(dev_priv);
3862 gen8_de_irq_postinstall(dev_priv);
3863
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003864 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303865 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003866
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003867 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003868 POSTING_READ(GEN8_MASTER_IRQ);
3869
3870 return 0;
3871}
3872
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003873static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3874{
3875 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
3876
3877 BUILD_BUG_ON(irqs & 0xffff0000);
3878
3879 /* Enable RCS, BCS, VCS and VECS class interrupts. */
3880 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
3881 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
3882
3883 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
3884 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
3885 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
3886 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
3887 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
3888 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
3889
3890 dev_priv->pm_imr = 0xffffffff; /* TODO */
3891}
3892
3893static int gen11_irq_postinstall(struct drm_device *dev)
3894{
3895 struct drm_i915_private *dev_priv = dev->dev_private;
3896
3897 gen11_gt_irq_postinstall(dev_priv);
3898 gen8_de_irq_postinstall(dev_priv);
3899
3900 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
3901
3902 I915_WRITE(GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
3903 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3904
3905 return 0;
3906}
3907
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003908static int cherryview_irq_postinstall(struct drm_device *dev)
3909{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003910 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003911
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003912 gen8_gt_irq_postinstall(dev_priv);
3913
Ville Syrjäläad22d102016-04-12 18:56:14 +03003914 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003915 if (dev_priv->display_irqs_enabled)
3916 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003917 spin_unlock_irq(&dev_priv->irq_lock);
3918
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003919 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003920 POSTING_READ(GEN8_MASTER_IRQ);
3921
3922 return 0;
3923}
3924
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003925static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003926{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003927 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003928
Ville Syrjälä44d92412017-08-18 21:36:51 +03003929 i9xx_pipestat_irq_reset(dev_priv);
3930
Ville Syrjäläd420a502017-08-18 21:37:03 +03003931 I915_WRITE16(HWSTAM, 0xffff);
3932
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003933 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01003934}
3935
3936static int i8xx_irq_postinstall(struct drm_device *dev)
3937{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003938 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003939 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003940
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003941 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
3942 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01003943
3944 /* Unmask the interrupts that we always want on. */
3945 dev_priv->irq_mask =
3946 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003947 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003948
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003949 enable_mask =
3950 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3951 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3952 I915_USER_INTERRUPT;
3953
3954 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003955
Daniel Vetter379ef822013-10-16 22:55:56 +02003956 /* Interrupt setup is already guaranteed to be single-threaded, this is
3957 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003958 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003959 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3960 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003961 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003962
Chris Wilsonc2798b12012-04-22 21:13:57 +01003963 return 0;
3964}
3965
Daniel Vetterff1f5252012-10-02 15:10:55 +02003966static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003967{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003968 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003969 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003970 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003971
Imre Deak2dd2a882015-02-24 11:14:30 +02003972 if (!intel_irqs_enabled(dev_priv))
3973 return IRQ_NONE;
3974
Imre Deak1f814da2015-12-16 02:52:19 +02003975 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3976 disable_rpm_wakeref_asserts(dev_priv);
3977
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003978 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003979 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003980 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03003981
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003982 iir = I915_READ16(IIR);
3983 if (iir == 0)
3984 break;
3985
3986 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003987
Ville Syrjäläeb643432017-08-18 21:36:59 +03003988 /* Call regardless, as some status bits might not be
3989 * signalled in iir */
3990 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003991
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003992 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003993
Chris Wilsonc2798b12012-04-22 21:13:57 +01003994 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303995 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003996
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003997 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3998 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3999
Ville Syrjäläeb643432017-08-18 21:36:59 +03004000 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004001 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004002
Imre Deak1f814da2015-12-16 02:52:19 +02004003 enable_rpm_wakeref_asserts(dev_priv);
4004
4005 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004006}
4007
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004008static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004009{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004010 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004011
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004012 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004013 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004014 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4015 }
4016
Ville Syrjälä44d92412017-08-18 21:36:51 +03004017 i9xx_pipestat_irq_reset(dev_priv);
4018
Ville Syrjäläd420a502017-08-18 21:37:03 +03004019 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004020
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004021 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004022}
4023
4024static int i915_irq_postinstall(struct drm_device *dev)
4025{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004026 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004027 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004028
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004029 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
4030 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01004031
4032 /* Unmask the interrupts that we always want on. */
4033 dev_priv->irq_mask =
4034 ~(I915_ASLE_INTERRUPT |
4035 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004036 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004037
4038 enable_mask =
4039 I915_ASLE_INTERRUPT |
4040 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4041 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004042 I915_USER_INTERRUPT;
4043
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004044 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004045 /* Enable in IER... */
4046 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4047 /* and unmask in IMR */
4048 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4049 }
4050
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004051 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004052
Daniel Vetter379ef822013-10-16 22:55:56 +02004053 /* Interrupt setup is already guaranteed to be single-threaded, this is
4054 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004055 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004056 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4057 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004058 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004059
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004060 i915_enable_asle_pipestat(dev_priv);
4061
Daniel Vetter20afbda2012-12-11 14:05:07 +01004062 return 0;
4063}
4064
Daniel Vetterff1f5252012-10-02 15:10:55 +02004065static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004066{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004067 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004068 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004069 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004070
Imre Deak2dd2a882015-02-24 11:14:30 +02004071 if (!intel_irqs_enabled(dev_priv))
4072 return IRQ_NONE;
4073
Imre Deak1f814da2015-12-16 02:52:19 +02004074 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4075 disable_rpm_wakeref_asserts(dev_priv);
4076
Chris Wilson38bde182012-04-24 22:59:50 +01004077 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004078 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004079 u32 hotplug_status = 0;
4080 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004081
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004082 iir = I915_READ(IIR);
4083 if (iir == 0)
4084 break;
4085
4086 ret = IRQ_HANDLED;
4087
4088 if (I915_HAS_HOTPLUG(dev_priv) &&
4089 iir & I915_DISPLAY_PORT_INTERRUPT)
4090 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004091
Ville Syrjäläeb643432017-08-18 21:36:59 +03004092 /* Call regardless, as some status bits might not be
4093 * signalled in iir */
4094 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004095
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004096 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004097
Chris Wilsona266c7d2012-04-24 22:59:44 +01004098 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304099 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004100
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004101 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4102 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004103
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004104 if (hotplug_status)
4105 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4106
4107 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4108 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004109
Imre Deak1f814da2015-12-16 02:52:19 +02004110 enable_rpm_wakeref_asserts(dev_priv);
4111
Chris Wilsona266c7d2012-04-24 22:59:44 +01004112 return ret;
4113}
4114
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004115static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004116{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004117 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004118
Egbert Eich0706f172015-09-23 16:15:27 +02004119 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004120 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004121
Ville Syrjälä44d92412017-08-18 21:36:51 +03004122 i9xx_pipestat_irq_reset(dev_priv);
4123
Ville Syrjäläd420a502017-08-18 21:37:03 +03004124 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004125
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004126 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004127}
4128
4129static int i965_irq_postinstall(struct drm_device *dev)
4130{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004131 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004132 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004133 u32 error_mask;
4134
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004135 /*
4136 * Enable some error detection, note the instruction error mask
4137 * bit is reserved, so we leave it masked.
4138 */
4139 if (IS_G4X(dev_priv)) {
4140 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4141 GM45_ERROR_MEM_PRIV |
4142 GM45_ERROR_CP_PRIV |
4143 I915_ERROR_MEMORY_REFRESH);
4144 } else {
4145 error_mask = ~(I915_ERROR_PAGE_TABLE |
4146 I915_ERROR_MEMORY_REFRESH);
4147 }
4148 I915_WRITE(EMR, error_mask);
4149
Chris Wilsona266c7d2012-04-24 22:59:44 +01004150 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004151 dev_priv->irq_mask =
4152 ~(I915_ASLE_INTERRUPT |
4153 I915_DISPLAY_PORT_INTERRUPT |
4154 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4155 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4156 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004157
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004158 enable_mask =
4159 I915_ASLE_INTERRUPT |
4160 I915_DISPLAY_PORT_INTERRUPT |
4161 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4162 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4163 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4164 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004165
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004166 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004167 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004168
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004169 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
4170
Daniel Vetterb79480b2013-06-27 17:52:10 +02004171 /* Interrupt setup is already guaranteed to be single-threaded, this is
4172 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004173 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004174 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4175 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4176 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004177 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004178
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004179 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004180
4181 return 0;
4182}
4183
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004184static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004185{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004186 u32 hotplug_en;
4187
Chris Wilson67520412017-03-02 13:28:01 +00004188 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004189
Ville Syrjälä778eb332015-01-09 14:21:13 +02004190 /* Note HDMI and DP share hotplug bits */
4191 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004192 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004193 /* Programming the CRT detection parameters tends
4194 to generate a spurious hotplug event about three
4195 seconds later. So just do it once.
4196 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004197 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004198 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004199 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004200
Ville Syrjälä778eb332015-01-09 14:21:13 +02004201 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004202 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004203 HOTPLUG_INT_EN_MASK |
4204 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4205 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4206 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004207}
4208
Daniel Vetterff1f5252012-10-02 15:10:55 +02004209static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004210{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004211 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004212 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004213 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004214
Imre Deak2dd2a882015-02-24 11:14:30 +02004215 if (!intel_irqs_enabled(dev_priv))
4216 return IRQ_NONE;
4217
Imre Deak1f814da2015-12-16 02:52:19 +02004218 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4219 disable_rpm_wakeref_asserts(dev_priv);
4220
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004221 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004222 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004223 u32 hotplug_status = 0;
4224 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004225
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004226 iir = I915_READ(IIR);
4227 if (iir == 0)
4228 break;
4229
4230 ret = IRQ_HANDLED;
4231
4232 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4233 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004234
Ville Syrjäläeb643432017-08-18 21:36:59 +03004235 /* Call regardless, as some status bits might not be
4236 * signalled in iir */
4237 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004238
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004239 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004240
Chris Wilsona266c7d2012-04-24 22:59:44 +01004241 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304242 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004243
Chris Wilsona266c7d2012-04-24 22:59:44 +01004244 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304245 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004246
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004247 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4248 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004249
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004250 if (hotplug_status)
4251 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4252
4253 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4254 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004255
Imre Deak1f814da2015-12-16 02:52:19 +02004256 enable_rpm_wakeref_asserts(dev_priv);
4257
Chris Wilsona266c7d2012-04-24 22:59:44 +01004258 return ret;
4259}
4260
Daniel Vetterfca52a52014-09-30 10:56:45 +02004261/**
4262 * intel_irq_init - initializes irq support
4263 * @dev_priv: i915 device instance
4264 *
4265 * This function initializes all the irq support including work items, timers
4266 * and all the vtables. It does not setup the interrupt itself though.
4267 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004268void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004269{
Chris Wilson91c8a322016-07-05 10:40:23 +01004270 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004271 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004272 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004273
Jani Nikula77913b32015-06-18 13:06:16 +03004274 intel_hpd_init_work(dev_priv);
4275
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004276 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004277
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004278 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004279 for (i = 0; i < MAX_L3_SLICES; ++i)
4280 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004281
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004282 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304283 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4284
Deepak Sa6706b42014-03-15 20:23:22 +05304285 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004286 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a5872014-08-29 14:14:07 +03004287 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004288 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004289 else
4290 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304291
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004292 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304293
4294 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004295 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304296 * if GEN6_PM_UP_EI_EXPIRED is masked.
4297 *
4298 * TODO: verify if this can be reproduced on VLV,CHV.
4299 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004300 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004301 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304302
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004303 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004304 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304305
Daniel Vetterb9632912014-09-30 10:56:44 +02004306 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004307 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004308 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004309 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004310 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f507c2015-09-18 20:03:42 +03004311 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004312 } else {
4313 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4314 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004315 }
4316
Ville Syrjälä21da2702014-08-06 14:49:55 +03004317 /*
4318 * Opt out of the vblank disable timer on everything except gen2.
4319 * Gen2 doesn't have a hardware frame counter and so depends on
4320 * vblank interrupts to produce sane vblank seuquence numbers.
4321 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004322 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004323 dev->vblank_disable_immediate = true;
4324
Chris Wilson262fd482017-02-15 13:15:47 +00004325 /* Most platforms treat the display irq block as an always-on
4326 * power domain. vlv/chv can disable it at runtime and need
4327 * special care to avoid writing any of the display block registers
4328 * outside of the power domain. We defer setting up the display irqs
4329 * in this case to the runtime pm.
4330 */
4331 dev_priv->display_irqs_enabled = true;
4332 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4333 dev_priv->display_irqs_enabled = false;
4334
Lyude317eaa92017-02-03 21:18:25 -05004335 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4336
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004337 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004338 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004339
Daniel Vetterb9632912014-09-30 10:56:44 +02004340 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004341 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004342 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004343 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004344 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004345 dev->driver->enable_vblank = i965_enable_vblank;
4346 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004347 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004348 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004349 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004350 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004351 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004352 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004353 dev->driver->enable_vblank = i965_enable_vblank;
4354 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004355 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004356 } else if (INTEL_GEN(dev_priv) >= 11) {
4357 dev->driver->irq_handler = gen11_irq_handler;
4358 dev->driver->irq_preinstall = gen11_irq_reset;
4359 dev->driver->irq_postinstall = gen11_irq_postinstall;
4360 dev->driver->irq_uninstall = gen11_irq_reset;
4361 dev->driver->enable_vblank = gen8_enable_vblank;
4362 dev->driver->disable_vblank = gen8_disable_vblank;
4363 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004364 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004365 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004366 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004367 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004368 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004369 dev->driver->enable_vblank = gen8_enable_vblank;
4370 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004371 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004372 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004373 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4374 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004375 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4376 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004377 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004378 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004379 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004380 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004381 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004382 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004383 dev->driver->enable_vblank = ironlake_enable_vblank;
4384 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004385 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004386 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004387 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004388 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004389 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4390 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004391 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004392 dev->driver->enable_vblank = i8xx_enable_vblank;
4393 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004394 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004395 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004396 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004397 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004398 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004399 dev->driver->enable_vblank = i8xx_enable_vblank;
4400 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004401 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004402 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004403 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004404 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004405 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004406 dev->driver->enable_vblank = i965_enable_vblank;
4407 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004408 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004409 if (I915_HAS_HOTPLUG(dev_priv))
4410 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004411 }
4412}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004413
Daniel Vetterfca52a52014-09-30 10:56:45 +02004414/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004415 * intel_irq_fini - deinitializes IRQ support
4416 * @i915: i915 device instance
4417 *
4418 * This function deinitializes all the IRQ support.
4419 */
4420void intel_irq_fini(struct drm_i915_private *i915)
4421{
4422 int i;
4423
4424 for (i = 0; i < MAX_L3_SLICES; ++i)
4425 kfree(i915->l3_parity.remap_info[i]);
4426}
4427
4428/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004429 * intel_irq_install - enables the hardware interrupt
4430 * @dev_priv: i915 device instance
4431 *
4432 * This function enables the hardware interrupt handling, but leaves the hotplug
4433 * handling still disabled. It is called after intel_irq_init().
4434 *
4435 * In the driver load and resume code we need working interrupts in a few places
4436 * but don't want to deal with the hassle of concurrent probe and hotplug
4437 * workers. Hence the split into this two-stage approach.
4438 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004439int intel_irq_install(struct drm_i915_private *dev_priv)
4440{
4441 /*
4442 * We enable some interrupt sources in our postinstall hooks, so mark
4443 * interrupts as enabled _before_ actually enabling them to avoid
4444 * special cases in our ordering checks.
4445 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004446 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004447
Chris Wilson91c8a322016-07-05 10:40:23 +01004448 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004449}
4450
Daniel Vetterfca52a52014-09-30 10:56:45 +02004451/**
4452 * intel_irq_uninstall - finilizes all irq handling
4453 * @dev_priv: i915 device instance
4454 *
4455 * This stops interrupt and hotplug handling and unregisters and frees all
4456 * resources acquired in the init functions.
4457 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004458void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4459{
Chris Wilson91c8a322016-07-05 10:40:23 +01004460 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004461 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004462 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004463}
4464
Daniel Vetterfca52a52014-09-30 10:56:45 +02004465/**
4466 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4467 * @dev_priv: i915 device instance
4468 *
4469 * This function is used to disable interrupts at runtime, both in the runtime
4470 * pm and the system suspend/resume code.
4471 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004472void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004473{
Chris Wilson91c8a322016-07-05 10:40:23 +01004474 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004475 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004476 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004477}
4478
Daniel Vetterfca52a52014-09-30 10:56:45 +02004479/**
4480 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4481 * @dev_priv: i915 device instance
4482 *
4483 * This function is used to enable interrupts at runtime, both in the runtime
4484 * pm and the system suspend/resume code.
4485 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004486void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004487{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004488 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004489 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4490 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004491}