blob: f9bc3aaa90d0f5de110e893415be0a6ee1c40448 [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
Oscar Mateo96606f32018-04-06 12:32:37 +0300246static u32
247gen11_gt_engine_identity(struct drm_i915_private * const i915,
248 const unsigned int bank, const unsigned int bit);
249
Oscar Mateoff047a82018-04-24 14:39:55 -0700250bool gen11_reset_one_iir(struct drm_i915_private * const i915,
251 const unsigned int bank,
252 const unsigned int bit)
Oscar Mateo96606f32018-04-06 12:32:37 +0300253{
254 void __iomem * const regs = i915->regs;
255 u32 dw;
256
257 lockdep_assert_held(&i915->irq_lock);
258
259 dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
260 if (dw & BIT(bit)) {
261 /*
262 * According to the BSpec, DW_IIR bits cannot be cleared without
263 * first servicing the Selector & Shared IIR registers.
264 */
265 gen11_gt_engine_identity(i915, bank, bit);
266
267 /*
268 * We locked GT INT DW by reading it. If we want to (try
269 * to) recover from this succesfully, we need to clear
270 * our bit, otherwise we are locking the register for
271 * everybody.
272 */
273 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), BIT(bit));
274
275 return true;
276 }
277
278 return false;
279}
280
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300281/**
282 * ilk_update_display_irq - update DEIMR
283 * @dev_priv: driver private
284 * @interrupt_mask: mask of interrupt bits to update
285 * @enabled_irq_mask: mask of interrupt bits to enable
286 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200287void ilk_update_display_irq(struct drm_i915_private *dev_priv,
288 uint32_t interrupt_mask,
289 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800290{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300291 uint32_t new_val;
292
Chris Wilson67520412017-03-02 13:28:01 +0000293 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200294
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300295 WARN_ON(enabled_irq_mask & ~interrupt_mask);
296
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700297 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300298 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300299
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300300 new_val = dev_priv->irq_mask;
301 new_val &= ~interrupt_mask;
302 new_val |= (~enabled_irq_mask & interrupt_mask);
303
304 if (new_val != dev_priv->irq_mask) {
305 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000306 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000307 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800308 }
309}
310
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300311/**
312 * ilk_update_gt_irq - update GTIMR
313 * @dev_priv: driver private
314 * @interrupt_mask: mask of interrupt bits to update
315 * @enabled_irq_mask: mask of interrupt bits to enable
316 */
317static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
318 uint32_t interrupt_mask,
319 uint32_t enabled_irq_mask)
320{
Chris Wilson67520412017-03-02 13:28:01 +0000321 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300322
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100323 WARN_ON(enabled_irq_mask & ~interrupt_mask);
324
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700325 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300326 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300327
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300328 dev_priv->gt_irq_mask &= ~interrupt_mask;
329 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
330 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300331}
332
Daniel Vetter480c8032014-07-16 09:49:40 +0200333void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300334{
335 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100336 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300337}
338
Daniel Vetter480c8032014-07-16 09:49:40 +0200339void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300340{
341 ilk_update_gt_irq(dev_priv, mask, 0);
342}
343
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200344static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200345{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300346 WARN_ON_ONCE(INTEL_GEN(dev_priv) >= 11);
347
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700348 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
Imre Deakb900b942014-11-05 20:48:48 +0200349}
350
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200351static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200352{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300353 if (INTEL_GEN(dev_priv) >= 11)
354 return GEN11_GPM_WGBOXPERF_INTR_MASK;
355 else if (INTEL_GEN(dev_priv) >= 8)
356 return GEN8_GT_IMR(2);
357 else
358 return GEN6_PMIMR;
Imre Deaka72fbc32014-11-05 20:48:31 +0200359}
360
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200361static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200362{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300363 if (INTEL_GEN(dev_priv) >= 11)
364 return GEN11_GPM_WGBOXPERF_INTR_ENABLE;
365 else if (INTEL_GEN(dev_priv) >= 8)
366 return GEN8_GT_IER(2);
367 else
368 return GEN6_PMIER;
Imre Deakb900b942014-11-05 20:48:48 +0200369}
370
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300371/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200372 * snb_update_pm_irq - update GEN6_PMIMR
373 * @dev_priv: driver private
374 * @interrupt_mask: mask of interrupt bits to update
375 * @enabled_irq_mask: mask of interrupt bits to enable
376 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300377static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
378 uint32_t interrupt_mask,
379 uint32_t enabled_irq_mask)
380{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300381 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300382
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100383 WARN_ON(enabled_irq_mask & ~interrupt_mask);
384
Chris Wilson67520412017-03-02 13:28:01 +0000385 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300386
Akash Goelf4e9af42016-10-12 21:54:30 +0530387 new_val = dev_priv->pm_imr;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300388 new_val &= ~interrupt_mask;
389 new_val |= (~enabled_irq_mask & interrupt_mask);
390
Akash Goelf4e9af42016-10-12 21:54:30 +0530391 if (new_val != dev_priv->pm_imr) {
392 dev_priv->pm_imr = new_val;
393 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_imr);
Imre Deaka72fbc32014-11-05 20:48:31 +0200394 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300395 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300396}
397
Akash Goelf4e9af42016-10-12 21:54:30 +0530398void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300399{
Imre Deak9939fba2014-11-20 23:01:47 +0200400 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
401 return;
402
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300403 snb_update_pm_irq(dev_priv, mask, mask);
404}
405
Akash Goelf4e9af42016-10-12 21:54:30 +0530406static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Imre Deak9939fba2014-11-20 23:01:47 +0200407{
408 snb_update_pm_irq(dev_priv, mask, 0);
409}
410
Akash Goelf4e9af42016-10-12 21:54:30 +0530411void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300412{
Imre Deak9939fba2014-11-20 23:01:47 +0200413 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
414 return;
415
Akash Goelf4e9af42016-10-12 21:54:30 +0530416 __gen6_mask_pm_irq(dev_priv, mask);
417}
418
Oscar Mateo3814fd72017-08-23 16:58:24 -0700419static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530420{
421 i915_reg_t reg = gen6_pm_iir(dev_priv);
422
Chris Wilson67520412017-03-02 13:28:01 +0000423 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530424
425 I915_WRITE(reg, reset_mask);
426 I915_WRITE(reg, reset_mask);
427 POSTING_READ(reg);
428}
429
Oscar Mateo3814fd72017-08-23 16:58:24 -0700430static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530431{
Chris Wilson67520412017-03-02 13:28:01 +0000432 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530433
434 dev_priv->pm_ier |= enable_mask;
435 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
436 gen6_unmask_pm_irq(dev_priv, enable_mask);
437 /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */
438}
439
Oscar Mateo3814fd72017-08-23 16:58:24 -0700440static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530441{
Chris Wilson67520412017-03-02 13:28:01 +0000442 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530443
444 dev_priv->pm_ier &= ~disable_mask;
445 __gen6_mask_pm_irq(dev_priv, disable_mask);
446 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
447 /* though a barrier is missing here, but don't really need a one */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300448}
449
Oscar Mateod02b98b2018-04-05 17:00:50 +0300450void gen11_reset_rps_interrupts(struct drm_i915_private *dev_priv)
451{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300452 spin_lock_irq(&dev_priv->irq_lock);
453
Oscar Mateo96606f32018-04-06 12:32:37 +0300454 while (gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM))
455 ;
Oscar Mateod02b98b2018-04-05 17:00:50 +0300456
457 dev_priv->gt_pm.rps.pm_iir = 0;
458
459 spin_unlock_irq(&dev_priv->irq_lock);
460}
461
Chris Wilsondc979972016-05-10 14:10:04 +0100462void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200463{
Imre Deak3cc134e2014-11-19 15:30:03 +0200464 spin_lock_irq(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530465 gen6_reset_pm_iir(dev_priv, dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100466 dev_priv->gt_pm.rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200467 spin_unlock_irq(&dev_priv->irq_lock);
468}
469
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100470void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200471{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100472 struct intel_rps *rps = &dev_priv->gt_pm.rps;
473
474 if (READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100475 return;
476
Imre Deakb900b942014-11-05 20:48:48 +0200477 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100478 WARN_ON_ONCE(rps->pm_iir);
Oscar Mateo96606f32018-04-06 12:32:37 +0300479
Oscar Mateod02b98b2018-04-05 17:00:50 +0300480 if (INTEL_GEN(dev_priv) >= 11)
Oscar Mateo96606f32018-04-06 12:32:37 +0300481 WARN_ON_ONCE(gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM));
Oscar Mateod02b98b2018-04-05 17:00:50 +0300482 else
483 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Oscar Mateo96606f32018-04-06 12:32:37 +0300484
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100485 rps->interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200486 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200487
Imre Deakb900b942014-11-05 20:48:48 +0200488 spin_unlock_irq(&dev_priv->irq_lock);
489}
490
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100491void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200492{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100493 struct intel_rps *rps = &dev_priv->gt_pm.rps;
494
495 if (!READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100496 return;
497
Imre Deakd4d70aa2014-11-19 15:30:04 +0200498 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100499 rps->interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200500
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100501 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200502
Akash Goelf4e9af42016-10-12 21:54:30 +0530503 gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200504
505 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100506 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100507
508 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700509 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100510 * we will reset the GPU to minimum frequencies, so the current
511 * state of the worker can be discarded.
512 */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100513 cancel_work_sync(&rps->work);
Oscar Mateod02b98b2018-04-05 17:00:50 +0300514 if (INTEL_GEN(dev_priv) >= 11)
515 gen11_reset_rps_interrupts(dev_priv);
516 else
517 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200518}
519
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530520void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
521{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530522 assert_rpm_wakelock_held(dev_priv);
523
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530524 spin_lock_irq(&dev_priv->irq_lock);
525 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
526 spin_unlock_irq(&dev_priv->irq_lock);
527}
528
529void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
530{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530531 assert_rpm_wakelock_held(dev_priv);
532
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530533 spin_lock_irq(&dev_priv->irq_lock);
534 if (!dev_priv->guc.interrupts_enabled) {
535 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
536 dev_priv->pm_guc_events);
537 dev_priv->guc.interrupts_enabled = true;
538 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
539 }
540 spin_unlock_irq(&dev_priv->irq_lock);
541}
542
543void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
544{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530545 assert_rpm_wakelock_held(dev_priv);
546
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530547 spin_lock_irq(&dev_priv->irq_lock);
548 dev_priv->guc.interrupts_enabled = false;
549
550 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
551
552 spin_unlock_irq(&dev_priv->irq_lock);
553 synchronize_irq(dev_priv->drm.irq);
554
555 gen9_reset_guc_interrupts(dev_priv);
556}
557
Ben Widawsky09610212014-05-15 20:58:08 +0300558/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200559 * bdw_update_port_irq - update DE port interrupt
560 * @dev_priv: driver private
561 * @interrupt_mask: mask of interrupt bits to update
562 * @enabled_irq_mask: mask of interrupt bits to enable
563 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300564static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
565 uint32_t interrupt_mask,
566 uint32_t enabled_irq_mask)
567{
568 uint32_t new_val;
569 uint32_t old_val;
570
Chris Wilson67520412017-03-02 13:28:01 +0000571 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300572
573 WARN_ON(enabled_irq_mask & ~interrupt_mask);
574
575 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
576 return;
577
578 old_val = I915_READ(GEN8_DE_PORT_IMR);
579
580 new_val = old_val;
581 new_val &= ~interrupt_mask;
582 new_val |= (~enabled_irq_mask & interrupt_mask);
583
584 if (new_val != old_val) {
585 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
586 POSTING_READ(GEN8_DE_PORT_IMR);
587 }
588}
589
590/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200591 * bdw_update_pipe_irq - update DE pipe interrupt
592 * @dev_priv: driver private
593 * @pipe: pipe whose interrupt to update
594 * @interrupt_mask: mask of interrupt bits to update
595 * @enabled_irq_mask: mask of interrupt bits to enable
596 */
597void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
598 enum pipe pipe,
599 uint32_t interrupt_mask,
600 uint32_t enabled_irq_mask)
601{
602 uint32_t new_val;
603
Chris Wilson67520412017-03-02 13:28:01 +0000604 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200605
606 WARN_ON(enabled_irq_mask & ~interrupt_mask);
607
608 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
609 return;
610
611 new_val = dev_priv->de_irq_mask[pipe];
612 new_val &= ~interrupt_mask;
613 new_val |= (~enabled_irq_mask & interrupt_mask);
614
615 if (new_val != dev_priv->de_irq_mask[pipe]) {
616 dev_priv->de_irq_mask[pipe] = new_val;
617 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
618 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
619 }
620}
621
622/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200623 * ibx_display_interrupt_update - update SDEIMR
624 * @dev_priv: driver private
625 * @interrupt_mask: mask of interrupt bits to update
626 * @enabled_irq_mask: mask of interrupt bits to enable
627 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200628void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
629 uint32_t interrupt_mask,
630 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200631{
632 uint32_t sdeimr = I915_READ(SDEIMR);
633 sdeimr &= ~interrupt_mask;
634 sdeimr |= (~enabled_irq_mask & interrupt_mask);
635
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100636 WARN_ON(enabled_irq_mask & ~interrupt_mask);
637
Chris Wilson67520412017-03-02 13:28:01 +0000638 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200639
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700640 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300641 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300642
Daniel Vetterfee884e2013-07-04 23:35:21 +0200643 I915_WRITE(SDEIMR, sdeimr);
644 POSTING_READ(SDEIMR);
645}
Paulo Zanoni86642812013-04-12 17:57:57 -0300646
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300647u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
648 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800649{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300650 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200651 u32 enable_mask = status_mask << 16;
652
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300653 lockdep_assert_held(&dev_priv->irq_lock);
654
655 if (INTEL_GEN(dev_priv) < 5)
656 goto out;
657
Imre Deak10c59c52014-02-10 18:42:48 +0200658 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300659 * On pipe A we don't support the PSR interrupt yet,
660 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200661 */
662 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
663 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300664 /*
665 * On pipe B and C we don't support the PSR interrupt yet, on pipe
666 * A the same bit is for perf counters which we don't use either.
667 */
668 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
669 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200670
671 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
672 SPRITE0_FLIP_DONE_INT_EN_VLV |
673 SPRITE1_FLIP_DONE_INT_EN_VLV);
674 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
675 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
676 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
677 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
678
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300679out:
680 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
681 status_mask & ~PIPESTAT_INT_STATUS_MASK,
682 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
683 pipe_name(pipe), enable_mask, status_mask);
684
Imre Deak10c59c52014-02-10 18:42:48 +0200685 return enable_mask;
686}
687
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300688void i915_enable_pipestat(struct drm_i915_private *dev_priv,
689 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200690{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300691 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200692 u32 enable_mask;
693
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300694 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
695 "pipe %c: status_mask=0x%x\n",
696 pipe_name(pipe), status_mask);
697
698 lockdep_assert_held(&dev_priv->irq_lock);
699 WARN_ON(!intel_irqs_enabled(dev_priv));
700
701 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
702 return;
703
704 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
705 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
706
707 I915_WRITE(reg, enable_mask | status_mask);
708 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200709}
710
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300711void i915_disable_pipestat(struct drm_i915_private *dev_priv,
712 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200713{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300714 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200715 u32 enable_mask;
716
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300717 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
718 "pipe %c: status_mask=0x%x\n",
719 pipe_name(pipe), status_mask);
720
721 lockdep_assert_held(&dev_priv->irq_lock);
722 WARN_ON(!intel_irqs_enabled(dev_priv));
723
724 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
725 return;
726
727 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
728 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
729
730 I915_WRITE(reg, enable_mask | status_mask);
731 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200732}
733
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000734/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300735 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100736 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000737 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100738static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000739{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100740 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300741 return;
742
Daniel Vetter13321782014-09-15 14:55:29 +0200743 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000744
Imre Deak755e9012014-02-10 18:42:47 +0200745 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100746 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200747 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200748 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000749
Daniel Vetter13321782014-09-15 14:55:29 +0200750 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000751}
752
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300753/*
754 * This timing diagram depicts the video signal in and
755 * around the vertical blanking period.
756 *
757 * Assumptions about the fictitious mode used in this example:
758 * vblank_start >= 3
759 * vsync_start = vblank_start + 1
760 * vsync_end = vblank_start + 2
761 * vtotal = vblank_start + 3
762 *
763 * start of vblank:
764 * latch double buffered registers
765 * increment frame counter (ctg+)
766 * generate start of vblank interrupt (gen4+)
767 * |
768 * | frame start:
769 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
770 * | may be shifted forward 1-3 extra lines via PIPECONF
771 * | |
772 * | | start of vsync:
773 * | | generate vsync interrupt
774 * | | |
775 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
776 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
777 * ----va---> <-----------------vb--------------------> <--------va-------------
778 * | | <----vs-----> |
779 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
780 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
781 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
782 * | | |
783 * last visible pixel first visible pixel
784 * | increment frame counter (gen3/4)
785 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
786 *
787 * x = horizontal active
788 * _ = horizontal blanking
789 * hs = horizontal sync
790 * va = vertical active
791 * vb = vertical blanking
792 * vs = vertical sync
793 * vbs = vblank_start (number)
794 *
795 * Summary:
796 * - most events happen at the start of horizontal sync
797 * - frame start happens at the start of horizontal blank, 1-4 lines
798 * (depending on PIPECONF settings) after the start of vblank
799 * - gen3/4 pixel and frame counter are synchronized with the start
800 * of horizontal active on the first line of vertical active
801 */
802
Keith Packard42f52ef2008-10-18 19:39:29 -0700803/* Called from drm generic code, passed a 'crtc', which
804 * we use as a pipe index
805 */
Thierry Reding88e72712015-09-24 18:35:31 +0200806static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700807{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100808 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200809 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300810 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200811 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200812 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700813
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100814 htotal = mode->crtc_htotal;
815 hsync_start = mode->crtc_hsync_start;
816 vbl_start = mode->crtc_vblank_start;
817 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
818 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300819
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300820 /* Convert to pixel count */
821 vbl_start *= htotal;
822
823 /* Start of vblank event occurs at start of hsync */
824 vbl_start -= htotal - hsync_start;
825
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800826 high_frame = PIPEFRAME(pipe);
827 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100828
Ville Syrjälä694e4092017-03-09 17:44:30 +0200829 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
830
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700831 /*
832 * High & low register fields aren't synchronized, so make sure
833 * we get a low value that's stable across two reads of the high
834 * register.
835 */
836 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200837 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
838 low = I915_READ_FW(low_frame);
839 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700840 } while (high1 != high2);
841
Ville Syrjälä694e4092017-03-09 17:44:30 +0200842 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
843
Chris Wilson5eddb702010-09-11 13:48:45 +0100844 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300845 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100846 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300847
848 /*
849 * The frame counter increments at beginning of active.
850 * Cook up a vblank counter by also checking the pixel
851 * counter against vblank start.
852 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200853 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700854}
855
Dave Airlie974e59b2015-10-30 09:45:33 +1000856static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800857{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100858 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800859
Ville Syrjälä649636e2015-09-22 19:50:01 +0300860 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800861}
862
Uma Shankaraec02462017-09-25 19:26:01 +0530863/*
864 * On certain encoders on certain platforms, pipe
865 * scanline register will not work to get the scanline,
866 * since the timings are driven from the PORT or issues
867 * with scanline register updates.
868 * This function will use Framestamp and current
869 * timestamp registers to calculate the scanline.
870 */
871static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
872{
873 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
874 struct drm_vblank_crtc *vblank =
875 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
876 const struct drm_display_mode *mode = &vblank->hwmode;
877 u32 vblank_start = mode->crtc_vblank_start;
878 u32 vtotal = mode->crtc_vtotal;
879 u32 htotal = mode->crtc_htotal;
880 u32 clock = mode->crtc_clock;
881 u32 scanline, scan_prev_time, scan_curr_time, scan_post_time;
882
883 /*
884 * To avoid the race condition where we might cross into the
885 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
886 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
887 * during the same frame.
888 */
889 do {
890 /*
891 * This field provides read back of the display
892 * pipe frame time stamp. The time stamp value
893 * is sampled at every start of vertical blank.
894 */
895 scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
896
897 /*
898 * The TIMESTAMP_CTR register has the current
899 * time stamp value.
900 */
901 scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR);
902
903 scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
904 } while (scan_post_time != scan_prev_time);
905
906 scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
907 clock), 1000 * htotal);
908 scanline = min(scanline, vtotal - 1);
909 scanline = (scanline + vblank_start) % vtotal;
910
911 return scanline;
912}
913
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300914/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300915static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
916{
917 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100918 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200919 const struct drm_display_mode *mode;
920 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300921 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300922 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300923
Ville Syrjälä72259532017-03-02 19:15:05 +0200924 if (!crtc->active)
925 return -1;
926
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200927 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
928 mode = &vblank->hwmode;
929
Uma Shankaraec02462017-09-25 19:26:01 +0530930 if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
931 return __intel_get_crtc_scanline_from_timestamp(crtc);
932
Ville Syrjälä80715b22014-05-15 20:23:23 +0300933 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300934 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
935 vtotal /= 2;
936
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100937 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300938 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300939 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300940 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300941
942 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700943 * On HSW, the DSL reg (0x70000) appears to return 0 if we
944 * read it just before the start of vblank. So try it again
945 * so we don't accidentally end up spanning a vblank frame
946 * increment, causing the pipe_update_end() code to squak at us.
947 *
948 * The nature of this problem means we can't simply check the ISR
949 * bit and return the vblank start value; nor can we use the scanline
950 * debug register in the transcoder as it appears to have the same
951 * problem. We may need to extend this to include other platforms,
952 * but so far testing only shows the problem on HSW.
953 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100954 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700955 int i, temp;
956
957 for (i = 0; i < 100; i++) {
958 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200959 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700960 if (temp != position) {
961 position = temp;
962 break;
963 }
964 }
965 }
966
967 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300968 * See update_scanline_offset() for the details on the
969 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300970 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300971 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300972}
973
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200974static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
975 bool in_vblank_irq, int *vpos, int *hpos,
976 ktime_t *stime, ktime_t *etime,
977 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100978{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100979 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200980 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
981 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300982 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300983 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100984 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100985
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200986 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100987 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800988 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200989 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100990 }
991
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300992 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300993 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300994 vtotal = mode->crtc_vtotal;
995 vbl_start = mode->crtc_vblank_start;
996 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100997
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200998 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
999 vbl_start = DIV_ROUND_UP(vbl_start, 2);
1000 vbl_end /= 2;
1001 vtotal /= 2;
1002 }
1003
Mario Kleinerad3543e2013-10-30 05:13:08 +01001004 /*
1005 * Lock uncore.lock, as we will do multiple timing critical raw
1006 * register reads, potentially with preemption disabled, so the
1007 * following code must not block on uncore.lock.
1008 */
1009 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001010
Mario Kleinerad3543e2013-10-30 05:13:08 +01001011 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
1012
1013 /* Get optional system timestamp before query. */
1014 if (stime)
1015 *stime = ktime_get();
1016
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001017 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001018 /* No obvious pixelcount register. Only query vertical
1019 * scanout position from Display scan line register.
1020 */
Ville Syrjäläa225f072014-04-29 13:35:45 +03001021 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001022 } else {
1023 /* Have access to pixelcount since start of frame.
1024 * We can split this into vertical and horizontal
1025 * scanout position.
1026 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001027 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001028
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001029 /* convert to pixel counts */
1030 vbl_start *= htotal;
1031 vbl_end *= htotal;
1032 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001033
1034 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +03001035 * In interlaced modes, the pixel counter counts all pixels,
1036 * so one field will have htotal more pixels. In order to avoid
1037 * the reported position from jumping backwards when the pixel
1038 * counter is beyond the length of the shorter field, just
1039 * clamp the position the length of the shorter field. This
1040 * matches how the scanline counter based position works since
1041 * the scanline counter doesn't count the two half lines.
1042 */
1043 if (position >= vtotal)
1044 position = vtotal - 1;
1045
1046 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001047 * Start of vblank interrupt is triggered at start of hsync,
1048 * just prior to the first active line of vblank. However we
1049 * consider lines to start at the leading edge of horizontal
1050 * active. So, should we get here before we've crossed into
1051 * the horizontal active of the first line in vblank, we would
1052 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
1053 * always add htotal-hsync_start to the current pixel position.
1054 */
1055 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001056 }
1057
Mario Kleinerad3543e2013-10-30 05:13:08 +01001058 /* Get optional system timestamp after query. */
1059 if (etime)
1060 *etime = ktime_get();
1061
1062 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1063
1064 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1065
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001066 /*
1067 * While in vblank, position will be negative
1068 * counting up towards 0 at vbl_end. And outside
1069 * vblank, position will be positive counting
1070 * up since vbl_end.
1071 */
1072 if (position >= vbl_start)
1073 position -= vbl_end;
1074 else
1075 position += vtotal - vbl_end;
1076
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001077 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001078 *vpos = position;
1079 *hpos = 0;
1080 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001081 *vpos = position / htotal;
1082 *hpos = position - (*vpos * htotal);
1083 }
1084
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001085 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001086}
1087
Ville Syrjäläa225f072014-04-29 13:35:45 +03001088int intel_get_crtc_scanline(struct intel_crtc *crtc)
1089{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001090 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +03001091 unsigned long irqflags;
1092 int position;
1093
1094 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1095 position = __intel_get_crtc_scanline(crtc);
1096 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1097
1098 return position;
1099}
1100
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001101static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001102{
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001103 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001104 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001105
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001106 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001107
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001108 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1109
Daniel Vetter20e4d402012-08-08 23:35:39 +02001110 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001111
Jesse Barnes7648fa92010-05-20 14:28:11 -07001112 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001113 busy_up = I915_READ(RCPREVBSYTUPAVG);
1114 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001115 max_avg = I915_READ(RCBMAXAVG);
1116 min_avg = I915_READ(RCBMINAVG);
1117
1118 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001119 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001120 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1121 new_delay = dev_priv->ips.cur_delay - 1;
1122 if (new_delay < dev_priv->ips.max_delay)
1123 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001124 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001125 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1126 new_delay = dev_priv->ips.cur_delay + 1;
1127 if (new_delay > dev_priv->ips.min_delay)
1128 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001129 }
1130
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001131 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001132 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001133
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001134 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001135
Jesse Barnesf97108d2010-01-29 11:27:07 -08001136 return;
1137}
1138
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001139static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001140{
Chris Wilsone61e0f52018-02-21 09:56:36 +00001141 struct i915_request *rq = NULL;
Chris Wilson56299fb2017-02-27 20:58:48 +00001142 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001143
Chris Wilsonbcbd5c32017-10-25 15:39:42 +01001144 if (!engine->breadcrumbs.irq_armed)
1145 return;
1146
Chris Wilson2246bea2017-02-17 15:13:00 +00001147 atomic_inc(&engine->irq_count);
Chris Wilson538b2572017-01-24 15:18:05 +00001148 set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson56299fb2017-02-27 20:58:48 +00001149
Chris Wilson61d3dc72017-03-03 19:08:24 +00001150 spin_lock(&engine->breadcrumbs.irq_lock);
1151 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001152 if (wait) {
Chris Wilson17b51ad2017-09-18 17:27:33 +01001153 bool wakeup = engine->irq_seqno_barrier;
1154
Chris Wilson56299fb2017-02-27 20:58:48 +00001155 /* We use a callback from the dma-fence to submit
1156 * requests after waiting on our own requests. To
1157 * ensure minimum delay in queuing the next request to
1158 * hardware, signal the fence now rather than wait for
1159 * the signaler to be woken up. We still wake up the
1160 * waiter in order to handle the irq-seqno coherency
1161 * issues (we may receive the interrupt before the
1162 * seqno is written, see __i915_request_irq_complete())
1163 * and to handle coalescing of multiple seqno updates
1164 * and many waiters.
1165 */
1166 if (i915_seqno_passed(intel_engine_get_seqno(engine),
Chris Wilson17b51ad2017-09-18 17:27:33 +01001167 wait->seqno)) {
Chris Wilsone61e0f52018-02-21 09:56:36 +00001168 struct i915_request *waiter = wait->request;
Chris Wilsonde4d2102017-09-18 17:27:34 +01001169
Chris Wilson17b51ad2017-09-18 17:27:33 +01001170 wakeup = true;
1171 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Chris Wilsonde4d2102017-09-18 17:27:34 +01001172 &waiter->fence.flags) &&
1173 intel_wait_check_request(wait, waiter))
Chris Wilsone61e0f52018-02-21 09:56:36 +00001174 rq = i915_request_get(waiter);
Chris Wilson17b51ad2017-09-18 17:27:33 +01001175 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001176
Chris Wilson17b51ad2017-09-18 17:27:33 +01001177 if (wakeup)
1178 wake_up_process(wait->tsk);
Chris Wilson67b807a82017-02-27 20:58:50 +00001179 } else {
Chris Wilsonbcbd5c32017-10-25 15:39:42 +01001180 if (engine->breadcrumbs.irq_armed)
1181 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001182 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001183 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001184
Chris Wilson24754d72017-03-03 14:45:57 +00001185 if (rq) {
Chris Wilson56299fb2017-02-27 20:58:48 +00001186 dma_fence_signal(&rq->fence);
Chris Wilson4e9a8be2018-03-05 10:41:05 +00001187 GEM_BUG_ON(!i915_request_completed(rq));
Chris Wilsone61e0f52018-02-21 09:56:36 +00001188 i915_request_put(rq);
Chris Wilson24754d72017-03-03 14:45:57 +00001189 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001190
1191 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001192}
1193
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001194static void vlv_c0_read(struct drm_i915_private *dev_priv,
1195 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001196{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001197 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001198 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1199 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001200}
1201
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001202void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1203{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001204 memset(&dev_priv->gt_pm.rps.ei, 0, sizeof(dev_priv->gt_pm.rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001205}
1206
1207static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1208{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001209 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1210 const struct intel_rps_ei *prev = &rps->ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001211 struct intel_rps_ei now;
1212 u32 events = 0;
1213
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001214 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001215 return 0;
1216
1217 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001218
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001219 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001220 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001221 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001222
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001223 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001224
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001225 time *= dev_priv->czclk_freq;
1226
1227 /* Workload can be split between render + media,
1228 * e.g. SwapBuffers being blitted in X after being rendered in
1229 * mesa. To account for this we need to combine both engines
1230 * into our activity counter.
1231 */
Chris Wilson569884e2017-03-09 21:12:31 +00001232 render = now.render_c0 - prev->render_c0;
1233 media = now.media_c0 - prev->media_c0;
1234 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001235 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001236
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001237 if (c0 > time * rps->up_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001238 events = GEN6_PM_RP_UP_THRESHOLD;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001239 else if (c0 < time * rps->down_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001240 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001241 }
1242
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001243 rps->ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001244 return events;
Deepak S31685c22014-07-03 17:33:01 -04001245}
1246
Ben Widawsky4912d042011-04-25 11:25:20 -07001247static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001248{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001249 struct drm_i915_private *dev_priv =
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001250 container_of(work, struct drm_i915_private, gt_pm.rps.work);
1251 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001252 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001253 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001254 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001255
Daniel Vetter59cdb632013-07-04 23:35:28 +02001256 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001257 if (rps->interrupts_enabled) {
1258 pm_iir = fetch_and_zero(&rps->pm_iir);
1259 client_boost = atomic_read(&rps->num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001260 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001261 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001262
Paulo Zanoni60611c12013-08-15 11:50:01 -03001263 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301264 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001265 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001266 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001267
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001268 mutex_lock(&dev_priv->pcu_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001269
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001270 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1271
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001272 adj = rps->last_adj;
1273 new_delay = rps->cur_freq;
1274 min = rps->min_freq_softlimit;
1275 max = rps->max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001276 if (client_boost)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001277 max = rps->max_freq;
1278 if (client_boost && new_delay < rps->boost_freq) {
1279 new_delay = rps->boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001280 adj = 0;
1281 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001282 if (adj > 0)
1283 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001284 else /* CHV needs even encode values */
1285 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301286
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001287 if (new_delay >= rps->max_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301288 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001289 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001290 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001291 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001292 if (rps->cur_freq > rps->efficient_freq)
1293 new_delay = rps->efficient_freq;
1294 else if (rps->cur_freq > rps->min_freq_softlimit)
1295 new_delay = rps->min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001296 adj = 0;
1297 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1298 if (adj < 0)
1299 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001300 else /* CHV needs even encode values */
1301 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301302
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001303 if (new_delay <= rps->min_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301304 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001305 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001306 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001307 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001308
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001309 rps->last_adj = adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001310
Ben Widawsky79249632012-09-07 19:43:42 -07001311 /* sysfs frequency interfaces may have snuck in while servicing the
1312 * interrupt
1313 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001314 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001315 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301316
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001317 if (intel_set_rps(dev_priv, new_delay)) {
1318 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001319 rps->last_adj = 0;
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001320 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001321
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001322 mutex_unlock(&dev_priv->pcu_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001323
1324out:
1325 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1326 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001327 if (rps->interrupts_enabled)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001328 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1329 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001330}
1331
Ben Widawskye3689192012-05-25 16:56:22 -07001332
1333/**
1334 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1335 * occurred.
1336 * @work: workqueue struct
1337 *
1338 * Doesn't actually do anything except notify userspace. As a consequence of
1339 * this event, userspace should try to remap the bad rows since statistically
1340 * it is likely the same row is more likely to go bad again.
1341 */
1342static void ivybridge_parity_work(struct work_struct *work)
1343{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001344 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001345 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001346 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001347 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001348 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001349 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001350
1351 /* We must turn off DOP level clock gating to access the L3 registers.
1352 * In order to prevent a get/put style interface, acquire struct mutex
1353 * any time we access those registers.
1354 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001355 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001356
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001357 /* If we've screwed up tracking, just let the interrupt fire again */
1358 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1359 goto out;
1360
Ben Widawskye3689192012-05-25 16:56:22 -07001361 misccpctl = I915_READ(GEN7_MISCCPCTL);
1362 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1363 POSTING_READ(GEN7_MISCCPCTL);
1364
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001365 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001366 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001367
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001368 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001369 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001370 break;
1371
1372 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1373
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001374 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001375
1376 error_status = I915_READ(reg);
1377 row = GEN7_PARITY_ERROR_ROW(error_status);
1378 bank = GEN7_PARITY_ERROR_BANK(error_status);
1379 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1380
1381 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1382 POSTING_READ(reg);
1383
1384 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1385 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1386 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1387 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1388 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1389 parity_event[5] = NULL;
1390
Chris Wilson91c8a322016-07-05 10:40:23 +01001391 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001392 KOBJ_CHANGE, parity_event);
1393
1394 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1395 slice, row, bank, subbank);
1396
1397 kfree(parity_event[4]);
1398 kfree(parity_event[3]);
1399 kfree(parity_event[2]);
1400 kfree(parity_event[1]);
1401 }
Ben Widawskye3689192012-05-25 16:56:22 -07001402
1403 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1404
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001405out:
1406 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001407 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001408 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001409 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001410
Chris Wilson91c8a322016-07-05 10:40:23 +01001411 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001412}
1413
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001414static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1415 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001416{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001417 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001418 return;
1419
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001420 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001421 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001422 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001423
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001424 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001425 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1426 dev_priv->l3_parity.which_slice |= 1 << 1;
1427
1428 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1429 dev_priv->l3_parity.which_slice |= 1 << 0;
1430
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001431 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001432}
1433
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001434static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001435 u32 gt_iir)
1436{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001437 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301438 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001439 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301440 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001441}
1442
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001443static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001444 u32 gt_iir)
1445{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001446 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301447 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001448 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301449 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001450 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301451 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001452
Ben Widawskycc609d52013-05-28 19:22:29 -07001453 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1454 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001455 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1456 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001457
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001458 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1459 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001460}
1461
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001462static void
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001463gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001464{
Mika Kuoppalab620e872017-09-22 15:43:03 +03001465 struct intel_engine_execlists * const execlists = &engine->execlists;
Chris Wilson31de7352017-03-16 12:56:18 +00001466 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001467
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001468 if (iir & GT_CONTEXT_SWITCH_INTERRUPT) {
Chris Wilson1c645bf2018-03-22 07:35:32 +00001469 if (READ_ONCE(engine->execlists.active))
1470 tasklet = !test_and_set_bit(ENGINE_IRQ_EXECLIST,
1471 &engine->irq_posted);
Chris Wilsonf7470262017-01-24 15:20:21 +00001472 }
Chris Wilson31de7352017-03-16 12:56:18 +00001473
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001474 if (iir & GT_RENDER_USER_INTERRUPT) {
Chris Wilson31de7352017-03-16 12:56:18 +00001475 notify_ring(engine);
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +00001476 tasklet |= USES_GUC_SUBMISSION(engine->i915);
Chris Wilson31de7352017-03-16 12:56:18 +00001477 }
1478
1479 if (tasklet)
Sagar Arun Kamblec6dce8f2017-11-16 19:02:37 +05301480 tasklet_hi_schedule(&execlists->tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001481}
1482
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001483static void gen8_gt_irq_ack(struct drm_i915_private *i915,
Chris Wilson55ef72f2018-02-02 15:34:48 +00001484 u32 master_ctl, u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001485{
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001486 void __iomem * const regs = i915->regs;
1487
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001488#define GEN8_GT_IRQS (GEN8_GT_RCS_IRQ | \
1489 GEN8_GT_BCS_IRQ | \
1490 GEN8_GT_VCS1_IRQ | \
1491 GEN8_GT_VCS2_IRQ | \
1492 GEN8_GT_VECS_IRQ | \
1493 GEN8_GT_PM_IRQ | \
1494 GEN8_GT_GUC_IRQ)
1495
Ben Widawskyabd58f02013-11-02 21:07:09 -07001496 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001497 gt_iir[0] = raw_reg_read(regs, GEN8_GT_IIR(0));
1498 if (likely(gt_iir[0]))
1499 raw_reg_write(regs, GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001500 }
1501
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001502 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001503 gt_iir[1] = raw_reg_read(regs, GEN8_GT_IIR(1));
1504 if (likely(gt_iir[1]))
1505 raw_reg_write(regs, GEN8_GT_IIR(1), gt_iir[1]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001506 }
1507
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301508 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001509 gt_iir[2] = raw_reg_read(regs, GEN8_GT_IIR(2));
1510 if (likely(gt_iir[2] & (i915->pm_rps_events |
1511 i915->pm_guc_events)))
1512 raw_reg_write(regs, GEN8_GT_IIR(2),
1513 gt_iir[2] & (i915->pm_rps_events |
1514 i915->pm_guc_events));
1515 }
1516
1517 if (master_ctl & GEN8_GT_VECS_IRQ) {
1518 gt_iir[3] = raw_reg_read(regs, GEN8_GT_IIR(3));
1519 if (likely(gt_iir[3]))
1520 raw_reg_write(regs, GEN8_GT_IIR(3), gt_iir[3]);
Ben Widawsky09610212014-05-15 20:58:08 +03001521 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07001522}
1523
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001524static void gen8_gt_irq_handler(struct drm_i915_private *i915,
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001525 u32 master_ctl, u32 gt_iir[4])
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001526{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001527 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001528 gen8_cs_irq_handler(i915->engine[RCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001529 gt_iir[0] >> GEN8_RCS_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001530 gen8_cs_irq_handler(i915->engine[BCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001531 gt_iir[0] >> GEN8_BCS_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001532 }
1533
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001534 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001535 gen8_cs_irq_handler(i915->engine[VCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001536 gt_iir[1] >> GEN8_VCS1_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001537 gen8_cs_irq_handler(i915->engine[VCS2],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001538 gt_iir[1] >> GEN8_VCS2_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001539 }
1540
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001541 if (master_ctl & GEN8_GT_VECS_IRQ) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001542 gen8_cs_irq_handler(i915->engine[VECS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001543 gt_iir[3] >> GEN8_VECS_IRQ_SHIFT);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001544 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001545
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001546 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001547 gen6_rps_irq_handler(i915, gt_iir[2]);
1548 gen9_guc_irq_handler(i915, gt_iir[2]);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001549 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001550}
1551
Imre Deak63c88d22015-07-20 14:43:39 -07001552static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1553{
1554 switch (port) {
1555 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001556 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001557 case PORT_B:
1558 return val & PORTB_HOTPLUG_LONG_DETECT;
1559 case PORT_C:
1560 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001561 default:
1562 return false;
1563 }
1564}
1565
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001566static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1567{
1568 switch (port) {
1569 case PORT_E:
1570 return val & PORTE_HOTPLUG_LONG_DETECT;
1571 default:
1572 return false;
1573 }
1574}
1575
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001576static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1577{
1578 switch (port) {
1579 case PORT_A:
1580 return val & PORTA_HOTPLUG_LONG_DETECT;
1581 case PORT_B:
1582 return val & PORTB_HOTPLUG_LONG_DETECT;
1583 case PORT_C:
1584 return val & PORTC_HOTPLUG_LONG_DETECT;
1585 case PORT_D:
1586 return val & PORTD_HOTPLUG_LONG_DETECT;
1587 default:
1588 return false;
1589 }
1590}
1591
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001592static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1593{
1594 switch (port) {
1595 case PORT_A:
1596 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1597 default:
1598 return false;
1599 }
1600}
1601
Jani Nikula676574d2015-05-28 15:43:53 +03001602static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001603{
1604 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001605 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001606 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001607 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001608 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001609 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001610 return val & PORTD_HOTPLUG_LONG_DETECT;
1611 default:
1612 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001613 }
1614}
1615
Jani Nikula676574d2015-05-28 15:43:53 +03001616static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001617{
1618 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001619 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001620 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001621 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001622 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001623 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001624 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1625 default:
1626 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001627 }
1628}
1629
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001630/*
1631 * Get a bit mask of pins that have triggered, and which ones may be long.
1632 * This can be called multiple times with the same masks to accumulate
1633 * hotplug detection results from several registers.
1634 *
1635 * Note that the caller is expected to zero out the masks initially.
1636 */
Rodrigo Vivicf539022018-01-29 15:22:21 -08001637static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1638 u32 *pin_mask, u32 *long_mask,
1639 u32 hotplug_trigger, u32 dig_hotplug_reg,
1640 const u32 hpd[HPD_NUM_PINS],
1641 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001642{
Jani Nikula8c841e52015-06-18 13:06:17 +03001643 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001644 int i;
1645
Jani Nikula676574d2015-05-28 15:43:53 +03001646 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001647 if ((hpd[i] & hotplug_trigger) == 0)
1648 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001649
Jani Nikula8c841e52015-06-18 13:06:17 +03001650 *pin_mask |= BIT(i);
1651
Rodrigo Vivicf539022018-01-29 15:22:21 -08001652 port = intel_hpd_pin_to_port(dev_priv, i);
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07001653 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001654 continue;
1655
Imre Deakfd63e2a2015-07-21 15:32:44 -07001656 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001657 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001658 }
1659
1660 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1661 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1662
1663}
1664
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001665static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001666{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001667 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001668}
1669
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001670static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001671{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001672 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001673}
1674
Shuang He8bf1e9f2013-10-15 18:55:27 +01001675#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001676static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1677 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001678 uint32_t crc0, uint32_t crc1,
1679 uint32_t crc2, uint32_t crc3,
1680 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001681{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001682 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1683 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001684 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1685 struct drm_driver *driver = dev_priv->drm.driver;
1686 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001687 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001688
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001689 spin_lock(&pipe_crc->lock);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +01001690 if (pipe_crc->source && !crtc->base.crc.opened) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001691 if (!pipe_crc->entries) {
1692 spin_unlock(&pipe_crc->lock);
1693 DRM_DEBUG_KMS("spurious interrupt\n");
1694 return;
1695 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001696
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001697 head = pipe_crc->head;
1698 tail = pipe_crc->tail;
1699
1700 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1701 spin_unlock(&pipe_crc->lock);
1702 DRM_ERROR("CRC buffer overflowing\n");
1703 return;
1704 }
1705
1706 entry = &pipe_crc->entries[head];
1707
1708 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1709 entry->crc[0] = crc0;
1710 entry->crc[1] = crc1;
1711 entry->crc[2] = crc2;
1712 entry->crc[3] = crc3;
1713 entry->crc[4] = crc4;
1714
1715 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1716 pipe_crc->head = head;
1717
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001718 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001719
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001720 wake_up_interruptible(&pipe_crc->wq);
1721 } else {
1722 /*
1723 * For some not yet identified reason, the first CRC is
1724 * bonkers. So let's just wait for the next vblank and read
1725 * out the buggy result.
1726 *
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001727 * On GEN8+ sometimes the second CRC is bonkers as well, so
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001728 * don't trust that one either.
1729 */
Maarten Lankhorst033b7a22018-03-08 13:02:02 +01001730 if (pipe_crc->skipped <= 0 ||
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001731 (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001732 pipe_crc->skipped++;
1733 spin_unlock(&pipe_crc->lock);
1734 return;
1735 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001736 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001737 crcs[0] = crc0;
1738 crcs[1] = crc1;
1739 crcs[2] = crc2;
1740 crcs[3] = crc3;
1741 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001742 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001743 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001744 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001745 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001746}
Daniel Vetter277de952013-10-18 16:37:07 +02001747#else
1748static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001749display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1750 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001751 uint32_t crc0, uint32_t crc1,
1752 uint32_t crc2, uint32_t crc3,
1753 uint32_t crc4) {}
1754#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001755
Daniel Vetter277de952013-10-18 16:37:07 +02001756
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001757static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1758 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001759{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001760 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001761 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1762 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001763}
1764
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001765static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1766 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001767{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001768 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001769 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1770 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1771 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1772 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1773 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001774}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001775
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001776static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1777 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001778{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001779 uint32_t res1, res2;
1780
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001781 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001782 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1783 else
1784 res1 = 0;
1785
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001786 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001787 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1788 else
1789 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001790
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001791 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001792 I915_READ(PIPE_CRC_RES_RED(pipe)),
1793 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1794 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1795 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001796}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001797
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001798/* The RPS events need forcewake, so we add them to a work queue and mask their
1799 * IMR bits until the work is done. Other interrupts can be processed without
1800 * the work queue. */
1801static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001802{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001803 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1804
Deepak Sa6706b42014-03-15 20:23:22 +05301805 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001806 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301807 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001808 if (rps->interrupts_enabled) {
1809 rps->pm_iir |= pm_iir & dev_priv->pm_rps_events;
1810 schedule_work(&rps->work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001811 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001812 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001813 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001814
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001815 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001816 return;
1817
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001818 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001819 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301820 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001821
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001822 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1823 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001824 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001825}
1826
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301827static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1828{
Michal Wajdeczko93bf8092018-03-08 16:46:55 +01001829 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT)
1830 intel_guc_to_host_event_handler(&dev_priv->guc);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301831}
1832
Ville Syrjälä44d92412017-08-18 21:36:51 +03001833static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1834{
1835 enum pipe pipe;
1836
1837 for_each_pipe(dev_priv, pipe) {
1838 I915_WRITE(PIPESTAT(pipe),
1839 PIPESTAT_INT_STATUS_MASK |
1840 PIPE_FIFO_UNDERRUN_STATUS);
1841
1842 dev_priv->pipestat_irq_mask[pipe] = 0;
1843 }
1844}
1845
Ville Syrjäläeb643432017-08-18 21:36:59 +03001846static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1847 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001848{
Imre Deakc1874ed2014-02-04 21:35:46 +02001849 int pipe;
1850
Imre Deak58ead0d2014-02-04 21:35:47 +02001851 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001852
1853 if (!dev_priv->display_irqs_enabled) {
1854 spin_unlock(&dev_priv->irq_lock);
1855 return;
1856 }
1857
Damien Lespiau055e3932014-08-18 13:49:10 +01001858 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001859 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001860 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001861
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001862 /*
1863 * PIPESTAT bits get signalled even when the interrupt is
1864 * disabled with the mask bits, and some of the status bits do
1865 * not generate interrupts at all (like the underrun bit). Hence
1866 * we need to be careful that we only handle what we want to
1867 * handle.
1868 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001869
1870 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001871 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001872
1873 switch (pipe) {
1874 case PIPE_A:
1875 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1876 break;
1877 case PIPE_B:
1878 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1879 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001880 case PIPE_C:
1881 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1882 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001883 }
1884 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001885 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001886
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001887 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001888 continue;
1889
1890 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001891 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1892 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001893
1894 /*
1895 * Clear the PIPE*STAT regs before the IIR
1896 */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001897 if (pipe_stats[pipe])
1898 I915_WRITE(reg, enable_mask | pipe_stats[pipe]);
Imre Deakc1874ed2014-02-04 21:35:46 +02001899 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001900 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001901}
1902
Ville Syrjäläeb643432017-08-18 21:36:59 +03001903static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1904 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1905{
1906 enum pipe pipe;
1907
1908 for_each_pipe(dev_priv, pipe) {
1909 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1910 drm_handle_vblank(&dev_priv->drm, pipe);
1911
1912 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1913 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1914
1915 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1916 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1917 }
1918}
1919
1920static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1921 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1922{
1923 bool blc_event = false;
1924 enum pipe pipe;
1925
1926 for_each_pipe(dev_priv, pipe) {
1927 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1928 drm_handle_vblank(&dev_priv->drm, pipe);
1929
1930 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1931 blc_event = true;
1932
1933 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1934 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1935
1936 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1937 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1938 }
1939
1940 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1941 intel_opregion_asle_intr(dev_priv);
1942}
1943
1944static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1945 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1946{
1947 bool blc_event = false;
1948 enum pipe pipe;
1949
1950 for_each_pipe(dev_priv, pipe) {
1951 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1952 drm_handle_vblank(&dev_priv->drm, pipe);
1953
1954 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1955 blc_event = true;
1956
1957 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1958 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1959
1960 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1961 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1962 }
1963
1964 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1965 intel_opregion_asle_intr(dev_priv);
1966
1967 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1968 gmbus_irq_handler(dev_priv);
1969}
1970
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001971static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001972 u32 pipe_stats[I915_MAX_PIPES])
1973{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001974 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001975
Damien Lespiau055e3932014-08-18 13:49:10 +01001976 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001977 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1978 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001979
1980 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001981 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001982
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001983 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1984 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001985 }
1986
1987 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001988 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001989}
1990
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001991static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001992{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001993 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001994
1995 if (hotplug_status)
1996 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1997
1998 return hotplug_status;
1999}
2000
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002001static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002002 u32 hotplug_status)
2003{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03002004 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002005
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002006 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2007 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03002008 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002009
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002010 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002011 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2012 hotplug_trigger, hotplug_trigger,
2013 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002014 i9xx_port_hotplug_long_detect);
2015
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002016 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002017 }
Jani Nikula369712e2015-05-27 15:03:40 +03002018
2019 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002020 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03002021 } else {
2022 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002023
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002024 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002025 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2026 hotplug_trigger, hotplug_trigger,
2027 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002028 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002029 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002030 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002031 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002032}
2033
Daniel Vetterff1f5252012-10-02 15:10:55 +02002034static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002035{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002036 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002037 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002038 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002039
Imre Deak2dd2a882015-02-24 11:14:30 +02002040 if (!intel_irqs_enabled(dev_priv))
2041 return IRQ_NONE;
2042
Imre Deak1f814da2015-12-16 02:52:19 +02002043 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2044 disable_rpm_wakeref_asserts(dev_priv);
2045
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002046 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002047 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002048 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002049 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002050 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002051
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002052 gt_iir = I915_READ(GTIIR);
2053 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002054 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002055
2056 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002057 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002058
2059 ret = IRQ_HANDLED;
2060
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002061 /*
2062 * Theory on interrupt generation, based on empirical evidence:
2063 *
2064 * x = ((VLV_IIR & VLV_IER) ||
2065 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2066 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2067 *
2068 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2069 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2070 * guarantee the CPU interrupt will be raised again even if we
2071 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2072 * bits this time around.
2073 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002074 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002075 ier = I915_READ(VLV_IER);
2076 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002077
2078 if (gt_iir)
2079 I915_WRITE(GTIIR, gt_iir);
2080 if (pm_iir)
2081 I915_WRITE(GEN6_PMIIR, pm_iir);
2082
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002083 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002084 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002085
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002086 /* Call regardless, as some status bits might not be
2087 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002088 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002089
Jerome Anandeef57322017-01-25 04:27:49 +05302090 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2091 I915_LPE_PIPE_B_INTERRUPT))
2092 intel_lpe_audio_irq_handler(dev_priv);
2093
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002094 /*
2095 * VLV_IIR is single buffered, and reflects the level
2096 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2097 */
2098 if (iir)
2099 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002100
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002101 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002102 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2103 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002104
Ville Syrjälä52894872016-04-13 21:19:56 +03002105 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002106 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002107 if (pm_iir)
2108 gen6_rps_irq_handler(dev_priv, pm_iir);
2109
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002110 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002111 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002112
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002113 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002114 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002115
Imre Deak1f814da2015-12-16 02:52:19 +02002116 enable_rpm_wakeref_asserts(dev_priv);
2117
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002118 return ret;
2119}
2120
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002121static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2122{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002123 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002124 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002125 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002126
Imre Deak2dd2a882015-02-24 11:14:30 +02002127 if (!intel_irqs_enabled(dev_priv))
2128 return IRQ_NONE;
2129
Imre Deak1f814da2015-12-16 02:52:19 +02002130 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2131 disable_rpm_wakeref_asserts(dev_priv);
2132
Chris Wilson579de732016-03-14 09:01:57 +00002133 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002134 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002135 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002136 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002137 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002138 u32 ier = 0;
2139
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002140 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2141 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002142
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002143 if (master_ctl == 0 && iir == 0)
2144 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002145
Oscar Mateo27b6c122014-06-16 16:11:00 +01002146 ret = IRQ_HANDLED;
2147
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002148 /*
2149 * Theory on interrupt generation, based on empirical evidence:
2150 *
2151 * x = ((VLV_IIR & VLV_IER) ||
2152 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2153 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2154 *
2155 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2156 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2157 * guarantee the CPU interrupt will be raised again even if we
2158 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2159 * bits this time around.
2160 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002161 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002162 ier = I915_READ(VLV_IER);
2163 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002164
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002165 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002166
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002167 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002168 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002169
Oscar Mateo27b6c122014-06-16 16:11:00 +01002170 /* Call regardless, as some status bits might not be
2171 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002172 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002173
Jerome Anandeef57322017-01-25 04:27:49 +05302174 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2175 I915_LPE_PIPE_B_INTERRUPT |
2176 I915_LPE_PIPE_C_INTERRUPT))
2177 intel_lpe_audio_irq_handler(dev_priv);
2178
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002179 /*
2180 * VLV_IIR is single buffered, and reflects the level
2181 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2182 */
2183 if (iir)
2184 I915_WRITE(VLV_IIR, iir);
2185
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002186 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002187 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002188 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002189
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002190 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002191
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002192 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002193 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002194
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002195 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002196 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002197
Imre Deak1f814da2015-12-16 02:52:19 +02002198 enable_rpm_wakeref_asserts(dev_priv);
2199
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002200 return ret;
2201}
2202
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002203static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2204 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002205 const u32 hpd[HPD_NUM_PINS])
2206{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002207 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2208
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002209 /*
2210 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2211 * unless we touch the hotplug register, even if hotplug_trigger is
2212 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2213 * errors.
2214 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002215 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002216 if (!hotplug_trigger) {
2217 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2218 PORTD_HOTPLUG_STATUS_MASK |
2219 PORTC_HOTPLUG_STATUS_MASK |
2220 PORTB_HOTPLUG_STATUS_MASK;
2221 dig_hotplug_reg &= ~mask;
2222 }
2223
Ville Syrjälä40e56412015-08-27 23:56:10 +03002224 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002225 if (!hotplug_trigger)
2226 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002227
Rodrigo Vivicf539022018-01-29 15:22:21 -08002228 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002229 dig_hotplug_reg, hpd,
2230 pch_port_hotplug_long_detect);
2231
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002232 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002233}
2234
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002235static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002236{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002237 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002238 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002239
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002240 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002241
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002242 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2243 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2244 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002245 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002246 port_name(port));
2247 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002248
Daniel Vetterce99c252012-12-01 13:53:47 +01002249 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002250 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002251
Jesse Barnes776ad802011-01-04 15:09:39 -08002252 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002253 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002254
2255 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2256 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2257
2258 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2259 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2260
2261 if (pch_iir & SDE_POISON)
2262 DRM_ERROR("PCH poison interrupt\n");
2263
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002264 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002265 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002266 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2267 pipe_name(pipe),
2268 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002269
2270 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2271 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2272
2273 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2274 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2275
Jesse Barnes776ad802011-01-04 15:09:39 -08002276 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002277 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002278
2279 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002280 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002281}
2282
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002283static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002284{
Paulo Zanoni86642812013-04-12 17:57:57 -03002285 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002286 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002287
Paulo Zanonide032bf2013-04-12 17:57:58 -03002288 if (err_int & ERR_INT_POISON)
2289 DRM_ERROR("Poison interrupt\n");
2290
Damien Lespiau055e3932014-08-18 13:49:10 +01002291 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002292 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2293 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002294
Daniel Vetter5a69b892013-10-16 22:55:52 +02002295 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002296 if (IS_IVYBRIDGE(dev_priv))
2297 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002298 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002299 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002300 }
2301 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002302
Paulo Zanoni86642812013-04-12 17:57:57 -03002303 I915_WRITE(GEN7_ERR_INT, err_int);
2304}
2305
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002306static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002307{
Paulo Zanoni86642812013-04-12 17:57:57 -03002308 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002309 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002310
Paulo Zanonide032bf2013-04-12 17:57:58 -03002311 if (serr_int & SERR_INT_POISON)
2312 DRM_ERROR("PCH poison interrupt\n");
2313
Mika Kahola45c1cd82017-10-10 13:17:06 +03002314 for_each_pipe(dev_priv, pipe)
2315 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2316 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002317
2318 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002319}
2320
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002321static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002322{
Adam Jackson23e81d62012-06-06 15:45:44 -04002323 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002324 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002325
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002326 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002327
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002328 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2329 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2330 SDE_AUDIO_POWER_SHIFT_CPT);
2331 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2332 port_name(port));
2333 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002334
2335 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002336 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002337
2338 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002339 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002340
2341 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2342 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2343
2344 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2345 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2346
2347 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002348 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002349 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2350 pipe_name(pipe),
2351 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002352
2353 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002354 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002355}
2356
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002357static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002358{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002359 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2360 ~SDE_PORTE_HOTPLUG_SPT;
2361 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2362 u32 pin_mask = 0, long_mask = 0;
2363
2364 if (hotplug_trigger) {
2365 u32 dig_hotplug_reg;
2366
2367 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2368 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2369
Rodrigo Vivicf539022018-01-29 15:22:21 -08002370 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2371 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002372 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002373 }
2374
2375 if (hotplug2_trigger) {
2376 u32 dig_hotplug_reg;
2377
2378 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2379 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2380
Rodrigo Vivicf539022018-01-29 15:22:21 -08002381 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2382 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002383 spt_port_hotplug2_long_detect);
2384 }
2385
2386 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002387 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002388
2389 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002390 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002391}
2392
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002393static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2394 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002395 const u32 hpd[HPD_NUM_PINS])
2396{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002397 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2398
2399 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2400 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2401
Rodrigo Vivicf539022018-01-29 15:22:21 -08002402 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002403 dig_hotplug_reg, hpd,
2404 ilk_port_hotplug_long_detect);
2405
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002406 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002407}
2408
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002409static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2410 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002411{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002412 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002413 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2414
Ville Syrjälä40e56412015-08-27 23:56:10 +03002415 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002416 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002417
2418 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002419 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002420
2421 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002422 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002423
Paulo Zanonic008bc62013-07-12 16:35:10 -03002424 if (de_iir & DE_POISON)
2425 DRM_ERROR("Poison interrupt\n");
2426
Damien Lespiau055e3932014-08-18 13:49:10 +01002427 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002428 if (de_iir & DE_PIPE_VBLANK(pipe))
2429 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002430
Daniel Vetter40da17c22013-10-21 18:04:36 +02002431 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002432 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002433
Daniel Vetter40da17c22013-10-21 18:04:36 +02002434 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002435 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002436 }
2437
2438 /* check event from PCH */
2439 if (de_iir & DE_PCH_EVENT) {
2440 u32 pch_iir = I915_READ(SDEIIR);
2441
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002442 if (HAS_PCH_CPT(dev_priv))
2443 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002444 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002445 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002446
2447 /* should clear PCH hotplug event before clear CPU irq */
2448 I915_WRITE(SDEIIR, pch_iir);
2449 }
2450
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002451 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2452 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002453}
2454
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002455static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2456 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002457{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002458 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002459 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2460
Ville Syrjälä40e56412015-08-27 23:56:10 +03002461 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002462 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002463
2464 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002465 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002466
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002467 if (de_iir & DE_EDP_PSR_INT_HSW) {
2468 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2469
2470 intel_psr_irq_handler(dev_priv, psr_iir);
2471 I915_WRITE(EDP_PSR_IIR, psr_iir);
2472 }
Daniel Vetterfc340442018-04-05 15:00:23 -07002473
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002474 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002475 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002476
2477 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002478 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002479
Damien Lespiau055e3932014-08-18 13:49:10 +01002480 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002481 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2482 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002483 }
2484
2485 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002486 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002487 u32 pch_iir = I915_READ(SDEIIR);
2488
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002489 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002490
2491 /* clear PCH hotplug event before clear CPU irq */
2492 I915_WRITE(SDEIIR, pch_iir);
2493 }
2494}
2495
Oscar Mateo72c90f62014-06-16 16:10:57 +01002496/*
2497 * To handle irqs with the minimum potential races with fresh interrupts, we:
2498 * 1 - Disable Master Interrupt Control.
2499 * 2 - Find the source(s) of the interrupt.
2500 * 3 - Clear the Interrupt Identity bits (IIR).
2501 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2502 * 5 - Re-enable Master Interrupt Control.
2503 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002504static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002505{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002506 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002507 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002508 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002509 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002510
Imre Deak2dd2a882015-02-24 11:14:30 +02002511 if (!intel_irqs_enabled(dev_priv))
2512 return IRQ_NONE;
2513
Imre Deak1f814da2015-12-16 02:52:19 +02002514 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2515 disable_rpm_wakeref_asserts(dev_priv);
2516
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002517 /* disable master interrupt before clearing iir */
2518 de_ier = I915_READ(DEIER);
2519 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002520 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002521
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002522 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2523 * interrupts will will be stored on its back queue, and then we'll be
2524 * able to process them after we restore SDEIER (as soon as we restore
2525 * it, we'll get an interrupt if SDEIIR still has something to process
2526 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002527 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002528 sde_ier = I915_READ(SDEIER);
2529 I915_WRITE(SDEIER, 0);
2530 POSTING_READ(SDEIER);
2531 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002532
Oscar Mateo72c90f62014-06-16 16:10:57 +01002533 /* Find, clear, then process each source of interrupt */
2534
Chris Wilson0e434062012-05-09 21:45:44 +01002535 gt_iir = I915_READ(GTIIR);
2536 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002537 I915_WRITE(GTIIR, gt_iir);
2538 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002539 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002540 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002541 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002542 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002543 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002544
2545 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002546 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002547 I915_WRITE(DEIIR, de_iir);
2548 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002549 if (INTEL_GEN(dev_priv) >= 7)
2550 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002551 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002552 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002553 }
2554
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002555 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002556 u32 pm_iir = I915_READ(GEN6_PMIIR);
2557 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002558 I915_WRITE(GEN6_PMIIR, pm_iir);
2559 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002560 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002561 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002562 }
2563
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002564 I915_WRITE(DEIER, de_ier);
2565 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002566 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002567 I915_WRITE(SDEIER, sde_ier);
2568 POSTING_READ(SDEIER);
2569 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002570
Imre Deak1f814da2015-12-16 02:52:19 +02002571 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2572 enable_rpm_wakeref_asserts(dev_priv);
2573
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002574 return ret;
2575}
2576
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002577static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2578 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002579 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302580{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002581 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302582
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002583 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2584 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302585
Rodrigo Vivicf539022018-01-29 15:22:21 -08002586 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002587 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002588 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002589
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002590 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302591}
2592
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002593static irqreturn_t
2594gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002595{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002596 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002597 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002598 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002599
Ben Widawskyabd58f02013-11-02 21:07:09 -07002600 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002601 iir = I915_READ(GEN8_DE_MISC_IIR);
2602 if (iir) {
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002603 bool found = false;
2604
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002605 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002606 ret = IRQ_HANDLED;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002607
2608 if (iir & GEN8_DE_MISC_GSE) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002609 intel_opregion_asle_intr(dev_priv);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002610 found = true;
2611 }
2612
2613 if (iir & GEN8_DE_EDP_PSR) {
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002614 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2615
2616 intel_psr_irq_handler(dev_priv, psr_iir);
2617 I915_WRITE(EDP_PSR_IIR, psr_iir);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002618 found = true;
2619 }
2620
2621 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002622 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002623 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002624 else
2625 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002626 }
2627
Daniel Vetter6d766f02013-11-07 14:49:55 +01002628 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002629 iir = I915_READ(GEN8_DE_PORT_IIR);
2630 if (iir) {
2631 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302632 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002633
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002634 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002635 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002636
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002637 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002638 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002639 tmp_mask |= GEN9_AUX_CHANNEL_B |
2640 GEN9_AUX_CHANNEL_C |
2641 GEN9_AUX_CHANNEL_D;
2642
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002643 if (IS_CNL_WITH_PORT_F(dev_priv))
2644 tmp_mask |= CNL_AUX_CHANNEL_F;
2645
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002646 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002647 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302648 found = true;
2649 }
2650
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002651 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002652 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2653 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002654 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2655 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002656 found = true;
2657 }
2658 } else if (IS_BROADWELL(dev_priv)) {
2659 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2660 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002661 ilk_hpd_irq_handler(dev_priv,
2662 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002663 found = true;
2664 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302665 }
2666
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002667 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002668 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302669 found = true;
2670 }
2671
Shashank Sharmad04a4922014-08-22 17:40:41 +05302672 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002673 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002674 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002675 else
2676 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002677 }
2678
Damien Lespiau055e3932014-08-18 13:49:10 +01002679 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002680 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002681
Daniel Vetterc42664c2013-11-07 11:05:40 +01002682 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2683 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002684
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002685 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2686 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002687 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002688 continue;
2689 }
2690
2691 ret = IRQ_HANDLED;
2692 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2693
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002694 if (iir & GEN8_PIPE_VBLANK)
2695 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002696
2697 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002698 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002699
2700 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2701 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2702
2703 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002704 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002705 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2706 else
2707 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2708
2709 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002710 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002711 pipe_name(pipe),
2712 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002713 }
2714
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002715 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302716 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002717 /*
2718 * FIXME(BDW): Assume for now that the new interrupt handling
2719 * scheme also closed the SDE interrupt handling race we've seen
2720 * on older pch-split platforms. But this needs testing.
2721 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002722 iir = I915_READ(SDEIIR);
2723 if (iir) {
2724 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002725 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002726
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002727 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2728 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002729 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002730 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002731 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002732 } else {
2733 /*
2734 * Like on previous PCH there seems to be something
2735 * fishy going on with forwarding PCH interrupts.
2736 */
2737 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2738 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002739 }
2740
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002741 return ret;
2742}
2743
2744static irqreturn_t gen8_irq_handler(int irq, void *arg)
2745{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002746 struct drm_i915_private *dev_priv = to_i915(arg);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002747 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002748 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002749
2750 if (!intel_irqs_enabled(dev_priv))
2751 return IRQ_NONE;
2752
2753 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2754 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2755 if (!master_ctl)
2756 return IRQ_NONE;
2757
2758 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2759
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002760 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002761 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002762
2763 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2764 if (master_ctl & ~GEN8_GT_IRQS) {
2765 disable_rpm_wakeref_asserts(dev_priv);
2766 gen8_de_irq_handler(dev_priv, master_ctl);
2767 enable_rpm_wakeref_asserts(dev_priv);
2768 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002769
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002770 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002771
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002772 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002773
Chris Wilson55ef72f2018-02-02 15:34:48 +00002774 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002775}
2776
Chris Wilson36703e72017-06-22 11:56:25 +01002777struct wedge_me {
2778 struct delayed_work work;
2779 struct drm_i915_private *i915;
2780 const char *name;
2781};
2782
2783static void wedge_me(struct work_struct *work)
2784{
2785 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2786
2787 dev_err(w->i915->drm.dev,
2788 "%s timed out, cancelling all in-flight rendering.\n",
2789 w->name);
2790 i915_gem_set_wedged(w->i915);
2791}
2792
2793static void __init_wedge(struct wedge_me *w,
2794 struct drm_i915_private *i915,
2795 long timeout,
2796 const char *name)
2797{
2798 w->i915 = i915;
2799 w->name = name;
2800
2801 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2802 schedule_delayed_work(&w->work, timeout);
2803}
2804
2805static void __fini_wedge(struct wedge_me *w)
2806{
2807 cancel_delayed_work_sync(&w->work);
2808 destroy_delayed_work_on_stack(&w->work);
2809 w->i915 = NULL;
2810}
2811
2812#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2813 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2814 (W)->i915; \
2815 __fini_wedge((W)))
2816
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002817static u32
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002818gen11_gt_engine_identity(struct drm_i915_private * const i915,
2819 const unsigned int bank, const unsigned int bit)
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002820{
2821 void __iomem * const regs = i915->regs;
2822 u32 timeout_ts;
2823 u32 ident;
2824
Oscar Mateo96606f32018-04-06 12:32:37 +03002825 lockdep_assert_held(&i915->irq_lock);
2826
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002827 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
2828
2829 /*
2830 * NB: Specs do not specify how long to spin wait,
2831 * so we do ~100us as an educated guess.
2832 */
2833 timeout_ts = (local_clock() >> 10) + 100;
2834 do {
2835 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
2836 } while (!(ident & GEN11_INTR_DATA_VALID) &&
2837 !time_after32(local_clock() >> 10, timeout_ts));
2838
2839 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
2840 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
2841 bank, bit, ident);
2842 return 0;
2843 }
2844
2845 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
2846 GEN11_INTR_DATA_VALID);
2847
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002848 return ident;
2849}
2850
2851static void
2852gen11_other_irq_handler(struct drm_i915_private * const i915,
2853 const u8 instance, const u16 iir)
2854{
Oscar Mateod02b98b2018-04-05 17:00:50 +03002855 if (instance == OTHER_GTPM_INSTANCE)
2856 return gen6_rps_irq_handler(i915, iir);
2857
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002858 WARN_ONCE(1, "unhandled other interrupt instance=0x%x, iir=0x%x\n",
2859 instance, iir);
2860}
2861
2862static void
2863gen11_engine_irq_handler(struct drm_i915_private * const i915,
2864 const u8 class, const u8 instance, const u16 iir)
2865{
2866 struct intel_engine_cs *engine;
2867
2868 if (instance <= MAX_ENGINE_INSTANCE)
2869 engine = i915->engine_class[class][instance];
2870 else
2871 engine = NULL;
2872
2873 if (likely(engine))
2874 return gen8_cs_irq_handler(engine, iir);
2875
2876 WARN_ONCE(1, "unhandled engine interrupt class=0x%x, instance=0x%x\n",
2877 class, instance);
2878}
2879
2880static void
2881gen11_gt_identity_handler(struct drm_i915_private * const i915,
2882 const u32 identity)
2883{
2884 const u8 class = GEN11_INTR_ENGINE_CLASS(identity);
2885 const u8 instance = GEN11_INTR_ENGINE_INSTANCE(identity);
2886 const u16 intr = GEN11_INTR_ENGINE_INTR(identity);
2887
2888 if (unlikely(!intr))
2889 return;
2890
2891 if (class <= COPY_ENGINE_CLASS)
2892 return gen11_engine_irq_handler(i915, class, instance, intr);
2893
2894 if (class == OTHER_CLASS)
2895 return gen11_other_irq_handler(i915, instance, intr);
2896
2897 WARN_ONCE(1, "unknown interrupt class=0x%x, instance=0x%x, intr=0x%x\n",
2898 class, instance, intr);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002899}
2900
2901static void
Oscar Mateo96606f32018-04-06 12:32:37 +03002902gen11_gt_bank_handler(struct drm_i915_private * const i915,
2903 const unsigned int bank)
2904{
2905 void __iomem * const regs = i915->regs;
2906 unsigned long intr_dw;
2907 unsigned int bit;
2908
2909 lockdep_assert_held(&i915->irq_lock);
2910
2911 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
2912
2913 if (unlikely(!intr_dw)) {
2914 DRM_ERROR("GT_INTR_DW%u blank!\n", bank);
2915 return;
2916 }
2917
2918 for_each_set_bit(bit, &intr_dw, 32) {
2919 const u32 ident = gen11_gt_engine_identity(i915,
2920 bank, bit);
2921
2922 gen11_gt_identity_handler(i915, ident);
2923 }
2924
2925 /* Clear must be after shared has been served for engine */
2926 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
2927}
2928
2929static void
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002930gen11_gt_irq_handler(struct drm_i915_private * const i915,
2931 const u32 master_ctl)
2932{
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002933 unsigned int bank;
2934
Oscar Mateo96606f32018-04-06 12:32:37 +03002935 spin_lock(&i915->irq_lock);
2936
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002937 for (bank = 0; bank < 2; bank++) {
Oscar Mateo96606f32018-04-06 12:32:37 +03002938 if (master_ctl & GEN11_GT_DW_IRQ(bank))
2939 gen11_gt_bank_handler(i915, bank);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002940 }
Oscar Mateo96606f32018-04-06 12:32:37 +03002941
2942 spin_unlock(&i915->irq_lock);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002943}
2944
2945static irqreturn_t gen11_irq_handler(int irq, void *arg)
2946{
2947 struct drm_i915_private * const i915 = to_i915(arg);
2948 void __iomem * const regs = i915->regs;
2949 u32 master_ctl;
2950
2951 if (!intel_irqs_enabled(i915))
2952 return IRQ_NONE;
2953
2954 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2955 master_ctl &= ~GEN11_MASTER_IRQ;
2956 if (!master_ctl)
2957 return IRQ_NONE;
2958
2959 /* Disable interrupts. */
2960 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2961
2962 /* Find, clear, then process each source of interrupt. */
2963 gen11_gt_irq_handler(i915, master_ctl);
2964
2965 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2966 if (master_ctl & GEN11_DISPLAY_IRQ) {
2967 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2968
2969 disable_rpm_wakeref_asserts(i915);
2970 /*
2971 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2972 * for the display related bits.
2973 */
2974 gen8_de_irq_handler(i915, disp_ctl);
2975 enable_rpm_wakeref_asserts(i915);
2976 }
2977
2978 /* Acknowledge and enable interrupts. */
2979 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ | master_ctl);
2980
2981 return IRQ_HANDLED;
2982}
2983
Chris Wilsonce800752018-03-20 10:04:49 +00002984static void i915_reset_device(struct drm_i915_private *dev_priv,
Chris Wilsond0667e92018-04-06 23:03:54 +01002985 u32 engine_mask,
2986 const char *reason)
Jesse Barnes8a905232009-07-11 16:48:03 -04002987{
Chris Wilsonce800752018-03-20 10:04:49 +00002988 struct i915_gpu_error *error = &dev_priv->gpu_error;
Chris Wilson91c8a322016-07-05 10:40:23 +01002989 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002990 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2991 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2992 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002993 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002994
Chris Wilsonc0336662016-05-06 15:40:21 +01002995 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002996
Chris Wilson8af29b02016-09-09 14:11:47 +01002997 DRM_DEBUG_DRIVER("resetting chip\n");
2998 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2999
Chris Wilson36703e72017-06-22 11:56:25 +01003000 /* Use a watchdog to ensure that our reset completes */
3001 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
3002 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003003
Chris Wilsond0667e92018-04-06 23:03:54 +01003004 error->reason = reason;
3005 error->stalled_mask = engine_mask;
Chris Wilsonce800752018-03-20 10:04:49 +00003006
Chris Wilson36703e72017-06-22 11:56:25 +01003007 /* Signal that locked waiters should reset the GPU */
Chris Wilsond0667e92018-04-06 23:03:54 +01003008 smp_mb__before_atomic();
Chris Wilsonce800752018-03-20 10:04:49 +00003009 set_bit(I915_RESET_HANDOFF, &error->flags);
3010 wake_up_all(&error->wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00003011
Chris Wilson36703e72017-06-22 11:56:25 +01003012 /* Wait for anyone holding the lock to wakeup, without
3013 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01003014 */
Chris Wilson36703e72017-06-22 11:56:25 +01003015 do {
3016 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilsond0667e92018-04-06 23:03:54 +01003017 i915_reset(dev_priv, engine_mask, reason);
Chris Wilson36703e72017-06-22 11:56:25 +01003018 mutex_unlock(&dev_priv->drm.struct_mutex);
3019 }
Chris Wilsonce800752018-03-20 10:04:49 +00003020 } while (wait_on_bit_timeout(&error->flags,
Chris Wilson36703e72017-06-22 11:56:25 +01003021 I915_RESET_HANDOFF,
3022 TASK_UNINTERRUPTIBLE,
3023 1));
Chris Wilson780f2622016-09-09 14:11:52 +01003024
Chris Wilsond0667e92018-04-06 23:03:54 +01003025 error->stalled_mask = 0;
Chris Wilsonce800752018-03-20 10:04:49 +00003026 error->reason = NULL;
3027
Chris Wilson36703e72017-06-22 11:56:25 +01003028 intel_finish_reset(dev_priv);
3029 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02003030
Chris Wilsonce800752018-03-20 10:04:49 +00003031 if (!test_bit(I915_WEDGED, &error->flags))
3032 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04003033}
3034
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003035static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04003036{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003037 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04003038
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003039 if (!IS_GEN2(dev_priv))
3040 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04003041
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003042 if (INTEL_GEN(dev_priv) < 4)
3043 I915_WRITE(IPEIR, I915_READ(IPEIR));
3044 else
3045 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04003046
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003047 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04003048 eir = I915_READ(EIR);
3049 if (eir) {
3050 /*
3051 * some errors might have become stuck,
3052 * mask them.
3053 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003054 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04003055 I915_WRITE(EMR, I915_READ(EMR) | eir);
3056 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3057 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01003058}
3059
3060/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003061 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003062 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00003063 * @engine_mask: mask representing engines that are hung
Chris Wilsonce800752018-03-20 10:04:49 +00003064 * @flags: control flags
Michel Thierry87c390b2017-01-11 20:18:08 -08003065 * @fmt: Error message format string
3066 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02003067 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01003068 * dump it to the syslog. Also call i915_capture_error_state() to make
3069 * sure we get a record and make it available in debugfs. Fire a uevent
3070 * so userspace knows something bad happened (should trigger collection
3071 * of a ring dump etc.).
3072 */
Chris Wilsonc0336662016-05-06 15:40:21 +01003073void i915_handle_error(struct drm_i915_private *dev_priv,
3074 u32 engine_mask,
Chris Wilsonce800752018-03-20 10:04:49 +00003075 unsigned long flags,
Mika Kuoppala58174462014-02-25 17:11:26 +02003076 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01003077{
Michel Thierry142bc7d2017-06-20 10:57:46 +01003078 struct intel_engine_cs *engine;
3079 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02003080 char error_msg[80];
Chris Wilsonce800752018-03-20 10:04:49 +00003081 char *msg = NULL;
Chris Wilson35aed2e2010-05-27 13:18:12 +01003082
Chris Wilsonce800752018-03-20 10:04:49 +00003083 if (fmt) {
3084 va_list args;
3085
3086 va_start(args, fmt);
3087 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
3088 va_end(args);
3089
3090 msg = error_msg;
3091 }
Mika Kuoppala58174462014-02-25 17:11:26 +02003092
Chris Wilson1604a862017-03-14 17:18:40 +00003093 /*
3094 * In most cases it's guaranteed that we get here with an RPM
3095 * reference held, for example because there is a pending GPU
3096 * request that won't finish until the reset is done. This
3097 * isn't the case at least when we get here by doing a
3098 * simulated reset via debugfs, so get an RPM reference.
3099 */
3100 intel_runtime_pm_get(dev_priv);
3101
Chris Wilson873d66f2018-03-16 21:49:59 +00003102 engine_mask &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilsonce800752018-03-20 10:04:49 +00003103
3104 if (flags & I915_ERROR_CAPTURE) {
3105 i915_capture_error_state(dev_priv, engine_mask, msg);
3106 i915_clear_error_registers(dev_priv);
3107 }
Jesse Barnes8a905232009-07-11 16:48:03 -04003108
Michel Thierry142bc7d2017-06-20 10:57:46 +01003109 /*
3110 * Try engine reset when available. We fall back to full reset if
3111 * single reset fails.
3112 */
3113 if (intel_has_reset_engine(dev_priv)) {
3114 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02003115 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01003116 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3117 &dev_priv->gpu_error.flags))
3118 continue;
3119
Chris Wilsonce800752018-03-20 10:04:49 +00003120 if (i915_reset_engine(engine, msg) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01003121 engine_mask &= ~intel_engine_flag(engine);
3122
3123 clear_bit(I915_RESET_ENGINE + engine->id,
3124 &dev_priv->gpu_error.flags);
3125 wake_up_bit(&dev_priv->gpu_error.flags,
3126 I915_RESET_ENGINE + engine->id);
3127 }
3128 }
3129
Chris Wilson8af29b02016-09-09 14:11:47 +01003130 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00003131 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04003132
Michel Thierry142bc7d2017-06-20 10:57:46 +01003133 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01003134 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
3135 wait_event(dev_priv->gpu_error.reset_queue,
3136 !test_bit(I915_RESET_BACKOFF,
3137 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00003138 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01003139 }
Chris Wilson8af29b02016-09-09 14:11:47 +01003140
Michel Thierry142bc7d2017-06-20 10:57:46 +01003141 /* Prevent any other reset-engine attempt. */
3142 for_each_engine(engine, dev_priv, tmp) {
3143 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3144 &dev_priv->gpu_error.flags))
3145 wait_on_bit(&dev_priv->gpu_error.flags,
3146 I915_RESET_ENGINE + engine->id,
3147 TASK_UNINTERRUPTIBLE);
3148 }
3149
Chris Wilsond0667e92018-04-06 23:03:54 +01003150 i915_reset_device(dev_priv, engine_mask, msg);
Chris Wilsond5367302017-06-20 10:57:43 +01003151
Michel Thierry142bc7d2017-06-20 10:57:46 +01003152 for_each_engine(engine, dev_priv, tmp) {
3153 clear_bit(I915_RESET_ENGINE + engine->id,
3154 &dev_priv->gpu_error.flags);
3155 }
3156
Chris Wilsond5367302017-06-20 10:57:43 +01003157 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
3158 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00003159
3160out:
3161 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04003162}
3163
Keith Packard42f52ef2008-10-18 19:39:29 -07003164/* Called from drm generic code, passed 'crtc' which
3165 * we use as a pipe index
3166 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003167static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003168{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003169 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003170 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003171
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003172 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003173 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3174 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3175
3176 return 0;
3177}
3178
3179static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3180{
3181 struct drm_i915_private *dev_priv = to_i915(dev);
3182 unsigned long irqflags;
3183
3184 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3185 i915_enable_pipestat(dev_priv, pipe,
3186 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003187 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003188
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003189 return 0;
3190}
3191
Thierry Reding88e72712015-09-24 18:35:31 +02003192static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003193{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003194 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003195 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003196 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003197 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003198
Jesse Barnesf796cf82011-04-07 13:58:17 -07003199 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003200 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003201 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3202
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003203 /* Even though there is no DMC, frame counter can get stuck when
3204 * PSR is active as no frames are generated.
3205 */
3206 if (HAS_PSR(dev_priv))
3207 drm_vblank_restore(dev, pipe);
3208
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003209 return 0;
3210}
3211
Thierry Reding88e72712015-09-24 18:35:31 +02003212static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003213{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003214 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003215 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003216
Ben Widawskyabd58f02013-11-02 21:07:09 -07003217 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003218 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003219 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003220
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003221 /* Even if there is no DMC, frame counter can get stuck when
3222 * PSR is active as no frames are generated, so check only for PSR.
3223 */
3224 if (HAS_PSR(dev_priv))
3225 drm_vblank_restore(dev, pipe);
3226
Ben Widawskyabd58f02013-11-02 21:07:09 -07003227 return 0;
3228}
3229
Keith Packard42f52ef2008-10-18 19:39:29 -07003230/* Called from drm generic code, passed 'crtc' which
3231 * we use as a pipe index
3232 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003233static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3234{
3235 struct drm_i915_private *dev_priv = to_i915(dev);
3236 unsigned long irqflags;
3237
3238 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3239 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3240 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3241}
3242
3243static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003244{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003245 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003246 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003247
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003248 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003249 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003250 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003251 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3252}
3253
Thierry Reding88e72712015-09-24 18:35:31 +02003254static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003255{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003256 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003257 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003258 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003259 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003260
3261 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003262 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003263 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3264}
3265
Thierry Reding88e72712015-09-24 18:35:31 +02003266static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003267{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003268 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003269 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003270
Ben Widawskyabd58f02013-11-02 21:07:09 -07003271 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003272 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003273 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3274}
3275
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003276static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003277{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003278 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003279 return;
3280
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003281 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003282
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003283 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003284 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003285}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003286
Paulo Zanoni622364b2014-04-01 15:37:22 -03003287/*
3288 * SDEIER is also touched by the interrupt handler to work around missed PCH
3289 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3290 * instead we unconditionally enable all PCH interrupt sources here, but then
3291 * only unmask them as needed with SDEIMR.
3292 *
3293 * This function needs to be called before interrupts are enabled.
3294 */
3295static void ibx_irq_pre_postinstall(struct drm_device *dev)
3296{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003297 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003298
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003299 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003300 return;
3301
3302 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003303 I915_WRITE(SDEIER, 0xffffffff);
3304 POSTING_READ(SDEIER);
3305}
3306
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003307static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003308{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003309 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003310 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003311 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003312}
3313
Ville Syrjälä70591a42014-10-30 19:42:58 +02003314static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3315{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003316 if (IS_CHERRYVIEW(dev_priv))
3317 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3318 else
3319 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3320
Ville Syrjäläad22d102016-04-12 18:56:14 +03003321 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003322 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3323
Ville Syrjälä44d92412017-08-18 21:36:51 +03003324 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003325
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003326 GEN3_IRQ_RESET(VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003327 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003328}
3329
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003330static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3331{
3332 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003333 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003334 enum pipe pipe;
3335
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003336 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003337
3338 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3339 for_each_pipe(dev_priv, pipe)
3340 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3341
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003342 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3343 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003344 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3345 I915_LPE_PIPE_A_INTERRUPT |
3346 I915_LPE_PIPE_B_INTERRUPT;
3347
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003348 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003349 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3350 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003351
Chris Wilson8bd099a2017-11-30 12:52:53 +00003352 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003353
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003354 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003355
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003356 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003357}
3358
3359/* drm_dma.h hooks
3360*/
3361static void ironlake_irq_reset(struct drm_device *dev)
3362{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003363 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003364
Ville Syrjäläd420a502017-08-18 21:37:03 +03003365 if (IS_GEN5(dev_priv))
3366 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003367
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003368 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003369 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003370 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3371
Daniel Vetterfc340442018-04-05 15:00:23 -07003372 if (IS_HASWELL(dev_priv)) {
3373 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3374 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3375 }
3376
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003377 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003378
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003379 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003380}
3381
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003382static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003383{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003384 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003385
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003386 I915_WRITE(VLV_MASTER_IER, 0);
3387 POSTING_READ(VLV_MASTER_IER);
3388
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003389 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003390
Ville Syrjäläad22d102016-04-12 18:56:14 +03003391 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003392 if (dev_priv->display_irqs_enabled)
3393 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003394 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003395}
3396
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003397static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3398{
3399 GEN8_IRQ_RESET_NDX(GT, 0);
3400 GEN8_IRQ_RESET_NDX(GT, 1);
3401 GEN8_IRQ_RESET_NDX(GT, 2);
3402 GEN8_IRQ_RESET_NDX(GT, 3);
3403}
3404
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003405static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003406{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003407 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003408 int pipe;
3409
Ben Widawskyabd58f02013-11-02 21:07:09 -07003410 I915_WRITE(GEN8_MASTER_IRQ, 0);
3411 POSTING_READ(GEN8_MASTER_IRQ);
3412
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003413 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003414
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003415 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3416 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3417
Damien Lespiau055e3932014-08-18 13:49:10 +01003418 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003419 if (intel_display_power_is_enabled(dev_priv,
3420 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003421 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003422
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003423 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3424 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3425 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003426
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003427 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003428 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003429}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003430
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003431static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3432{
3433 /* Disable RCS, BCS, VCS and VECS class engines. */
3434 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3435 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3436
3437 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3438 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3439 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3440 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3441 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3442 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003443
3444 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
3445 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003446}
3447
3448static void gen11_irq_reset(struct drm_device *dev)
3449{
3450 struct drm_i915_private *dev_priv = dev->dev_private;
3451 int pipe;
3452
3453 I915_WRITE(GEN11_GFX_MSTR_IRQ, 0);
3454 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3455
3456 gen11_gt_irq_reset(dev_priv);
3457
3458 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3459
3460 for_each_pipe(dev_priv, pipe)
3461 if (intel_display_power_is_enabled(dev_priv,
3462 POWER_DOMAIN_PIPE(pipe)))
3463 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3464
3465 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3466 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3467 GEN3_IRQ_RESET(GEN8_PCU_);
3468}
3469
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003470void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003471 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003472{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003473 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003474 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003475
Daniel Vetter13321782014-09-15 14:55:29 +02003476 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003477
3478 if (!intel_irqs_enabled(dev_priv)) {
3479 spin_unlock_irq(&dev_priv->irq_lock);
3480 return;
3481 }
3482
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003483 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3484 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3485 dev_priv->de_irq_mask[pipe],
3486 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003487
Daniel Vetter13321782014-09-15 14:55:29 +02003488 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003489}
3490
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003491void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003492 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003493{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003494 enum pipe pipe;
3495
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003496 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003497
3498 if (!intel_irqs_enabled(dev_priv)) {
3499 spin_unlock_irq(&dev_priv->irq_lock);
3500 return;
3501 }
3502
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003503 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3504 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003505
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003506 spin_unlock_irq(&dev_priv->irq_lock);
3507
3508 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003509 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003510}
3511
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003512static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003513{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003514 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003515
3516 I915_WRITE(GEN8_MASTER_IRQ, 0);
3517 POSTING_READ(GEN8_MASTER_IRQ);
3518
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003519 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003520
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003521 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003522
Ville Syrjäläad22d102016-04-12 18:56:14 +03003523 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003524 if (dev_priv->display_irqs_enabled)
3525 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003526 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003527}
3528
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003529static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003530 const u32 hpd[HPD_NUM_PINS])
3531{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003532 struct intel_encoder *encoder;
3533 u32 enabled_irqs = 0;
3534
Chris Wilson91c8a322016-07-05 10:40:23 +01003535 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003536 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3537 enabled_irqs |= hpd[encoder->hpd_pin];
3538
3539 return enabled_irqs;
3540}
3541
Imre Deak1a56b1a2017-01-27 11:39:21 +02003542static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3543{
3544 u32 hotplug;
3545
3546 /*
3547 * Enable digital hotplug on the PCH, and configure the DP short pulse
3548 * duration to 2ms (which is the minimum in the Display Port spec).
3549 * The pulse duration bits are reserved on LPT+.
3550 */
3551 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3552 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3553 PORTC_PULSE_DURATION_MASK |
3554 PORTD_PULSE_DURATION_MASK);
3555 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3556 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3557 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3558 /*
3559 * When CPU and PCH are on the same package, port A
3560 * HPD must be enabled in both north and south.
3561 */
3562 if (HAS_PCH_LPT_LP(dev_priv))
3563 hotplug |= PORTA_HOTPLUG_ENABLE;
3564 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3565}
3566
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003567static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003568{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003569 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003570
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003571 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003572 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003573 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003574 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003575 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003576 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003577 }
3578
Daniel Vetterfee884e2013-07-04 23:35:21 +02003579 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003580
Imre Deak1a56b1a2017-01-27 11:39:21 +02003581 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003582}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003583
Imre Deak2a57d9c2017-01-27 11:39:18 +02003584static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3585{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003586 u32 val, hotplug;
3587
3588 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3589 if (HAS_PCH_CNP(dev_priv)) {
3590 val = I915_READ(SOUTH_CHICKEN1);
3591 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3592 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3593 I915_WRITE(SOUTH_CHICKEN1, val);
3594 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003595
3596 /* Enable digital hotplug on the PCH */
3597 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3598 hotplug |= PORTA_HOTPLUG_ENABLE |
3599 PORTB_HOTPLUG_ENABLE |
3600 PORTC_HOTPLUG_ENABLE |
3601 PORTD_HOTPLUG_ENABLE;
3602 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3603
3604 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3605 hotplug |= PORTE_HOTPLUG_ENABLE;
3606 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3607}
3608
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003609static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003610{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003611 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003612
3613 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003614 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003615
3616 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3617
Imre Deak2a57d9c2017-01-27 11:39:18 +02003618 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003619}
3620
Imre Deak1a56b1a2017-01-27 11:39:21 +02003621static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3622{
3623 u32 hotplug;
3624
3625 /*
3626 * Enable digital hotplug on the CPU, and configure the DP short pulse
3627 * duration to 2ms (which is the minimum in the Display Port spec)
3628 * The pulse duration bits are reserved on HSW+.
3629 */
3630 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3631 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3632 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3633 DIGITAL_PORTA_PULSE_DURATION_2ms;
3634 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3635}
3636
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003637static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003638{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003639 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003640
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003641 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003642 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003643 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003644
3645 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003646 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003647 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003648 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003649
3650 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003651 } else {
3652 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003653 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003654
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003655 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3656 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003657
Imre Deak1a56b1a2017-01-27 11:39:21 +02003658 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003659
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003660 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003661}
3662
Imre Deak2a57d9c2017-01-27 11:39:18 +02003663static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3664 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003665{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003666 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003667
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003668 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003669 hotplug |= PORTA_HOTPLUG_ENABLE |
3670 PORTB_HOTPLUG_ENABLE |
3671 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303672
3673 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3674 hotplug, enabled_irqs);
3675 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3676
3677 /*
3678 * For BXT invert bit has to be set based on AOB design
3679 * for HPD detection logic, update it based on VBT fields.
3680 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303681 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3682 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3683 hotplug |= BXT_DDIA_HPD_INVERT;
3684 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3685 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3686 hotplug |= BXT_DDIB_HPD_INVERT;
3687 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3688 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3689 hotplug |= BXT_DDIC_HPD_INVERT;
3690
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003691 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003692}
3693
Imre Deak2a57d9c2017-01-27 11:39:18 +02003694static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3695{
3696 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3697}
3698
3699static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3700{
3701 u32 hotplug_irqs, enabled_irqs;
3702
3703 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3704 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3705
3706 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3707
3708 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3709}
3710
Paulo Zanonid46da432013-02-08 17:35:15 -02003711static void ibx_irq_postinstall(struct drm_device *dev)
3712{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003713 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003714 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003715
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003716 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003717 return;
3718
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003719 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003720 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003721 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003722 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003723 else
3724 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003725
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003726 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003727 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003728
3729 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3730 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003731 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003732 else
3733 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003734}
3735
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003736static void gen5_gt_irq_postinstall(struct drm_device *dev)
3737{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003738 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003739 u32 pm_irqs, gt_irqs;
3740
3741 pm_irqs = gt_irqs = 0;
3742
3743 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003744 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003745 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003746 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3747 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003748 }
3749
3750 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003751 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003752 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003753 } else {
3754 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3755 }
3756
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003757 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003758
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003759 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003760 /*
3761 * RPS interrupts will get enabled/disabled on demand when RPS
3762 * itself is enabled/disabled.
3763 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303764 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003765 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303766 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3767 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003768
Akash Goelf4e9af42016-10-12 21:54:30 +05303769 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003770 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003771 }
3772}
3773
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003774static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003775{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003776 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003777 u32 display_mask, extra_mask;
3778
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003779 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003780 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003781 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003782 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003783 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3784 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003785 } else {
3786 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003787 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3788 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003789 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3790 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3791 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003792 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003793
Daniel Vetterfc340442018-04-05 15:00:23 -07003794 if (IS_HASWELL(dev_priv)) {
3795 gen3_assert_iir_is_zero(dev_priv, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07003796 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Daniel Vetterfc340442018-04-05 15:00:23 -07003797 display_mask |= DE_EDP_PSR_INT_HSW;
3798 }
3799
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003800 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003801
Paulo Zanoni622364b2014-04-01 15:37:22 -03003802 ibx_irq_pre_postinstall(dev);
3803
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003804 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003805
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003806 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003807
Imre Deak1a56b1a2017-01-27 11:39:21 +02003808 ilk_hpd_detection_setup(dev_priv);
3809
Paulo Zanonid46da432013-02-08 17:35:15 -02003810 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003811
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003812 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003813 /* Enable PCU event interrupts
3814 *
3815 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003816 * setup is guaranteed to run in single-threaded context. But we
3817 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003818 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003819 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003820 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003821 }
3822
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003823 return 0;
3824}
3825
Imre Deakf8b79e52014-03-04 19:23:07 +02003826void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3827{
Chris Wilson67520412017-03-02 13:28:01 +00003828 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003829
3830 if (dev_priv->display_irqs_enabled)
3831 return;
3832
3833 dev_priv->display_irqs_enabled = true;
3834
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003835 if (intel_irqs_enabled(dev_priv)) {
3836 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003837 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003838 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003839}
3840
3841void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3842{
Chris Wilson67520412017-03-02 13:28:01 +00003843 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003844
3845 if (!dev_priv->display_irqs_enabled)
3846 return;
3847
3848 dev_priv->display_irqs_enabled = false;
3849
Imre Deak950eaba2014-09-08 15:21:09 +03003850 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003851 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003852}
3853
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003854
3855static int valleyview_irq_postinstall(struct drm_device *dev)
3856{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003857 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003858
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003859 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003860
Ville Syrjäläad22d102016-04-12 18:56:14 +03003861 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003862 if (dev_priv->display_irqs_enabled)
3863 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003864 spin_unlock_irq(&dev_priv->irq_lock);
3865
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003866 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003867 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003868
3869 return 0;
3870}
3871
Ben Widawskyabd58f02013-11-02 21:07:09 -07003872static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3873{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003874 /* These are interrupts we'll toggle with the ring mask register */
3875 uint32_t gt_interrupts[] = {
3876 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003877 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003878 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3879 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003880 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003881 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3882 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3883 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003884 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003885 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3886 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003887 };
3888
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003889 if (HAS_L3_DPF(dev_priv))
3890 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3891
Akash Goelf4e9af42016-10-12 21:54:30 +05303892 dev_priv->pm_ier = 0x0;
3893 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303894 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3895 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003896 /*
3897 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303898 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003899 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303900 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303901 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003902}
3903
3904static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3905{
Damien Lespiau770de832014-03-20 20:45:01 +00003906 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3907 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003908 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3909 u32 de_port_enables;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003910 u32 de_misc_masked = GEN8_DE_MISC_GSE | GEN8_DE_EDP_PSR;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003911 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003912
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003913 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003914 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003915 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3916 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003917 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003918 de_port_masked |= BXT_DE_PORT_GMBUS;
3919 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003920 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003921 }
Damien Lespiau770de832014-03-20 20:45:01 +00003922
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003923 if (IS_CNL_WITH_PORT_F(dev_priv))
3924 de_port_masked |= CNL_AUX_CHANNEL_F;
3925
Damien Lespiau770de832014-03-20 20:45:01 +00003926 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3927 GEN8_PIPE_FIFO_UNDERRUN;
3928
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003929 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003930 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003931 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3932 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003933 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3934
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003935 gen3_assert_iir_is_zero(dev_priv, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07003936 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003937
Mika Kahola0a195c02017-10-10 13:17:04 +03003938 for_each_pipe(dev_priv, pipe) {
3939 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003940
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003941 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003942 POWER_DOMAIN_PIPE(pipe)))
3943 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3944 dev_priv->de_irq_mask[pipe],
3945 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03003946 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07003947
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003948 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3949 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003950
3951 if (IS_GEN9_LP(dev_priv))
3952 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003953 else if (IS_BROADWELL(dev_priv))
3954 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003955}
3956
3957static int gen8_irq_postinstall(struct drm_device *dev)
3958{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003959 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003960
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003961 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303962 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003963
Ben Widawskyabd58f02013-11-02 21:07:09 -07003964 gen8_gt_irq_postinstall(dev_priv);
3965 gen8_de_irq_postinstall(dev_priv);
3966
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003967 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303968 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003969
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003970 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003971 POSTING_READ(GEN8_MASTER_IRQ);
3972
3973 return 0;
3974}
3975
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003976static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3977{
3978 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
3979
3980 BUILD_BUG_ON(irqs & 0xffff0000);
3981
3982 /* Enable RCS, BCS, VCS and VECS class interrupts. */
3983 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
3984 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
3985
3986 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
3987 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
3988 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
3989 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
3990 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
3991 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
3992
Oscar Mateod02b98b2018-04-05 17:00:50 +03003993 /*
3994 * RPS interrupts will get enabled/disabled on demand when RPS itself
3995 * is enabled/disabled.
3996 */
3997 dev_priv->pm_ier = 0x0;
3998 dev_priv->pm_imr = ~dev_priv->pm_ier;
3999 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
4000 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004001}
4002
4003static int gen11_irq_postinstall(struct drm_device *dev)
4004{
4005 struct drm_i915_private *dev_priv = dev->dev_private;
4006
4007 gen11_gt_irq_postinstall(dev_priv);
4008 gen8_de_irq_postinstall(dev_priv);
4009
4010 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
4011
4012 I915_WRITE(GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
4013 POSTING_READ(GEN11_GFX_MSTR_IRQ);
4014
4015 return 0;
4016}
4017
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004018static int cherryview_irq_postinstall(struct drm_device *dev)
4019{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004020 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004021
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004022 gen8_gt_irq_postinstall(dev_priv);
4023
Ville Syrjäläad22d102016-04-12 18:56:14 +03004024 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004025 if (dev_priv->display_irqs_enabled)
4026 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004027 spin_unlock_irq(&dev_priv->irq_lock);
4028
Ville Syrjäläe5328c42016-04-13 21:19:47 +03004029 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004030 POSTING_READ(GEN8_MASTER_IRQ);
4031
4032 return 0;
4033}
4034
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004035static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004036{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004037 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004038
Ville Syrjälä44d92412017-08-18 21:36:51 +03004039 i9xx_pipestat_irq_reset(dev_priv);
4040
Ville Syrjäläd420a502017-08-18 21:37:03 +03004041 I915_WRITE16(HWSTAM, 0xffff);
4042
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004043 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01004044}
4045
4046static int i8xx_irq_postinstall(struct drm_device *dev)
4047{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004048 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004049 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004050
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004051 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
4052 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01004053
4054 /* Unmask the interrupts that we always want on. */
4055 dev_priv->irq_mask =
4056 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004057 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004058
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004059 enable_mask =
4060 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4061 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4062 I915_USER_INTERRUPT;
4063
4064 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004065
Daniel Vetter379ef822013-10-16 22:55:56 +02004066 /* Interrupt setup is already guaranteed to be single-threaded, this is
4067 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004068 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004069 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4070 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004071 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004072
Chris Wilsonc2798b12012-04-22 21:13:57 +01004073 return 0;
4074}
4075
Daniel Vetterff1f5252012-10-02 15:10:55 +02004076static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004077{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004078 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004079 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004080 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004081
Imre Deak2dd2a882015-02-24 11:14:30 +02004082 if (!intel_irqs_enabled(dev_priv))
4083 return IRQ_NONE;
4084
Imre Deak1f814da2015-12-16 02:52:19 +02004085 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4086 disable_rpm_wakeref_asserts(dev_priv);
4087
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004088 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004089 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004090 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03004091
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004092 iir = I915_READ16(IIR);
4093 if (iir == 0)
4094 break;
4095
4096 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004097
Ville Syrjäläeb643432017-08-18 21:36:59 +03004098 /* Call regardless, as some status bits might not be
4099 * signalled in iir */
4100 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004101
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004102 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004103
Chris Wilsonc2798b12012-04-22 21:13:57 +01004104 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304105 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004106
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004107 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4108 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
4109
Ville Syrjäläeb643432017-08-18 21:36:59 +03004110 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004111 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004112
Imre Deak1f814da2015-12-16 02:52:19 +02004113 enable_rpm_wakeref_asserts(dev_priv);
4114
4115 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004116}
4117
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004118static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004119{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004120 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004121
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004122 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004123 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004124 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4125 }
4126
Ville Syrjälä44d92412017-08-18 21:36:51 +03004127 i9xx_pipestat_irq_reset(dev_priv);
4128
Ville Syrjäläd420a502017-08-18 21:37:03 +03004129 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004130
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004131 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004132}
4133
4134static int i915_irq_postinstall(struct drm_device *dev)
4135{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004136 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004137 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004138
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004139 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
4140 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01004141
4142 /* Unmask the interrupts that we always want on. */
4143 dev_priv->irq_mask =
4144 ~(I915_ASLE_INTERRUPT |
4145 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004146 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004147
4148 enable_mask =
4149 I915_ASLE_INTERRUPT |
4150 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4151 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004152 I915_USER_INTERRUPT;
4153
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004154 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004155 /* Enable in IER... */
4156 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4157 /* and unmask in IMR */
4158 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4159 }
4160
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004161 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004162
Daniel Vetter379ef822013-10-16 22:55:56 +02004163 /* Interrupt setup is already guaranteed to be single-threaded, this is
4164 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004165 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004166 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4167 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004168 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004169
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004170 i915_enable_asle_pipestat(dev_priv);
4171
Daniel Vetter20afbda2012-12-11 14:05:07 +01004172 return 0;
4173}
4174
Daniel Vetterff1f5252012-10-02 15:10:55 +02004175static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004176{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004177 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004178 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004179 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180
Imre Deak2dd2a882015-02-24 11:14:30 +02004181 if (!intel_irqs_enabled(dev_priv))
4182 return IRQ_NONE;
4183
Imre Deak1f814da2015-12-16 02:52:19 +02004184 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4185 disable_rpm_wakeref_asserts(dev_priv);
4186
Chris Wilson38bde182012-04-24 22:59:50 +01004187 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004188 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004189 u32 hotplug_status = 0;
4190 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004191
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004192 iir = I915_READ(IIR);
4193 if (iir == 0)
4194 break;
4195
4196 ret = IRQ_HANDLED;
4197
4198 if (I915_HAS_HOTPLUG(dev_priv) &&
4199 iir & I915_DISPLAY_PORT_INTERRUPT)
4200 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004201
Ville Syrjäläeb643432017-08-18 21:36:59 +03004202 /* Call regardless, as some status bits might not be
4203 * signalled in iir */
4204 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004205
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004206 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004207
Chris Wilsona266c7d2012-04-24 22:59:44 +01004208 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304209 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004210
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004211 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4212 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004213
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004214 if (hotplug_status)
4215 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4216
4217 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4218 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004219
Imre Deak1f814da2015-12-16 02:52:19 +02004220 enable_rpm_wakeref_asserts(dev_priv);
4221
Chris Wilsona266c7d2012-04-24 22:59:44 +01004222 return ret;
4223}
4224
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004225static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004226{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004227 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004228
Egbert Eich0706f172015-09-23 16:15:27 +02004229 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004230 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004231
Ville Syrjälä44d92412017-08-18 21:36:51 +03004232 i9xx_pipestat_irq_reset(dev_priv);
4233
Ville Syrjäläd420a502017-08-18 21:37:03 +03004234 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004235
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004236 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004237}
4238
4239static int i965_irq_postinstall(struct drm_device *dev)
4240{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004241 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004242 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004243 u32 error_mask;
4244
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004245 /*
4246 * Enable some error detection, note the instruction error mask
4247 * bit is reserved, so we leave it masked.
4248 */
4249 if (IS_G4X(dev_priv)) {
4250 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4251 GM45_ERROR_MEM_PRIV |
4252 GM45_ERROR_CP_PRIV |
4253 I915_ERROR_MEMORY_REFRESH);
4254 } else {
4255 error_mask = ~(I915_ERROR_PAGE_TABLE |
4256 I915_ERROR_MEMORY_REFRESH);
4257 }
4258 I915_WRITE(EMR, error_mask);
4259
Chris Wilsona266c7d2012-04-24 22:59:44 +01004260 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004261 dev_priv->irq_mask =
4262 ~(I915_ASLE_INTERRUPT |
4263 I915_DISPLAY_PORT_INTERRUPT |
4264 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4265 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4266 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004267
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004268 enable_mask =
4269 I915_ASLE_INTERRUPT |
4270 I915_DISPLAY_PORT_INTERRUPT |
4271 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4272 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4273 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4274 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004275
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004276 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004277 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004278
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004279 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
4280
Daniel Vetterb79480b2013-06-27 17:52:10 +02004281 /* Interrupt setup is already guaranteed to be single-threaded, this is
4282 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004283 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004284 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4285 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4286 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004287 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004288
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004289 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004290
4291 return 0;
4292}
4293
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004294static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004295{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004296 u32 hotplug_en;
4297
Chris Wilson67520412017-03-02 13:28:01 +00004298 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004299
Ville Syrjälä778eb332015-01-09 14:21:13 +02004300 /* Note HDMI and DP share hotplug bits */
4301 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004302 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004303 /* Programming the CRT detection parameters tends
4304 to generate a spurious hotplug event about three
4305 seconds later. So just do it once.
4306 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004307 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004308 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004309 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004310
Ville Syrjälä778eb332015-01-09 14:21:13 +02004311 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004312 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004313 HOTPLUG_INT_EN_MASK |
4314 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4315 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4316 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004317}
4318
Daniel Vetterff1f5252012-10-02 15:10:55 +02004319static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004320{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004321 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004322 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004323 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004324
Imre Deak2dd2a882015-02-24 11:14:30 +02004325 if (!intel_irqs_enabled(dev_priv))
4326 return IRQ_NONE;
4327
Imre Deak1f814da2015-12-16 02:52:19 +02004328 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4329 disable_rpm_wakeref_asserts(dev_priv);
4330
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004331 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004332 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004333 u32 hotplug_status = 0;
4334 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004335
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004336 iir = I915_READ(IIR);
4337 if (iir == 0)
4338 break;
4339
4340 ret = IRQ_HANDLED;
4341
4342 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4343 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004344
Ville Syrjäläeb643432017-08-18 21:36:59 +03004345 /* Call regardless, as some status bits might not be
4346 * signalled in iir */
4347 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004348
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004349 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004350
Chris Wilsona266c7d2012-04-24 22:59:44 +01004351 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304352 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004353
Chris Wilsona266c7d2012-04-24 22:59:44 +01004354 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304355 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004356
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004357 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4358 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004359
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004360 if (hotplug_status)
4361 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4362
4363 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4364 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004365
Imre Deak1f814da2015-12-16 02:52:19 +02004366 enable_rpm_wakeref_asserts(dev_priv);
4367
Chris Wilsona266c7d2012-04-24 22:59:44 +01004368 return ret;
4369}
4370
Daniel Vetterfca52a52014-09-30 10:56:45 +02004371/**
4372 * intel_irq_init - initializes irq support
4373 * @dev_priv: i915 device instance
4374 *
4375 * This function initializes all the irq support including work items, timers
4376 * and all the vtables. It does not setup the interrupt itself though.
4377 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004378void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004379{
Chris Wilson91c8a322016-07-05 10:40:23 +01004380 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004381 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004382 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004383
Jani Nikula77913b32015-06-18 13:06:16 +03004384 intel_hpd_init_work(dev_priv);
4385
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004386 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004387
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004388 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004389 for (i = 0; i < MAX_L3_SLICES; ++i)
4390 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004391
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004392 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304393 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4394
Deepak Sa6706b42014-03-15 20:23:22 +05304395 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004396 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004397 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004398 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004399 else
4400 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304401
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004402 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304403
4404 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004405 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304406 * if GEN6_PM_UP_EI_EXPIRED is masked.
4407 *
4408 * TODO: verify if this can be reproduced on VLV,CHV.
4409 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004410 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004411 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304412
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004413 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004414 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304415
Daniel Vetterb9632912014-09-30 10:56:44 +02004416 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004417 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004418 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004419 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004420 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004421 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004422 } else {
4423 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4424 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004425 }
4426
Ville Syrjälä21da2702014-08-06 14:49:55 +03004427 /*
4428 * Opt out of the vblank disable timer on everything except gen2.
4429 * Gen2 doesn't have a hardware frame counter and so depends on
4430 * vblank interrupts to produce sane vblank seuquence numbers.
4431 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004432 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004433 dev->vblank_disable_immediate = true;
4434
Chris Wilson262fd482017-02-15 13:15:47 +00004435 /* Most platforms treat the display irq block as an always-on
4436 * power domain. vlv/chv can disable it at runtime and need
4437 * special care to avoid writing any of the display block registers
4438 * outside of the power domain. We defer setting up the display irqs
4439 * in this case to the runtime pm.
4440 */
4441 dev_priv->display_irqs_enabled = true;
4442 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4443 dev_priv->display_irqs_enabled = false;
4444
Lyude317eaa92017-02-03 21:18:25 -05004445 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4446
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004447 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004448 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004449
Daniel Vetterb9632912014-09-30 10:56:44 +02004450 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004451 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004452 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004453 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004454 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004455 dev->driver->enable_vblank = i965_enable_vblank;
4456 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004457 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004458 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004459 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004460 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004461 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004462 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004463 dev->driver->enable_vblank = i965_enable_vblank;
4464 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004465 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004466 } else if (INTEL_GEN(dev_priv) >= 11) {
4467 dev->driver->irq_handler = gen11_irq_handler;
4468 dev->driver->irq_preinstall = gen11_irq_reset;
4469 dev->driver->irq_postinstall = gen11_irq_postinstall;
4470 dev->driver->irq_uninstall = gen11_irq_reset;
4471 dev->driver->enable_vblank = gen8_enable_vblank;
4472 dev->driver->disable_vblank = gen8_disable_vblank;
4473 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004474 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004475 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004476 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004477 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004478 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004479 dev->driver->enable_vblank = gen8_enable_vblank;
4480 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004481 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004482 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004483 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4484 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004485 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4486 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004487 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004488 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004489 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004490 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004491 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004492 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004493 dev->driver->enable_vblank = ironlake_enable_vblank;
4494 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004495 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004496 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004497 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004498 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004499 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4500 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004501 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004502 dev->driver->enable_vblank = i8xx_enable_vblank;
4503 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004504 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004505 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004506 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004507 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004508 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004509 dev->driver->enable_vblank = i8xx_enable_vblank;
4510 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004511 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004512 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004513 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004514 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004515 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004516 dev->driver->enable_vblank = i965_enable_vblank;
4517 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004518 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004519 if (I915_HAS_HOTPLUG(dev_priv))
4520 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004521 }
4522}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004523
Daniel Vetterfca52a52014-09-30 10:56:45 +02004524/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004525 * intel_irq_fini - deinitializes IRQ support
4526 * @i915: i915 device instance
4527 *
4528 * This function deinitializes all the IRQ support.
4529 */
4530void intel_irq_fini(struct drm_i915_private *i915)
4531{
4532 int i;
4533
4534 for (i = 0; i < MAX_L3_SLICES; ++i)
4535 kfree(i915->l3_parity.remap_info[i]);
4536}
4537
4538/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004539 * intel_irq_install - enables the hardware interrupt
4540 * @dev_priv: i915 device instance
4541 *
4542 * This function enables the hardware interrupt handling, but leaves the hotplug
4543 * handling still disabled. It is called after intel_irq_init().
4544 *
4545 * In the driver load and resume code we need working interrupts in a few places
4546 * but don't want to deal with the hassle of concurrent probe and hotplug
4547 * workers. Hence the split into this two-stage approach.
4548 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004549int intel_irq_install(struct drm_i915_private *dev_priv)
4550{
4551 /*
4552 * We enable some interrupt sources in our postinstall hooks, so mark
4553 * interrupts as enabled _before_ actually enabling them to avoid
4554 * special cases in our ordering checks.
4555 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004556 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004557
Chris Wilson91c8a322016-07-05 10:40:23 +01004558 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004559}
4560
Daniel Vetterfca52a52014-09-30 10:56:45 +02004561/**
4562 * intel_irq_uninstall - finilizes all irq handling
4563 * @dev_priv: i915 device instance
4564 *
4565 * This stops interrupt and hotplug handling and unregisters and frees all
4566 * resources acquired in the init functions.
4567 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004568void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4569{
Chris Wilson91c8a322016-07-05 10:40:23 +01004570 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004571 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004572 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004573}
4574
Daniel Vetterfca52a52014-09-30 10:56:45 +02004575/**
4576 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4577 * @dev_priv: i915 device instance
4578 *
4579 * This function is used to disable interrupts at runtime, both in the runtime
4580 * pm and the system suspend/resume code.
4581 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004582void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004583{
Chris Wilson91c8a322016-07-05 10:40:23 +01004584 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004585 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004586 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004587}
4588
Daniel Vetterfca52a52014-09-30 10:56:45 +02004589/**
4590 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4591 * @dev_priv: i915 device instance
4592 *
4593 * This function is used to enable interrupts at runtime, both in the runtime
4594 * pm and the system suspend/resume code.
4595 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004596void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004597{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004598 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004599 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4600 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004601}