blob: 7fb493b7aa7427a9854f945b0df59aaa2e481b1a [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
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -0700118static const u32 hpd_gen11[HPD_NUM_PINS] = {
119 [HPD_PORT_C] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG,
120 [HPD_PORT_D] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG,
121 [HPD_PORT_E] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG,
122 [HPD_PORT_F] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -0700123};
124
Anusha Srivatsa31604222018-06-26 13:52:23 -0700125static const u32 hpd_icp[HPD_NUM_PINS] = {
126 [HPD_PORT_A] = SDE_DDIA_HOTPLUG_ICP,
127 [HPD_PORT_B] = SDE_DDIB_HOTPLUG_ICP,
128 [HPD_PORT_C] = SDE_TC1_HOTPLUG_ICP,
129 [HPD_PORT_D] = SDE_TC2_HOTPLUG_ICP,
130 [HPD_PORT_E] = SDE_TC3_HOTPLUG_ICP,
131 [HPD_PORT_F] = SDE_TC4_HOTPLUG_ICP
132};
133
Paulo Zanoni5c502442014-04-01 15:37:11 -0300134/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300135#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300136 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
137 POSTING_READ(GEN8_##type##_IMR(which)); \
138 I915_WRITE(GEN8_##type##_IER(which), 0); \
139 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
140 POSTING_READ(GEN8_##type##_IIR(which)); \
141 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
142 POSTING_READ(GEN8_##type##_IIR(which)); \
143} while (0)
144
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300145#define GEN3_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300146 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300147 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300148 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300149 I915_WRITE(type##IIR, 0xffffffff); \
150 POSTING_READ(type##IIR); \
151 I915_WRITE(type##IIR, 0xffffffff); \
152 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300153} while (0)
154
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300155#define GEN2_IRQ_RESET(type) do { \
156 I915_WRITE16(type##IMR, 0xffff); \
157 POSTING_READ16(type##IMR); \
158 I915_WRITE16(type##IER, 0); \
159 I915_WRITE16(type##IIR, 0xffff); \
160 POSTING_READ16(type##IIR); \
161 I915_WRITE16(type##IIR, 0xffff); \
162 POSTING_READ16(type##IIR); \
163} while (0)
164
Paulo Zanoni337ba012014-04-01 15:37:16 -0300165/*
166 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
167 */
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300168static void gen3_assert_iir_is_zero(struct drm_i915_private *dev_priv,
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200169 i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300170{
171 u32 val = I915_READ(reg);
172
173 if (val == 0)
174 return;
175
176 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200177 i915_mmio_reg_offset(reg), val);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300178 I915_WRITE(reg, 0xffffffff);
179 POSTING_READ(reg);
180 I915_WRITE(reg, 0xffffffff);
181 POSTING_READ(reg);
182}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300183
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300184static void gen2_assert_iir_is_zero(struct drm_i915_private *dev_priv,
185 i915_reg_t reg)
186{
187 u16 val = I915_READ16(reg);
188
189 if (val == 0)
190 return;
191
192 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
193 i915_mmio_reg_offset(reg), val);
194 I915_WRITE16(reg, 0xffff);
195 POSTING_READ16(reg);
196 I915_WRITE16(reg, 0xffff);
197 POSTING_READ16(reg);
198}
199
Paulo Zanoni35079892014-04-01 15:37:15 -0300200#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300201 gen3_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300202 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200203 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
204 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300205} while (0)
206
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300207#define GEN3_IRQ_INIT(type, imr_val, ier_val) do { \
208 gen3_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300209 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200210 I915_WRITE(type##IMR, (imr_val)); \
211 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300212} while (0)
213
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300214#define GEN2_IRQ_INIT(type, imr_val, ier_val) do { \
215 gen2_assert_iir_is_zero(dev_priv, type##IIR); \
216 I915_WRITE16(type##IER, (ier_val)); \
217 I915_WRITE16(type##IMR, (imr_val)); \
218 POSTING_READ16(type##IMR); \
219} while (0)
220
Imre Deakc9a9a262014-11-05 20:48:37 +0200221static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530222static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Imre Deakc9a9a262014-11-05 20:48:37 +0200223
Egbert Eich0706f172015-09-23 16:15:27 +0200224/* For display hotplug interrupt */
225static inline void
226i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
227 uint32_t mask,
228 uint32_t bits)
229{
230 uint32_t val;
231
Chris Wilson67520412017-03-02 13:28:01 +0000232 lockdep_assert_held(&dev_priv->irq_lock);
Egbert Eich0706f172015-09-23 16:15:27 +0200233 WARN_ON(bits & ~mask);
234
235 val = I915_READ(PORT_HOTPLUG_EN);
236 val &= ~mask;
237 val |= bits;
238 I915_WRITE(PORT_HOTPLUG_EN, val);
239}
240
241/**
242 * i915_hotplug_interrupt_update - update hotplug interrupt enable
243 * @dev_priv: driver private
244 * @mask: bits to update
245 * @bits: bits to enable
246 * NOTE: the HPD enable bits are modified both inside and outside
247 * of an interrupt context. To avoid that read-modify-write cycles
248 * interfer, these bits are protected by a spinlock. Since this
249 * function is usually not called from a context where the lock is
250 * held already, this function acquires the lock itself. A non-locking
251 * version is also available.
252 */
253void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
254 uint32_t mask,
255 uint32_t bits)
256{
257 spin_lock_irq(&dev_priv->irq_lock);
258 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
259 spin_unlock_irq(&dev_priv->irq_lock);
260}
261
Oscar Mateo96606f32018-04-06 12:32:37 +0300262static u32
263gen11_gt_engine_identity(struct drm_i915_private * const i915,
264 const unsigned int bank, const unsigned int bit);
265
Oscar Mateoff047a82018-04-24 14:39:55 -0700266bool gen11_reset_one_iir(struct drm_i915_private * const i915,
267 const unsigned int bank,
268 const unsigned int bit)
Oscar Mateo96606f32018-04-06 12:32:37 +0300269{
270 void __iomem * const regs = i915->regs;
271 u32 dw;
272
273 lockdep_assert_held(&i915->irq_lock);
274
275 dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
276 if (dw & BIT(bit)) {
277 /*
278 * According to the BSpec, DW_IIR bits cannot be cleared without
279 * first servicing the Selector & Shared IIR registers.
280 */
281 gen11_gt_engine_identity(i915, bank, bit);
282
283 /*
284 * We locked GT INT DW by reading it. If we want to (try
285 * to) recover from this succesfully, we need to clear
286 * our bit, otherwise we are locking the register for
287 * everybody.
288 */
289 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), BIT(bit));
290
291 return true;
292 }
293
294 return false;
295}
296
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300297/**
298 * ilk_update_display_irq - update DEIMR
299 * @dev_priv: driver private
300 * @interrupt_mask: mask of interrupt bits to update
301 * @enabled_irq_mask: mask of interrupt bits to enable
302 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200303void ilk_update_display_irq(struct drm_i915_private *dev_priv,
304 uint32_t interrupt_mask,
305 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800306{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300307 uint32_t new_val;
308
Chris Wilson67520412017-03-02 13:28:01 +0000309 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200310
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300311 WARN_ON(enabled_irq_mask & ~interrupt_mask);
312
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700313 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300314 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300315
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300316 new_val = dev_priv->irq_mask;
317 new_val &= ~interrupt_mask;
318 new_val |= (~enabled_irq_mask & interrupt_mask);
319
320 if (new_val != dev_priv->irq_mask) {
321 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000322 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000323 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800324 }
325}
326
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300327/**
328 * ilk_update_gt_irq - update GTIMR
329 * @dev_priv: driver private
330 * @interrupt_mask: mask of interrupt bits to update
331 * @enabled_irq_mask: mask of interrupt bits to enable
332 */
333static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
334 uint32_t interrupt_mask,
335 uint32_t enabled_irq_mask)
336{
Chris Wilson67520412017-03-02 13:28:01 +0000337 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300338
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100339 WARN_ON(enabled_irq_mask & ~interrupt_mask);
340
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700341 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300342 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300343
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300344 dev_priv->gt_irq_mask &= ~interrupt_mask;
345 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
346 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300347}
348
Daniel Vetter480c8032014-07-16 09:49:40 +0200349void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300350{
351 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100352 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300353}
354
Daniel Vetter480c8032014-07-16 09:49:40 +0200355void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300356{
357 ilk_update_gt_irq(dev_priv, mask, 0);
358}
359
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200360static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200361{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300362 WARN_ON_ONCE(INTEL_GEN(dev_priv) >= 11);
363
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700364 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
Imre Deakb900b942014-11-05 20:48:48 +0200365}
366
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200367static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200368{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300369 if (INTEL_GEN(dev_priv) >= 11)
370 return GEN11_GPM_WGBOXPERF_INTR_MASK;
371 else if (INTEL_GEN(dev_priv) >= 8)
372 return GEN8_GT_IMR(2);
373 else
374 return GEN6_PMIMR;
Imre Deaka72fbc32014-11-05 20:48:31 +0200375}
376
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200377static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200378{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300379 if (INTEL_GEN(dev_priv) >= 11)
380 return GEN11_GPM_WGBOXPERF_INTR_ENABLE;
381 else if (INTEL_GEN(dev_priv) >= 8)
382 return GEN8_GT_IER(2);
383 else
384 return GEN6_PMIER;
Imre Deakb900b942014-11-05 20:48:48 +0200385}
386
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300387/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200388 * snb_update_pm_irq - update GEN6_PMIMR
389 * @dev_priv: driver private
390 * @interrupt_mask: mask of interrupt bits to update
391 * @enabled_irq_mask: mask of interrupt bits to enable
392 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300393static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
394 uint32_t interrupt_mask,
395 uint32_t enabled_irq_mask)
396{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300397 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300398
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100399 WARN_ON(enabled_irq_mask & ~interrupt_mask);
400
Chris Wilson67520412017-03-02 13:28:01 +0000401 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300402
Akash Goelf4e9af42016-10-12 21:54:30 +0530403 new_val = dev_priv->pm_imr;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300404 new_val &= ~interrupt_mask;
405 new_val |= (~enabled_irq_mask & interrupt_mask);
406
Akash Goelf4e9af42016-10-12 21:54:30 +0530407 if (new_val != dev_priv->pm_imr) {
408 dev_priv->pm_imr = new_val;
409 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_imr);
Imre Deaka72fbc32014-11-05 20:48:31 +0200410 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300411 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300412}
413
Akash Goelf4e9af42016-10-12 21:54:30 +0530414void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300415{
Imre Deak9939fba2014-11-20 23:01:47 +0200416 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
417 return;
418
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300419 snb_update_pm_irq(dev_priv, mask, mask);
420}
421
Akash Goelf4e9af42016-10-12 21:54:30 +0530422static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Imre Deak9939fba2014-11-20 23:01:47 +0200423{
424 snb_update_pm_irq(dev_priv, mask, 0);
425}
426
Akash Goelf4e9af42016-10-12 21:54:30 +0530427void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300428{
Imre Deak9939fba2014-11-20 23:01:47 +0200429 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
430 return;
431
Akash Goelf4e9af42016-10-12 21:54:30 +0530432 __gen6_mask_pm_irq(dev_priv, mask);
433}
434
Oscar Mateo3814fd72017-08-23 16:58:24 -0700435static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530436{
437 i915_reg_t reg = gen6_pm_iir(dev_priv);
438
Chris Wilson67520412017-03-02 13:28:01 +0000439 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530440
441 I915_WRITE(reg, reset_mask);
442 I915_WRITE(reg, reset_mask);
443 POSTING_READ(reg);
444}
445
Oscar Mateo3814fd72017-08-23 16:58:24 -0700446static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530447{
Chris Wilson67520412017-03-02 13:28:01 +0000448 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530449
450 dev_priv->pm_ier |= enable_mask;
451 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
452 gen6_unmask_pm_irq(dev_priv, enable_mask);
453 /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */
454}
455
Oscar Mateo3814fd72017-08-23 16:58:24 -0700456static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530457{
Chris Wilson67520412017-03-02 13:28:01 +0000458 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530459
460 dev_priv->pm_ier &= ~disable_mask;
461 __gen6_mask_pm_irq(dev_priv, disable_mask);
462 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
463 /* though a barrier is missing here, but don't really need a one */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300464}
465
Oscar Mateod02b98b2018-04-05 17:00:50 +0300466void gen11_reset_rps_interrupts(struct drm_i915_private *dev_priv)
467{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300468 spin_lock_irq(&dev_priv->irq_lock);
469
Oscar Mateo96606f32018-04-06 12:32:37 +0300470 while (gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM))
471 ;
Oscar Mateod02b98b2018-04-05 17:00:50 +0300472
473 dev_priv->gt_pm.rps.pm_iir = 0;
474
475 spin_unlock_irq(&dev_priv->irq_lock);
476}
477
Chris Wilsondc979972016-05-10 14:10:04 +0100478void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200479{
Imre Deak3cc134e2014-11-19 15:30:03 +0200480 spin_lock_irq(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530481 gen6_reset_pm_iir(dev_priv, dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100482 dev_priv->gt_pm.rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200483 spin_unlock_irq(&dev_priv->irq_lock);
484}
485
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100486void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200487{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100488 struct intel_rps *rps = &dev_priv->gt_pm.rps;
489
490 if (READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100491 return;
492
Imre Deakb900b942014-11-05 20:48:48 +0200493 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100494 WARN_ON_ONCE(rps->pm_iir);
Oscar Mateo96606f32018-04-06 12:32:37 +0300495
Oscar Mateod02b98b2018-04-05 17:00:50 +0300496 if (INTEL_GEN(dev_priv) >= 11)
Oscar Mateo96606f32018-04-06 12:32:37 +0300497 WARN_ON_ONCE(gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM));
Oscar Mateod02b98b2018-04-05 17:00:50 +0300498 else
499 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Oscar Mateo96606f32018-04-06 12:32:37 +0300500
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100501 rps->interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200502 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200503
Imre Deakb900b942014-11-05 20:48:48 +0200504 spin_unlock_irq(&dev_priv->irq_lock);
505}
506
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100507void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200508{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100509 struct intel_rps *rps = &dev_priv->gt_pm.rps;
510
511 if (!READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100512 return;
513
Imre Deakd4d70aa2014-11-19 15:30:04 +0200514 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100515 rps->interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200516
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100517 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200518
Akash Goelf4e9af42016-10-12 21:54:30 +0530519 gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200520
521 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100522 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100523
524 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700525 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100526 * we will reset the GPU to minimum frequencies, so the current
527 * state of the worker can be discarded.
528 */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100529 cancel_work_sync(&rps->work);
Oscar Mateod02b98b2018-04-05 17:00:50 +0300530 if (INTEL_GEN(dev_priv) >= 11)
531 gen11_reset_rps_interrupts(dev_priv);
532 else
533 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200534}
535
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530536void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
537{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530538 assert_rpm_wakelock_held(dev_priv);
539
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530540 spin_lock_irq(&dev_priv->irq_lock);
541 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
542 spin_unlock_irq(&dev_priv->irq_lock);
543}
544
545void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
546{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530547 assert_rpm_wakelock_held(dev_priv);
548
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530549 spin_lock_irq(&dev_priv->irq_lock);
550 if (!dev_priv->guc.interrupts_enabled) {
551 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
552 dev_priv->pm_guc_events);
553 dev_priv->guc.interrupts_enabled = true;
554 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
555 }
556 spin_unlock_irq(&dev_priv->irq_lock);
557}
558
559void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
560{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530561 assert_rpm_wakelock_held(dev_priv);
562
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530563 spin_lock_irq(&dev_priv->irq_lock);
564 dev_priv->guc.interrupts_enabled = false;
565
566 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
567
568 spin_unlock_irq(&dev_priv->irq_lock);
569 synchronize_irq(dev_priv->drm.irq);
570
571 gen9_reset_guc_interrupts(dev_priv);
572}
573
Ben Widawsky09610212014-05-15 20:58:08 +0300574/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200575 * bdw_update_port_irq - update DE port interrupt
576 * @dev_priv: driver private
577 * @interrupt_mask: mask of interrupt bits to update
578 * @enabled_irq_mask: mask of interrupt bits to enable
579 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300580static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
581 uint32_t interrupt_mask,
582 uint32_t enabled_irq_mask)
583{
584 uint32_t new_val;
585 uint32_t old_val;
586
Chris Wilson67520412017-03-02 13:28:01 +0000587 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300588
589 WARN_ON(enabled_irq_mask & ~interrupt_mask);
590
591 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
592 return;
593
594 old_val = I915_READ(GEN8_DE_PORT_IMR);
595
596 new_val = old_val;
597 new_val &= ~interrupt_mask;
598 new_val |= (~enabled_irq_mask & interrupt_mask);
599
600 if (new_val != old_val) {
601 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
602 POSTING_READ(GEN8_DE_PORT_IMR);
603 }
604}
605
606/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200607 * bdw_update_pipe_irq - update DE pipe interrupt
608 * @dev_priv: driver private
609 * @pipe: pipe whose interrupt to update
610 * @interrupt_mask: mask of interrupt bits to update
611 * @enabled_irq_mask: mask of interrupt bits to enable
612 */
613void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
614 enum pipe pipe,
615 uint32_t interrupt_mask,
616 uint32_t enabled_irq_mask)
617{
618 uint32_t new_val;
619
Chris Wilson67520412017-03-02 13:28:01 +0000620 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200621
622 WARN_ON(enabled_irq_mask & ~interrupt_mask);
623
624 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
625 return;
626
627 new_val = dev_priv->de_irq_mask[pipe];
628 new_val &= ~interrupt_mask;
629 new_val |= (~enabled_irq_mask & interrupt_mask);
630
631 if (new_val != dev_priv->de_irq_mask[pipe]) {
632 dev_priv->de_irq_mask[pipe] = new_val;
633 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
634 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
635 }
636}
637
638/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200639 * ibx_display_interrupt_update - update SDEIMR
640 * @dev_priv: driver private
641 * @interrupt_mask: mask of interrupt bits to update
642 * @enabled_irq_mask: mask of interrupt bits to enable
643 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200644void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
645 uint32_t interrupt_mask,
646 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200647{
648 uint32_t sdeimr = I915_READ(SDEIMR);
649 sdeimr &= ~interrupt_mask;
650 sdeimr |= (~enabled_irq_mask & interrupt_mask);
651
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100652 WARN_ON(enabled_irq_mask & ~interrupt_mask);
653
Chris Wilson67520412017-03-02 13:28:01 +0000654 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200655
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700656 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300657 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300658
Daniel Vetterfee884e2013-07-04 23:35:21 +0200659 I915_WRITE(SDEIMR, sdeimr);
660 POSTING_READ(SDEIMR);
661}
Paulo Zanoni86642812013-04-12 17:57:57 -0300662
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300663u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
664 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800665{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300666 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200667 u32 enable_mask = status_mask << 16;
668
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300669 lockdep_assert_held(&dev_priv->irq_lock);
670
671 if (INTEL_GEN(dev_priv) < 5)
672 goto out;
673
Imre Deak10c59c52014-02-10 18:42:48 +0200674 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300675 * On pipe A we don't support the PSR interrupt yet,
676 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200677 */
678 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
679 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300680 /*
681 * On pipe B and C we don't support the PSR interrupt yet, on pipe
682 * A the same bit is for perf counters which we don't use either.
683 */
684 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
685 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200686
687 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
688 SPRITE0_FLIP_DONE_INT_EN_VLV |
689 SPRITE1_FLIP_DONE_INT_EN_VLV);
690 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
691 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
692 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
693 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
694
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300695out:
696 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
697 status_mask & ~PIPESTAT_INT_STATUS_MASK,
698 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
699 pipe_name(pipe), enable_mask, status_mask);
700
Imre Deak10c59c52014-02-10 18:42:48 +0200701 return enable_mask;
702}
703
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300704void i915_enable_pipestat(struct drm_i915_private *dev_priv,
705 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200706{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300707 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200708 u32 enable_mask;
709
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300710 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
711 "pipe %c: status_mask=0x%x\n",
712 pipe_name(pipe), status_mask);
713
714 lockdep_assert_held(&dev_priv->irq_lock);
715 WARN_ON(!intel_irqs_enabled(dev_priv));
716
717 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
718 return;
719
720 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
721 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
722
723 I915_WRITE(reg, enable_mask | status_mask);
724 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200725}
726
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300727void i915_disable_pipestat(struct drm_i915_private *dev_priv,
728 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200729{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300730 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200731 u32 enable_mask;
732
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300733 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
734 "pipe %c: status_mask=0x%x\n",
735 pipe_name(pipe), status_mask);
736
737 lockdep_assert_held(&dev_priv->irq_lock);
738 WARN_ON(!intel_irqs_enabled(dev_priv));
739
740 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
741 return;
742
743 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
744 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
745
746 I915_WRITE(reg, enable_mask | status_mask);
747 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200748}
749
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000750/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300751 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100752 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000753 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100754static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000755{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100756 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300757 return;
758
Daniel Vetter13321782014-09-15 14:55:29 +0200759 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000760
Imre Deak755e9012014-02-10 18:42:47 +0200761 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100762 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200763 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200764 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000765
Daniel Vetter13321782014-09-15 14:55:29 +0200766 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000767}
768
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300769/*
770 * This timing diagram depicts the video signal in and
771 * around the vertical blanking period.
772 *
773 * Assumptions about the fictitious mode used in this example:
774 * vblank_start >= 3
775 * vsync_start = vblank_start + 1
776 * vsync_end = vblank_start + 2
777 * vtotal = vblank_start + 3
778 *
779 * start of vblank:
780 * latch double buffered registers
781 * increment frame counter (ctg+)
782 * generate start of vblank interrupt (gen4+)
783 * |
784 * | frame start:
785 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
786 * | may be shifted forward 1-3 extra lines via PIPECONF
787 * | |
788 * | | start of vsync:
789 * | | generate vsync interrupt
790 * | | |
791 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
792 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
793 * ----va---> <-----------------vb--------------------> <--------va-------------
794 * | | <----vs-----> |
795 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
796 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
797 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
798 * | | |
799 * last visible pixel first visible pixel
800 * | increment frame counter (gen3/4)
801 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
802 *
803 * x = horizontal active
804 * _ = horizontal blanking
805 * hs = horizontal sync
806 * va = vertical active
807 * vb = vertical blanking
808 * vs = vertical sync
809 * vbs = vblank_start (number)
810 *
811 * Summary:
812 * - most events happen at the start of horizontal sync
813 * - frame start happens at the start of horizontal blank, 1-4 lines
814 * (depending on PIPECONF settings) after the start of vblank
815 * - gen3/4 pixel and frame counter are synchronized with the start
816 * of horizontal active on the first line of vertical active
817 */
818
Keith Packard42f52ef2008-10-18 19:39:29 -0700819/* Called from drm generic code, passed a 'crtc', which
820 * we use as a pipe index
821 */
Thierry Reding88e72712015-09-24 18:35:31 +0200822static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700823{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100824 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200825 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300826 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200827 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200828 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700829
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100830 htotal = mode->crtc_htotal;
831 hsync_start = mode->crtc_hsync_start;
832 vbl_start = mode->crtc_vblank_start;
833 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
834 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300835
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300836 /* Convert to pixel count */
837 vbl_start *= htotal;
838
839 /* Start of vblank event occurs at start of hsync */
840 vbl_start -= htotal - hsync_start;
841
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800842 high_frame = PIPEFRAME(pipe);
843 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100844
Ville Syrjälä694e4092017-03-09 17:44:30 +0200845 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
846
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700847 /*
848 * High & low register fields aren't synchronized, so make sure
849 * we get a low value that's stable across two reads of the high
850 * register.
851 */
852 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200853 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
854 low = I915_READ_FW(low_frame);
855 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700856 } while (high1 != high2);
857
Ville Syrjälä694e4092017-03-09 17:44:30 +0200858 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
859
Chris Wilson5eddb702010-09-11 13:48:45 +0100860 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300861 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100862 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300863
864 /*
865 * The frame counter increments at beginning of active.
866 * Cook up a vblank counter by also checking the pixel
867 * counter against vblank start.
868 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200869 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700870}
871
Dave Airlie974e59b2015-10-30 09:45:33 +1000872static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800873{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100874 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800875
Ville Syrjälä649636e2015-09-22 19:50:01 +0300876 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800877}
878
Uma Shankaraec02462017-09-25 19:26:01 +0530879/*
880 * On certain encoders on certain platforms, pipe
881 * scanline register will not work to get the scanline,
882 * since the timings are driven from the PORT or issues
883 * with scanline register updates.
884 * This function will use Framestamp and current
885 * timestamp registers to calculate the scanline.
886 */
887static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
888{
889 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
890 struct drm_vblank_crtc *vblank =
891 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
892 const struct drm_display_mode *mode = &vblank->hwmode;
893 u32 vblank_start = mode->crtc_vblank_start;
894 u32 vtotal = mode->crtc_vtotal;
895 u32 htotal = mode->crtc_htotal;
896 u32 clock = mode->crtc_clock;
897 u32 scanline, scan_prev_time, scan_curr_time, scan_post_time;
898
899 /*
900 * To avoid the race condition where we might cross into the
901 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
902 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
903 * during the same frame.
904 */
905 do {
906 /*
907 * This field provides read back of the display
908 * pipe frame time stamp. The time stamp value
909 * is sampled at every start of vertical blank.
910 */
911 scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
912
913 /*
914 * The TIMESTAMP_CTR register has the current
915 * time stamp value.
916 */
917 scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR);
918
919 scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
920 } while (scan_post_time != scan_prev_time);
921
922 scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
923 clock), 1000 * htotal);
924 scanline = min(scanline, vtotal - 1);
925 scanline = (scanline + vblank_start) % vtotal;
926
927 return scanline;
928}
929
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300930/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300931static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
932{
933 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100934 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200935 const struct drm_display_mode *mode;
936 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300937 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300938 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300939
Ville Syrjälä72259532017-03-02 19:15:05 +0200940 if (!crtc->active)
941 return -1;
942
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200943 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
944 mode = &vblank->hwmode;
945
Uma Shankaraec02462017-09-25 19:26:01 +0530946 if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
947 return __intel_get_crtc_scanline_from_timestamp(crtc);
948
Ville Syrjälä80715b22014-05-15 20:23:23 +0300949 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300950 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
951 vtotal /= 2;
952
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100953 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300954 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300955 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300956 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300957
958 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700959 * On HSW, the DSL reg (0x70000) appears to return 0 if we
960 * read it just before the start of vblank. So try it again
961 * so we don't accidentally end up spanning a vblank frame
962 * increment, causing the pipe_update_end() code to squak at us.
963 *
964 * The nature of this problem means we can't simply check the ISR
965 * bit and return the vblank start value; nor can we use the scanline
966 * debug register in the transcoder as it appears to have the same
967 * problem. We may need to extend this to include other platforms,
968 * but so far testing only shows the problem on HSW.
969 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100970 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700971 int i, temp;
972
973 for (i = 0; i < 100; i++) {
974 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200975 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700976 if (temp != position) {
977 position = temp;
978 break;
979 }
980 }
981 }
982
983 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300984 * See update_scanline_offset() for the details on the
985 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300986 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300987 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300988}
989
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200990static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
991 bool in_vblank_irq, int *vpos, int *hpos,
992 ktime_t *stime, ktime_t *etime,
993 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100994{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100995 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200996 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
997 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300998 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300999 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +01001000 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001001
Maarten Lankhorstfc467a222015-06-01 12:50:07 +02001002 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001003 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001004 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001005 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001006 }
1007
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03001008 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001009 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03001010 vtotal = mode->crtc_vtotal;
1011 vbl_start = mode->crtc_vblank_start;
1012 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001013
Ville Syrjäläd31faf62013-10-28 16:31:41 +02001014 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1015 vbl_start = DIV_ROUND_UP(vbl_start, 2);
1016 vbl_end /= 2;
1017 vtotal /= 2;
1018 }
1019
Mario Kleinerad3543e2013-10-30 05:13:08 +01001020 /*
1021 * Lock uncore.lock, as we will do multiple timing critical raw
1022 * register reads, potentially with preemption disabled, so the
1023 * following code must not block on uncore.lock.
1024 */
1025 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001026
Mario Kleinerad3543e2013-10-30 05:13:08 +01001027 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
1028
1029 /* Get optional system timestamp before query. */
1030 if (stime)
1031 *stime = ktime_get();
1032
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001033 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001034 /* No obvious pixelcount register. Only query vertical
1035 * scanout position from Display scan line register.
1036 */
Ville Syrjäläa225f072014-04-29 13:35:45 +03001037 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001038 } else {
1039 /* Have access to pixelcount since start of frame.
1040 * We can split this into vertical and horizontal
1041 * scanout position.
1042 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001043 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001044
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001045 /* convert to pixel counts */
1046 vbl_start *= htotal;
1047 vbl_end *= htotal;
1048 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001049
1050 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +03001051 * In interlaced modes, the pixel counter counts all pixels,
1052 * so one field will have htotal more pixels. In order to avoid
1053 * the reported position from jumping backwards when the pixel
1054 * counter is beyond the length of the shorter field, just
1055 * clamp the position the length of the shorter field. This
1056 * matches how the scanline counter based position works since
1057 * the scanline counter doesn't count the two half lines.
1058 */
1059 if (position >= vtotal)
1060 position = vtotal - 1;
1061
1062 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001063 * Start of vblank interrupt is triggered at start of hsync,
1064 * just prior to the first active line of vblank. However we
1065 * consider lines to start at the leading edge of horizontal
1066 * active. So, should we get here before we've crossed into
1067 * the horizontal active of the first line in vblank, we would
1068 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
1069 * always add htotal-hsync_start to the current pixel position.
1070 */
1071 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001072 }
1073
Mario Kleinerad3543e2013-10-30 05:13:08 +01001074 /* Get optional system timestamp after query. */
1075 if (etime)
1076 *etime = ktime_get();
1077
1078 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1079
1080 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1081
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001082 /*
1083 * While in vblank, position will be negative
1084 * counting up towards 0 at vbl_end. And outside
1085 * vblank, position will be positive counting
1086 * up since vbl_end.
1087 */
1088 if (position >= vbl_start)
1089 position -= vbl_end;
1090 else
1091 position += vtotal - vbl_end;
1092
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001093 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001094 *vpos = position;
1095 *hpos = 0;
1096 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001097 *vpos = position / htotal;
1098 *hpos = position - (*vpos * htotal);
1099 }
1100
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001101 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001102}
1103
Ville Syrjäläa225f072014-04-29 13:35:45 +03001104int intel_get_crtc_scanline(struct intel_crtc *crtc)
1105{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001106 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +03001107 unsigned long irqflags;
1108 int position;
1109
1110 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1111 position = __intel_get_crtc_scanline(crtc);
1112 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1113
1114 return position;
1115}
1116
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001117static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001118{
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001119 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001120 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001121
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001122 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001123
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001124 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1125
Daniel Vetter20e4d402012-08-08 23:35:39 +02001126 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001127
Jesse Barnes7648fa92010-05-20 14:28:11 -07001128 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001129 busy_up = I915_READ(RCPREVBSYTUPAVG);
1130 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001131 max_avg = I915_READ(RCBMAXAVG);
1132 min_avg = I915_READ(RCBMINAVG);
1133
1134 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001135 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001136 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1137 new_delay = dev_priv->ips.cur_delay - 1;
1138 if (new_delay < dev_priv->ips.max_delay)
1139 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001140 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001141 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1142 new_delay = dev_priv->ips.cur_delay + 1;
1143 if (new_delay > dev_priv->ips.min_delay)
1144 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001145 }
1146
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001147 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001148 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001149
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001150 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001151
Jesse Barnesf97108d2010-01-29 11:27:07 -08001152 return;
1153}
1154
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001155static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001156{
Chris Wilson3f883252018-06-27 21:13:01 +01001157 const u32 seqno = intel_engine_get_seqno(engine);
Chris Wilsone61e0f52018-02-21 09:56:36 +00001158 struct i915_request *rq = NULL;
Chris Wilson3f883252018-06-27 21:13:01 +01001159 struct task_struct *tsk = NULL;
Chris Wilson56299fb2017-02-27 20:58:48 +00001160 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001161
Chris Wilson3f883252018-06-27 21:13:01 +01001162 if (unlikely(!engine->breadcrumbs.irq_armed))
Chris Wilsonbcbd5c32017-10-25 15:39:42 +01001163 return;
1164
Chris Wilson3f883252018-06-27 21:13:01 +01001165 rcu_read_lock();
Chris Wilson56299fb2017-02-27 20:58:48 +00001166
Chris Wilson61d3dc72017-03-03 19:08:24 +00001167 spin_lock(&engine->breadcrumbs.irq_lock);
1168 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001169 if (wait) {
Chris Wilson3f883252018-06-27 21:13:01 +01001170 /*
1171 * We use a callback from the dma-fence to submit
Chris Wilson56299fb2017-02-27 20:58:48 +00001172 * requests after waiting on our own requests. To
1173 * ensure minimum delay in queuing the next request to
1174 * hardware, signal the fence now rather than wait for
1175 * the signaler to be woken up. We still wake up the
1176 * waiter in order to handle the irq-seqno coherency
1177 * issues (we may receive the interrupt before the
1178 * seqno is written, see __i915_request_irq_complete())
1179 * and to handle coalescing of multiple seqno updates
1180 * and many waiters.
1181 */
Chris Wilson3f883252018-06-27 21:13:01 +01001182 if (i915_seqno_passed(seqno, wait->seqno)) {
Chris Wilsone61e0f52018-02-21 09:56:36 +00001183 struct i915_request *waiter = wait->request;
Chris Wilsonde4d2102017-09-18 17:27:34 +01001184
Chris Wilsone3be4072018-06-27 21:13:04 +01001185 if (waiter &&
1186 !test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Chris Wilsonde4d2102017-09-18 17:27:34 +01001187 &waiter->fence.flags) &&
1188 intel_wait_check_request(wait, waiter))
Chris Wilsone61e0f52018-02-21 09:56:36 +00001189 rq = i915_request_get(waiter);
Chris Wilson56299fb2017-02-27 20:58:48 +00001190
Chris Wilson3f883252018-06-27 21:13:01 +01001191 tsk = wait->tsk;
1192 } else {
Chris Wilson69dc4d02018-06-27 21:13:02 +01001193 if (engine->irq_seqno_barrier &&
1194 i915_seqno_passed(seqno, wait->seqno - 1)) {
Chris Wilson3f883252018-06-27 21:13:01 +01001195 set_bit(ENGINE_IRQ_BREADCRUMB,
1196 &engine->irq_posted);
1197 tsk = wait->tsk;
1198 }
1199 }
Chris Wilson78796872018-06-27 21:13:03 +01001200
1201 engine->breadcrumbs.irq_count++;
Chris Wilson67b807a82017-02-27 20:58:50 +00001202 } else {
Chris Wilsonbcbd5c32017-10-25 15:39:42 +01001203 if (engine->breadcrumbs.irq_armed)
1204 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001205 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001206 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001207
Chris Wilson24754d72017-03-03 14:45:57 +00001208 if (rq) {
Chris Wilsone3be4072018-06-27 21:13:04 +01001209 spin_lock(&rq->lock);
1210 dma_fence_signal_locked(&rq->fence);
Chris Wilson4e9a8be2018-03-05 10:41:05 +00001211 GEM_BUG_ON(!i915_request_completed(rq));
Chris Wilsone3be4072018-06-27 21:13:04 +01001212 spin_unlock(&rq->lock);
1213
Chris Wilsone61e0f52018-02-21 09:56:36 +00001214 i915_request_put(rq);
Chris Wilson24754d72017-03-03 14:45:57 +00001215 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001216
Chris Wilson3f883252018-06-27 21:13:01 +01001217 if (tsk && tsk->state & TASK_NORMAL)
1218 wake_up_process(tsk);
1219
1220 rcu_read_unlock();
1221
Chris Wilson56299fb2017-02-27 20:58:48 +00001222 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001223}
1224
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001225static void vlv_c0_read(struct drm_i915_private *dev_priv,
1226 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001227{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001228 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001229 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1230 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001231}
1232
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001233void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1234{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001235 memset(&dev_priv->gt_pm.rps.ei, 0, sizeof(dev_priv->gt_pm.rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001236}
1237
1238static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1239{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001240 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1241 const struct intel_rps_ei *prev = &rps->ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001242 struct intel_rps_ei now;
1243 u32 events = 0;
1244
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001245 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001246 return 0;
1247
1248 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001249
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001250 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001251 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001252 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001253
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001254 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001255
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001256 time *= dev_priv->czclk_freq;
1257
1258 /* Workload can be split between render + media,
1259 * e.g. SwapBuffers being blitted in X after being rendered in
1260 * mesa. To account for this we need to combine both engines
1261 * into our activity counter.
1262 */
Chris Wilson569884e2017-03-09 21:12:31 +00001263 render = now.render_c0 - prev->render_c0;
1264 media = now.media_c0 - prev->media_c0;
1265 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001266 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001267
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001268 if (c0 > time * rps->up_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001269 events = GEN6_PM_RP_UP_THRESHOLD;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001270 else if (c0 < time * rps->down_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001271 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001272 }
1273
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001274 rps->ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001275 return events;
Deepak S31685c22014-07-03 17:33:01 -04001276}
1277
Ben Widawsky4912d042011-04-25 11:25:20 -07001278static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001279{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001280 struct drm_i915_private *dev_priv =
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001281 container_of(work, struct drm_i915_private, gt_pm.rps.work);
1282 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001283 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001284 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001285 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001286
Daniel Vetter59cdb632013-07-04 23:35:28 +02001287 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001288 if (rps->interrupts_enabled) {
1289 pm_iir = fetch_and_zero(&rps->pm_iir);
1290 client_boost = atomic_read(&rps->num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001291 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001292 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001293
Paulo Zanoni60611c12013-08-15 11:50:01 -03001294 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301295 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001296 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001297 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001298
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001299 mutex_lock(&dev_priv->pcu_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001300
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001301 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1302
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001303 adj = rps->last_adj;
1304 new_delay = rps->cur_freq;
1305 min = rps->min_freq_softlimit;
1306 max = rps->max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001307 if (client_boost)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001308 max = rps->max_freq;
1309 if (client_boost && new_delay < rps->boost_freq) {
1310 new_delay = rps->boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001311 adj = 0;
1312 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001313 if (adj > 0)
1314 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001315 else /* CHV needs even encode values */
1316 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301317
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001318 if (new_delay >= rps->max_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301319 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001320 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001321 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001322 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001323 if (rps->cur_freq > rps->efficient_freq)
1324 new_delay = rps->efficient_freq;
1325 else if (rps->cur_freq > rps->min_freq_softlimit)
1326 new_delay = rps->min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001327 adj = 0;
1328 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1329 if (adj < 0)
1330 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001331 else /* CHV needs even encode values */
1332 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301333
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001334 if (new_delay <= rps->min_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301335 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001336 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001337 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001338 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001339
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001340 rps->last_adj = adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001341
Ben Widawsky79249632012-09-07 19:43:42 -07001342 /* sysfs frequency interfaces may have snuck in while servicing the
1343 * interrupt
1344 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001345 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001346 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301347
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001348 if (intel_set_rps(dev_priv, new_delay)) {
1349 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001350 rps->last_adj = 0;
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001351 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001352
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001353 mutex_unlock(&dev_priv->pcu_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001354
1355out:
1356 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1357 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001358 if (rps->interrupts_enabled)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001359 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1360 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001361}
1362
Ben Widawskye3689192012-05-25 16:56:22 -07001363
1364/**
1365 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1366 * occurred.
1367 * @work: workqueue struct
1368 *
1369 * Doesn't actually do anything except notify userspace. As a consequence of
1370 * this event, userspace should try to remap the bad rows since statistically
1371 * it is likely the same row is more likely to go bad again.
1372 */
1373static void ivybridge_parity_work(struct work_struct *work)
1374{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001375 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001376 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001377 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001378 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001379 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001380 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001381
1382 /* We must turn off DOP level clock gating to access the L3 registers.
1383 * In order to prevent a get/put style interface, acquire struct mutex
1384 * any time we access those registers.
1385 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001386 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001387
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001388 /* If we've screwed up tracking, just let the interrupt fire again */
1389 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1390 goto out;
1391
Ben Widawskye3689192012-05-25 16:56:22 -07001392 misccpctl = I915_READ(GEN7_MISCCPCTL);
1393 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1394 POSTING_READ(GEN7_MISCCPCTL);
1395
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001396 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001397 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001398
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001399 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001400 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001401 break;
1402
1403 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1404
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001405 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001406
1407 error_status = I915_READ(reg);
1408 row = GEN7_PARITY_ERROR_ROW(error_status);
1409 bank = GEN7_PARITY_ERROR_BANK(error_status);
1410 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1411
1412 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1413 POSTING_READ(reg);
1414
1415 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1416 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1417 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1418 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1419 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1420 parity_event[5] = NULL;
1421
Chris Wilson91c8a322016-07-05 10:40:23 +01001422 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001423 KOBJ_CHANGE, parity_event);
1424
1425 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1426 slice, row, bank, subbank);
1427
1428 kfree(parity_event[4]);
1429 kfree(parity_event[3]);
1430 kfree(parity_event[2]);
1431 kfree(parity_event[1]);
1432 }
Ben Widawskye3689192012-05-25 16:56:22 -07001433
1434 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1435
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001436out:
1437 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001438 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001439 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001440 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001441
Chris Wilson91c8a322016-07-05 10:40:23 +01001442 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001443}
1444
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001445static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1446 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001447{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001448 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001449 return;
1450
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001451 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001452 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001453 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001454
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001455 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001456 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1457 dev_priv->l3_parity.which_slice |= 1 << 1;
1458
1459 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1460 dev_priv->l3_parity.which_slice |= 1 << 0;
1461
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001462 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001463}
1464
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001465static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001466 u32 gt_iir)
1467{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001468 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301469 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001470 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301471 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001472}
1473
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001474static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001475 u32 gt_iir)
1476{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001477 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301478 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001479 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301480 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001481 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301482 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001483
Ben Widawskycc609d52013-05-28 19:22:29 -07001484 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1485 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001486 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1487 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001488
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001489 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1490 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001491}
1492
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001493static void
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001494gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001495{
Chris Wilson31de7352017-03-16 12:56:18 +00001496 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001497
Chris Wilsonfd8526e2018-06-28 21:12:10 +01001498 if (iir & GT_CONTEXT_SWITCH_INTERRUPT)
1499 tasklet = true;
Chris Wilson31de7352017-03-16 12:56:18 +00001500
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001501 if (iir & GT_RENDER_USER_INTERRUPT) {
Chris Wilson31de7352017-03-16 12:56:18 +00001502 notify_ring(engine);
Michal Wajdeczko93ffbe82017-12-06 13:53:12 +00001503 tasklet |= USES_GUC_SUBMISSION(engine->i915);
Chris Wilson31de7352017-03-16 12:56:18 +00001504 }
1505
1506 if (tasklet)
Chris Wilsonfd8526e2018-06-28 21:12:10 +01001507 tasklet_hi_schedule(&engine->execlists.tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001508}
1509
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001510static void gen8_gt_irq_ack(struct drm_i915_private *i915,
Chris Wilson55ef72f2018-02-02 15:34:48 +00001511 u32 master_ctl, u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001512{
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001513 void __iomem * const regs = i915->regs;
1514
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001515#define GEN8_GT_IRQS (GEN8_GT_RCS_IRQ | \
1516 GEN8_GT_BCS_IRQ | \
1517 GEN8_GT_VCS1_IRQ | \
1518 GEN8_GT_VCS2_IRQ | \
1519 GEN8_GT_VECS_IRQ | \
1520 GEN8_GT_PM_IRQ | \
1521 GEN8_GT_GUC_IRQ)
1522
Ben Widawskyabd58f02013-11-02 21:07:09 -07001523 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001524 gt_iir[0] = raw_reg_read(regs, GEN8_GT_IIR(0));
1525 if (likely(gt_iir[0]))
1526 raw_reg_write(regs, GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001527 }
1528
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001529 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001530 gt_iir[1] = raw_reg_read(regs, GEN8_GT_IIR(1));
1531 if (likely(gt_iir[1]))
1532 raw_reg_write(regs, GEN8_GT_IIR(1), gt_iir[1]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001533 }
1534
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301535 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001536 gt_iir[2] = raw_reg_read(regs, GEN8_GT_IIR(2));
1537 if (likely(gt_iir[2] & (i915->pm_rps_events |
1538 i915->pm_guc_events)))
1539 raw_reg_write(regs, GEN8_GT_IIR(2),
1540 gt_iir[2] & (i915->pm_rps_events |
1541 i915->pm_guc_events));
1542 }
1543
1544 if (master_ctl & GEN8_GT_VECS_IRQ) {
1545 gt_iir[3] = raw_reg_read(regs, GEN8_GT_IIR(3));
1546 if (likely(gt_iir[3]))
1547 raw_reg_write(regs, GEN8_GT_IIR(3), gt_iir[3]);
Ben Widawsky09610212014-05-15 20:58:08 +03001548 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07001549}
1550
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001551static void gen8_gt_irq_handler(struct drm_i915_private *i915,
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001552 u32 master_ctl, u32 gt_iir[4])
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001553{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001554 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001555 gen8_cs_irq_handler(i915->engine[RCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001556 gt_iir[0] >> GEN8_RCS_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001557 gen8_cs_irq_handler(i915->engine[BCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001558 gt_iir[0] >> GEN8_BCS_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001559 }
1560
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001561 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001562 gen8_cs_irq_handler(i915->engine[VCS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001563 gt_iir[1] >> GEN8_VCS1_IRQ_SHIFT);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001564 gen8_cs_irq_handler(i915->engine[VCS2],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001565 gt_iir[1] >> GEN8_VCS2_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001566 }
1567
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001568 if (master_ctl & GEN8_GT_VECS_IRQ) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001569 gen8_cs_irq_handler(i915->engine[VECS],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001570 gt_iir[3] >> GEN8_VECS_IRQ_SHIFT);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001571 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001572
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001573 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001574 gen6_rps_irq_handler(i915, gt_iir[2]);
1575 gen9_guc_irq_handler(i915, gt_iir[2]);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001576 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001577}
1578
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001579static bool gen11_port_hotplug_long_detect(enum port port, u32 val)
1580{
1581 switch (port) {
1582 case PORT_C:
1583 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1);
1584 case PORT_D:
1585 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2);
1586 case PORT_E:
1587 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3);
1588 case PORT_F:
1589 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4);
1590 default:
1591 return false;
1592 }
1593}
1594
Imre Deak63c88d22015-07-20 14:43:39 -07001595static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1596{
1597 switch (port) {
1598 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001599 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001600 case PORT_B:
1601 return val & PORTB_HOTPLUG_LONG_DETECT;
1602 case PORT_C:
1603 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001604 default:
1605 return false;
1606 }
1607}
1608
Anusha Srivatsa31604222018-06-26 13:52:23 -07001609static bool icp_ddi_port_hotplug_long_detect(enum port port, u32 val)
1610{
1611 switch (port) {
1612 case PORT_A:
1613 return val & ICP_DDIA_HPD_LONG_DETECT;
1614 case PORT_B:
1615 return val & ICP_DDIB_HPD_LONG_DETECT;
1616 default:
1617 return false;
1618 }
1619}
1620
1621static bool icp_tc_port_hotplug_long_detect(enum port port, u32 val)
1622{
1623 switch (port) {
1624 case PORT_C:
1625 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1);
1626 case PORT_D:
1627 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2);
1628 case PORT_E:
1629 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3);
1630 case PORT_F:
1631 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4);
1632 default:
1633 return false;
1634 }
1635}
1636
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001637static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1638{
1639 switch (port) {
1640 case PORT_E:
1641 return val & PORTE_HOTPLUG_LONG_DETECT;
1642 default:
1643 return false;
1644 }
1645}
1646
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001647static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1648{
1649 switch (port) {
1650 case PORT_A:
1651 return val & PORTA_HOTPLUG_LONG_DETECT;
1652 case PORT_B:
1653 return val & PORTB_HOTPLUG_LONG_DETECT;
1654 case PORT_C:
1655 return val & PORTC_HOTPLUG_LONG_DETECT;
1656 case PORT_D:
1657 return val & PORTD_HOTPLUG_LONG_DETECT;
1658 default:
1659 return false;
1660 }
1661}
1662
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001663static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1664{
1665 switch (port) {
1666 case PORT_A:
1667 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1668 default:
1669 return false;
1670 }
1671}
1672
Jani Nikula676574d2015-05-28 15:43:53 +03001673static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001674{
1675 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001676 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001677 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001678 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001679 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001680 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001681 return val & PORTD_HOTPLUG_LONG_DETECT;
1682 default:
1683 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001684 }
1685}
1686
Jani Nikula676574d2015-05-28 15:43:53 +03001687static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001688{
1689 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001690 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001691 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001692 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001693 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001694 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001695 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1696 default:
1697 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001698 }
1699}
1700
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001701/*
1702 * Get a bit mask of pins that have triggered, and which ones may be long.
1703 * This can be called multiple times with the same masks to accumulate
1704 * hotplug detection results from several registers.
1705 *
1706 * Note that the caller is expected to zero out the masks initially.
1707 */
Rodrigo Vivicf539022018-01-29 15:22:21 -08001708static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1709 u32 *pin_mask, u32 *long_mask,
1710 u32 hotplug_trigger, u32 dig_hotplug_reg,
1711 const u32 hpd[HPD_NUM_PINS],
1712 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001713{
Jani Nikula8c841e52015-06-18 13:06:17 +03001714 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001715 int i;
1716
Jani Nikula676574d2015-05-28 15:43:53 +03001717 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001718 if ((hpd[i] & hotplug_trigger) == 0)
1719 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001720
Jani Nikula8c841e52015-06-18 13:06:17 +03001721 *pin_mask |= BIT(i);
1722
Rodrigo Vivicf539022018-01-29 15:22:21 -08001723 port = intel_hpd_pin_to_port(dev_priv, i);
Rodrigo Vivi256cfdde2017-08-11 11:26:49 -07001724 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001725 continue;
1726
Imre Deakfd63e2a2015-07-21 15:32:44 -07001727 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001728 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001729 }
1730
1731 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1732 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1733
1734}
1735
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001736static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001737{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001738 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001739}
1740
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001741static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001742{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001743 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001744}
1745
Shuang He8bf1e9f2013-10-15 18:55:27 +01001746#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001747static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1748 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001749 uint32_t crc0, uint32_t crc1,
1750 uint32_t crc2, uint32_t crc3,
1751 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001752{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001753 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1754 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001755 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1756 struct drm_driver *driver = dev_priv->drm.driver;
1757 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001758 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001759
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001760 spin_lock(&pipe_crc->lock);
Maarten Lankhorst033b7a22018-03-08 13:02:02 +01001761 if (pipe_crc->source && !crtc->base.crc.opened) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001762 if (!pipe_crc->entries) {
1763 spin_unlock(&pipe_crc->lock);
1764 DRM_DEBUG_KMS("spurious interrupt\n");
1765 return;
1766 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001767
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001768 head = pipe_crc->head;
1769 tail = pipe_crc->tail;
1770
1771 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1772 spin_unlock(&pipe_crc->lock);
1773 DRM_ERROR("CRC buffer overflowing\n");
1774 return;
1775 }
1776
1777 entry = &pipe_crc->entries[head];
1778
1779 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1780 entry->crc[0] = crc0;
1781 entry->crc[1] = crc1;
1782 entry->crc[2] = crc2;
1783 entry->crc[3] = crc3;
1784 entry->crc[4] = crc4;
1785
1786 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1787 pipe_crc->head = head;
1788
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001789 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001790
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001791 wake_up_interruptible(&pipe_crc->wq);
1792 } else {
1793 /*
1794 * For some not yet identified reason, the first CRC is
1795 * bonkers. So let's just wait for the next vblank and read
1796 * out the buggy result.
1797 *
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001798 * On GEN8+ sometimes the second CRC is bonkers as well, so
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001799 * don't trust that one either.
1800 */
Maarten Lankhorst033b7a22018-03-08 13:02:02 +01001801 if (pipe_crc->skipped <= 0 ||
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001802 (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001803 pipe_crc->skipped++;
1804 spin_unlock(&pipe_crc->lock);
1805 return;
1806 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001807 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001808 crcs[0] = crc0;
1809 crcs[1] = crc1;
1810 crcs[2] = crc2;
1811 crcs[3] = crc3;
1812 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001813 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001814 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001815 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001816 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001817}
Daniel Vetter277de952013-10-18 16:37:07 +02001818#else
1819static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001820display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1821 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001822 uint32_t crc0, uint32_t crc1,
1823 uint32_t crc2, uint32_t crc3,
1824 uint32_t crc4) {}
1825#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001826
Daniel Vetter277de952013-10-18 16:37:07 +02001827
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001828static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1829 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001830{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001831 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001832 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1833 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001834}
1835
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001836static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1837 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001838{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001839 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001840 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1841 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1842 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1843 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1844 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001845}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001846
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001847static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1848 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001849{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001850 uint32_t res1, res2;
1851
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001852 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001853 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1854 else
1855 res1 = 0;
1856
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001857 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001858 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1859 else
1860 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001861
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001862 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001863 I915_READ(PIPE_CRC_RES_RED(pipe)),
1864 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1865 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1866 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001867}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001868
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001869/* The RPS events need forcewake, so we add them to a work queue and mask their
1870 * IMR bits until the work is done. Other interrupts can be processed without
1871 * the work queue. */
1872static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001873{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001874 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1875
Deepak Sa6706b42014-03-15 20:23:22 +05301876 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001877 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301878 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001879 if (rps->interrupts_enabled) {
1880 rps->pm_iir |= pm_iir & dev_priv->pm_rps_events;
1881 schedule_work(&rps->work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001882 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001883 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001884 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001885
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001886 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001887 return;
1888
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001889 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001890 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301891 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001892
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001893 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1894 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001895 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001896}
1897
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301898static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1899{
Michal Wajdeczko93bf8092018-03-08 16:46:55 +01001900 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT)
1901 intel_guc_to_host_event_handler(&dev_priv->guc);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301902}
1903
Ville Syrjälä44d92412017-08-18 21:36:51 +03001904static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1905{
1906 enum pipe pipe;
1907
1908 for_each_pipe(dev_priv, pipe) {
1909 I915_WRITE(PIPESTAT(pipe),
1910 PIPESTAT_INT_STATUS_MASK |
1911 PIPE_FIFO_UNDERRUN_STATUS);
1912
1913 dev_priv->pipestat_irq_mask[pipe] = 0;
1914 }
1915}
1916
Ville Syrjäläeb643432017-08-18 21:36:59 +03001917static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1918 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001919{
Imre Deakc1874ed2014-02-04 21:35:46 +02001920 int pipe;
1921
Imre Deak58ead0d2014-02-04 21:35:47 +02001922 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001923
1924 if (!dev_priv->display_irqs_enabled) {
1925 spin_unlock(&dev_priv->irq_lock);
1926 return;
1927 }
1928
Damien Lespiau055e3932014-08-18 13:49:10 +01001929 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001930 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001931 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001932
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001933 /*
1934 * PIPESTAT bits get signalled even when the interrupt is
1935 * disabled with the mask bits, and some of the status bits do
1936 * not generate interrupts at all (like the underrun bit). Hence
1937 * we need to be careful that we only handle what we want to
1938 * handle.
1939 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001940
1941 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001942 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001943
1944 switch (pipe) {
1945 case PIPE_A:
1946 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1947 break;
1948 case PIPE_B:
1949 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1950 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001951 case PIPE_C:
1952 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1953 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001954 }
1955 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001956 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001957
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001958 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001959 continue;
1960
1961 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001962 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1963 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001964
1965 /*
1966 * Clear the PIPE*STAT regs before the IIR
Ville Syrjälä132c27c2018-06-11 23:02:55 +03001967 *
1968 * Toggle the enable bits to make sure we get an
1969 * edge in the ISR pipe event bit if we don't clear
1970 * all the enabled status bits. Otherwise the edge
1971 * triggered IIR on i965/g4x wouldn't notice that
1972 * an interrupt is still pending.
Imre Deakc1874ed2014-02-04 21:35:46 +02001973 */
Ville Syrjälä132c27c2018-06-11 23:02:55 +03001974 if (pipe_stats[pipe]) {
1975 I915_WRITE(reg, pipe_stats[pipe]);
1976 I915_WRITE(reg, enable_mask);
1977 }
Imre Deakc1874ed2014-02-04 21:35:46 +02001978 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001979 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001980}
1981
Ville Syrjäläeb643432017-08-18 21:36:59 +03001982static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1983 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1984{
1985 enum pipe pipe;
1986
1987 for_each_pipe(dev_priv, pipe) {
1988 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1989 drm_handle_vblank(&dev_priv->drm, pipe);
1990
1991 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1992 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1993
1994 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1995 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1996 }
1997}
1998
1999static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
2000 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
2001{
2002 bool blc_event = false;
2003 enum pipe pipe;
2004
2005 for_each_pipe(dev_priv, pipe) {
2006 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
2007 drm_handle_vblank(&dev_priv->drm, pipe);
2008
2009 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2010 blc_event = true;
2011
2012 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2013 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2014
2015 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2016 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2017 }
2018
2019 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2020 intel_opregion_asle_intr(dev_priv);
2021}
2022
2023static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
2024 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
2025{
2026 bool blc_event = false;
2027 enum pipe pipe;
2028
2029 for_each_pipe(dev_priv, pipe) {
2030 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
2031 drm_handle_vblank(&dev_priv->drm, pipe);
2032
2033 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2034 blc_event = true;
2035
2036 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2037 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2038
2039 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2040 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2041 }
2042
2043 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2044 intel_opregion_asle_intr(dev_priv);
2045
2046 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2047 gmbus_irq_handler(dev_priv);
2048}
2049
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002050static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002051 u32 pipe_stats[I915_MAX_PIPES])
2052{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002053 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02002054
Damien Lespiau055e3932014-08-18 13:49:10 +01002055 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002056 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
2057 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002058
2059 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002060 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002061
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002062 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2063 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002064 }
2065
2066 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002067 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02002068}
2069
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002070static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002071{
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002072 u32 hotplug_status = 0, hotplug_status_mask;
2073 int i;
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002074
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002075 if (IS_G4X(dev_priv) ||
2076 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2077 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
2078 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
2079 else
2080 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
2081
2082 /*
2083 * We absolutely have to clear all the pending interrupt
2084 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
2085 * interrupt bit won't have an edge, and the i965/g4x
2086 * edge triggered IIR will not notice that an interrupt
2087 * is still pending. We can't use PORT_HOTPLUG_EN to
2088 * guarantee the edge as the act of toggling the enable
2089 * bits can itself generate a new hotplug interrupt :(
2090 */
2091 for (i = 0; i < 10; i++) {
2092 u32 tmp = I915_READ(PORT_HOTPLUG_STAT) & hotplug_status_mask;
2093
2094 if (tmp == 0)
2095 return hotplug_status;
2096
2097 hotplug_status |= tmp;
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002098 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002099 }
2100
2101 WARN_ONCE(1,
2102 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
2103 I915_READ(PORT_HOTPLUG_STAT));
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002104
2105 return hotplug_status;
2106}
2107
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002108static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002109 u32 hotplug_status)
2110{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03002111 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002112
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002113 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2114 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03002115 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002116
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002117 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002118 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2119 hotplug_trigger, hotplug_trigger,
2120 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002121 i9xx_port_hotplug_long_detect);
2122
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002123 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002124 }
Jani Nikula369712e2015-05-27 15:03:40 +03002125
2126 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002127 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03002128 } else {
2129 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002130
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002131 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002132 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2133 hotplug_trigger, hotplug_trigger,
2134 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002135 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002136 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002137 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002138 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002139}
2140
Daniel Vetterff1f5252012-10-02 15:10:55 +02002141static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002142{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002143 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002144 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002145 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002146
Imre Deak2dd2a882015-02-24 11:14:30 +02002147 if (!intel_irqs_enabled(dev_priv))
2148 return IRQ_NONE;
2149
Imre Deak1f814da2015-12-16 02:52:19 +02002150 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2151 disable_rpm_wakeref_asserts(dev_priv);
2152
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002153 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002154 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002155 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002156 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002157 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002158
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002159 gt_iir = I915_READ(GTIIR);
2160 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002161 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002162
2163 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002164 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002165
2166 ret = IRQ_HANDLED;
2167
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002168 /*
2169 * Theory on interrupt generation, based on empirical evidence:
2170 *
2171 * x = ((VLV_IIR & VLV_IER) ||
2172 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2173 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2174 *
2175 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2176 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2177 * guarantee the CPU interrupt will be raised again even if we
2178 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2179 * bits this time around.
2180 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002181 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002182 ier = I915_READ(VLV_IER);
2183 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002184
2185 if (gt_iir)
2186 I915_WRITE(GTIIR, gt_iir);
2187 if (pm_iir)
2188 I915_WRITE(GEN6_PMIIR, pm_iir);
2189
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002190 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002191 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002192
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002193 /* Call regardless, as some status bits might not be
2194 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002195 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002196
Jerome Anandeef57322017-01-25 04:27:49 +05302197 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2198 I915_LPE_PIPE_B_INTERRUPT))
2199 intel_lpe_audio_irq_handler(dev_priv);
2200
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002201 /*
2202 * VLV_IIR is single buffered, and reflects the level
2203 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2204 */
2205 if (iir)
2206 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002207
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002208 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002209 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002210
Ville Syrjälä52894872016-04-13 21:19:56 +03002211 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002212 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002213 if (pm_iir)
2214 gen6_rps_irq_handler(dev_priv, pm_iir);
2215
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002216 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002217 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002218
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002219 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002220 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002221
Imre Deak1f814da2015-12-16 02:52:19 +02002222 enable_rpm_wakeref_asserts(dev_priv);
2223
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002224 return ret;
2225}
2226
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002227static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2228{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002229 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002230 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002231 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002232
Imre Deak2dd2a882015-02-24 11:14:30 +02002233 if (!intel_irqs_enabled(dev_priv))
2234 return IRQ_NONE;
2235
Imre Deak1f814da2015-12-16 02:52:19 +02002236 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2237 disable_rpm_wakeref_asserts(dev_priv);
2238
Chris Wilson579de732016-03-14 09:01:57 +00002239 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002240 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002241 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002242 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002243 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002244 u32 ier = 0;
2245
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002246 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2247 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002248
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002249 if (master_ctl == 0 && iir == 0)
2250 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002251
Oscar Mateo27b6c122014-06-16 16:11:00 +01002252 ret = IRQ_HANDLED;
2253
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002254 /*
2255 * Theory on interrupt generation, based on empirical evidence:
2256 *
2257 * x = ((VLV_IIR & VLV_IER) ||
2258 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2259 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2260 *
2261 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2262 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2263 * guarantee the CPU interrupt will be raised again even if we
2264 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2265 * bits this time around.
2266 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002267 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002268 ier = I915_READ(VLV_IER);
2269 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002270
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002271 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002272
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002273 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002274 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002275
Oscar Mateo27b6c122014-06-16 16:11:00 +01002276 /* Call regardless, as some status bits might not be
2277 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002278 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002279
Jerome Anandeef57322017-01-25 04:27:49 +05302280 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2281 I915_LPE_PIPE_B_INTERRUPT |
2282 I915_LPE_PIPE_C_INTERRUPT))
2283 intel_lpe_audio_irq_handler(dev_priv);
2284
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002285 /*
2286 * VLV_IIR is single buffered, and reflects the level
2287 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2288 */
2289 if (iir)
2290 I915_WRITE(VLV_IIR, iir);
2291
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002292 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002293 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002294
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002295 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002296
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002297 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002298 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002299
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002300 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002301 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002302
Imre Deak1f814da2015-12-16 02:52:19 +02002303 enable_rpm_wakeref_asserts(dev_priv);
2304
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002305 return ret;
2306}
2307
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002308static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2309 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002310 const u32 hpd[HPD_NUM_PINS])
2311{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002312 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2313
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002314 /*
2315 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2316 * unless we touch the hotplug register, even if hotplug_trigger is
2317 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2318 * errors.
2319 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002320 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002321 if (!hotplug_trigger) {
2322 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2323 PORTD_HOTPLUG_STATUS_MASK |
2324 PORTC_HOTPLUG_STATUS_MASK |
2325 PORTB_HOTPLUG_STATUS_MASK;
2326 dig_hotplug_reg &= ~mask;
2327 }
2328
Ville Syrjälä40e56412015-08-27 23:56:10 +03002329 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002330 if (!hotplug_trigger)
2331 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002332
Rodrigo Vivicf539022018-01-29 15:22:21 -08002333 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002334 dig_hotplug_reg, hpd,
2335 pch_port_hotplug_long_detect);
2336
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002337 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002338}
2339
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002340static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002341{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002342 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002343 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002344
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002345 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002346
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002347 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2348 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2349 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002350 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002351 port_name(port));
2352 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002353
Daniel Vetterce99c252012-12-01 13:53:47 +01002354 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002355 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002356
Jesse Barnes776ad802011-01-04 15:09:39 -08002357 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002358 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002359
2360 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2361 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2362
2363 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2364 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2365
2366 if (pch_iir & SDE_POISON)
2367 DRM_ERROR("PCH poison interrupt\n");
2368
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002369 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002370 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002371 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2372 pipe_name(pipe),
2373 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002374
2375 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2376 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2377
2378 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2379 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2380
Jesse Barnes776ad802011-01-04 15:09:39 -08002381 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002382 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002383
2384 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002385 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002386}
2387
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002388static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002389{
Paulo Zanoni86642812013-04-12 17:57:57 -03002390 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002391 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002392
Paulo Zanonide032bf2013-04-12 17:57:58 -03002393 if (err_int & ERR_INT_POISON)
2394 DRM_ERROR("Poison interrupt\n");
2395
Damien Lespiau055e3932014-08-18 13:49:10 +01002396 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002397 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2398 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002399
Daniel Vetter5a69b892013-10-16 22:55:52 +02002400 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002401 if (IS_IVYBRIDGE(dev_priv))
2402 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002403 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002404 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002405 }
2406 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002407
Paulo Zanoni86642812013-04-12 17:57:57 -03002408 I915_WRITE(GEN7_ERR_INT, err_int);
2409}
2410
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002411static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002412{
Paulo Zanoni86642812013-04-12 17:57:57 -03002413 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002414 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002415
Paulo Zanonide032bf2013-04-12 17:57:58 -03002416 if (serr_int & SERR_INT_POISON)
2417 DRM_ERROR("PCH poison interrupt\n");
2418
Mika Kahola45c1cd82017-10-10 13:17:06 +03002419 for_each_pipe(dev_priv, pipe)
2420 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2421 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002422
2423 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002424}
2425
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002426static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002427{
Adam Jackson23e81d62012-06-06 15:45:44 -04002428 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002429 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002430
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002431 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002432
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002433 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2434 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2435 SDE_AUDIO_POWER_SHIFT_CPT);
2436 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2437 port_name(port));
2438 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002439
2440 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002441 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002442
2443 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002444 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002445
2446 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2447 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2448
2449 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2450 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2451
2452 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002453 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002454 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2455 pipe_name(pipe),
2456 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002457
2458 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002459 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002460}
2461
Anusha Srivatsa31604222018-06-26 13:52:23 -07002462static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
2463{
2464 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP;
2465 u32 tc_hotplug_trigger = pch_iir & SDE_TC_MASK_ICP;
2466 u32 pin_mask = 0, long_mask = 0;
2467
2468 if (ddi_hotplug_trigger) {
2469 u32 dig_hotplug_reg;
2470
2471 dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_DDI);
2472 I915_WRITE(SHOTPLUG_CTL_DDI, dig_hotplug_reg);
2473
2474 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2475 ddi_hotplug_trigger,
2476 dig_hotplug_reg, hpd_icp,
2477 icp_ddi_port_hotplug_long_detect);
2478 }
2479
2480 if (tc_hotplug_trigger) {
2481 u32 dig_hotplug_reg;
2482
2483 dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_TC);
2484 I915_WRITE(SHOTPLUG_CTL_TC, dig_hotplug_reg);
2485
2486 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2487 tc_hotplug_trigger,
2488 dig_hotplug_reg, hpd_icp,
2489 icp_tc_port_hotplug_long_detect);
2490 }
2491
2492 if (pin_mask)
2493 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2494
2495 if (pch_iir & SDE_GMBUS_ICP)
2496 gmbus_irq_handler(dev_priv);
2497}
2498
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002499static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002500{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002501 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2502 ~SDE_PORTE_HOTPLUG_SPT;
2503 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2504 u32 pin_mask = 0, long_mask = 0;
2505
2506 if (hotplug_trigger) {
2507 u32 dig_hotplug_reg;
2508
2509 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2510 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2511
Rodrigo Vivicf539022018-01-29 15:22:21 -08002512 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2513 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002514 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002515 }
2516
2517 if (hotplug2_trigger) {
2518 u32 dig_hotplug_reg;
2519
2520 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2521 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2522
Rodrigo Vivicf539022018-01-29 15:22:21 -08002523 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2524 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002525 spt_port_hotplug2_long_detect);
2526 }
2527
2528 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002529 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002530
2531 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002532 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002533}
2534
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002535static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2536 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002537 const u32 hpd[HPD_NUM_PINS])
2538{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002539 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2540
2541 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2542 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2543
Rodrigo Vivicf539022018-01-29 15:22:21 -08002544 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002545 dig_hotplug_reg, hpd,
2546 ilk_port_hotplug_long_detect);
2547
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002548 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002549}
2550
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002551static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2552 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002553{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002554 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002555 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2556
Ville Syrjälä40e56412015-08-27 23:56:10 +03002557 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002558 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002559
2560 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002561 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002562
2563 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002564 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002565
Paulo Zanonic008bc62013-07-12 16:35:10 -03002566 if (de_iir & DE_POISON)
2567 DRM_ERROR("Poison interrupt\n");
2568
Damien Lespiau055e3932014-08-18 13:49:10 +01002569 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002570 if (de_iir & DE_PIPE_VBLANK(pipe))
2571 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002572
Daniel Vetter40da17c22013-10-21 18:04:36 +02002573 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002574 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002575
Daniel Vetter40da17c22013-10-21 18:04:36 +02002576 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002577 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002578 }
2579
2580 /* check event from PCH */
2581 if (de_iir & DE_PCH_EVENT) {
2582 u32 pch_iir = I915_READ(SDEIIR);
2583
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002584 if (HAS_PCH_CPT(dev_priv))
2585 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002586 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002587 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002588
2589 /* should clear PCH hotplug event before clear CPU irq */
2590 I915_WRITE(SDEIIR, pch_iir);
2591 }
2592
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002593 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2594 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002595}
2596
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002597static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2598 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002599{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002600 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002601 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2602
Ville Syrjälä40e56412015-08-27 23:56:10 +03002603 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002604 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002605
2606 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002607 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002608
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002609 if (de_iir & DE_EDP_PSR_INT_HSW) {
2610 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2611
2612 intel_psr_irq_handler(dev_priv, psr_iir);
2613 I915_WRITE(EDP_PSR_IIR, psr_iir);
2614 }
Daniel Vetterfc340442018-04-05 15:00:23 -07002615
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002616 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002617 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002618
2619 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002620 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002621
Damien Lespiau055e3932014-08-18 13:49:10 +01002622 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002623 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2624 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002625 }
2626
2627 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002628 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002629 u32 pch_iir = I915_READ(SDEIIR);
2630
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002631 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002632
2633 /* clear PCH hotplug event before clear CPU irq */
2634 I915_WRITE(SDEIIR, pch_iir);
2635 }
2636}
2637
Oscar Mateo72c90f62014-06-16 16:10:57 +01002638/*
2639 * To handle irqs with the minimum potential races with fresh interrupts, we:
2640 * 1 - Disable Master Interrupt Control.
2641 * 2 - Find the source(s) of the interrupt.
2642 * 3 - Clear the Interrupt Identity bits (IIR).
2643 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2644 * 5 - Re-enable Master Interrupt Control.
2645 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002646static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002647{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002648 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002649 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002650 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002651 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002652
Imre Deak2dd2a882015-02-24 11:14:30 +02002653 if (!intel_irqs_enabled(dev_priv))
2654 return IRQ_NONE;
2655
Imre Deak1f814da2015-12-16 02:52:19 +02002656 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2657 disable_rpm_wakeref_asserts(dev_priv);
2658
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002659 /* disable master interrupt before clearing iir */
2660 de_ier = I915_READ(DEIER);
2661 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson0e434062012-05-09 21:45:44 +01002662
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002663 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2664 * interrupts will will be stored on its back queue, and then we'll be
2665 * able to process them after we restore SDEIER (as soon as we restore
2666 * it, we'll get an interrupt if SDEIIR still has something to process
2667 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002668 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002669 sde_ier = I915_READ(SDEIER);
2670 I915_WRITE(SDEIER, 0);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002671 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002672
Oscar Mateo72c90f62014-06-16 16:10:57 +01002673 /* Find, clear, then process each source of interrupt */
2674
Chris Wilson0e434062012-05-09 21:45:44 +01002675 gt_iir = I915_READ(GTIIR);
2676 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002677 I915_WRITE(GTIIR, gt_iir);
2678 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002679 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002680 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002681 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002682 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002683 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002684
2685 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002686 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002687 I915_WRITE(DEIIR, de_iir);
2688 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002689 if (INTEL_GEN(dev_priv) >= 7)
2690 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002691 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002692 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002693 }
2694
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002695 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002696 u32 pm_iir = I915_READ(GEN6_PMIIR);
2697 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002698 I915_WRITE(GEN6_PMIIR, pm_iir);
2699 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002700 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002701 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002702 }
2703
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002704 I915_WRITE(DEIER, de_ier);
Chris Wilson74093f32018-06-28 21:12:03 +01002705 if (!HAS_PCH_NOP(dev_priv))
Ben Widawskyab5c6082013-04-05 13:12:41 -07002706 I915_WRITE(SDEIER, sde_ier);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002707
Imre Deak1f814da2015-12-16 02:52:19 +02002708 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2709 enable_rpm_wakeref_asserts(dev_priv);
2710
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002711 return ret;
2712}
2713
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002714static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2715 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002716 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302717{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002718 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302719
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002720 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2721 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302722
Rodrigo Vivicf539022018-01-29 15:22:21 -08002723 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002724 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002725 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002726
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002727 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302728}
2729
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002730static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2731{
2732 u32 pin_mask = 0, long_mask = 0;
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002733 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
2734 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002735
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002736 if (trigger_tc) {
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002737 u32 dig_hotplug_reg;
2738
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002739 dig_hotplug_reg = I915_READ(GEN11_TC_HOTPLUG_CTL);
2740 I915_WRITE(GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg);
2741
2742 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tc,
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002743 dig_hotplug_reg, hpd_gen11,
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002744 gen11_port_hotplug_long_detect);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002745 }
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002746
2747 if (trigger_tbt) {
2748 u32 dig_hotplug_reg;
2749
2750 dig_hotplug_reg = I915_READ(GEN11_TBT_HOTPLUG_CTL);
2751 I915_WRITE(GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg);
2752
2753 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tbt,
2754 dig_hotplug_reg, hpd_gen11,
2755 gen11_port_hotplug_long_detect);
2756 }
2757
2758 if (pin_mask)
2759 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2760 else
2761 DRM_ERROR("Unexpected DE HPD interrupt 0x%08x\n", iir);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002762}
2763
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002764static irqreturn_t
2765gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002766{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002767 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002768 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002769 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002770
Ben Widawskyabd58f02013-11-02 21:07:09 -07002771 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002772 iir = I915_READ(GEN8_DE_MISC_IIR);
2773 if (iir) {
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002774 bool found = false;
2775
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002776 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002777 ret = IRQ_HANDLED;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002778
2779 if (iir & GEN8_DE_MISC_GSE) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002780 intel_opregion_asle_intr(dev_priv);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002781 found = true;
2782 }
2783
2784 if (iir & GEN8_DE_EDP_PSR) {
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002785 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2786
2787 intel_psr_irq_handler(dev_priv, psr_iir);
2788 I915_WRITE(EDP_PSR_IIR, psr_iir);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002789 found = true;
2790 }
2791
2792 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002793 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002794 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002795 else
2796 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002797 }
2798
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002799 if (INTEL_GEN(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
2800 iir = I915_READ(GEN11_DE_HPD_IIR);
2801 if (iir) {
2802 I915_WRITE(GEN11_DE_HPD_IIR, iir);
2803 ret = IRQ_HANDLED;
2804 gen11_hpd_irq_handler(dev_priv, iir);
2805 } else {
2806 DRM_ERROR("The master control interrupt lied, (DE HPD)!\n");
2807 }
2808 }
2809
Daniel Vetter6d766f02013-11-07 14:49:55 +01002810 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002811 iir = I915_READ(GEN8_DE_PORT_IIR);
2812 if (iir) {
2813 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302814 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002815
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002816 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002817 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002818
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002819 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002820 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002821 tmp_mask |= GEN9_AUX_CHANNEL_B |
2822 GEN9_AUX_CHANNEL_C |
2823 GEN9_AUX_CHANNEL_D;
2824
James Ausmusbb187e92018-06-11 17:25:12 -07002825 if (INTEL_GEN(dev_priv) >= 11)
2826 tmp_mask |= ICL_AUX_CHANNEL_E;
2827
Dhinakaran Pandiyan9bb635d2018-05-21 17:25:35 -07002828 if (IS_CNL_WITH_PORT_F(dev_priv) ||
2829 INTEL_GEN(dev_priv) >= 11)
Rodrigo Vivia324fca2018-01-29 15:22:15 -08002830 tmp_mask |= CNL_AUX_CHANNEL_F;
2831
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002832 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002833 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302834 found = true;
2835 }
2836
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002837 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002838 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2839 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002840 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2841 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002842 found = true;
2843 }
2844 } else if (IS_BROADWELL(dev_priv)) {
2845 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2846 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002847 ilk_hpd_irq_handler(dev_priv,
2848 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002849 found = true;
2850 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302851 }
2852
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002853 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002854 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302855 found = true;
2856 }
2857
Shashank Sharmad04a4922014-08-22 17:40:41 +05302858 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002859 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002860 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002861 else
2862 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002863 }
2864
Damien Lespiau055e3932014-08-18 13:49:10 +01002865 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002866 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002867
Daniel Vetterc42664c2013-11-07 11:05:40 +01002868 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2869 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002870
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002871 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2872 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002873 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002874 continue;
2875 }
2876
2877 ret = IRQ_HANDLED;
2878 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2879
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002880 if (iir & GEN8_PIPE_VBLANK)
2881 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002882
2883 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002884 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002885
2886 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2887 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2888
2889 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002890 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002891 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2892 else
2893 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2894
2895 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002896 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002897 pipe_name(pipe),
2898 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002899 }
2900
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002901 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302902 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002903 /*
2904 * FIXME(BDW): Assume for now that the new interrupt handling
2905 * scheme also closed the SDE interrupt handling race we've seen
2906 * on older pch-split platforms. But this needs testing.
2907 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002908 iir = I915_READ(SDEIIR);
2909 if (iir) {
2910 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002911 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002912
Anusha Srivatsa31604222018-06-26 13:52:23 -07002913 if (HAS_PCH_ICP(dev_priv))
2914 icp_irq_handler(dev_priv, iir);
2915 else if (HAS_PCH_SPT(dev_priv) ||
2916 HAS_PCH_KBP(dev_priv) ||
2917 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002918 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002919 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002920 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002921 } else {
2922 /*
2923 * Like on previous PCH there seems to be something
2924 * fishy going on with forwarding PCH interrupts.
2925 */
2926 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2927 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002928 }
2929
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002930 return ret;
2931}
2932
2933static irqreturn_t gen8_irq_handler(int irq, void *arg)
2934{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002935 struct drm_i915_private *dev_priv = to_i915(arg);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002936 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002937 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002938
2939 if (!intel_irqs_enabled(dev_priv))
2940 return IRQ_NONE;
2941
2942 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2943 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2944 if (!master_ctl)
2945 return IRQ_NONE;
2946
2947 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2948
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002949 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002950 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002951
2952 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2953 if (master_ctl & ~GEN8_GT_IRQS) {
2954 disable_rpm_wakeref_asserts(dev_priv);
2955 gen8_de_irq_handler(dev_priv, master_ctl);
2956 enable_rpm_wakeref_asserts(dev_priv);
2957 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002958
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002959 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002960
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002961 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002962
Chris Wilson55ef72f2018-02-02 15:34:48 +00002963 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002964}
2965
Chris Wilson36703e72017-06-22 11:56:25 +01002966struct wedge_me {
2967 struct delayed_work work;
2968 struct drm_i915_private *i915;
2969 const char *name;
2970};
2971
2972static void wedge_me(struct work_struct *work)
2973{
2974 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2975
2976 dev_err(w->i915->drm.dev,
2977 "%s timed out, cancelling all in-flight rendering.\n",
2978 w->name);
2979 i915_gem_set_wedged(w->i915);
2980}
2981
2982static void __init_wedge(struct wedge_me *w,
2983 struct drm_i915_private *i915,
2984 long timeout,
2985 const char *name)
2986{
2987 w->i915 = i915;
2988 w->name = name;
2989
2990 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2991 schedule_delayed_work(&w->work, timeout);
2992}
2993
2994static void __fini_wedge(struct wedge_me *w)
2995{
2996 cancel_delayed_work_sync(&w->work);
2997 destroy_delayed_work_on_stack(&w->work);
2998 w->i915 = NULL;
2999}
3000
3001#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
3002 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
3003 (W)->i915; \
3004 __fini_wedge((W)))
3005
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003006static u32
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003007gen11_gt_engine_identity(struct drm_i915_private * const i915,
3008 const unsigned int bank, const unsigned int bit)
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003009{
3010 void __iomem * const regs = i915->regs;
3011 u32 timeout_ts;
3012 u32 ident;
3013
Oscar Mateo96606f32018-04-06 12:32:37 +03003014 lockdep_assert_held(&i915->irq_lock);
3015
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003016 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
3017
3018 /*
3019 * NB: Specs do not specify how long to spin wait,
3020 * so we do ~100us as an educated guess.
3021 */
3022 timeout_ts = (local_clock() >> 10) + 100;
3023 do {
3024 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
3025 } while (!(ident & GEN11_INTR_DATA_VALID) &&
3026 !time_after32(local_clock() >> 10, timeout_ts));
3027
3028 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
3029 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
3030 bank, bit, ident);
3031 return 0;
3032 }
3033
3034 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
3035 GEN11_INTR_DATA_VALID);
3036
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003037 return ident;
3038}
3039
3040static void
3041gen11_other_irq_handler(struct drm_i915_private * const i915,
3042 const u8 instance, const u16 iir)
3043{
Oscar Mateod02b98b2018-04-05 17:00:50 +03003044 if (instance == OTHER_GTPM_INSTANCE)
3045 return gen6_rps_irq_handler(i915, iir);
3046
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003047 WARN_ONCE(1, "unhandled other interrupt instance=0x%x, iir=0x%x\n",
3048 instance, iir);
3049}
3050
3051static void
3052gen11_engine_irq_handler(struct drm_i915_private * const i915,
3053 const u8 class, const u8 instance, const u16 iir)
3054{
3055 struct intel_engine_cs *engine;
3056
3057 if (instance <= MAX_ENGINE_INSTANCE)
3058 engine = i915->engine_class[class][instance];
3059 else
3060 engine = NULL;
3061
3062 if (likely(engine))
3063 return gen8_cs_irq_handler(engine, iir);
3064
3065 WARN_ONCE(1, "unhandled engine interrupt class=0x%x, instance=0x%x\n",
3066 class, instance);
3067}
3068
3069static void
3070gen11_gt_identity_handler(struct drm_i915_private * const i915,
3071 const u32 identity)
3072{
3073 const u8 class = GEN11_INTR_ENGINE_CLASS(identity);
3074 const u8 instance = GEN11_INTR_ENGINE_INSTANCE(identity);
3075 const u16 intr = GEN11_INTR_ENGINE_INTR(identity);
3076
3077 if (unlikely(!intr))
3078 return;
3079
3080 if (class <= COPY_ENGINE_CLASS)
3081 return gen11_engine_irq_handler(i915, class, instance, intr);
3082
3083 if (class == OTHER_CLASS)
3084 return gen11_other_irq_handler(i915, instance, intr);
3085
3086 WARN_ONCE(1, "unknown interrupt class=0x%x, instance=0x%x, intr=0x%x\n",
3087 class, instance, intr);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003088}
3089
3090static void
Oscar Mateo96606f32018-04-06 12:32:37 +03003091gen11_gt_bank_handler(struct drm_i915_private * const i915,
3092 const unsigned int bank)
3093{
3094 void __iomem * const regs = i915->regs;
3095 unsigned long intr_dw;
3096 unsigned int bit;
3097
3098 lockdep_assert_held(&i915->irq_lock);
3099
3100 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
3101
3102 if (unlikely(!intr_dw)) {
3103 DRM_ERROR("GT_INTR_DW%u blank!\n", bank);
3104 return;
3105 }
3106
3107 for_each_set_bit(bit, &intr_dw, 32) {
3108 const u32 ident = gen11_gt_engine_identity(i915,
3109 bank, bit);
3110
3111 gen11_gt_identity_handler(i915, ident);
3112 }
3113
3114 /* Clear must be after shared has been served for engine */
3115 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
3116}
3117
3118static void
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003119gen11_gt_irq_handler(struct drm_i915_private * const i915,
3120 const u32 master_ctl)
3121{
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003122 unsigned int bank;
3123
Oscar Mateo96606f32018-04-06 12:32:37 +03003124 spin_lock(&i915->irq_lock);
3125
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003126 for (bank = 0; bank < 2; bank++) {
Oscar Mateo96606f32018-04-06 12:32:37 +03003127 if (master_ctl & GEN11_GT_DW_IRQ(bank))
3128 gen11_gt_bank_handler(i915, bank);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003129 }
Oscar Mateo96606f32018-04-06 12:32:37 +03003130
3131 spin_unlock(&i915->irq_lock);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003132}
3133
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003134static void
3135gen11_gu_misc_irq_ack(struct drm_i915_private *dev_priv, const u32 master_ctl,
3136 u32 *iir)
3137{
3138 void __iomem * const regs = dev_priv->regs;
3139
3140 if (!(master_ctl & GEN11_GU_MISC_IRQ))
3141 return;
3142
3143 *iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
3144 if (likely(*iir))
3145 raw_reg_write(regs, GEN11_GU_MISC_IIR, *iir);
3146}
3147
3148static void
3149gen11_gu_misc_irq_handler(struct drm_i915_private *dev_priv,
3150 const u32 master_ctl, const u32 iir)
3151{
3152 if (!(master_ctl & GEN11_GU_MISC_IRQ))
3153 return;
3154
3155 if (unlikely(!iir)) {
3156 DRM_ERROR("GU_MISC iir blank!\n");
3157 return;
3158 }
3159
3160 if (iir & GEN11_GU_MISC_GSE)
3161 intel_opregion_asle_intr(dev_priv);
3162 else
3163 DRM_ERROR("Unexpected GU_MISC interrupt 0x%x\n", iir);
3164}
3165
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003166static irqreturn_t gen11_irq_handler(int irq, void *arg)
3167{
3168 struct drm_i915_private * const i915 = to_i915(arg);
3169 void __iomem * const regs = i915->regs;
3170 u32 master_ctl;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003171 u32 gu_misc_iir;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003172
3173 if (!intel_irqs_enabled(i915))
3174 return IRQ_NONE;
3175
3176 master_ctl = raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
3177 master_ctl &= ~GEN11_MASTER_IRQ;
3178 if (!master_ctl)
3179 return IRQ_NONE;
3180
3181 /* Disable interrupts. */
3182 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
3183
3184 /* Find, clear, then process each source of interrupt. */
3185 gen11_gt_irq_handler(i915, master_ctl);
3186
3187 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3188 if (master_ctl & GEN11_DISPLAY_IRQ) {
3189 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
3190
3191 disable_rpm_wakeref_asserts(i915);
3192 /*
3193 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
3194 * for the display related bits.
3195 */
3196 gen8_de_irq_handler(i915, disp_ctl);
3197 enable_rpm_wakeref_asserts(i915);
3198 }
3199
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003200 gen11_gu_misc_irq_ack(i915, master_ctl, &gu_misc_iir);
3201
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003202 /* Acknowledge and enable interrupts. */
3203 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ | master_ctl);
3204
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003205 gen11_gu_misc_irq_handler(i915, master_ctl, gu_misc_iir);
3206
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003207 return IRQ_HANDLED;
3208}
3209
Chris Wilsonce800752018-03-20 10:04:49 +00003210static void i915_reset_device(struct drm_i915_private *dev_priv,
Chris Wilsond0667e92018-04-06 23:03:54 +01003211 u32 engine_mask,
3212 const char *reason)
Jesse Barnes8a905232009-07-11 16:48:03 -04003213{
Chris Wilsonce800752018-03-20 10:04:49 +00003214 struct i915_gpu_error *error = &dev_priv->gpu_error;
Chris Wilson91c8a322016-07-05 10:40:23 +01003215 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07003216 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
3217 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
3218 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01003219 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04003220
Chris Wilsonc0336662016-05-06 15:40:21 +01003221 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04003222
Chris Wilson8af29b02016-09-09 14:11:47 +01003223 DRM_DEBUG_DRIVER("resetting chip\n");
3224 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
3225
Chris Wilson36703e72017-06-22 11:56:25 +01003226 /* Use a watchdog to ensure that our reset completes */
3227 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
3228 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02003229
Chris Wilsond0667e92018-04-06 23:03:54 +01003230 error->reason = reason;
3231 error->stalled_mask = engine_mask;
Chris Wilsonce800752018-03-20 10:04:49 +00003232
Chris Wilson36703e72017-06-22 11:56:25 +01003233 /* Signal that locked waiters should reset the GPU */
Chris Wilsond0667e92018-04-06 23:03:54 +01003234 smp_mb__before_atomic();
Chris Wilsonce800752018-03-20 10:04:49 +00003235 set_bit(I915_RESET_HANDOFF, &error->flags);
3236 wake_up_all(&error->wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00003237
Chris Wilson36703e72017-06-22 11:56:25 +01003238 /* Wait for anyone holding the lock to wakeup, without
3239 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01003240 */
Chris Wilson36703e72017-06-22 11:56:25 +01003241 do {
3242 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilsond0667e92018-04-06 23:03:54 +01003243 i915_reset(dev_priv, engine_mask, reason);
Chris Wilson36703e72017-06-22 11:56:25 +01003244 mutex_unlock(&dev_priv->drm.struct_mutex);
3245 }
Chris Wilsonce800752018-03-20 10:04:49 +00003246 } while (wait_on_bit_timeout(&error->flags,
Chris Wilson36703e72017-06-22 11:56:25 +01003247 I915_RESET_HANDOFF,
3248 TASK_UNINTERRUPTIBLE,
3249 1));
Chris Wilson780f2622016-09-09 14:11:52 +01003250
Chris Wilsond0667e92018-04-06 23:03:54 +01003251 error->stalled_mask = 0;
Chris Wilsonce800752018-03-20 10:04:49 +00003252 error->reason = NULL;
3253
Chris Wilson36703e72017-06-22 11:56:25 +01003254 intel_finish_reset(dev_priv);
3255 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02003256
Chris Wilsonce800752018-03-20 10:04:49 +00003257 if (!test_bit(I915_WEDGED, &error->flags))
3258 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04003259}
3260
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003261static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04003262{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003263 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04003264
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003265 if (!IS_GEN2(dev_priv))
3266 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04003267
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003268 if (INTEL_GEN(dev_priv) < 4)
3269 I915_WRITE(IPEIR, I915_READ(IPEIR));
3270 else
3271 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04003272
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003273 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04003274 eir = I915_READ(EIR);
3275 if (eir) {
3276 /*
3277 * some errors might have become stuck,
3278 * mask them.
3279 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01003280 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04003281 I915_WRITE(EMR, I915_READ(EMR) | eir);
Ville Syrjälä78c357d2018-06-11 23:02:57 +03003282 I915_WRITE(IIR, I915_MASTER_ERROR_INTERRUPT);
Jesse Barnes8a905232009-07-11 16:48:03 -04003283 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01003284}
3285
3286/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02003287 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01003288 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00003289 * @engine_mask: mask representing engines that are hung
Chris Wilsonce800752018-03-20 10:04:49 +00003290 * @flags: control flags
Michel Thierry87c390b2017-01-11 20:18:08 -08003291 * @fmt: Error message format string
3292 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02003293 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01003294 * dump it to the syslog. Also call i915_capture_error_state() to make
3295 * sure we get a record and make it available in debugfs. Fire a uevent
3296 * so userspace knows something bad happened (should trigger collection
3297 * of a ring dump etc.).
3298 */
Chris Wilsonc0336662016-05-06 15:40:21 +01003299void i915_handle_error(struct drm_i915_private *dev_priv,
3300 u32 engine_mask,
Chris Wilsonce800752018-03-20 10:04:49 +00003301 unsigned long flags,
Mika Kuoppala58174462014-02-25 17:11:26 +02003302 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01003303{
Michel Thierry142bc7d2017-06-20 10:57:46 +01003304 struct intel_engine_cs *engine;
3305 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02003306 char error_msg[80];
Chris Wilsonce800752018-03-20 10:04:49 +00003307 char *msg = NULL;
Chris Wilson35aed2e2010-05-27 13:18:12 +01003308
Chris Wilsonce800752018-03-20 10:04:49 +00003309 if (fmt) {
3310 va_list args;
3311
3312 va_start(args, fmt);
3313 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
3314 va_end(args);
3315
3316 msg = error_msg;
3317 }
Mika Kuoppala58174462014-02-25 17:11:26 +02003318
Chris Wilson1604a862017-03-14 17:18:40 +00003319 /*
3320 * In most cases it's guaranteed that we get here with an RPM
3321 * reference held, for example because there is a pending GPU
3322 * request that won't finish until the reset is done. This
3323 * isn't the case at least when we get here by doing a
3324 * simulated reset via debugfs, so get an RPM reference.
3325 */
3326 intel_runtime_pm_get(dev_priv);
3327
Chris Wilson873d66f2018-03-16 21:49:59 +00003328 engine_mask &= INTEL_INFO(dev_priv)->ring_mask;
Chris Wilsonce800752018-03-20 10:04:49 +00003329
3330 if (flags & I915_ERROR_CAPTURE) {
3331 i915_capture_error_state(dev_priv, engine_mask, msg);
3332 i915_clear_error_registers(dev_priv);
3333 }
Jesse Barnes8a905232009-07-11 16:48:03 -04003334
Michel Thierry142bc7d2017-06-20 10:57:46 +01003335 /*
3336 * Try engine reset when available. We fall back to full reset if
3337 * single reset fails.
3338 */
3339 if (intel_has_reset_engine(dev_priv)) {
3340 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02003341 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01003342 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3343 &dev_priv->gpu_error.flags))
3344 continue;
3345
Chris Wilsonce800752018-03-20 10:04:49 +00003346 if (i915_reset_engine(engine, msg) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01003347 engine_mask &= ~intel_engine_flag(engine);
3348
3349 clear_bit(I915_RESET_ENGINE + engine->id,
3350 &dev_priv->gpu_error.flags);
3351 wake_up_bit(&dev_priv->gpu_error.flags,
3352 I915_RESET_ENGINE + engine->id);
3353 }
3354 }
3355
Chris Wilson8af29b02016-09-09 14:11:47 +01003356 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00003357 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04003358
Michel Thierry142bc7d2017-06-20 10:57:46 +01003359 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01003360 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
3361 wait_event(dev_priv->gpu_error.reset_queue,
3362 !test_bit(I915_RESET_BACKOFF,
3363 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00003364 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01003365 }
Chris Wilson8af29b02016-09-09 14:11:47 +01003366
Michel Thierry142bc7d2017-06-20 10:57:46 +01003367 /* Prevent any other reset-engine attempt. */
3368 for_each_engine(engine, dev_priv, tmp) {
3369 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
3370 &dev_priv->gpu_error.flags))
3371 wait_on_bit(&dev_priv->gpu_error.flags,
3372 I915_RESET_ENGINE + engine->id,
3373 TASK_UNINTERRUPTIBLE);
3374 }
3375
Chris Wilsond0667e92018-04-06 23:03:54 +01003376 i915_reset_device(dev_priv, engine_mask, msg);
Chris Wilsond5367302017-06-20 10:57:43 +01003377
Michel Thierry142bc7d2017-06-20 10:57:46 +01003378 for_each_engine(engine, dev_priv, tmp) {
3379 clear_bit(I915_RESET_ENGINE + engine->id,
3380 &dev_priv->gpu_error.flags);
3381 }
3382
Chris Wilsond5367302017-06-20 10:57:43 +01003383 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
3384 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00003385
3386out:
3387 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04003388}
3389
Keith Packard42f52ef2008-10-18 19:39:29 -07003390/* Called from drm generic code, passed 'crtc' which
3391 * we use as a pipe index
3392 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003393static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003394{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003395 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003396 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003397
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003398 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003399 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3400 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3401
3402 return 0;
3403}
3404
3405static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3406{
3407 struct drm_i915_private *dev_priv = to_i915(dev);
3408 unsigned long irqflags;
3409
3410 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3411 i915_enable_pipestat(dev_priv, pipe,
3412 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003413 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003414
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003415 return 0;
3416}
3417
Thierry Reding88e72712015-09-24 18:35:31 +02003418static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003419{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003420 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003421 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003422 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003423 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003424
Jesse Barnesf796cf82011-04-07 13:58:17 -07003425 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003426 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003427 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3428
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003429 /* Even though there is no DMC, frame counter can get stuck when
3430 * PSR is active as no frames are generated.
3431 */
3432 if (HAS_PSR(dev_priv))
3433 drm_vblank_restore(dev, pipe);
3434
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003435 return 0;
3436}
3437
Thierry Reding88e72712015-09-24 18:35:31 +02003438static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003439{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003440 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003441 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003442
Ben Widawskyabd58f02013-11-02 21:07:09 -07003443 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003444 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003445 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003446
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003447 /* Even if there is no DMC, frame counter can get stuck when
3448 * PSR is active as no frames are generated, so check only for PSR.
3449 */
3450 if (HAS_PSR(dev_priv))
3451 drm_vblank_restore(dev, pipe);
3452
Ben Widawskyabd58f02013-11-02 21:07:09 -07003453 return 0;
3454}
3455
Keith Packard42f52ef2008-10-18 19:39:29 -07003456/* Called from drm generic code, passed 'crtc' which
3457 * we use as a pipe index
3458 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003459static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3460{
3461 struct drm_i915_private *dev_priv = to_i915(dev);
3462 unsigned long irqflags;
3463
3464 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3465 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3466 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3467}
3468
3469static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003470{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003471 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003472 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003473
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003474 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003475 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003476 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003477 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3478}
3479
Thierry Reding88e72712015-09-24 18:35:31 +02003480static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003481{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003482 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003483 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01003484 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003485 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003486
3487 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003488 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003489 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3490}
3491
Thierry Reding88e72712015-09-24 18:35:31 +02003492static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003493{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003494 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003495 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003496
Ben Widawskyabd58f02013-11-02 21:07:09 -07003497 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003498 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003499 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3500}
3501
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003502static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003503{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003504 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003505 return;
3506
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003507 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003508
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003509 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003510 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003511}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003512
Paulo Zanoni622364b2014-04-01 15:37:22 -03003513/*
3514 * SDEIER is also touched by the interrupt handler to work around missed PCH
3515 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3516 * instead we unconditionally enable all PCH interrupt sources here, but then
3517 * only unmask them as needed with SDEIMR.
3518 *
3519 * This function needs to be called before interrupts are enabled.
3520 */
3521static void ibx_irq_pre_postinstall(struct drm_device *dev)
3522{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003523 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003524
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003525 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003526 return;
3527
3528 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003529 I915_WRITE(SDEIER, 0xffffffff);
3530 POSTING_READ(SDEIER);
3531}
3532
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003533static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003534{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003535 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003536 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003537 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003538}
3539
Ville Syrjälä70591a42014-10-30 19:42:58 +02003540static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3541{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003542 if (IS_CHERRYVIEW(dev_priv))
3543 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3544 else
3545 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3546
Ville Syrjäläad22d102016-04-12 18:56:14 +03003547 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003548 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3549
Ville Syrjälä44d92412017-08-18 21:36:51 +03003550 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003551
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003552 GEN3_IRQ_RESET(VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003553 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003554}
3555
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003556static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3557{
3558 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003559 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003560 enum pipe pipe;
3561
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003562 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003563
3564 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3565 for_each_pipe(dev_priv, pipe)
3566 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3567
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003568 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3569 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003570 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3571 I915_LPE_PIPE_A_INTERRUPT |
3572 I915_LPE_PIPE_B_INTERRUPT;
3573
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003574 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003575 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3576 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003577
Chris Wilson8bd099a2017-11-30 12:52:53 +00003578 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003579
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003580 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003581
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003582 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003583}
3584
3585/* drm_dma.h hooks
3586*/
3587static void ironlake_irq_reset(struct drm_device *dev)
3588{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003589 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003590
Ville Syrjäläd420a502017-08-18 21:37:03 +03003591 if (IS_GEN5(dev_priv))
3592 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003593
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003594 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003595 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003596 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3597
Daniel Vetterfc340442018-04-05 15:00:23 -07003598 if (IS_HASWELL(dev_priv)) {
3599 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3600 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3601 }
3602
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003603 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003604
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003605 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003606}
3607
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003608static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003609{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003610 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003611
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003612 I915_WRITE(VLV_MASTER_IER, 0);
3613 POSTING_READ(VLV_MASTER_IER);
3614
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003615 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003616
Ville Syrjäläad22d102016-04-12 18:56:14 +03003617 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003618 if (dev_priv->display_irqs_enabled)
3619 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003620 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003621}
3622
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003623static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3624{
3625 GEN8_IRQ_RESET_NDX(GT, 0);
3626 GEN8_IRQ_RESET_NDX(GT, 1);
3627 GEN8_IRQ_RESET_NDX(GT, 2);
3628 GEN8_IRQ_RESET_NDX(GT, 3);
3629}
3630
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003631static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003632{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003633 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003634 int pipe;
3635
Ben Widawskyabd58f02013-11-02 21:07:09 -07003636 I915_WRITE(GEN8_MASTER_IRQ, 0);
3637 POSTING_READ(GEN8_MASTER_IRQ);
3638
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003639 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003640
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003641 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3642 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3643
Damien Lespiau055e3932014-08-18 13:49:10 +01003644 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003645 if (intel_display_power_is_enabled(dev_priv,
3646 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003647 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003648
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003649 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3650 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3651 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003652
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003653 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003654 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003655}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003656
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003657static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3658{
3659 /* Disable RCS, BCS, VCS and VECS class engines. */
3660 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3661 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3662
3663 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3664 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3665 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3666 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3667 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3668 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003669
3670 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
3671 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003672}
3673
3674static void gen11_irq_reset(struct drm_device *dev)
3675{
3676 struct drm_i915_private *dev_priv = dev->dev_private;
3677 int pipe;
3678
3679 I915_WRITE(GEN11_GFX_MSTR_IRQ, 0);
3680 POSTING_READ(GEN11_GFX_MSTR_IRQ);
3681
3682 gen11_gt_irq_reset(dev_priv);
3683
3684 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3685
3686 for_each_pipe(dev_priv, pipe)
3687 if (intel_display_power_is_enabled(dev_priv,
3688 POWER_DOMAIN_PIPE(pipe)))
3689 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3690
3691 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3692 GEN3_IRQ_RESET(GEN8_DE_MISC_);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003693 GEN3_IRQ_RESET(GEN11_DE_HPD_);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003694 GEN3_IRQ_RESET(GEN11_GU_MISC_);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003695 GEN3_IRQ_RESET(GEN8_PCU_);
Anusha Srivatsa31604222018-06-26 13:52:23 -07003696
3697 if (HAS_PCH_ICP(dev_priv))
3698 GEN3_IRQ_RESET(SDE);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003699}
3700
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003701void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003702 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003703{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003704 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003705 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003706
Daniel Vetter13321782014-09-15 14:55:29 +02003707 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003708
3709 if (!intel_irqs_enabled(dev_priv)) {
3710 spin_unlock_irq(&dev_priv->irq_lock);
3711 return;
3712 }
3713
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003714 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3715 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3716 dev_priv->de_irq_mask[pipe],
3717 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003718
Daniel Vetter13321782014-09-15 14:55:29 +02003719 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003720}
3721
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003722void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003723 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003724{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003725 enum pipe pipe;
3726
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003727 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003728
3729 if (!intel_irqs_enabled(dev_priv)) {
3730 spin_unlock_irq(&dev_priv->irq_lock);
3731 return;
3732 }
3733
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003734 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3735 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003736
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003737 spin_unlock_irq(&dev_priv->irq_lock);
3738
3739 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003740 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003741}
3742
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003743static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003744{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003745 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003746
3747 I915_WRITE(GEN8_MASTER_IRQ, 0);
3748 POSTING_READ(GEN8_MASTER_IRQ);
3749
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003750 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003751
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003752 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003753
Ville Syrjäläad22d102016-04-12 18:56:14 +03003754 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003755 if (dev_priv->display_irqs_enabled)
3756 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003757 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003758}
3759
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003760static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003761 const u32 hpd[HPD_NUM_PINS])
3762{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003763 struct intel_encoder *encoder;
3764 u32 enabled_irqs = 0;
3765
Chris Wilson91c8a322016-07-05 10:40:23 +01003766 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003767 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3768 enabled_irqs |= hpd[encoder->hpd_pin];
3769
3770 return enabled_irqs;
3771}
3772
Imre Deak1a56b1a2017-01-27 11:39:21 +02003773static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3774{
3775 u32 hotplug;
3776
3777 /*
3778 * Enable digital hotplug on the PCH, and configure the DP short pulse
3779 * duration to 2ms (which is the minimum in the Display Port spec).
3780 * The pulse duration bits are reserved on LPT+.
3781 */
3782 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3783 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3784 PORTC_PULSE_DURATION_MASK |
3785 PORTD_PULSE_DURATION_MASK);
3786 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3787 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3788 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3789 /*
3790 * When CPU and PCH are on the same package, port A
3791 * HPD must be enabled in both north and south.
3792 */
3793 if (HAS_PCH_LPT_LP(dev_priv))
3794 hotplug |= PORTA_HOTPLUG_ENABLE;
3795 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3796}
3797
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003798static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003799{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003800 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003801
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003802 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003803 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003804 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003805 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003806 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003807 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003808 }
3809
Daniel Vetterfee884e2013-07-04 23:35:21 +02003810 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003811
Imre Deak1a56b1a2017-01-27 11:39:21 +02003812 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003813}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003814
Anusha Srivatsa31604222018-06-26 13:52:23 -07003815static void icp_hpd_detection_setup(struct drm_i915_private *dev_priv)
3816{
3817 u32 hotplug;
3818
3819 hotplug = I915_READ(SHOTPLUG_CTL_DDI);
3820 hotplug |= ICP_DDIA_HPD_ENABLE |
3821 ICP_DDIB_HPD_ENABLE;
3822 I915_WRITE(SHOTPLUG_CTL_DDI, hotplug);
3823
3824 hotplug = I915_READ(SHOTPLUG_CTL_TC);
3825 hotplug |= ICP_TC_HPD_ENABLE(PORT_TC1) |
3826 ICP_TC_HPD_ENABLE(PORT_TC2) |
3827 ICP_TC_HPD_ENABLE(PORT_TC3) |
3828 ICP_TC_HPD_ENABLE(PORT_TC4);
3829 I915_WRITE(SHOTPLUG_CTL_TC, hotplug);
3830}
3831
3832static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
3833{
3834 u32 hotplug_irqs, enabled_irqs;
3835
3836 hotplug_irqs = SDE_DDI_MASK_ICP | SDE_TC_MASK_ICP;
3837 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_icp);
3838
3839 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3840
3841 icp_hpd_detection_setup(dev_priv);
3842}
3843
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003844static void gen11_hpd_detection_setup(struct drm_i915_private *dev_priv)
3845{
3846 u32 hotplug;
3847
3848 hotplug = I915_READ(GEN11_TC_HOTPLUG_CTL);
3849 hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) |
3850 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) |
3851 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) |
3852 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4);
3853 I915_WRITE(GEN11_TC_HOTPLUG_CTL, hotplug);
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07003854
3855 hotplug = I915_READ(GEN11_TBT_HOTPLUG_CTL);
3856 hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) |
3857 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) |
3858 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) |
3859 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4);
3860 I915_WRITE(GEN11_TBT_HOTPLUG_CTL, hotplug);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003861}
3862
3863static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3864{
3865 u32 hotplug_irqs, enabled_irqs;
3866 u32 val;
3867
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07003868 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_gen11);
3869 hotplug_irqs = GEN11_DE_TC_HOTPLUG_MASK | GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003870
3871 val = I915_READ(GEN11_DE_HPD_IMR);
3872 val &= ~hotplug_irqs;
3873 I915_WRITE(GEN11_DE_HPD_IMR, val);
3874 POSTING_READ(GEN11_DE_HPD_IMR);
3875
3876 gen11_hpd_detection_setup(dev_priv);
Anusha Srivatsa31604222018-06-26 13:52:23 -07003877
3878 if (HAS_PCH_ICP(dev_priv))
3879 icp_hpd_irq_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003880}
3881
Imre Deak2a57d9c2017-01-27 11:39:18 +02003882static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3883{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003884 u32 val, hotplug;
3885
3886 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3887 if (HAS_PCH_CNP(dev_priv)) {
3888 val = I915_READ(SOUTH_CHICKEN1);
3889 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3890 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3891 I915_WRITE(SOUTH_CHICKEN1, val);
3892 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003893
3894 /* Enable digital hotplug on the PCH */
3895 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3896 hotplug |= PORTA_HOTPLUG_ENABLE |
3897 PORTB_HOTPLUG_ENABLE |
3898 PORTC_HOTPLUG_ENABLE |
3899 PORTD_HOTPLUG_ENABLE;
3900 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3901
3902 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3903 hotplug |= PORTE_HOTPLUG_ENABLE;
3904 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3905}
3906
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003907static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003908{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003909 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003910
3911 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003912 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003913
3914 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3915
Imre Deak2a57d9c2017-01-27 11:39:18 +02003916 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003917}
3918
Imre Deak1a56b1a2017-01-27 11:39:21 +02003919static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3920{
3921 u32 hotplug;
3922
3923 /*
3924 * Enable digital hotplug on the CPU, and configure the DP short pulse
3925 * duration to 2ms (which is the minimum in the Display Port spec)
3926 * The pulse duration bits are reserved on HSW+.
3927 */
3928 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3929 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3930 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3931 DIGITAL_PORTA_PULSE_DURATION_2ms;
3932 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3933}
3934
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003935static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003936{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003937 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003938
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003939 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003940 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003941 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003942
3943 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003944 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003945 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003946 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003947
3948 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003949 } else {
3950 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003951 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003952
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003953 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3954 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003955
Imre Deak1a56b1a2017-01-27 11:39:21 +02003956 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003957
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003958 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003959}
3960
Imre Deak2a57d9c2017-01-27 11:39:18 +02003961static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3962 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003963{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003964 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003965
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003966 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003967 hotplug |= PORTA_HOTPLUG_ENABLE |
3968 PORTB_HOTPLUG_ENABLE |
3969 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303970
3971 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3972 hotplug, enabled_irqs);
3973 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3974
3975 /*
3976 * For BXT invert bit has to be set based on AOB design
3977 * for HPD detection logic, update it based on VBT fields.
3978 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303979 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3980 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3981 hotplug |= BXT_DDIA_HPD_INVERT;
3982 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3983 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3984 hotplug |= BXT_DDIB_HPD_INVERT;
3985 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3986 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3987 hotplug |= BXT_DDIC_HPD_INVERT;
3988
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003989 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003990}
3991
Imre Deak2a57d9c2017-01-27 11:39:18 +02003992static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3993{
3994 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3995}
3996
3997static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3998{
3999 u32 hotplug_irqs, enabled_irqs;
4000
4001 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
4002 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
4003
4004 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
4005
4006 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
4007}
4008
Paulo Zanonid46da432013-02-08 17:35:15 -02004009static void ibx_irq_postinstall(struct drm_device *dev)
4010{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004011 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004012 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02004013
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004014 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02004015 return;
4016
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004017 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01004018 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07004019 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01004020 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07004021 else
4022 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03004023
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03004024 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02004025 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02004026
4027 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
4028 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02004029 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02004030 else
4031 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02004032}
4033
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004034static void gen5_gt_irq_postinstall(struct drm_device *dev)
4035{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004036 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004037 u32 pm_irqs, gt_irqs;
4038
4039 pm_irqs = gt_irqs = 0;
4040
4041 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01004042 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004043 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01004044 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
4045 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004046 }
4047
4048 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01004049 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01004050 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004051 } else {
4052 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
4053 }
4054
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03004055 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004056
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00004057 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02004058 /*
4059 * RPS interrupts will get enabled/disabled on demand when RPS
4060 * itself is enabled/disabled.
4061 */
Akash Goelf4e9af42016-10-12 21:54:30 +05304062 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004063 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05304064 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
4065 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004066
Akash Goelf4e9af42016-10-12 21:54:30 +05304067 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03004068 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004069 }
4070}
4071
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004072static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004073{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004074 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03004075 u32 display_mask, extra_mask;
4076
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00004077 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03004078 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004079 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03004080 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004081 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
4082 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03004083 } else {
4084 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004085 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
4086 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03004087 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
4088 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
4089 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03004090 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004091
Daniel Vetterfc340442018-04-05 15:00:23 -07004092 if (IS_HASWELL(dev_priv)) {
4093 gen3_assert_iir_is_zero(dev_priv, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07004094 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Daniel Vetterfc340442018-04-05 15:00:23 -07004095 display_mask |= DE_EDP_PSR_INT_HSW;
4096 }
4097
Chris Wilson1ec14ad2010-12-04 11:30:53 +00004098 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004099
Paulo Zanoni622364b2014-04-01 15:37:22 -03004100 ibx_irq_pre_postinstall(dev);
4101
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03004102 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004103
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004104 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004105
Imre Deak1a56b1a2017-01-27 11:39:21 +02004106 ilk_hpd_detection_setup(dev_priv);
4107
Paulo Zanonid46da432013-02-08 17:35:15 -02004108 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07004109
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01004110 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02004111 /* Enable PCU event interrupts
4112 *
4113 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02004114 * setup is guaranteed to run in single-threaded context. But we
4115 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004116 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02004117 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02004118 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08004119 }
4120
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004121 return 0;
4122}
4123
Imre Deakf8b79e52014-03-04 19:23:07 +02004124void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
4125{
Chris Wilson67520412017-03-02 13:28:01 +00004126 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02004127
4128 if (dev_priv->display_irqs_enabled)
4129 return;
4130
4131 dev_priv->display_irqs_enabled = true;
4132
Ville Syrjäläd6c69802016-04-11 16:56:27 +03004133 if (intel_irqs_enabled(dev_priv)) {
4134 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004135 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03004136 }
Imre Deakf8b79e52014-03-04 19:23:07 +02004137}
4138
4139void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
4140{
Chris Wilson67520412017-03-02 13:28:01 +00004141 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02004142
4143 if (!dev_priv->display_irqs_enabled)
4144 return;
4145
4146 dev_priv->display_irqs_enabled = false;
4147
Imre Deak950eaba2014-09-08 15:21:09 +03004148 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03004149 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02004150}
4151
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02004152
4153static int valleyview_irq_postinstall(struct drm_device *dev)
4154{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004155 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02004156
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004157 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004158
Ville Syrjäläad22d102016-04-12 18:56:14 +03004159 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004160 if (dev_priv->display_irqs_enabled)
4161 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004162 spin_unlock_irq(&dev_priv->irq_lock);
4163
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004164 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03004165 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004166
4167 return 0;
4168}
4169
Ben Widawskyabd58f02013-11-02 21:07:09 -07004170static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
4171{
Ben Widawskyabd58f02013-11-02 21:07:09 -07004172 /* These are interrupts we'll toggle with the ring mask register */
4173 uint32_t gt_interrupts[] = {
4174 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01004175 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01004176 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
4177 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07004178 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01004179 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
4180 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
4181 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07004182 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01004183 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
4184 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07004185 };
4186
Tvrtko Ursulin98735732016-04-19 16:46:08 +01004187 if (HAS_L3_DPF(dev_priv))
4188 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
4189
Akash Goelf4e9af42016-10-12 21:54:30 +05304190 dev_priv->pm_ier = 0x0;
4191 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05304192 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
4193 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02004194 /*
4195 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304196 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02004197 */
Akash Goelf4e9af42016-10-12 21:54:30 +05304198 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05304199 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004200}
4201
4202static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
4203{
Damien Lespiau770de83d2014-03-20 20:45:01 +00004204 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
4205 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004206 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
4207 u32 de_port_enables;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004208 u32 de_misc_masked = GEN8_DE_EDP_PSR;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004209 enum pipe pipe;
Damien Lespiau770de83d2014-03-20 20:45:01 +00004210
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004211 if (INTEL_GEN(dev_priv) <= 10)
4212 de_misc_masked |= GEN8_DE_MISC_GSE;
4213
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004214 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004215 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004216 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
4217 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004218 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004219 de_port_masked |= BXT_DE_PORT_GMBUS;
4220 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004221 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004222 }
Damien Lespiau770de83d2014-03-20 20:45:01 +00004223
James Ausmusbb187e92018-06-11 17:25:12 -07004224 if (INTEL_GEN(dev_priv) >= 11)
4225 de_port_masked |= ICL_AUX_CHANNEL_E;
4226
Dhinakaran Pandiyan9bb635d2018-05-21 17:25:35 -07004227 if (IS_CNL_WITH_PORT_F(dev_priv) || INTEL_GEN(dev_priv) >= 11)
Rodrigo Vivia324fca2018-01-29 15:22:15 -08004228 de_port_masked |= CNL_AUX_CHANNEL_F;
4229
Damien Lespiau770de83d2014-03-20 20:45:01 +00004230 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
4231 GEN8_PIPE_FIFO_UNDERRUN;
4232
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004233 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004234 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03004235 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
4236 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004237 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
4238
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07004239 gen3_assert_iir_is_zero(dev_priv, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07004240 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07004241
Mika Kahola0a195c02017-10-10 13:17:04 +03004242 for_each_pipe(dev_priv, pipe) {
4243 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004244
Daniel Vetterf458ebb2014-09-30 10:56:39 +02004245 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03004246 POWER_DOMAIN_PIPE(pipe)))
4247 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
4248 dev_priv->de_irq_mask[pipe],
4249 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03004250 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07004251
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03004252 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
4253 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02004254
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004255 if (INTEL_GEN(dev_priv) >= 11) {
4256 u32 de_hpd_masked = 0;
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07004257 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
4258 GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004259
4260 GEN3_IRQ_INIT(GEN11_DE_HPD_, ~de_hpd_masked, de_hpd_enables);
4261 gen11_hpd_detection_setup(dev_priv);
4262 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deak2a57d9c2017-01-27 11:39:18 +02004263 bxt_hpd_detection_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004264 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak1a56b1a2017-01-27 11:39:21 +02004265 ilk_hpd_detection_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004266 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07004267}
4268
4269static int gen8_irq_postinstall(struct drm_device *dev)
4270{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004271 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004272
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004273 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05304274 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03004275
Ben Widawskyabd58f02013-11-02 21:07:09 -07004276 gen8_gt_irq_postinstall(dev_priv);
4277 gen8_de_irq_postinstall(dev_priv);
4278
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004279 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05304280 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004281
Ville Syrjäläe5328c42016-04-13 21:19:47 +03004282 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004283 POSTING_READ(GEN8_MASTER_IRQ);
4284
4285 return 0;
4286}
4287
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004288static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
4289{
4290 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
4291
4292 BUILD_BUG_ON(irqs & 0xffff0000);
4293
4294 /* Enable RCS, BCS, VCS and VECS class interrupts. */
4295 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
4296 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
4297
4298 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
4299 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
4300 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
4301 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
4302 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
4303 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
4304
Oscar Mateod02b98b2018-04-05 17:00:50 +03004305 /*
4306 * RPS interrupts will get enabled/disabled on demand when RPS itself
4307 * is enabled/disabled.
4308 */
4309 dev_priv->pm_ier = 0x0;
4310 dev_priv->pm_imr = ~dev_priv->pm_ier;
4311 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
4312 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004313}
4314
Anusha Srivatsa31604222018-06-26 13:52:23 -07004315static void icp_irq_postinstall(struct drm_device *dev)
4316{
4317 struct drm_i915_private *dev_priv = to_i915(dev);
4318 u32 mask = SDE_GMBUS_ICP;
4319
4320 WARN_ON(I915_READ(SDEIER) != 0);
4321 I915_WRITE(SDEIER, 0xffffffff);
4322 POSTING_READ(SDEIER);
4323
4324 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
4325 I915_WRITE(SDEIMR, ~mask);
4326
4327 icp_hpd_detection_setup(dev_priv);
4328}
4329
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004330static int gen11_irq_postinstall(struct drm_device *dev)
4331{
4332 struct drm_i915_private *dev_priv = dev->dev_private;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004333 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004334
Anusha Srivatsa31604222018-06-26 13:52:23 -07004335 if (HAS_PCH_ICP(dev_priv))
4336 icp_irq_postinstall(dev);
4337
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004338 gen11_gt_irq_postinstall(dev_priv);
4339 gen8_de_irq_postinstall(dev_priv);
4340
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004341 GEN3_IRQ_INIT(GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
4342
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004343 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
4344
4345 I915_WRITE(GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
4346 POSTING_READ(GEN11_GFX_MSTR_IRQ);
4347
4348 return 0;
4349}
4350
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004351static int cherryview_irq_postinstall(struct drm_device *dev)
4352{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004353 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004354
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004355 gen8_gt_irq_postinstall(dev_priv);
4356
Ville Syrjäläad22d102016-04-12 18:56:14 +03004357 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004358 if (dev_priv->display_irqs_enabled)
4359 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004360 spin_unlock_irq(&dev_priv->irq_lock);
4361
Ville Syrjäläe5328c42016-04-13 21:19:47 +03004362 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004363 POSTING_READ(GEN8_MASTER_IRQ);
4364
4365 return 0;
4366}
4367
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004368static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004369{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004370 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004371
Ville Syrjälä44d92412017-08-18 21:36:51 +03004372 i9xx_pipestat_irq_reset(dev_priv);
4373
Ville Syrjäläd420a502017-08-18 21:37:03 +03004374 I915_WRITE16(HWSTAM, 0xffff);
4375
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004376 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01004377}
4378
4379static int i8xx_irq_postinstall(struct drm_device *dev)
4380{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004381 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004382 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004383
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004384 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
4385 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01004386
4387 /* Unmask the interrupts that we always want on. */
4388 dev_priv->irq_mask =
4389 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004390 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004391
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004392 enable_mask =
4393 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4394 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4395 I915_USER_INTERRUPT;
4396
4397 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004398
Daniel Vetter379ef822013-10-16 22:55:56 +02004399 /* Interrupt setup is already guaranteed to be single-threaded, this is
4400 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004401 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004402 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4403 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004404 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004405
Chris Wilsonc2798b12012-04-22 21:13:57 +01004406 return 0;
4407}
4408
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004409static void i8xx_error_irq_ack(struct drm_i915_private *dev_priv,
4410 u16 *eir, u16 *eir_stuck)
4411{
4412 u16 emr;
4413
4414 *eir = I915_READ16(EIR);
4415
4416 if (*eir)
4417 I915_WRITE16(EIR, *eir);
4418
4419 *eir_stuck = I915_READ16(EIR);
4420 if (*eir_stuck == 0)
4421 return;
4422
4423 /*
4424 * Toggle all EMR bits to make sure we get an edge
4425 * in the ISR master error bit if we don't clear
4426 * all the EIR bits. Otherwise the edge triggered
4427 * IIR on i965/g4x wouldn't notice that an interrupt
4428 * is still pending. Also some EIR bits can't be
4429 * cleared except by handling the underlying error
4430 * (or by a GPU reset) so we mask any bit that
4431 * remains set.
4432 */
4433 emr = I915_READ16(EMR);
4434 I915_WRITE16(EMR, 0xffff);
4435 I915_WRITE16(EMR, emr | *eir_stuck);
4436}
4437
4438static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
4439 u16 eir, u16 eir_stuck)
4440{
4441 DRM_DEBUG("Master Error: EIR 0x%04x\n", eir);
4442
4443 if (eir_stuck)
4444 DRM_DEBUG_DRIVER("EIR stuck: 0x%04x, masked\n", eir_stuck);
4445}
4446
4447static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
4448 u32 *eir, u32 *eir_stuck)
4449{
4450 u32 emr;
4451
4452 *eir = I915_READ(EIR);
4453
4454 I915_WRITE(EIR, *eir);
4455
4456 *eir_stuck = I915_READ(EIR);
4457 if (*eir_stuck == 0)
4458 return;
4459
4460 /*
4461 * Toggle all EMR bits to make sure we get an edge
4462 * in the ISR master error bit if we don't clear
4463 * all the EIR bits. Otherwise the edge triggered
4464 * IIR on i965/g4x wouldn't notice that an interrupt
4465 * is still pending. Also some EIR bits can't be
4466 * cleared except by handling the underlying error
4467 * (or by a GPU reset) so we mask any bit that
4468 * remains set.
4469 */
4470 emr = I915_READ(EMR);
4471 I915_WRITE(EMR, 0xffffffff);
4472 I915_WRITE(EMR, emr | *eir_stuck);
4473}
4474
4475static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
4476 u32 eir, u32 eir_stuck)
4477{
4478 DRM_DEBUG("Master Error, EIR 0x%08x\n", eir);
4479
4480 if (eir_stuck)
4481 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masked\n", eir_stuck);
4482}
4483
Daniel Vetterff1f5252012-10-02 15:10:55 +02004484static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004485{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004486 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004487 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004488 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004489
Imre Deak2dd2a882015-02-24 11:14:30 +02004490 if (!intel_irqs_enabled(dev_priv))
4491 return IRQ_NONE;
4492
Imre Deak1f814da2015-12-16 02:52:19 +02004493 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4494 disable_rpm_wakeref_asserts(dev_priv);
4495
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004496 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004497 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004498 u16 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004499 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03004500
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004501 iir = I915_READ16(IIR);
4502 if (iir == 0)
4503 break;
4504
4505 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004506
Ville Syrjäläeb643432017-08-18 21:36:59 +03004507 /* Call regardless, as some status bits might not be
4508 * signalled in iir */
4509 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004510
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004511 if (iir & I915_MASTER_ERROR_INTERRUPT)
4512 i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4513
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004514 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004515
Chris Wilsonc2798b12012-04-22 21:13:57 +01004516 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304517 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004518
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004519 if (iir & I915_MASTER_ERROR_INTERRUPT)
4520 i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004521
Ville Syrjäläeb643432017-08-18 21:36:59 +03004522 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004523 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004524
Imre Deak1f814da2015-12-16 02:52:19 +02004525 enable_rpm_wakeref_asserts(dev_priv);
4526
4527 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004528}
4529
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004530static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004531{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004532 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004533
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004534 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004535 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004536 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4537 }
4538
Ville Syrjälä44d92412017-08-18 21:36:51 +03004539 i9xx_pipestat_irq_reset(dev_priv);
4540
Ville Syrjäläd420a502017-08-18 21:37:03 +03004541 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004542
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004543 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004544}
4545
4546static int i915_irq_postinstall(struct drm_device *dev)
4547{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004548 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004549 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004550
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004551 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
4552 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01004553
4554 /* Unmask the interrupts that we always want on. */
4555 dev_priv->irq_mask =
4556 ~(I915_ASLE_INTERRUPT |
4557 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004558 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004559
4560 enable_mask =
4561 I915_ASLE_INTERRUPT |
4562 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4563 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004564 I915_USER_INTERRUPT;
4565
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004566 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004567 /* Enable in IER... */
4568 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4569 /* and unmask in IMR */
4570 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4571 }
4572
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004573 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004574
Daniel Vetter379ef822013-10-16 22:55:56 +02004575 /* Interrupt setup is already guaranteed to be single-threaded, this is
4576 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004577 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004578 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4579 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004580 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004581
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004582 i915_enable_asle_pipestat(dev_priv);
4583
Daniel Vetter20afbda2012-12-11 14:05:07 +01004584 return 0;
4585}
4586
Daniel Vetterff1f5252012-10-02 15:10:55 +02004587static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004588{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004589 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004590 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004591 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004592
Imre Deak2dd2a882015-02-24 11:14:30 +02004593 if (!intel_irqs_enabled(dev_priv))
4594 return IRQ_NONE;
4595
Imre Deak1f814da2015-12-16 02:52:19 +02004596 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4597 disable_rpm_wakeref_asserts(dev_priv);
4598
Chris Wilson38bde182012-04-24 22:59:50 +01004599 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004600 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004601 u32 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004602 u32 hotplug_status = 0;
4603 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004604
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004605 iir = I915_READ(IIR);
4606 if (iir == 0)
4607 break;
4608
4609 ret = IRQ_HANDLED;
4610
4611 if (I915_HAS_HOTPLUG(dev_priv) &&
4612 iir & I915_DISPLAY_PORT_INTERRUPT)
4613 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004614
Ville Syrjäläeb643432017-08-18 21:36:59 +03004615 /* Call regardless, as some status bits might not be
4616 * signalled in iir */
4617 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004618
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004619 if (iir & I915_MASTER_ERROR_INTERRUPT)
4620 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4621
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004622 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004623
Chris Wilsona266c7d2012-04-24 22:59:44 +01004624 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304625 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004626
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004627 if (iir & I915_MASTER_ERROR_INTERRUPT)
4628 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004629
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004630 if (hotplug_status)
4631 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4632
4633 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4634 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004635
Imre Deak1f814da2015-12-16 02:52:19 +02004636 enable_rpm_wakeref_asserts(dev_priv);
4637
Chris Wilsona266c7d2012-04-24 22:59:44 +01004638 return ret;
4639}
4640
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004641static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004642{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004643 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004644
Egbert Eich0706f172015-09-23 16:15:27 +02004645 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004646 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004647
Ville Syrjälä44d92412017-08-18 21:36:51 +03004648 i9xx_pipestat_irq_reset(dev_priv);
4649
Ville Syrjäläd420a502017-08-18 21:37:03 +03004650 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03004651
Ville Syrjäläba7eb782017-08-18 21:36:53 +03004652 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01004653}
4654
4655static int i965_irq_postinstall(struct drm_device *dev)
4656{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004657 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004658 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004659 u32 error_mask;
4660
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004661 /*
4662 * Enable some error detection, note the instruction error mask
4663 * bit is reserved, so we leave it masked.
4664 */
4665 if (IS_G4X(dev_priv)) {
4666 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4667 GM45_ERROR_MEM_PRIV |
4668 GM45_ERROR_CP_PRIV |
4669 I915_ERROR_MEMORY_REFRESH);
4670 } else {
4671 error_mask = ~(I915_ERROR_PAGE_TABLE |
4672 I915_ERROR_MEMORY_REFRESH);
4673 }
4674 I915_WRITE(EMR, error_mask);
4675
Chris Wilsona266c7d2012-04-24 22:59:44 +01004676 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004677 dev_priv->irq_mask =
4678 ~(I915_ASLE_INTERRUPT |
4679 I915_DISPLAY_PORT_INTERRUPT |
4680 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4681 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004682 I915_MASTER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004683
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004684 enable_mask =
4685 I915_ASLE_INTERRUPT |
4686 I915_DISPLAY_PORT_INTERRUPT |
4687 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4688 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004689 I915_MASTER_ERROR_INTERRUPT |
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004690 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004691
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004692 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004693 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004694
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004695 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
4696
Daniel Vetterb79480b2013-06-27 17:52:10 +02004697 /* Interrupt setup is already guaranteed to be single-threaded, this is
4698 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004699 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004700 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4701 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4702 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004703 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004704
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004705 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004706
4707 return 0;
4708}
4709
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004710static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004711{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004712 u32 hotplug_en;
4713
Chris Wilson67520412017-03-02 13:28:01 +00004714 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004715
Ville Syrjälä778eb332015-01-09 14:21:13 +02004716 /* Note HDMI and DP share hotplug bits */
4717 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004718 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004719 /* Programming the CRT detection parameters tends
4720 to generate a spurious hotplug event about three
4721 seconds later. So just do it once.
4722 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004723 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004724 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004725 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004726
Ville Syrjälä778eb332015-01-09 14:21:13 +02004727 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004728 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004729 HOTPLUG_INT_EN_MASK |
4730 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4731 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4732 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004733}
4734
Daniel Vetterff1f5252012-10-02 15:10:55 +02004735static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004736{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004737 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004738 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004739 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004740
Imre Deak2dd2a882015-02-24 11:14:30 +02004741 if (!intel_irqs_enabled(dev_priv))
4742 return IRQ_NONE;
4743
Imre Deak1f814da2015-12-16 02:52:19 +02004744 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4745 disable_rpm_wakeref_asserts(dev_priv);
4746
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004747 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004748 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004749 u32 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004750 u32 hotplug_status = 0;
4751 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004752
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004753 iir = I915_READ(IIR);
4754 if (iir == 0)
4755 break;
4756
4757 ret = IRQ_HANDLED;
4758
4759 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4760 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004761
Ville Syrjäläeb643432017-08-18 21:36:59 +03004762 /* Call regardless, as some status bits might not be
4763 * signalled in iir */
4764 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004765
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004766 if (iir & I915_MASTER_ERROR_INTERRUPT)
4767 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4768
Daniel Vetterfd3a4022017-07-20 19:57:51 +02004769 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004770
Chris Wilsona266c7d2012-04-24 22:59:44 +01004771 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304772 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004773
Chris Wilsona266c7d2012-04-24 22:59:44 +01004774 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05304775 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004776
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004777 if (iir & I915_MASTER_ERROR_INTERRUPT)
4778 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004779
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004780 if (hotplug_status)
4781 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4782
4783 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4784 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004785
Imre Deak1f814da2015-12-16 02:52:19 +02004786 enable_rpm_wakeref_asserts(dev_priv);
4787
Chris Wilsona266c7d2012-04-24 22:59:44 +01004788 return ret;
4789}
4790
Daniel Vetterfca52a52014-09-30 10:56:45 +02004791/**
4792 * intel_irq_init - initializes irq support
4793 * @dev_priv: i915 device instance
4794 *
4795 * This function initializes all the irq support including work items, timers
4796 * and all the vtables. It does not setup the interrupt itself though.
4797 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004798void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004799{
Chris Wilson91c8a322016-07-05 10:40:23 +01004800 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004801 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004802 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004803
Jani Nikula77913b32015-06-18 13:06:16 +03004804 intel_hpd_init_work(dev_priv);
4805
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004806 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004807
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004808 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004809 for (i = 0; i < MAX_L3_SLICES; ++i)
4810 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004811
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004812 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304813 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4814
Deepak Sa6706b42014-03-15 20:23:22 +05304815 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004816 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a5872014-08-29 14:14:07 +03004817 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004818 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004819 else
4820 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304821
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004822 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304823
4824 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004825 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304826 * if GEN6_PM_UP_EI_EXPIRED is masked.
4827 *
4828 * TODO: verify if this can be reproduced on VLV,CHV.
4829 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004830 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004831 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304832
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004833 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004834 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304835
Daniel Vetterb9632912014-09-30 10:56:44 +02004836 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004837 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004838 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004839 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004840 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f507c2015-09-18 20:03:42 +03004841 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004842 } else {
4843 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4844 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004845 }
4846
Ville Syrjälä21da2702014-08-06 14:49:55 +03004847 /*
4848 * Opt out of the vblank disable timer on everything except gen2.
4849 * Gen2 doesn't have a hardware frame counter and so depends on
4850 * vblank interrupts to produce sane vblank seuquence numbers.
4851 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004852 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004853 dev->vblank_disable_immediate = true;
4854
Chris Wilson262fd482017-02-15 13:15:47 +00004855 /* Most platforms treat the display irq block as an always-on
4856 * power domain. vlv/chv can disable it at runtime and need
4857 * special care to avoid writing any of the display block registers
4858 * outside of the power domain. We defer setting up the display irqs
4859 * in this case to the runtime pm.
4860 */
4861 dev_priv->display_irqs_enabled = true;
4862 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4863 dev_priv->display_irqs_enabled = false;
4864
Lyude317eaa92017-02-03 21:18:25 -05004865 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4866
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004867 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004868 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004869
Daniel Vetterb9632912014-09-30 10:56:44 +02004870 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004871 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004872 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004873 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004874 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004875 dev->driver->enable_vblank = i965_enable_vblank;
4876 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004877 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004878 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004879 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004880 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004881 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004882 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004883 dev->driver->enable_vblank = i965_enable_vblank;
4884 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004885 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004886 } else if (INTEL_GEN(dev_priv) >= 11) {
4887 dev->driver->irq_handler = gen11_irq_handler;
4888 dev->driver->irq_preinstall = gen11_irq_reset;
4889 dev->driver->irq_postinstall = gen11_irq_postinstall;
4890 dev->driver->irq_uninstall = gen11_irq_reset;
4891 dev->driver->enable_vblank = gen8_enable_vblank;
4892 dev->driver->disable_vblank = gen8_disable_vblank;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004893 dev_priv->display.hpd_irq_setup = gen11_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004894 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004895 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004896 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004897 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004898 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004899 dev->driver->enable_vblank = gen8_enable_vblank;
4900 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004901 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004902 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004903 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4904 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004905 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4906 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004907 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004908 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004909 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004910 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004911 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004912 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004913 dev->driver->enable_vblank = ironlake_enable_vblank;
4914 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004915 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004916 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004917 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004918 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004919 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4920 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004921 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004922 dev->driver->enable_vblank = i8xx_enable_vblank;
4923 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004924 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004925 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004926 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004927 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004928 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004929 dev->driver->enable_vblank = i8xx_enable_vblank;
4930 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004931 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004932 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004933 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004934 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004935 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004936 dev->driver->enable_vblank = i965_enable_vblank;
4937 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004938 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004939 if (I915_HAS_HOTPLUG(dev_priv))
4940 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004941 }
4942}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004943
Daniel Vetterfca52a52014-09-30 10:56:45 +02004944/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004945 * intel_irq_fini - deinitializes IRQ support
4946 * @i915: i915 device instance
4947 *
4948 * This function deinitializes all the IRQ support.
4949 */
4950void intel_irq_fini(struct drm_i915_private *i915)
4951{
4952 int i;
4953
4954 for (i = 0; i < MAX_L3_SLICES; ++i)
4955 kfree(i915->l3_parity.remap_info[i]);
4956}
4957
4958/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004959 * intel_irq_install - enables the hardware interrupt
4960 * @dev_priv: i915 device instance
4961 *
4962 * This function enables the hardware interrupt handling, but leaves the hotplug
4963 * handling still disabled. It is called after intel_irq_init().
4964 *
4965 * In the driver load and resume code we need working interrupts in a few places
4966 * but don't want to deal with the hassle of concurrent probe and hotplug
4967 * workers. Hence the split into this two-stage approach.
4968 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004969int intel_irq_install(struct drm_i915_private *dev_priv)
4970{
4971 /*
4972 * We enable some interrupt sources in our postinstall hooks, so mark
4973 * interrupts as enabled _before_ actually enabling them to avoid
4974 * special cases in our ordering checks.
4975 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004976 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004977
Chris Wilson91c8a322016-07-05 10:40:23 +01004978 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004979}
4980
Daniel Vetterfca52a52014-09-30 10:56:45 +02004981/**
4982 * intel_irq_uninstall - finilizes all irq handling
4983 * @dev_priv: i915 device instance
4984 *
4985 * This stops interrupt and hotplug handling and unregisters and frees all
4986 * resources acquired in the init functions.
4987 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004988void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4989{
Chris Wilson91c8a322016-07-05 10:40:23 +01004990 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004991 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004992 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004993}
4994
Daniel Vetterfca52a52014-09-30 10:56:45 +02004995/**
4996 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4997 * @dev_priv: i915 device instance
4998 *
4999 * This function is used to disable interrupts at runtime, both in the runtime
5000 * pm and the system suspend/resume code.
5001 */
Daniel Vetterb9632912014-09-30 10:56:44 +02005002void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03005003{
Chris Wilson91c8a322016-07-05 10:40:23 +01005004 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01005005 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01005006 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03005007}
5008
Daniel Vetterfca52a52014-09-30 10:56:45 +02005009/**
5010 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
5011 * @dev_priv: i915 device instance
5012 *
5013 * This function is used to enable interrupts at runtime, both in the runtime
5014 * pm and the system suspend/resume code.
5015 */
Daniel Vetterb9632912014-09-30 10:56:44 +02005016void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03005017{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01005018 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01005019 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
5020 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03005021}