blob: 4a02747ac65877ce5e7aa24a4363ecedbc7e024e [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
Ville Syrjälä4dc055c2018-06-11 23:02:55 +03001896 *
1897 * Toggle the enable bits to make sure we get an
1898 * edge in the ISR pipe event bit if we don't clear
1899 * all the enabled status bits. Otherwise the edge
1900 * triggered IIR on i965/g4x wouldn't notice that
1901 * an interrupt is still pending.
Imre Deakc1874ed2014-02-04 21:35:46 +02001902 */
Ville Syrjälä4dc055c2018-06-11 23:02:55 +03001903 if (pipe_stats[pipe]) {
1904 I915_WRITE(reg, pipe_stats[pipe]);
1905 I915_WRITE(reg, enable_mask);
1906 }
Imre Deakc1874ed2014-02-04 21:35:46 +02001907 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001908 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001909}
1910
Ville Syrjäläeb643432017-08-18 21:36:59 +03001911static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1912 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1913{
1914 enum pipe pipe;
1915
1916 for_each_pipe(dev_priv, pipe) {
1917 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1918 drm_handle_vblank(&dev_priv->drm, pipe);
1919
1920 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1921 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1922
1923 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1924 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1925 }
1926}
1927
1928static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1929 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1930{
1931 bool blc_event = false;
1932 enum pipe pipe;
1933
1934 for_each_pipe(dev_priv, pipe) {
1935 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1936 drm_handle_vblank(&dev_priv->drm, pipe);
1937
1938 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1939 blc_event = true;
1940
1941 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1942 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1943
1944 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1945 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1946 }
1947
1948 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1949 intel_opregion_asle_intr(dev_priv);
1950}
1951
1952static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1953 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1954{
1955 bool blc_event = false;
1956 enum pipe pipe;
1957
1958 for_each_pipe(dev_priv, pipe) {
1959 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1960 drm_handle_vblank(&dev_priv->drm, pipe);
1961
1962 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1963 blc_event = true;
1964
1965 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1966 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1967
1968 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1969 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1970 }
1971
1972 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1973 intel_opregion_asle_intr(dev_priv);
1974
1975 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1976 gmbus_irq_handler(dev_priv);
1977}
1978
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001979static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001980 u32 pipe_stats[I915_MAX_PIPES])
1981{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001982 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001983
Damien Lespiau055e3932014-08-18 13:49:10 +01001984 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001985 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1986 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001987
1988 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001989 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001990
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001991 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1992 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001993 }
1994
1995 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001996 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001997}
1998
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001999static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002000{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002001 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002002
2003 if (hotplug_status)
2004 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
2005
2006 return hotplug_status;
2007}
2008
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002009static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002010 u32 hotplug_status)
2011{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03002012 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002013
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002014 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2015 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03002016 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002017
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002018 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002019 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2020 hotplug_trigger, hotplug_trigger,
2021 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002022 i9xx_port_hotplug_long_detect);
2023
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002024 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002025 }
Jani Nikula369712e2015-05-27 15:03:40 +03002026
2027 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002028 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03002029 } else {
2030 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002031
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002032 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002033 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2034 hotplug_trigger, hotplug_trigger,
2035 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002036 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002037 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002038 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002039 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002040}
2041
Daniel Vetterff1f5252012-10-02 15:10:55 +02002042static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002043{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002044 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002045 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002046 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002047
Imre Deak2dd2a882015-02-24 11:14:30 +02002048 if (!intel_irqs_enabled(dev_priv))
2049 return IRQ_NONE;
2050
Imre Deak1f814da2015-12-16 02:52:19 +02002051 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2052 disable_rpm_wakeref_asserts(dev_priv);
2053
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002054 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002055 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002056 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002057 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002058 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002059
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002060 gt_iir = I915_READ(GTIIR);
2061 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002062 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002063
2064 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002065 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002066
2067 ret = IRQ_HANDLED;
2068
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002069 /*
2070 * Theory on interrupt generation, based on empirical evidence:
2071 *
2072 * x = ((VLV_IIR & VLV_IER) ||
2073 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2074 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2075 *
2076 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2077 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2078 * guarantee the CPU interrupt will be raised again even if we
2079 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2080 * bits this time around.
2081 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002082 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002083 ier = I915_READ(VLV_IER);
2084 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002085
2086 if (gt_iir)
2087 I915_WRITE(GTIIR, gt_iir);
2088 if (pm_iir)
2089 I915_WRITE(GEN6_PMIIR, pm_iir);
2090
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002091 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002092 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002093
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002094 /* Call regardless, as some status bits might not be
2095 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002096 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002097
Jerome Anandeef57322017-01-25 04:27:49 +05302098 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2099 I915_LPE_PIPE_B_INTERRUPT))
2100 intel_lpe_audio_irq_handler(dev_priv);
2101
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002102 /*
2103 * VLV_IIR is single buffered, and reflects the level
2104 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2105 */
2106 if (iir)
2107 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002108
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002109 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002110 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2111 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002112
Ville Syrjälä52894872016-04-13 21:19:56 +03002113 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002114 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002115 if (pm_iir)
2116 gen6_rps_irq_handler(dev_priv, pm_iir);
2117
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002118 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002119 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002120
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002121 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002122 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002123
Imre Deak1f814da2015-12-16 02:52:19 +02002124 enable_rpm_wakeref_asserts(dev_priv);
2125
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002126 return ret;
2127}
2128
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002129static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2130{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002131 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002132 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002133 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002134
Imre Deak2dd2a882015-02-24 11:14:30 +02002135 if (!intel_irqs_enabled(dev_priv))
2136 return IRQ_NONE;
2137
Imre Deak1f814da2015-12-16 02:52:19 +02002138 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2139 disable_rpm_wakeref_asserts(dev_priv);
2140
Chris Wilson579de732016-03-14 09:01:57 +00002141 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002142 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002143 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002144 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002145 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002146 u32 ier = 0;
2147
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002148 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2149 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002150
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002151 if (master_ctl == 0 && iir == 0)
2152 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002153
Oscar Mateo27b6c122014-06-16 16:11:00 +01002154 ret = IRQ_HANDLED;
2155
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002156 /*
2157 * Theory on interrupt generation, based on empirical evidence:
2158 *
2159 * x = ((VLV_IIR & VLV_IER) ||
2160 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2161 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2162 *
2163 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2164 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2165 * guarantee the CPU interrupt will be raised again even if we
2166 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2167 * bits this time around.
2168 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002169 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002170 ier = I915_READ(VLV_IER);
2171 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002172
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002173 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002174
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002175 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002176 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002177
Oscar Mateo27b6c122014-06-16 16:11:00 +01002178 /* Call regardless, as some status bits might not be
2179 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002180 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002181
Jerome Anandeef57322017-01-25 04:27:49 +05302182 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2183 I915_LPE_PIPE_B_INTERRUPT |
2184 I915_LPE_PIPE_C_INTERRUPT))
2185 intel_lpe_audio_irq_handler(dev_priv);
2186
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002187 /*
2188 * VLV_IIR is single buffered, and reflects the level
2189 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2190 */
2191 if (iir)
2192 I915_WRITE(VLV_IIR, iir);
2193
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002194 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002195 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002196 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002197
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002198 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002199
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002200 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002201 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002202
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002203 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002204 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002205
Imre Deak1f814da2015-12-16 02:52:19 +02002206 enable_rpm_wakeref_asserts(dev_priv);
2207
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002208 return ret;
2209}
2210
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002211static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2212 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002213 const u32 hpd[HPD_NUM_PINS])
2214{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002215 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2216
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002217 /*
2218 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2219 * unless we touch the hotplug register, even if hotplug_trigger is
2220 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2221 * errors.
2222 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002223 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002224 if (!hotplug_trigger) {
2225 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2226 PORTD_HOTPLUG_STATUS_MASK |
2227 PORTC_HOTPLUG_STATUS_MASK |
2228 PORTB_HOTPLUG_STATUS_MASK;
2229 dig_hotplug_reg &= ~mask;
2230 }
2231
Ville Syrjälä40e56412015-08-27 23:56:10 +03002232 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002233 if (!hotplug_trigger)
2234 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002235
Rodrigo Vivicf539022018-01-29 15:22:21 -08002236 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002237 dig_hotplug_reg, hpd,
2238 pch_port_hotplug_long_detect);
2239
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002240 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002241}
2242
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002243static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002244{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002245 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002246 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002247
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002248 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002249
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002250 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2251 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2252 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002253 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002254 port_name(port));
2255 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002256
Daniel Vetterce99c252012-12-01 13:53:47 +01002257 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002258 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002259
Jesse Barnes776ad802011-01-04 15:09:39 -08002260 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002261 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002262
2263 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2264 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2265
2266 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2267 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2268
2269 if (pch_iir & SDE_POISON)
2270 DRM_ERROR("PCH poison interrupt\n");
2271
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002272 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002273 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002274 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2275 pipe_name(pipe),
2276 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002277
2278 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2279 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2280
2281 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2282 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2283
Jesse Barnes776ad802011-01-04 15:09:39 -08002284 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002285 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002286
2287 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002288 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002289}
2290
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002291static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002292{
Paulo Zanoni86642812013-04-12 17:57:57 -03002293 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002294 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002295
Paulo Zanonide032bf2013-04-12 17:57:58 -03002296 if (err_int & ERR_INT_POISON)
2297 DRM_ERROR("Poison interrupt\n");
2298
Damien Lespiau055e3932014-08-18 13:49:10 +01002299 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002300 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2301 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002302
Daniel Vetter5a69b892013-10-16 22:55:52 +02002303 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002304 if (IS_IVYBRIDGE(dev_priv))
2305 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002306 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002307 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002308 }
2309 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002310
Paulo Zanoni86642812013-04-12 17:57:57 -03002311 I915_WRITE(GEN7_ERR_INT, err_int);
2312}
2313
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002314static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002315{
Paulo Zanoni86642812013-04-12 17:57:57 -03002316 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002317 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002318
Paulo Zanonide032bf2013-04-12 17:57:58 -03002319 if (serr_int & SERR_INT_POISON)
2320 DRM_ERROR("PCH poison interrupt\n");
2321
Mika Kahola45c1cd82017-10-10 13:17:06 +03002322 for_each_pipe(dev_priv, pipe)
2323 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2324 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002325
2326 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002327}
2328
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002329static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002330{
Adam Jackson23e81d62012-06-06 15:45:44 -04002331 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002332 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002333
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002334 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002335
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002336 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2337 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2338 SDE_AUDIO_POWER_SHIFT_CPT);
2339 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2340 port_name(port));
2341 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002342
2343 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002344 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002345
2346 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002347 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002348
2349 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2350 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2351
2352 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2353 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2354
2355 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002356 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002357 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2358 pipe_name(pipe),
2359 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002360
2361 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002362 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002363}
2364
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002365static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002366{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002367 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2368 ~SDE_PORTE_HOTPLUG_SPT;
2369 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2370 u32 pin_mask = 0, long_mask = 0;
2371
2372 if (hotplug_trigger) {
2373 u32 dig_hotplug_reg;
2374
2375 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2376 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2377
Rodrigo Vivicf539022018-01-29 15:22:21 -08002378 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2379 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002380 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002381 }
2382
2383 if (hotplug2_trigger) {
2384 u32 dig_hotplug_reg;
2385
2386 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2387 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2388
Rodrigo Vivicf539022018-01-29 15:22:21 -08002389 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2390 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002391 spt_port_hotplug2_long_detect);
2392 }
2393
2394 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002395 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002396
2397 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002398 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002399}
2400
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002401static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2402 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002403 const u32 hpd[HPD_NUM_PINS])
2404{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002405 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2406
2407 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2408 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2409
Rodrigo Vivicf539022018-01-29 15:22:21 -08002410 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002411 dig_hotplug_reg, hpd,
2412 ilk_port_hotplug_long_detect);
2413
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002414 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002415}
2416
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002417static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2418 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002419{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002420 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002421 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2422
Ville Syrjälä40e56412015-08-27 23:56:10 +03002423 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002424 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002425
2426 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002427 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002428
2429 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002430 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002431
Paulo Zanonic008bc62013-07-12 16:35:10 -03002432 if (de_iir & DE_POISON)
2433 DRM_ERROR("Poison interrupt\n");
2434
Damien Lespiau055e3932014-08-18 13:49:10 +01002435 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002436 if (de_iir & DE_PIPE_VBLANK(pipe))
2437 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002438
Daniel Vetter40da17c22013-10-21 18:04:36 +02002439 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002440 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002441
Daniel Vetter40da17c22013-10-21 18:04:36 +02002442 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002443 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002444 }
2445
2446 /* check event from PCH */
2447 if (de_iir & DE_PCH_EVENT) {
2448 u32 pch_iir = I915_READ(SDEIIR);
2449
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002450 if (HAS_PCH_CPT(dev_priv))
2451 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002452 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002453 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002454
2455 /* should clear PCH hotplug event before clear CPU irq */
2456 I915_WRITE(SDEIIR, pch_iir);
2457 }
2458
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002459 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2460 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002461}
2462
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002463static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2464 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002465{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002466 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002467 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2468
Ville Syrjälä40e56412015-08-27 23:56:10 +03002469 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002470 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002471
2472 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002473 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002474
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002475 if (de_iir & DE_EDP_PSR_INT_HSW) {
2476 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2477
2478 intel_psr_irq_handler(dev_priv, psr_iir);
2479 I915_WRITE(EDP_PSR_IIR, psr_iir);
2480 }
Daniel Vetterfc340442018-04-05 15:00:23 -07002481
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002482 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002483 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002484
2485 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002486 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002487
Damien Lespiau055e3932014-08-18 13:49:10 +01002488 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002489 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2490 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002491 }
2492
2493 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002494 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002495 u32 pch_iir = I915_READ(SDEIIR);
2496
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002497 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002498
2499 /* clear PCH hotplug event before clear CPU irq */
2500 I915_WRITE(SDEIIR, pch_iir);
2501 }
2502}
2503
Oscar Mateo72c90f62014-06-16 16:10:57 +01002504/*
2505 * To handle irqs with the minimum potential races with fresh interrupts, we:
2506 * 1 - Disable Master Interrupt Control.
2507 * 2 - Find the source(s) of the interrupt.
2508 * 3 - Clear the Interrupt Identity bits (IIR).
2509 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2510 * 5 - Re-enable Master Interrupt Control.
2511 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002512static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002513{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002514 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002515 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002516 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002517 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002518
Imre Deak2dd2a882015-02-24 11:14:30 +02002519 if (!intel_irqs_enabled(dev_priv))
2520 return IRQ_NONE;
2521
Imre Deak1f814da2015-12-16 02:52:19 +02002522 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2523 disable_rpm_wakeref_asserts(dev_priv);
2524
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002525 /* disable master interrupt before clearing iir */
2526 de_ier = I915_READ(DEIER);
2527 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002528 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002529
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002530 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2531 * interrupts will will be stored on its back queue, and then we'll be
2532 * able to process them after we restore SDEIER (as soon as we restore
2533 * it, we'll get an interrupt if SDEIIR still has something to process
2534 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002535 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002536 sde_ier = I915_READ(SDEIER);
2537 I915_WRITE(SDEIER, 0);
2538 POSTING_READ(SDEIER);
2539 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002540
Oscar Mateo72c90f62014-06-16 16:10:57 +01002541 /* Find, clear, then process each source of interrupt */
2542
Chris Wilson0e434062012-05-09 21:45:44 +01002543 gt_iir = I915_READ(GTIIR);
2544 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002545 I915_WRITE(GTIIR, gt_iir);
2546 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002547 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002548 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002549 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002550 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002551 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002552
2553 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002554 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002555 I915_WRITE(DEIIR, de_iir);
2556 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002557 if (INTEL_GEN(dev_priv) >= 7)
2558 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002559 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002560 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002561 }
2562
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002563 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002564 u32 pm_iir = I915_READ(GEN6_PMIIR);
2565 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002566 I915_WRITE(GEN6_PMIIR, pm_iir);
2567 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002568 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002569 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002570 }
2571
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002572 I915_WRITE(DEIER, de_ier);
2573 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002574 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002575 I915_WRITE(SDEIER, sde_ier);
2576 POSTING_READ(SDEIER);
2577 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002578
Imre Deak1f814da2015-12-16 02:52:19 +02002579 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2580 enable_rpm_wakeref_asserts(dev_priv);
2581
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002582 return ret;
2583}
2584
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002585static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2586 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002587 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302588{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002589 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302590
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002591 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2592 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302593
Rodrigo Vivicf539022018-01-29 15:22:21 -08002594 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002595 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002596 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002597
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002598 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302599}
2600
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002601static irqreturn_t
2602gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002603{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002604 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002605 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002606 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002607
Ben Widawskyabd58f02013-11-02 21:07:09 -07002608 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002609 iir = I915_READ(GEN8_DE_MISC_IIR);
2610 if (iir) {
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002611 bool found = false;
2612
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002613 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002614 ret = IRQ_HANDLED;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002615
2616 if (iir & GEN8_DE_MISC_GSE) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002617 intel_opregion_asle_intr(dev_priv);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002618 found = true;
2619 }
2620
2621 if (iir & GEN8_DE_EDP_PSR) {
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002622 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2623
2624 intel_psr_irq_handler(dev_priv, psr_iir);
2625 I915_WRITE(EDP_PSR_IIR, psr_iir);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002626 found = true;
2627 }
2628
2629 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002630 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002631 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002632 else
2633 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002634 }
2635
Daniel Vetter6d766f02013-11-07 14:49:55 +01002636 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002637 iir = I915_READ(GEN8_DE_PORT_IIR);
2638 if (iir) {
2639 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302640 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002641
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002642 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002643 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002644
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002645 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002646 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002647 tmp_mask |= GEN9_AUX_CHANNEL_B |
2648 GEN9_AUX_CHANNEL_C |
2649 GEN9_AUX_CHANNEL_D;
2650
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002651 if (IS_CNL_WITH_PORT_F(dev_priv))
2652 tmp_mask |= CNL_AUX_CHANNEL_F;
2653
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002654 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002655 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302656 found = true;
2657 }
2658
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002659 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002660 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2661 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002662 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2663 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002664 found = true;
2665 }
2666 } else if (IS_BROADWELL(dev_priv)) {
2667 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2668 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002669 ilk_hpd_irq_handler(dev_priv,
2670 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002671 found = true;
2672 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302673 }
2674
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002675 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002676 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302677 found = true;
2678 }
2679
Shashank Sharmad04a4922014-08-22 17:40:41 +05302680 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002681 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002682 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002683 else
2684 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002685 }
2686
Damien Lespiau055e3932014-08-18 13:49:10 +01002687 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002688 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002689
Daniel Vetterc42664c2013-11-07 11:05:40 +01002690 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2691 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002692
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002693 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2694 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002695 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002696 continue;
2697 }
2698
2699 ret = IRQ_HANDLED;
2700 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2701
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002702 if (iir & GEN8_PIPE_VBLANK)
2703 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002704
2705 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002706 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002707
2708 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2709 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2710
2711 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002712 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002713 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2714 else
2715 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2716
2717 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002718 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002719 pipe_name(pipe),
2720 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002721 }
2722
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002723 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302724 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002725 /*
2726 * FIXME(BDW): Assume for now that the new interrupt handling
2727 * scheme also closed the SDE interrupt handling race we've seen
2728 * on older pch-split platforms. But this needs testing.
2729 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002730 iir = I915_READ(SDEIIR);
2731 if (iir) {
2732 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002733 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002734
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002735 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2736 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002737 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002738 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002739 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002740 } else {
2741 /*
2742 * Like on previous PCH there seems to be something
2743 * fishy going on with forwarding PCH interrupts.
2744 */
2745 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2746 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002747 }
2748
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002749 return ret;
2750}
2751
2752static irqreturn_t gen8_irq_handler(int irq, void *arg)
2753{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002754 struct drm_i915_private *dev_priv = to_i915(arg);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002755 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002756 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002757
2758 if (!intel_irqs_enabled(dev_priv))
2759 return IRQ_NONE;
2760
2761 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2762 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2763 if (!master_ctl)
2764 return IRQ_NONE;
2765
2766 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2767
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002768 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002769 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002770
2771 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2772 if (master_ctl & ~GEN8_GT_IRQS) {
2773 disable_rpm_wakeref_asserts(dev_priv);
2774 gen8_de_irq_handler(dev_priv, master_ctl);
2775 enable_rpm_wakeref_asserts(dev_priv);
2776 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002777
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002778 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002779
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002780 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002781
Chris Wilson55ef72f2018-02-02 15:34:48 +00002782 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002783}
2784
Chris Wilson36703e72017-06-22 11:56:25 +01002785struct wedge_me {
2786 struct delayed_work work;
2787 struct drm_i915_private *i915;
2788 const char *name;
2789};
2790
2791static void wedge_me(struct work_struct *work)
2792{
2793 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2794
2795 dev_err(w->i915->drm.dev,
2796 "%s timed out, cancelling all in-flight rendering.\n",
2797 w->name);
2798 i915_gem_set_wedged(w->i915);
2799}
2800
2801static void __init_wedge(struct wedge_me *w,
2802 struct drm_i915_private *i915,
2803 long timeout,
2804 const char *name)
2805{
2806 w->i915 = i915;
2807 w->name = name;
2808
2809 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2810 schedule_delayed_work(&w->work, timeout);
2811}
2812
2813static void __fini_wedge(struct wedge_me *w)
2814{
2815 cancel_delayed_work_sync(&w->work);
2816 destroy_delayed_work_on_stack(&w->work);
2817 w->i915 = NULL;
2818}
2819
2820#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2821 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2822 (W)->i915; \
2823 __fini_wedge((W)))
2824
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002825static u32
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002826gen11_gt_engine_identity(struct drm_i915_private * const i915,
2827 const unsigned int bank, const unsigned int bit)
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002828{
2829 void __iomem * const regs = i915->regs;
2830 u32 timeout_ts;
2831 u32 ident;
2832
Oscar Mateo96606f32018-04-06 12:32:37 +03002833 lockdep_assert_held(&i915->irq_lock);
2834
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002835 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
2836
2837 /*
2838 * NB: Specs do not specify how long to spin wait,
2839 * so we do ~100us as an educated guess.
2840 */
2841 timeout_ts = (local_clock() >> 10) + 100;
2842 do {
2843 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
2844 } while (!(ident & GEN11_INTR_DATA_VALID) &&
2845 !time_after32(local_clock() >> 10, timeout_ts));
2846
2847 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
2848 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
2849 bank, bit, ident);
2850 return 0;
2851 }
2852
2853 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
2854 GEN11_INTR_DATA_VALID);
2855
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002856 return ident;
2857}
2858
2859static void
2860gen11_other_irq_handler(struct drm_i915_private * const i915,
2861 const u8 instance, const u16 iir)
2862{
Oscar Mateod02b98b2018-04-05 17:00:50 +03002863 if (instance == OTHER_GTPM_INSTANCE)
2864 return gen6_rps_irq_handler(i915, iir);
2865
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002866 WARN_ONCE(1, "unhandled other interrupt instance=0x%x, iir=0x%x\n",
2867 instance, iir);
2868}
2869
2870static void
2871gen11_engine_irq_handler(struct drm_i915_private * const i915,
2872 const u8 class, const u8 instance, const u16 iir)
2873{
2874 struct intel_engine_cs *engine;
2875
2876 if (instance <= MAX_ENGINE_INSTANCE)
2877 engine = i915->engine_class[class][instance];
2878 else
2879 engine = NULL;
2880
2881 if (likely(engine))
2882 return gen8_cs_irq_handler(engine, iir);
2883
2884 WARN_ONCE(1, "unhandled engine interrupt class=0x%x, instance=0x%x\n",
2885 class, instance);
2886}
2887
2888static void
2889gen11_gt_identity_handler(struct drm_i915_private * const i915,
2890 const u32 identity)
2891{
2892 const u8 class = GEN11_INTR_ENGINE_CLASS(identity);
2893 const u8 instance = GEN11_INTR_ENGINE_INSTANCE(identity);
2894 const u16 intr = GEN11_INTR_ENGINE_INTR(identity);
2895
2896 if (unlikely(!intr))
2897 return;
2898
2899 if (class <= COPY_ENGINE_CLASS)
2900 return gen11_engine_irq_handler(i915, class, instance, intr);
2901
2902 if (class == OTHER_CLASS)
2903 return gen11_other_irq_handler(i915, instance, intr);
2904
2905 WARN_ONCE(1, "unknown interrupt class=0x%x, instance=0x%x, intr=0x%x\n",
2906 class, instance, intr);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002907}
2908
2909static void
Oscar Mateo96606f32018-04-06 12:32:37 +03002910gen11_gt_bank_handler(struct drm_i915_private * const i915,
2911 const unsigned int bank)
2912{
2913 void __iomem * const regs = i915->regs;
2914 unsigned long intr_dw;
2915 unsigned int bit;
2916
2917 lockdep_assert_held(&i915->irq_lock);
2918
2919 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
2920
2921 if (unlikely(!intr_dw)) {
2922 DRM_ERROR("GT_INTR_DW%u blank!\n", bank);
2923 return;
2924 }
2925
2926 for_each_set_bit(bit, &intr_dw, 32) {
2927 const u32 ident = gen11_gt_engine_identity(i915,
2928 bank, bit);
2929
2930 gen11_gt_identity_handler(i915, ident);
2931 }
2932
2933 /* Clear must be after shared has been served for engine */
2934 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
2935}
2936
2937static void
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002938gen11_gt_irq_handler(struct drm_i915_private * const i915,
2939 const u32 master_ctl)
2940{
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002941 unsigned int bank;
2942
Oscar Mateo96606f32018-04-06 12:32:37 +03002943 spin_lock(&i915->irq_lock);
2944
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002945 for (bank = 0; bank < 2; bank++) {
Oscar Mateo96606f32018-04-06 12:32:37 +03002946 if (master_ctl & GEN11_GT_DW_IRQ(bank))
2947 gen11_gt_bank_handler(i915, bank);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002948 }
Oscar Mateo96606f32018-04-06 12:32:37 +03002949
2950 spin_unlock(&i915->irq_lock);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002951}
2952
2953static irqreturn_t gen11_irq_handler(int irq, void *arg)
2954{
2955 struct drm_i915_private * const i915 = to_i915(arg);
2956 void __iomem * const regs = i915->regs;
2957 u32 master_ctl;
2958
2959 if (!intel_irqs_enabled(i915))
2960 return IRQ_NONE;
2961
2962 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
2963 master_ctl &= ~GEN11_MASTER_IRQ;
2964 if (!master_ctl)
2965 return IRQ_NONE;
2966
2967 /* Disable interrupts. */
2968 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
2969
2970 /* Find, clear, then process each source of interrupt. */
2971 gen11_gt_irq_handler(i915, master_ctl);
2972
2973 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2974 if (master_ctl & GEN11_DISPLAY_IRQ) {
2975 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
2976
2977 disable_rpm_wakeref_asserts(i915);
2978 /*
2979 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
2980 * for the display related bits.
2981 */
2982 gen8_de_irq_handler(i915, disp_ctl);
2983 enable_rpm_wakeref_asserts(i915);
2984 }
2985
2986 /* Acknowledge and enable interrupts. */
2987 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ | master_ctl);
2988
2989 return IRQ_HANDLED;
2990}
2991
Chris Wilsonce800752018-03-20 10:04:49 +00002992static void i915_reset_device(struct drm_i915_private *dev_priv,
Chris Wilsond0667e92018-04-06 23:03:54 +01002993 u32 engine_mask,
2994 const char *reason)
Jesse Barnes8a905232009-07-11 16:48:03 -04002995{
Chris Wilsonce800752018-03-20 10:04:49 +00002996 struct i915_gpu_error *error = &dev_priv->gpu_error;
Chris Wilson91c8a322016-07-05 10:40:23 +01002997 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002998 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2999 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
3000 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01003001 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04003002
Chris Wilsonc0336662016-05-06 15:40:21 +01003003 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04003004
Chris Wilson8af29b02016-09-09 14:11:47 +01003005 DRM_DEBUG_DRIVER("resetting chip\n");
3006 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
3007
Chris Wilson36703e72017-06-22 11:56:25 +01003008 /* Use a watchdog to ensure that our reset completes */
3009 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
3010 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003011
Chris Wilsond0667e92018-04-06 23:03:54 +01003012 error->reason = reason;
3013 error->stalled_mask = engine_mask;
Chris Wilsonce800752018-03-20 10:04:49 +00003014
Chris Wilson36703e72017-06-22 11:56:25 +01003015 /* Signal that locked waiters should reset the GPU */
Chris Wilsond0667e92018-04-06 23:03:54 +01003016 smp_mb__before_atomic();
Chris Wilsonce800752018-03-20 10:04:49 +00003017 set_bit(I915_RESET_HANDOFF, &error->flags);
3018 wake_up_all(&error->wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00003019
Chris Wilson36703e72017-06-22 11:56:25 +01003020 /* Wait for anyone holding the lock to wakeup, without
3021 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01003022 */
Chris Wilson36703e72017-06-22 11:56:25 +01003023 do {
3024 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilsond0667e92018-04-06 23:03:54 +01003025 i915_reset(dev_priv, engine_mask, reason);
Chris Wilson36703e72017-06-22 11:56:25 +01003026 mutex_unlock(&dev_priv->drm.struct_mutex);
3027 }
Chris Wilsonce800752018-03-20 10:04:49 +00003028 } while (wait_on_bit_timeout(&error->flags,
Chris Wilson36703e72017-06-22 11:56:25 +01003029 I915_RESET_HANDOFF,
3030 TASK_UNINTERRUPTIBLE,
3031 1));
Chris Wilson780f2622016-09-09 14:11:52 +01003032
Chris Wilsond0667e92018-04-06 23:03:54 +01003033 error->stalled_mask = 0;
Chris Wilsonce800752018-03-20 10:04:49 +00003034 error->reason = NULL;
3035
Chris Wilson36703e72017-06-22 11:56:25 +01003036 intel_finish_reset(dev_priv);
3037 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02003038
Chris Wilsonce800752018-03-20 10:04:49 +00003039 if (!test_bit(I915_WEDGED, &error->flags))
3040 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04003041}
3042
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003043static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04003044{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003045 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04003046
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003047 if (!IS_GEN2(dev_priv))
3048 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04003049
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003050 if (INTEL_GEN(dev_priv) < 4)
3051 I915_WRITE(IPEIR, I915_READ(IPEIR));
3052 else
3053 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04003054
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003055 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04003056 eir = I915_READ(EIR);
3057 if (eir) {
3058 /*
3059 * some errors might have become stuck,
3060 * mask them.
3061 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003062 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04003063 I915_WRITE(EMR, I915_READ(EMR) | eir);
3064 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3065 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01003066}
3067
3068/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003069 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003070 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00003071 * @engine_mask: mask representing engines that are hung
Chris Wilsonce800752018-03-20 10:04:49 +00003072 * @flags: control flags
Michel Thierry87c390b2017-01-11 20:18:08 -08003073 * @fmt: Error message format string
3074 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02003075 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01003076 * dump it to the syslog. Also call i915_capture_error_state() to make
3077 * sure we get a record and make it available in debugfs. Fire a uevent
3078 * so userspace knows something bad happened (should trigger collection
3079 * of a ring dump etc.).
3080 */
Chris Wilsonc0336662016-05-06 15:40:21 +01003081void i915_handle_error(struct drm_i915_private *dev_priv,
3082 u32 engine_mask,
Chris Wilsonce800752018-03-20 10:04:49 +00003083 unsigned long flags,
Mika Kuoppala58174462014-02-25 17:11:26 +02003084 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01003085{
Michel Thierry142bc7d2017-06-20 10:57:46 +01003086 struct intel_engine_cs *engine;
3087 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02003088 char error_msg[80];
Chris Wilsonce800752018-03-20 10:04:49 +00003089 char *msg = NULL;
Chris Wilson35aed2e2010-05-27 13:18:12 +01003090
Chris Wilsonce800752018-03-20 10:04:49 +00003091 if (fmt) {
3092 va_list args;
3093
3094 va_start(args, fmt);
3095 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
3096 va_end(args);
3097
3098 msg = error_msg;
3099 }
Mika Kuoppala58174462014-02-25 17:11:26 +02003100
Chris Wilson1604a862017-03-14 17:18:40 +00003101 /*
3102 * In most cases it's guaranteed that we get here with an RPM
3103 * reference held, for example because there is a pending GPU
3104 * request that won't finish until the reset is done. This
3105 * isn't the case at least when we get here by doing a
3106 * simulated reset via debugfs, so get an RPM reference.
3107 */
3108 intel_runtime_pm_get(dev_priv);
3109
Chris Wilson873d66f2018-03-16 21:49:59 +00003110 engine_mask &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilsonce800752018-03-20 10:04:49 +00003111
3112 if (flags & I915_ERROR_CAPTURE) {
3113 i915_capture_error_state(dev_priv, engine_mask, msg);
3114 i915_clear_error_registers(dev_priv);
3115 }
Jesse Barnes8a905232009-07-11 16:48:03 -04003116
Michel Thierry142bc7d2017-06-20 10:57:46 +01003117 /*
3118 * Try engine reset when available. We fall back to full reset if
3119 * single reset fails.
3120 */
3121 if (intel_has_reset_engine(dev_priv)) {
3122 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02003123 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01003124 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3125 &dev_priv->gpu_error.flags))
3126 continue;
3127
Chris Wilsonce800752018-03-20 10:04:49 +00003128 if (i915_reset_engine(engine, msg) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01003129 engine_mask &= ~intel_engine_flag(engine);
3130
3131 clear_bit(I915_RESET_ENGINE + engine->id,
3132 &dev_priv->gpu_error.flags);
3133 wake_up_bit(&dev_priv->gpu_error.flags,
3134 I915_RESET_ENGINE + engine->id);
3135 }
3136 }
3137
Chris Wilson8af29b02016-09-09 14:11:47 +01003138 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00003139 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04003140
Michel Thierry142bc7d2017-06-20 10:57:46 +01003141 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01003142 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
3143 wait_event(dev_priv->gpu_error.reset_queue,
3144 !test_bit(I915_RESET_BACKOFF,
3145 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00003146 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01003147 }
Chris Wilson8af29b02016-09-09 14:11:47 +01003148
Michel Thierry142bc7d2017-06-20 10:57:46 +01003149 /* Prevent any other reset-engine attempt. */
3150 for_each_engine(engine, dev_priv, tmp) {
3151 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3152 &dev_priv->gpu_error.flags))
3153 wait_on_bit(&dev_priv->gpu_error.flags,
3154 I915_RESET_ENGINE + engine->id,
3155 TASK_UNINTERRUPTIBLE);
3156 }
3157
Chris Wilsond0667e92018-04-06 23:03:54 +01003158 i915_reset_device(dev_priv, engine_mask, msg);
Chris Wilsond5367302017-06-20 10:57:43 +01003159
Michel Thierry142bc7d2017-06-20 10:57:46 +01003160 for_each_engine(engine, dev_priv, tmp) {
3161 clear_bit(I915_RESET_ENGINE + engine->id,
3162 &dev_priv->gpu_error.flags);
3163 }
3164
Chris Wilsond5367302017-06-20 10:57:43 +01003165 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
3166 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00003167
3168out:
3169 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04003170}
3171
Keith Packard42f52ef2008-10-18 19:39:29 -07003172/* Called from drm generic code, passed 'crtc' which
3173 * we use as a pipe index
3174 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003175static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003176{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003177 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003178 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003179
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003180 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003181 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3182 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3183
3184 return 0;
3185}
3186
3187static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3188{
3189 struct drm_i915_private *dev_priv = to_i915(dev);
3190 unsigned long irqflags;
3191
3192 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3193 i915_enable_pipestat(dev_priv, pipe,
3194 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003195 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003196
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003197 return 0;
3198}
3199
Thierry Reding88e72712015-09-24 18:35:31 +02003200static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003201{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003202 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003203 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003204 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003205 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003206
Jesse Barnesf796cf82011-04-07 13:58:17 -07003207 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003208 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003209 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3210
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003211 /* Even though there is no DMC, frame counter can get stuck when
3212 * PSR is active as no frames are generated.
3213 */
3214 if (HAS_PSR(dev_priv))
3215 drm_vblank_restore(dev, pipe);
3216
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003217 return 0;
3218}
3219
Thierry Reding88e72712015-09-24 18:35:31 +02003220static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003221{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003222 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003223 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003224
Ben Widawskyabd58f02013-11-02 21:07:09 -07003225 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003226 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003227 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003228
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003229 /* Even if there is no DMC, frame counter can get stuck when
3230 * PSR is active as no frames are generated, so check only for PSR.
3231 */
3232 if (HAS_PSR(dev_priv))
3233 drm_vblank_restore(dev, pipe);
3234
Ben Widawskyabd58f02013-11-02 21:07:09 -07003235 return 0;
3236}
3237
Keith Packard42f52ef2008-10-18 19:39:29 -07003238/* Called from drm generic code, passed 'crtc' which
3239 * we use as a pipe index
3240 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003241static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3242{
3243 struct drm_i915_private *dev_priv = to_i915(dev);
3244 unsigned long irqflags;
3245
3246 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3247 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3248 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3249}
3250
3251static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003252{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003253 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003254 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003255
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003256 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003257 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003258 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003259 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3260}
3261
Thierry Reding88e72712015-09-24 18:35:31 +02003262static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003263{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003264 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003265 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003266 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003267 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003268
3269 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003270 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003271 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3272}
3273
Thierry Reding88e72712015-09-24 18:35:31 +02003274static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003275{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003276 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003277 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003278
Ben Widawskyabd58f02013-11-02 21:07:09 -07003279 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003280 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003281 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3282}
3283
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003284static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003285{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003286 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003287 return;
3288
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003289 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003290
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003291 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003292 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003293}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003294
Paulo Zanoni622364b2014-04-01 15:37:22 -03003295/*
3296 * SDEIER is also touched by the interrupt handler to work around missed PCH
3297 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3298 * instead we unconditionally enable all PCH interrupt sources here, but then
3299 * only unmask them as needed with SDEIMR.
3300 *
3301 * This function needs to be called before interrupts are enabled.
3302 */
3303static void ibx_irq_pre_postinstall(struct drm_device *dev)
3304{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003305 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003306
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003307 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003308 return;
3309
3310 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003311 I915_WRITE(SDEIER, 0xffffffff);
3312 POSTING_READ(SDEIER);
3313}
3314
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003315static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003316{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003317 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003318 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003319 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003320}
3321
Ville Syrjälä70591a42014-10-30 19:42:58 +02003322static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3323{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003324 if (IS_CHERRYVIEW(dev_priv))
3325 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3326 else
3327 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3328
Ville Syrjäläad22d102016-04-12 18:56:14 +03003329 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003330 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3331
Ville Syrjälä44d92412017-08-18 21:36:51 +03003332 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003333
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003334 GEN3_IRQ_RESET(VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003335 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003336}
3337
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003338static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3339{
3340 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003341 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003342 enum pipe pipe;
3343
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003344 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003345
3346 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3347 for_each_pipe(dev_priv, pipe)
3348 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3349
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003350 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3351 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003352 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3353 I915_LPE_PIPE_A_INTERRUPT |
3354 I915_LPE_PIPE_B_INTERRUPT;
3355
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003356 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003357 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3358 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003359
Chris Wilson8bd099a2017-11-30 12:52:53 +00003360 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003361
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003362 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003363
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003364 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003365}
3366
3367/* drm_dma.h hooks
3368*/
3369static void ironlake_irq_reset(struct drm_device *dev)
3370{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003371 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003372
Ville Syrjäläd420a502017-08-18 21:37:03 +03003373 if (IS_GEN5(dev_priv))
3374 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003375
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003376 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003377 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003378 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3379
Daniel Vetterfc340442018-04-05 15:00:23 -07003380 if (IS_HASWELL(dev_priv)) {
3381 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3382 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3383 }
3384
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003385 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003386
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003387 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003388}
3389
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003390static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003391{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003392 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003393
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003394 I915_WRITE(VLV_MASTER_IER, 0);
3395 POSTING_READ(VLV_MASTER_IER);
3396
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003397 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003398
Ville Syrjäläad22d102016-04-12 18:56:14 +03003399 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003400 if (dev_priv->display_irqs_enabled)
3401 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003402 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003403}
3404
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003405static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3406{
3407 GEN8_IRQ_RESET_NDX(GT, 0);
3408 GEN8_IRQ_RESET_NDX(GT, 1);
3409 GEN8_IRQ_RESET_NDX(GT, 2);
3410 GEN8_IRQ_RESET_NDX(GT, 3);
3411}
3412
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003413static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003414{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003415 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003416 int pipe;
3417
Ben Widawskyabd58f02013-11-02 21:07:09 -07003418 I915_WRITE(GEN8_MASTER_IRQ, 0);
3419 POSTING_READ(GEN8_MASTER_IRQ);
3420
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003421 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003422
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003423 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3424 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3425
Damien Lespiau055e3932014-08-18 13:49:10 +01003426 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003427 if (intel_display_power_is_enabled(dev_priv,
3428 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003429 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003430
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003431 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3432 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3433 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003434
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003435 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003436 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003437}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003438
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003439static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3440{
3441 /* Disable RCS, BCS, VCS and VECS class engines. */
3442 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3443 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3444
3445 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3446 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3447 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3448 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3449 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3450 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003451
3452 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
3453 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003454}
3455
3456static void gen11_irq_reset(struct drm_device *dev)
3457{
3458 struct drm_i915_private *dev_priv = dev->dev_private;
3459 int pipe;
3460
3461 I915_WRITE(GEN11_GFX_MSTR_IRQ, 0);
3462 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3463
3464 gen11_gt_irq_reset(dev_priv);
3465
3466 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3467
3468 for_each_pipe(dev_priv, pipe)
3469 if (intel_display_power_is_enabled(dev_priv,
3470 POWER_DOMAIN_PIPE(pipe)))
3471 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3472
3473 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3474 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3475 GEN3_IRQ_RESET(GEN8_PCU_);
3476}
3477
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003478void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003479 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003480{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003481 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003482 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003483
Daniel Vetter13321782014-09-15 14:55:29 +02003484 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003485
3486 if (!intel_irqs_enabled(dev_priv)) {
3487 spin_unlock_irq(&dev_priv->irq_lock);
3488 return;
3489 }
3490
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003491 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3492 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3493 dev_priv->de_irq_mask[pipe],
3494 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003495
Daniel Vetter13321782014-09-15 14:55:29 +02003496 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003497}
3498
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003499void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003500 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003501{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003502 enum pipe pipe;
3503
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003504 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003505
3506 if (!intel_irqs_enabled(dev_priv)) {
3507 spin_unlock_irq(&dev_priv->irq_lock);
3508 return;
3509 }
3510
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003511 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3512 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003513
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003514 spin_unlock_irq(&dev_priv->irq_lock);
3515
3516 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003517 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003518}
3519
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003520static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003521{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003522 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003523
3524 I915_WRITE(GEN8_MASTER_IRQ, 0);
3525 POSTING_READ(GEN8_MASTER_IRQ);
3526
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003527 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003528
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003529 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003530
Ville Syrjäläad22d102016-04-12 18:56:14 +03003531 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003532 if (dev_priv->display_irqs_enabled)
3533 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003534 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003535}
3536
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003537static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003538 const u32 hpd[HPD_NUM_PINS])
3539{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003540 struct intel_encoder *encoder;
3541 u32 enabled_irqs = 0;
3542
Chris Wilson91c8a322016-07-05 10:40:23 +01003543 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003544 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3545 enabled_irqs |= hpd[encoder->hpd_pin];
3546
3547 return enabled_irqs;
3548}
3549
Imre Deak1a56b1a2017-01-27 11:39:21 +02003550static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3551{
3552 u32 hotplug;
3553
3554 /*
3555 * Enable digital hotplug on the PCH, and configure the DP short pulse
3556 * duration to 2ms (which is the minimum in the Display Port spec).
3557 * The pulse duration bits are reserved on LPT+.
3558 */
3559 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3560 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3561 PORTC_PULSE_DURATION_MASK |
3562 PORTD_PULSE_DURATION_MASK);
3563 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3564 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3565 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3566 /*
3567 * When CPU and PCH are on the same package, port A
3568 * HPD must be enabled in both north and south.
3569 */
3570 if (HAS_PCH_LPT_LP(dev_priv))
3571 hotplug |= PORTA_HOTPLUG_ENABLE;
3572 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3573}
3574
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003575static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003576{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003577 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003578
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003579 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003580 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003581 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003582 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003583 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003584 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003585 }
3586
Daniel Vetterfee884e2013-07-04 23:35:21 +02003587 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003588
Imre Deak1a56b1a2017-01-27 11:39:21 +02003589 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003590}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003591
Imre Deak2a57d9c2017-01-27 11:39:18 +02003592static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3593{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003594 u32 val, hotplug;
3595
3596 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3597 if (HAS_PCH_CNP(dev_priv)) {
3598 val = I915_READ(SOUTH_CHICKEN1);
3599 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3600 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3601 I915_WRITE(SOUTH_CHICKEN1, val);
3602 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003603
3604 /* Enable digital hotplug on the PCH */
3605 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3606 hotplug |= PORTA_HOTPLUG_ENABLE |
3607 PORTB_HOTPLUG_ENABLE |
3608 PORTC_HOTPLUG_ENABLE |
3609 PORTD_HOTPLUG_ENABLE;
3610 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3611
3612 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3613 hotplug |= PORTE_HOTPLUG_ENABLE;
3614 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3615}
3616
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003617static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003618{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003619 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003620
3621 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003622 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003623
3624 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3625
Imre Deak2a57d9c2017-01-27 11:39:18 +02003626 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003627}
3628
Imre Deak1a56b1a2017-01-27 11:39:21 +02003629static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3630{
3631 u32 hotplug;
3632
3633 /*
3634 * Enable digital hotplug on the CPU, and configure the DP short pulse
3635 * duration to 2ms (which is the minimum in the Display Port spec)
3636 * The pulse duration bits are reserved on HSW+.
3637 */
3638 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3639 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3640 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3641 DIGITAL_PORTA_PULSE_DURATION_2ms;
3642 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3643}
3644
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003645static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003646{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003647 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003648
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003649 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003650 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003651 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003652
3653 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003654 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003655 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003656 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003657
3658 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003659 } else {
3660 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003661 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003662
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003663 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3664 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003665
Imre Deak1a56b1a2017-01-27 11:39:21 +02003666 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003667
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003668 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003669}
3670
Imre Deak2a57d9c2017-01-27 11:39:18 +02003671static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3672 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003673{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003674 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003675
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003676 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003677 hotplug |= PORTA_HOTPLUG_ENABLE |
3678 PORTB_HOTPLUG_ENABLE |
3679 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303680
3681 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3682 hotplug, enabled_irqs);
3683 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3684
3685 /*
3686 * For BXT invert bit has to be set based on AOB design
3687 * for HPD detection logic, update it based on VBT fields.
3688 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303689 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3690 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3691 hotplug |= BXT_DDIA_HPD_INVERT;
3692 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3693 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3694 hotplug |= BXT_DDIB_HPD_INVERT;
3695 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3696 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3697 hotplug |= BXT_DDIC_HPD_INVERT;
3698
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003699 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003700}
3701
Imre Deak2a57d9c2017-01-27 11:39:18 +02003702static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3703{
3704 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3705}
3706
3707static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3708{
3709 u32 hotplug_irqs, enabled_irqs;
3710
3711 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3712 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3713
3714 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3715
3716 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3717}
3718
Paulo Zanonid46da432013-02-08 17:35:15 -02003719static void ibx_irq_postinstall(struct drm_device *dev)
3720{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003721 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003722 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003723
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003724 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003725 return;
3726
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003727 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003728 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003729 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003730 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003731 else
3732 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003733
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003734 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003735 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003736
3737 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3738 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003739 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003740 else
3741 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003742}
3743
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003744static void gen5_gt_irq_postinstall(struct drm_device *dev)
3745{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003746 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003747 u32 pm_irqs, gt_irqs;
3748
3749 pm_irqs = gt_irqs = 0;
3750
3751 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003752 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003753 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003754 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3755 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003756 }
3757
3758 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003759 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003760 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003761 } else {
3762 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3763 }
3764
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003765 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003766
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003767 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003768 /*
3769 * RPS interrupts will get enabled/disabled on demand when RPS
3770 * itself is enabled/disabled.
3771 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303772 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003773 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303774 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3775 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003776
Akash Goelf4e9af42016-10-12 21:54:30 +05303777 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003778 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003779 }
3780}
3781
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003782static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003783{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003784 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003785 u32 display_mask, extra_mask;
3786
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003787 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003788 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003789 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003790 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003791 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3792 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003793 } else {
3794 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003795 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3796 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003797 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3798 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3799 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003800 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003801
Daniel Vetterfc340442018-04-05 15:00:23 -07003802 if (IS_HASWELL(dev_priv)) {
3803 gen3_assert_iir_is_zero(dev_priv, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07003804 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Daniel Vetterfc340442018-04-05 15:00:23 -07003805 display_mask |= DE_EDP_PSR_INT_HSW;
3806 }
3807
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003808 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003809
Paulo Zanoni622364b2014-04-01 15:37:22 -03003810 ibx_irq_pre_postinstall(dev);
3811
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003812 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003813
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003814 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003815
Imre Deak1a56b1a2017-01-27 11:39:21 +02003816 ilk_hpd_detection_setup(dev_priv);
3817
Paulo Zanonid46da432013-02-08 17:35:15 -02003818 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003819
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003820 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003821 /* Enable PCU event interrupts
3822 *
3823 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003824 * setup is guaranteed to run in single-threaded context. But we
3825 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003826 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003827 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003828 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003829 }
3830
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003831 return 0;
3832}
3833
Imre Deakf8b79e52014-03-04 19:23:07 +02003834void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3835{
Chris Wilson67520412017-03-02 13:28:01 +00003836 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003837
3838 if (dev_priv->display_irqs_enabled)
3839 return;
3840
3841 dev_priv->display_irqs_enabled = true;
3842
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003843 if (intel_irqs_enabled(dev_priv)) {
3844 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003845 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003846 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003847}
3848
3849void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3850{
Chris Wilson67520412017-03-02 13:28:01 +00003851 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003852
3853 if (!dev_priv->display_irqs_enabled)
3854 return;
3855
3856 dev_priv->display_irqs_enabled = false;
3857
Imre Deak950eaba2014-09-08 15:21:09 +03003858 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003859 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003860}
3861
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003862
3863static int valleyview_irq_postinstall(struct drm_device *dev)
3864{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003865 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003866
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003867 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003868
Ville Syrjäläad22d102016-04-12 18:56:14 +03003869 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003870 if (dev_priv->display_irqs_enabled)
3871 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003872 spin_unlock_irq(&dev_priv->irq_lock);
3873
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003874 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003875 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003876
3877 return 0;
3878}
3879
Ben Widawskyabd58f02013-11-02 21:07:09 -07003880static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3881{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003882 /* These are interrupts we'll toggle with the ring mask register */
3883 uint32_t gt_interrupts[] = {
3884 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003885 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003886 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3887 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003888 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003889 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3890 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3891 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003892 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003893 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3894 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003895 };
3896
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003897 if (HAS_L3_DPF(dev_priv))
3898 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3899
Akash Goelf4e9af42016-10-12 21:54:30 +05303900 dev_priv->pm_ier = 0x0;
3901 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303902 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3903 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003904 /*
3905 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303906 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003907 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303908 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303909 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003910}
3911
3912static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3913{
Damien Lespiau770de832014-03-20 20:45:01 +00003914 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3915 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003916 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3917 u32 de_port_enables;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003918 u32 de_misc_masked = GEN8_DE_MISC_GSE | GEN8_DE_EDP_PSR;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003919 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003920
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003921 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003922 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003923 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3924 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003925 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003926 de_port_masked |= BXT_DE_PORT_GMBUS;
3927 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003928 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003929 }
Damien Lespiau770de832014-03-20 20:45:01 +00003930
Rodrigo Vivia324fca2018-01-29 15:22:15 -08003931 if (IS_CNL_WITH_PORT_F(dev_priv))
3932 de_port_masked |= CNL_AUX_CHANNEL_F;
3933
Damien Lespiau770de832014-03-20 20:45:01 +00003934 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3935 GEN8_PIPE_FIFO_UNDERRUN;
3936
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003937 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003938 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003939 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3940 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003941 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3942
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003943 gen3_assert_iir_is_zero(dev_priv, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07003944 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003945
Mika Kahola0a195c02017-10-10 13:17:04 +03003946 for_each_pipe(dev_priv, pipe) {
3947 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003948
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003949 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003950 POWER_DOMAIN_PIPE(pipe)))
3951 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3952 dev_priv->de_irq_mask[pipe],
3953 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03003954 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07003955
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003956 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3957 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003958
3959 if (IS_GEN9_LP(dev_priv))
3960 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003961 else if (IS_BROADWELL(dev_priv))
3962 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003963}
3964
3965static int gen8_irq_postinstall(struct drm_device *dev)
3966{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003967 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003968
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003969 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303970 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003971
Ben Widawskyabd58f02013-11-02 21:07:09 -07003972 gen8_gt_irq_postinstall(dev_priv);
3973 gen8_de_irq_postinstall(dev_priv);
3974
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003975 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303976 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003977
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003978 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003979 POSTING_READ(GEN8_MASTER_IRQ);
3980
3981 return 0;
3982}
3983
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003984static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3985{
3986 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
3987
3988 BUILD_BUG_ON(irqs & 0xffff0000);
3989
3990 /* Enable RCS, BCS, VCS and VECS class interrupts. */
3991 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
3992 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
3993
3994 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
3995 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
3996 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
3997 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
3998 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
3999 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
4000
Oscar Mateod02b98b2018-04-05 17:00:50 +03004001 /*
4002 * RPS interrupts will get enabled/disabled on demand when RPS itself
4003 * is enabled/disabled.
4004 */
4005 dev_priv->pm_ier = 0x0;
4006 dev_priv->pm_imr = ~dev_priv->pm_ier;
4007 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
4008 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004009}
4010
4011static int gen11_irq_postinstall(struct drm_device *dev)
4012{
4013 struct drm_i915_private *dev_priv = dev->dev_private;
4014
4015 gen11_gt_irq_postinstall(dev_priv);
4016 gen8_de_irq_postinstall(dev_priv);
4017
4018 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
4019
4020 I915_WRITE(GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
4021 POSTING_READ(GEN11_GFX_MSTR_IRQ);
4022
4023 return 0;
4024}
4025
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004026static int cherryview_irq_postinstall(struct drm_device *dev)
4027{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004028 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004029
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004030 gen8_gt_irq_postinstall(dev_priv);
4031
Ville Syrjäläad22d102016-04-12 18:56:14 +03004032 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004033 if (dev_priv->display_irqs_enabled)
4034 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004035 spin_unlock_irq(&dev_priv->irq_lock);
4036
Ville Syrjäläe5328c42016-04-13 21:19:47 +03004037 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004038 POSTING_READ(GEN8_MASTER_IRQ);
4039
4040 return 0;
4041}
4042
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004043static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004044{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004045 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004046
Ville Syrjälä44d92412017-08-18 21:36:51 +03004047 i9xx_pipestat_irq_reset(dev_priv);
4048
Ville Syrjäläd420a502017-08-18 21:37:03 +03004049 I915_WRITE16(HWSTAM, 0xffff);
4050
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004051 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01004052}
4053
4054static int i8xx_irq_postinstall(struct drm_device *dev)
4055{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004056 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004057 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004058
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004059 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
4060 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01004061
4062 /* Unmask the interrupts that we always want on. */
4063 dev_priv->irq_mask =
4064 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004065 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004066
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004067 enable_mask =
4068 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4069 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4070 I915_USER_INTERRUPT;
4071
4072 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004073
Daniel Vetter379ef822013-10-16 22:55:56 +02004074 /* Interrupt setup is already guaranteed to be single-threaded, this is
4075 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004076 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004077 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4078 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004079 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004080
Chris Wilsonc2798b12012-04-22 21:13:57 +01004081 return 0;
4082}
4083
Daniel Vetterff1f5252012-10-02 15:10:55 +02004084static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004085{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004086 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004087 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004088 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004089
Imre Deak2dd2a882015-02-24 11:14:30 +02004090 if (!intel_irqs_enabled(dev_priv))
4091 return IRQ_NONE;
4092
Imre Deak1f814da2015-12-16 02:52:19 +02004093 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4094 disable_rpm_wakeref_asserts(dev_priv);
4095
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004096 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004097 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004098 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03004099
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004100 iir = I915_READ16(IIR);
4101 if (iir == 0)
4102 break;
4103
4104 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004105
Ville Syrjäläeb643432017-08-18 21:36:59 +03004106 /* Call regardless, as some status bits might not be
4107 * signalled in iir */
4108 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004109
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004110 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004111
Chris Wilsonc2798b12012-04-22 21:13:57 +01004112 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304113 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004114
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004115 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4116 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
4117
Ville Syrjäläeb643432017-08-18 21:36:59 +03004118 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004119 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004120
Imre Deak1f814da2015-12-16 02:52:19 +02004121 enable_rpm_wakeref_asserts(dev_priv);
4122
4123 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004124}
4125
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004126static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004127{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004128 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004129
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004130 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004131 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004132 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4133 }
4134
Ville Syrjälä44d92412017-08-18 21:36:51 +03004135 i9xx_pipestat_irq_reset(dev_priv);
4136
Ville Syrjäläd420a502017-08-18 21:37:03 +03004137 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004138
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004139 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004140}
4141
4142static int i915_irq_postinstall(struct drm_device *dev)
4143{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004144 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004145 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004146
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004147 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
4148 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01004149
4150 /* Unmask the interrupts that we always want on. */
4151 dev_priv->irq_mask =
4152 ~(I915_ASLE_INTERRUPT |
4153 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004154 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004155
4156 enable_mask =
4157 I915_ASLE_INTERRUPT |
4158 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4159 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004160 I915_USER_INTERRUPT;
4161
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004162 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004163 /* Enable in IER... */
4164 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4165 /* and unmask in IMR */
4166 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4167 }
4168
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004169 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004170
Daniel Vetter379ef822013-10-16 22:55:56 +02004171 /* Interrupt setup is already guaranteed to be single-threaded, this is
4172 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004173 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004174 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4175 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004176 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004177
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004178 i915_enable_asle_pipestat(dev_priv);
4179
Daniel Vetter20afbda2012-12-11 14:05:07 +01004180 return 0;
4181}
4182
Daniel Vetterff1f5252012-10-02 15:10:55 +02004183static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004184{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004185 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004186 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004187 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004188
Imre Deak2dd2a882015-02-24 11:14:30 +02004189 if (!intel_irqs_enabled(dev_priv))
4190 return IRQ_NONE;
4191
Imre Deak1f814da2015-12-16 02:52:19 +02004192 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4193 disable_rpm_wakeref_asserts(dev_priv);
4194
Chris Wilson38bde182012-04-24 22:59:50 +01004195 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004196 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004197 u32 hotplug_status = 0;
4198 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004199
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004200 iir = I915_READ(IIR);
4201 if (iir == 0)
4202 break;
4203
4204 ret = IRQ_HANDLED;
4205
4206 if (I915_HAS_HOTPLUG(dev_priv) &&
4207 iir & I915_DISPLAY_PORT_INTERRUPT)
4208 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004209
Ville Syrjäläeb643432017-08-18 21:36:59 +03004210 /* Call regardless, as some status bits might not be
4211 * signalled in iir */
4212 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004213
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004214 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004215
Chris Wilsona266c7d2012-04-24 22:59:44 +01004216 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304217 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004218
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004219 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4220 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004221
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004222 if (hotplug_status)
4223 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4224
4225 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4226 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004227
Imre Deak1f814da2015-12-16 02:52:19 +02004228 enable_rpm_wakeref_asserts(dev_priv);
4229
Chris Wilsona266c7d2012-04-24 22:59:44 +01004230 return ret;
4231}
4232
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004233static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004234{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004235 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004236
Egbert Eich0706f172015-09-23 16:15:27 +02004237 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004238 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004239
Ville Syrjälä44d92412017-08-18 21:36:51 +03004240 i9xx_pipestat_irq_reset(dev_priv);
4241
Ville Syrjäläd420a502017-08-18 21:37:03 +03004242 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004243
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004244 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004245}
4246
4247static int i965_irq_postinstall(struct drm_device *dev)
4248{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004249 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004250 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004251 u32 error_mask;
4252
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004253 /*
4254 * Enable some error detection, note the instruction error mask
4255 * bit is reserved, so we leave it masked.
4256 */
4257 if (IS_G4X(dev_priv)) {
4258 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4259 GM45_ERROR_MEM_PRIV |
4260 GM45_ERROR_CP_PRIV |
4261 I915_ERROR_MEMORY_REFRESH);
4262 } else {
4263 error_mask = ~(I915_ERROR_PAGE_TABLE |
4264 I915_ERROR_MEMORY_REFRESH);
4265 }
4266 I915_WRITE(EMR, error_mask);
4267
Chris Wilsona266c7d2012-04-24 22:59:44 +01004268 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004269 dev_priv->irq_mask =
4270 ~(I915_ASLE_INTERRUPT |
4271 I915_DISPLAY_PORT_INTERRUPT |
4272 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4273 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4274 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004275
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004276 enable_mask =
4277 I915_ASLE_INTERRUPT |
4278 I915_DISPLAY_PORT_INTERRUPT |
4279 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4280 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4281 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
4282 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004283
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004284 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004285 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004286
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004287 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
4288
Daniel Vetterb79480b2013-06-27 17:52:10 +02004289 /* Interrupt setup is already guaranteed to be single-threaded, this is
4290 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004291 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004292 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4293 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4294 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004295 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004296
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004297 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004298
4299 return 0;
4300}
4301
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004302static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004303{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004304 u32 hotplug_en;
4305
Chris Wilson67520412017-03-02 13:28:01 +00004306 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004307
Ville Syrjälä778eb332015-01-09 14:21:13 +02004308 /* Note HDMI and DP share hotplug bits */
4309 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004310 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004311 /* Programming the CRT detection parameters tends
4312 to generate a spurious hotplug event about three
4313 seconds later. So just do it once.
4314 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004315 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004316 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004317 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004318
Ville Syrjälä778eb332015-01-09 14:21:13 +02004319 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004320 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004321 HOTPLUG_INT_EN_MASK |
4322 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4323 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4324 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004325}
4326
Daniel Vetterff1f5252012-10-02 15:10:55 +02004327static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004328{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004329 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004330 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004331 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004332
Imre Deak2dd2a882015-02-24 11:14:30 +02004333 if (!intel_irqs_enabled(dev_priv))
4334 return IRQ_NONE;
4335
Imre Deak1f814da2015-12-16 02:52:19 +02004336 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4337 disable_rpm_wakeref_asserts(dev_priv);
4338
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004339 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004340 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004341 u32 hotplug_status = 0;
4342 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004343
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004344 iir = I915_READ(IIR);
4345 if (iir == 0)
4346 break;
4347
4348 ret = IRQ_HANDLED;
4349
4350 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4351 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004352
Ville Syrjäläeb643432017-08-18 21:36:59 +03004353 /* Call regardless, as some status bits might not be
4354 * signalled in iir */
4355 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004356
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004357 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004358
Chris Wilsona266c7d2012-04-24 22:59:44 +01004359 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304360 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004361
Chris Wilsona266c7d2012-04-24 22:59:44 +01004362 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304363 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004364
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004365 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
4366 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004367
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004368 if (hotplug_status)
4369 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4370
4371 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4372 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004373
Imre Deak1f814da2015-12-16 02:52:19 +02004374 enable_rpm_wakeref_asserts(dev_priv);
4375
Chris Wilsona266c7d2012-04-24 22:59:44 +01004376 return ret;
4377}
4378
Daniel Vetterfca52a52014-09-30 10:56:45 +02004379/**
4380 * intel_irq_init - initializes irq support
4381 * @dev_priv: i915 device instance
4382 *
4383 * This function initializes all the irq support including work items, timers
4384 * and all the vtables. It does not setup the interrupt itself though.
4385 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004386void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004387{
Chris Wilson91c8a322016-07-05 10:40:23 +01004388 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004389 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004390 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004391
Jani Nikula77913b32015-06-18 13:06:16 +03004392 intel_hpd_init_work(dev_priv);
4393
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004394 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004395
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004396 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004397 for (i = 0; i < MAX_L3_SLICES; ++i)
4398 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004399
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004400 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304401 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4402
Deepak Sa6706b42014-03-15 20:23:22 +05304403 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004404 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004405 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004406 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004407 else
4408 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304409
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004410 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304411
4412 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004413 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304414 * if GEN6_PM_UP_EI_EXPIRED is masked.
4415 *
4416 * TODO: verify if this can be reproduced on VLV,CHV.
4417 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004418 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004419 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304420
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004421 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004422 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304423
Daniel Vetterb9632912014-09-30 10:56:44 +02004424 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004425 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004426 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004427 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004428 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004429 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004430 } else {
4431 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4432 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004433 }
4434
Ville Syrjälä21da2702014-08-06 14:49:55 +03004435 /*
4436 * Opt out of the vblank disable timer on everything except gen2.
4437 * Gen2 doesn't have a hardware frame counter and so depends on
4438 * vblank interrupts to produce sane vblank seuquence numbers.
4439 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004440 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004441 dev->vblank_disable_immediate = true;
4442
Chris Wilson262fd482017-02-15 13:15:47 +00004443 /* Most platforms treat the display irq block as an always-on
4444 * power domain. vlv/chv can disable it at runtime and need
4445 * special care to avoid writing any of the display block registers
4446 * outside of the power domain. We defer setting up the display irqs
4447 * in this case to the runtime pm.
4448 */
4449 dev_priv->display_irqs_enabled = true;
4450 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4451 dev_priv->display_irqs_enabled = false;
4452
Lyude317eaa92017-02-03 21:18:25 -05004453 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4454
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004455 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004456 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004457
Daniel Vetterb9632912014-09-30 10:56:44 +02004458 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004459 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004460 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004461 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004462 dev->driver->irq_uninstall = cherryview_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;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004465 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004466 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004467 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004468 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004469 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004470 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004471 dev->driver->enable_vblank = i965_enable_vblank;
4472 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004473 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004474 } else if (INTEL_GEN(dev_priv) >= 11) {
4475 dev->driver->irq_handler = gen11_irq_handler;
4476 dev->driver->irq_preinstall = gen11_irq_reset;
4477 dev->driver->irq_postinstall = gen11_irq_postinstall;
4478 dev->driver->irq_uninstall = gen11_irq_reset;
4479 dev->driver->enable_vblank = gen8_enable_vblank;
4480 dev->driver->disable_vblank = gen8_disable_vblank;
4481 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004482 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004483 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004484 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004485 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004486 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004487 dev->driver->enable_vblank = gen8_enable_vblank;
4488 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004489 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004490 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004491 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4492 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004493 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4494 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004495 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004496 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004497 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004498 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004499 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004500 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004501 dev->driver->enable_vblank = ironlake_enable_vblank;
4502 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004503 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004504 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004505 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004506 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004507 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4508 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004509 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004510 dev->driver->enable_vblank = i8xx_enable_vblank;
4511 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004512 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004513 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004514 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004515 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004516 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004517 dev->driver->enable_vblank = i8xx_enable_vblank;
4518 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004519 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004520 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004521 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004522 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004523 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004524 dev->driver->enable_vblank = i965_enable_vblank;
4525 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004526 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004527 if (I915_HAS_HOTPLUG(dev_priv))
4528 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004529 }
4530}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004531
Daniel Vetterfca52a52014-09-30 10:56:45 +02004532/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004533 * intel_irq_fini - deinitializes IRQ support
4534 * @i915: i915 device instance
4535 *
4536 * This function deinitializes all the IRQ support.
4537 */
4538void intel_irq_fini(struct drm_i915_private *i915)
4539{
4540 int i;
4541
4542 for (i = 0; i < MAX_L3_SLICES; ++i)
4543 kfree(i915->l3_parity.remap_info[i]);
4544}
4545
4546/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004547 * intel_irq_install - enables the hardware interrupt
4548 * @dev_priv: i915 device instance
4549 *
4550 * This function enables the hardware interrupt handling, but leaves the hotplug
4551 * handling still disabled. It is called after intel_irq_init().
4552 *
4553 * In the driver load and resume code we need working interrupts in a few places
4554 * but don't want to deal with the hassle of concurrent probe and hotplug
4555 * workers. Hence the split into this two-stage approach.
4556 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004557int intel_irq_install(struct drm_i915_private *dev_priv)
4558{
4559 /*
4560 * We enable some interrupt sources in our postinstall hooks, so mark
4561 * interrupts as enabled _before_ actually enabling them to avoid
4562 * special cases in our ordering checks.
4563 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004564 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004565
Chris Wilson91c8a322016-07-05 10:40:23 +01004566 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004567}
4568
Daniel Vetterfca52a52014-09-30 10:56:45 +02004569/**
4570 * intel_irq_uninstall - finilizes all irq handling
4571 * @dev_priv: i915 device instance
4572 *
4573 * This stops interrupt and hotplug handling and unregisters and frees all
4574 * resources acquired in the init functions.
4575 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004576void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4577{
Chris Wilson91c8a322016-07-05 10:40:23 +01004578 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004579 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004580 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004581}
4582
Daniel Vetterfca52a52014-09-30 10:56:45 +02004583/**
4584 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4585 * @dev_priv: i915 device instance
4586 *
4587 * This function is used to disable interrupts at runtime, both in the runtime
4588 * pm and the system suspend/resume code.
4589 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004590void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004591{
Chris Wilson91c8a322016-07-05 10:40:23 +01004592 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004593 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004594 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004595}
4596
Daniel Vetterfca52a52014-09-30 10:56:45 +02004597/**
4598 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4599 * @dev_priv: i915 device instance
4600 *
4601 * This function is used to enable interrupts at runtime, both in the runtime
4602 * pm and the system suspend/resume code.
4603 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004604void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004605{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004606 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004607 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4608 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004609}