blob: efd7827ff18120cd39fbb876796699c281b6751b [file] [log] [blame]
Dave Airlie0d6aa602006-01-02 20:14:23 +11001/* i915_irq.c -- IRQ support for the I915 -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 */
Dave Airlie0d6aa602006-01-02 20:14:23 +11003/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas.
5 * All Rights Reserved.
Dave Airliebc54fd12005-06-23 22:46:46 +10006 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the
9 * "Software"), to deal in the Software without restriction, including
10 * without limitation the rights to use, copy, modify, merge, publish,
11 * distribute, sub license, and/or sell copies of the Software, and to
12 * permit persons to whom the Software is furnished to do so, subject to
13 * the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the
16 * next paragraph) shall be included in all copies or substantial portions
17 * of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 *
Dave Airlie0d6aa602006-01-02 20:14:23 +110027 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070028
Joe Perchesa70491c2012-03-18 13:00:11 -070029#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
30
Jesse Barnes63eeaf32009-06-18 16:56:52 -070031#include <linux/sysrq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090032#include <linux/slab.h>
Damien Lespiaub2c88f52013-10-15 18:55:29 +010033#include <linux/circ_buf.h>
David Howells760285e2012-10-02 18:01:07 +010034#include <drm/drmP.h>
35#include <drm/i915_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include "i915_drv.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010037#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080038#include "intel_drv.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070039
Daniel Vetterfca52a52014-09-30 10:56:45 +020040/**
41 * DOC: interrupt handling
42 *
43 * These functions provide the basic support for enabling and disabling the
44 * interrupt handling support. There's a lot more functionality in i915_irq.c
45 * and related files, but that will be described in separate chapters.
46 */
47
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +030048static const u32 hpd_ilk[HPD_NUM_PINS] = {
49 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
50};
51
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +030052static const u32 hpd_ivb[HPD_NUM_PINS] = {
53 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
54};
55
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +030056static const u32 hpd_bdw[HPD_NUM_PINS] = {
57 [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
58};
59
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020060static const u32 hpd_ibx[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050061 [HPD_CRT] = SDE_CRT_HOTPLUG,
62 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
63 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
64 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
65 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
66};
67
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020068static const u32 hpd_cpt[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050069 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010070 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050071 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
72 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
73 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
74};
75
Xiong Zhang26951ca2015-08-17 15:55:50 +080076static const u32 hpd_spt[HPD_NUM_PINS] = {
Ville Syrjälä74c0b392015-08-27 23:56:07 +030077 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
Xiong Zhang26951ca2015-08-17 15:55:50 +080078 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
79 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
80 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
81 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
82};
83
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020084static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050085 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
86 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
87 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
88 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
89 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
90 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
91};
92
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020093static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050094 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
95 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
96 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
97 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
98 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
99 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
100};
101
Ville Syrjälä4bca26d2015-05-11 20:49:10 +0300102static const u32 hpd_status_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -0500103 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
104 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
105 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
106 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
107 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
108 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
109};
110
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200111/* BXT hpd list */
112static const u32 hpd_bxt[HPD_NUM_PINS] = {
Sonika Jindal7f3561b2015-08-10 10:35:35 +0530113 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200114 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
115 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
116};
117
Paulo Zanoni5c502442014-04-01 15:37:11 -0300118/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300119#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300120 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
121 POSTING_READ(GEN8_##type##_IMR(which)); \
122 I915_WRITE(GEN8_##type##_IER(which), 0); \
123 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
124 POSTING_READ(GEN8_##type##_IIR(which)); \
125 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
126 POSTING_READ(GEN8_##type##_IIR(which)); \
127} while (0)
128
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300129#define GEN3_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300130 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300131 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300132 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300133 I915_WRITE(type##IIR, 0xffffffff); \
134 POSTING_READ(type##IIR); \
135 I915_WRITE(type##IIR, 0xffffffff); \
136 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300137} while (0)
138
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300139#define GEN2_IRQ_RESET(type) do { \
140 I915_WRITE16(type##IMR, 0xffff); \
141 POSTING_READ16(type##IMR); \
142 I915_WRITE16(type##IER, 0); \
143 I915_WRITE16(type##IIR, 0xffff); \
144 POSTING_READ16(type##IIR); \
145 I915_WRITE16(type##IIR, 0xffff); \
146 POSTING_READ16(type##IIR); \
147} while (0)
148
Paulo Zanoni337ba012014-04-01 15:37:16 -0300149/*
150 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
151 */
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300152static void gen3_assert_iir_is_zero(struct drm_i915_private *dev_priv,
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200153 i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300154{
155 u32 val = I915_READ(reg);
156
157 if (val == 0)
158 return;
159
160 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200161 i915_mmio_reg_offset(reg), val);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300162 I915_WRITE(reg, 0xffffffff);
163 POSTING_READ(reg);
164 I915_WRITE(reg, 0xffffffff);
165 POSTING_READ(reg);
166}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300167
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300168static void gen2_assert_iir_is_zero(struct drm_i915_private *dev_priv,
169 i915_reg_t reg)
170{
171 u16 val = I915_READ16(reg);
172
173 if (val == 0)
174 return;
175
176 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
177 i915_mmio_reg_offset(reg), val);
178 I915_WRITE16(reg, 0xffff);
179 POSTING_READ16(reg);
180 I915_WRITE16(reg, 0xffff);
181 POSTING_READ16(reg);
182}
183
Paulo Zanoni35079892014-04-01 15:37:15 -0300184#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300185 gen3_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300186 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200187 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
188 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300189} while (0)
190
Ville Syrjälä3488d4e2017-08-18 21:36:52 +0300191#define GEN3_IRQ_INIT(type, imr_val, ier_val) do { \
192 gen3_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300193 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200194 I915_WRITE(type##IMR, (imr_val)); \
195 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300196} while (0)
197
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300198#define GEN2_IRQ_INIT(type, imr_val, ier_val) do { \
199 gen2_assert_iir_is_zero(dev_priv, type##IIR); \
200 I915_WRITE16(type##IER, (ier_val)); \
201 I915_WRITE16(type##IMR, (imr_val)); \
202 POSTING_READ16(type##IMR); \
203} while (0)
204
Imre Deakc9a9a262014-11-05 20:48:37 +0200205static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530206static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Imre Deakc9a9a262014-11-05 20:48:37 +0200207
Egbert Eich0706f172015-09-23 16:15:27 +0200208/* For display hotplug interrupt */
209static inline void
210i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
211 uint32_t mask,
212 uint32_t bits)
213{
214 uint32_t val;
215
Chris Wilson67520412017-03-02 13:28:01 +0000216 lockdep_assert_held(&dev_priv->irq_lock);
Egbert Eich0706f172015-09-23 16:15:27 +0200217 WARN_ON(bits & ~mask);
218
219 val = I915_READ(PORT_HOTPLUG_EN);
220 val &= ~mask;
221 val |= bits;
222 I915_WRITE(PORT_HOTPLUG_EN, val);
223}
224
225/**
226 * i915_hotplug_interrupt_update - update hotplug interrupt enable
227 * @dev_priv: driver private
228 * @mask: bits to update
229 * @bits: bits to enable
230 * NOTE: the HPD enable bits are modified both inside and outside
231 * of an interrupt context. To avoid that read-modify-write cycles
232 * interfer, these bits are protected by a spinlock. Since this
233 * function is usually not called from a context where the lock is
234 * held already, this function acquires the lock itself. A non-locking
235 * version is also available.
236 */
237void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
238 uint32_t mask,
239 uint32_t bits)
240{
241 spin_lock_irq(&dev_priv->irq_lock);
242 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
243 spin_unlock_irq(&dev_priv->irq_lock);
244}
245
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300246/**
247 * ilk_update_display_irq - update DEIMR
248 * @dev_priv: driver private
249 * @interrupt_mask: mask of interrupt bits to update
250 * @enabled_irq_mask: mask of interrupt bits to enable
251 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200252void ilk_update_display_irq(struct drm_i915_private *dev_priv,
253 uint32_t interrupt_mask,
254 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800255{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300256 uint32_t new_val;
257
Chris Wilson67520412017-03-02 13:28:01 +0000258 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200259
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300260 WARN_ON(enabled_irq_mask & ~interrupt_mask);
261
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700262 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300263 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300264
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300265 new_val = dev_priv->irq_mask;
266 new_val &= ~interrupt_mask;
267 new_val |= (~enabled_irq_mask & interrupt_mask);
268
269 if (new_val != dev_priv->irq_mask) {
270 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000271 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000272 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800273 }
274}
275
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300276/**
277 * ilk_update_gt_irq - update GTIMR
278 * @dev_priv: driver private
279 * @interrupt_mask: mask of interrupt bits to update
280 * @enabled_irq_mask: mask of interrupt bits to enable
281 */
282static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
283 uint32_t interrupt_mask,
284 uint32_t enabled_irq_mask)
285{
Chris Wilson67520412017-03-02 13:28:01 +0000286 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300287
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100288 WARN_ON(enabled_irq_mask & ~interrupt_mask);
289
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700290 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300291 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300292
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300293 dev_priv->gt_irq_mask &= ~interrupt_mask;
294 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
295 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300296}
297
Daniel Vetter480c8032014-07-16 09:49:40 +0200298void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300299{
300 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100301 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300302}
303
Daniel Vetter480c8032014-07-16 09:49:40 +0200304void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300305{
306 ilk_update_gt_irq(dev_priv, mask, 0);
307}
308
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200309static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200310{
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700311 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
Imre Deakb900b942014-11-05 20:48:48 +0200312}
313
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200314static i915_reg_t gen6_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200315{
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700316 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
Imre Deaka72fbc32014-11-05 20:48:31 +0200317}
318
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200319static i915_reg_t gen6_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200320{
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700321 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
Imre Deakb900b942014-11-05 20:48:48 +0200322}
323
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300324/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200325 * snb_update_pm_irq - update GEN6_PMIMR
326 * @dev_priv: driver private
327 * @interrupt_mask: mask of interrupt bits to update
328 * @enabled_irq_mask: mask of interrupt bits to enable
329 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300330static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
331 uint32_t interrupt_mask,
332 uint32_t enabled_irq_mask)
333{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300334 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300335
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100336 WARN_ON(enabled_irq_mask & ~interrupt_mask);
337
Chris Wilson67520412017-03-02 13:28:01 +0000338 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300339
Akash Goelf4e9af42016-10-12 21:54:30 +0530340 new_val = dev_priv->pm_imr;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300341 new_val &= ~interrupt_mask;
342 new_val |= (~enabled_irq_mask & interrupt_mask);
343
Akash Goelf4e9af42016-10-12 21:54:30 +0530344 if (new_val != dev_priv->pm_imr) {
345 dev_priv->pm_imr = new_val;
346 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_imr);
Imre Deaka72fbc32014-11-05 20:48:31 +0200347 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300348 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300349}
350
Akash Goelf4e9af42016-10-12 21:54:30 +0530351void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300352{
Imre Deak9939fba2014-11-20 23:01:47 +0200353 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
354 return;
355
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300356 snb_update_pm_irq(dev_priv, mask, mask);
357}
358
Akash Goelf4e9af42016-10-12 21:54:30 +0530359static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Imre Deak9939fba2014-11-20 23:01:47 +0200360{
361 snb_update_pm_irq(dev_priv, mask, 0);
362}
363
Akash Goelf4e9af42016-10-12 21:54:30 +0530364void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300365{
Imre Deak9939fba2014-11-20 23:01:47 +0200366 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
367 return;
368
Akash Goelf4e9af42016-10-12 21:54:30 +0530369 __gen6_mask_pm_irq(dev_priv, mask);
370}
371
Oscar Mateo3814fd72017-08-23 16:58:24 -0700372static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530373{
374 i915_reg_t reg = gen6_pm_iir(dev_priv);
375
Chris Wilson67520412017-03-02 13:28:01 +0000376 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530377
378 I915_WRITE(reg, reset_mask);
379 I915_WRITE(reg, reset_mask);
380 POSTING_READ(reg);
381}
382
Oscar Mateo3814fd72017-08-23 16:58:24 -0700383static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530384{
Chris Wilson67520412017-03-02 13:28:01 +0000385 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530386
387 dev_priv->pm_ier |= enable_mask;
388 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
389 gen6_unmask_pm_irq(dev_priv, enable_mask);
390 /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */
391}
392
Oscar Mateo3814fd72017-08-23 16:58:24 -0700393static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530394{
Chris Wilson67520412017-03-02 13:28:01 +0000395 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530396
397 dev_priv->pm_ier &= ~disable_mask;
398 __gen6_mask_pm_irq(dev_priv, disable_mask);
399 I915_WRITE(gen6_pm_ier(dev_priv), dev_priv->pm_ier);
400 /* though a barrier is missing here, but don't really need a one */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300401}
402
Chris Wilsondc979972016-05-10 14:10:04 +0100403void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200404{
Imre Deak3cc134e2014-11-19 15:30:03 +0200405 spin_lock_irq(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530406 gen6_reset_pm_iir(dev_priv, dev_priv->pm_rps_events);
Imre Deak096fad92015-03-23 19:11:35 +0200407 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200408 spin_unlock_irq(&dev_priv->irq_lock);
409}
410
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100411void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200412{
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100413 if (READ_ONCE(dev_priv->rps.interrupts_enabled))
414 return;
415
Imre Deakb900b942014-11-05 20:48:48 +0200416 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100417 WARN_ON_ONCE(dev_priv->rps.pm_iir);
418 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200419 dev_priv->rps.interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200420 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200421
Imre Deakb900b942014-11-05 20:48:48 +0200422 spin_unlock_irq(&dev_priv->irq_lock);
423}
424
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100425void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200426{
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100427 if (!READ_ONCE(dev_priv->rps.interrupts_enabled))
428 return;
429
Imre Deakd4d70aa2014-11-19 15:30:04 +0200430 spin_lock_irq(&dev_priv->irq_lock);
431 dev_priv->rps.interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200432
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100433 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200434
Akash Goelf4e9af42016-10-12 21:54:30 +0530435 gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200436
437 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100438 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100439
440 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700441 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100442 * we will reset the GPU to minimum frequencies, so the current
443 * state of the worker can be discarded.
444 */
445 cancel_work_sync(&dev_priv->rps.work);
446 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200447}
448
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530449void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
450{
451 spin_lock_irq(&dev_priv->irq_lock);
452 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
453 spin_unlock_irq(&dev_priv->irq_lock);
454}
455
456void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
457{
458 spin_lock_irq(&dev_priv->irq_lock);
459 if (!dev_priv->guc.interrupts_enabled) {
460 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
461 dev_priv->pm_guc_events);
462 dev_priv->guc.interrupts_enabled = true;
463 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
464 }
465 spin_unlock_irq(&dev_priv->irq_lock);
466}
467
468void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
469{
470 spin_lock_irq(&dev_priv->irq_lock);
471 dev_priv->guc.interrupts_enabled = false;
472
473 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
474
475 spin_unlock_irq(&dev_priv->irq_lock);
476 synchronize_irq(dev_priv->drm.irq);
477
478 gen9_reset_guc_interrupts(dev_priv);
479}
480
Ben Widawsky09610212014-05-15 20:58:08 +0300481/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200482 * bdw_update_port_irq - update DE port interrupt
483 * @dev_priv: driver private
484 * @interrupt_mask: mask of interrupt bits to update
485 * @enabled_irq_mask: mask of interrupt bits to enable
486 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300487static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
488 uint32_t interrupt_mask,
489 uint32_t enabled_irq_mask)
490{
491 uint32_t new_val;
492 uint32_t old_val;
493
Chris Wilson67520412017-03-02 13:28:01 +0000494 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300495
496 WARN_ON(enabled_irq_mask & ~interrupt_mask);
497
498 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
499 return;
500
501 old_val = I915_READ(GEN8_DE_PORT_IMR);
502
503 new_val = old_val;
504 new_val &= ~interrupt_mask;
505 new_val |= (~enabled_irq_mask & interrupt_mask);
506
507 if (new_val != old_val) {
508 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
509 POSTING_READ(GEN8_DE_PORT_IMR);
510 }
511}
512
513/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200514 * bdw_update_pipe_irq - update DE pipe interrupt
515 * @dev_priv: driver private
516 * @pipe: pipe whose interrupt to update
517 * @interrupt_mask: mask of interrupt bits to update
518 * @enabled_irq_mask: mask of interrupt bits to enable
519 */
520void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
521 enum pipe pipe,
522 uint32_t interrupt_mask,
523 uint32_t enabled_irq_mask)
524{
525 uint32_t new_val;
526
Chris Wilson67520412017-03-02 13:28:01 +0000527 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200528
529 WARN_ON(enabled_irq_mask & ~interrupt_mask);
530
531 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
532 return;
533
534 new_val = dev_priv->de_irq_mask[pipe];
535 new_val &= ~interrupt_mask;
536 new_val |= (~enabled_irq_mask & interrupt_mask);
537
538 if (new_val != dev_priv->de_irq_mask[pipe]) {
539 dev_priv->de_irq_mask[pipe] = new_val;
540 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
541 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
542 }
543}
544
545/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200546 * ibx_display_interrupt_update - update SDEIMR
547 * @dev_priv: driver private
548 * @interrupt_mask: mask of interrupt bits to update
549 * @enabled_irq_mask: mask of interrupt bits to enable
550 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200551void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
552 uint32_t interrupt_mask,
553 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200554{
555 uint32_t sdeimr = I915_READ(SDEIMR);
556 sdeimr &= ~interrupt_mask;
557 sdeimr |= (~enabled_irq_mask & interrupt_mask);
558
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100559 WARN_ON(enabled_irq_mask & ~interrupt_mask);
560
Chris Wilson67520412017-03-02 13:28:01 +0000561 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200562
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700563 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300564 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300565
Daniel Vetterfee884e2013-07-04 23:35:21 +0200566 I915_WRITE(SDEIMR, sdeimr);
567 POSTING_READ(SDEIMR);
568}
Paulo Zanoni86642812013-04-12 17:57:57 -0300569
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300570u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
571 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800572{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300573 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200574 u32 enable_mask = status_mask << 16;
575
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300576 lockdep_assert_held(&dev_priv->irq_lock);
577
578 if (INTEL_GEN(dev_priv) < 5)
579 goto out;
580
Imre Deak10c59c52014-02-10 18:42:48 +0200581 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300582 * On pipe A we don't support the PSR interrupt yet,
583 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200584 */
585 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
586 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300587 /*
588 * On pipe B and C we don't support the PSR interrupt yet, on pipe
589 * A the same bit is for perf counters which we don't use either.
590 */
591 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
592 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200593
594 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
595 SPRITE0_FLIP_DONE_INT_EN_VLV |
596 SPRITE1_FLIP_DONE_INT_EN_VLV);
597 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
598 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
599 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
600 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
601
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300602out:
603 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
604 status_mask & ~PIPESTAT_INT_STATUS_MASK,
605 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
606 pipe_name(pipe), enable_mask, status_mask);
607
Imre Deak10c59c52014-02-10 18:42:48 +0200608 return enable_mask;
609}
610
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300611void i915_enable_pipestat(struct drm_i915_private *dev_priv,
612 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200613{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300614 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200615 u32 enable_mask;
616
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300617 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
618 "pipe %c: status_mask=0x%x\n",
619 pipe_name(pipe), status_mask);
620
621 lockdep_assert_held(&dev_priv->irq_lock);
622 WARN_ON(!intel_irqs_enabled(dev_priv));
623
624 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
625 return;
626
627 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
628 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
629
630 I915_WRITE(reg, enable_mask | status_mask);
631 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200632}
633
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300634void i915_disable_pipestat(struct drm_i915_private *dev_priv,
635 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200636{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300637 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200638 u32 enable_mask;
639
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300640 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
641 "pipe %c: status_mask=0x%x\n",
642 pipe_name(pipe), status_mask);
643
644 lockdep_assert_held(&dev_priv->irq_lock);
645 WARN_ON(!intel_irqs_enabled(dev_priv));
646
647 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
648 return;
649
650 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
651 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
652
653 I915_WRITE(reg, enable_mask | status_mask);
654 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200655}
656
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000657/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300658 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100659 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000660 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100661static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000662{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100663 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300664 return;
665
Daniel Vetter13321782014-09-15 14:55:29 +0200666 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000667
Imre Deak755e9012014-02-10 18:42:47 +0200668 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100669 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200670 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200671 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000672
Daniel Vetter13321782014-09-15 14:55:29 +0200673 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000674}
675
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300676/*
677 * This timing diagram depicts the video signal in and
678 * around the vertical blanking period.
679 *
680 * Assumptions about the fictitious mode used in this example:
681 * vblank_start >= 3
682 * vsync_start = vblank_start + 1
683 * vsync_end = vblank_start + 2
684 * vtotal = vblank_start + 3
685 *
686 * start of vblank:
687 * latch double buffered registers
688 * increment frame counter (ctg+)
689 * generate start of vblank interrupt (gen4+)
690 * |
691 * | frame start:
692 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
693 * | may be shifted forward 1-3 extra lines via PIPECONF
694 * | |
695 * | | start of vsync:
696 * | | generate vsync interrupt
697 * | | |
698 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
699 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
700 * ----va---> <-----------------vb--------------------> <--------va-------------
701 * | | <----vs-----> |
702 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
703 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
704 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
705 * | | |
706 * last visible pixel first visible pixel
707 * | increment frame counter (gen3/4)
708 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
709 *
710 * x = horizontal active
711 * _ = horizontal blanking
712 * hs = horizontal sync
713 * va = vertical active
714 * vb = vertical blanking
715 * vs = vertical sync
716 * vbs = vblank_start (number)
717 *
718 * Summary:
719 * - most events happen at the start of horizontal sync
720 * - frame start happens at the start of horizontal blank, 1-4 lines
721 * (depending on PIPECONF settings) after the start of vblank
722 * - gen3/4 pixel and frame counter are synchronized with the start
723 * of horizontal active on the first line of vertical active
724 */
725
Keith Packard42f52ef2008-10-18 19:39:29 -0700726/* Called from drm generic code, passed a 'crtc', which
727 * we use as a pipe index
728 */
Thierry Reding88e72712015-09-24 18:35:31 +0200729static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700730{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100731 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200732 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300733 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200734 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200735 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700736
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100737 htotal = mode->crtc_htotal;
738 hsync_start = mode->crtc_hsync_start;
739 vbl_start = mode->crtc_vblank_start;
740 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
741 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300742
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300743 /* Convert to pixel count */
744 vbl_start *= htotal;
745
746 /* Start of vblank event occurs at start of hsync */
747 vbl_start -= htotal - hsync_start;
748
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800749 high_frame = PIPEFRAME(pipe);
750 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100751
Ville Syrjälä694e4092017-03-09 17:44:30 +0200752 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
753
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700754 /*
755 * High & low register fields aren't synchronized, so make sure
756 * we get a low value that's stable across two reads of the high
757 * register.
758 */
759 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200760 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
761 low = I915_READ_FW(low_frame);
762 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700763 } while (high1 != high2);
764
Ville Syrjälä694e4092017-03-09 17:44:30 +0200765 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
766
Chris Wilson5eddb702010-09-11 13:48:45 +0100767 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300768 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100769 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300770
771 /*
772 * The frame counter increments at beginning of active.
773 * Cook up a vblank counter by also checking the pixel
774 * counter against vblank start.
775 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200776 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700777}
778
Dave Airlie974e59b2015-10-30 09:45:33 +1000779static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800780{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100781 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800782
Ville Syrjälä649636e2015-09-22 19:50:01 +0300783 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800784}
785
Uma Shankaraec02462017-09-25 19:26:01 +0530786/*
787 * On certain encoders on certain platforms, pipe
788 * scanline register will not work to get the scanline,
789 * since the timings are driven from the PORT or issues
790 * with scanline register updates.
791 * This function will use Framestamp and current
792 * timestamp registers to calculate the scanline.
793 */
794static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
795{
796 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
797 struct drm_vblank_crtc *vblank =
798 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
799 const struct drm_display_mode *mode = &vblank->hwmode;
800 u32 vblank_start = mode->crtc_vblank_start;
801 u32 vtotal = mode->crtc_vtotal;
802 u32 htotal = mode->crtc_htotal;
803 u32 clock = mode->crtc_clock;
804 u32 scanline, scan_prev_time, scan_curr_time, scan_post_time;
805
806 /*
807 * To avoid the race condition where we might cross into the
808 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
809 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
810 * during the same frame.
811 */
812 do {
813 /*
814 * This field provides read back of the display
815 * pipe frame time stamp. The time stamp value
816 * is sampled at every start of vertical blank.
817 */
818 scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
819
820 /*
821 * The TIMESTAMP_CTR register has the current
822 * time stamp value.
823 */
824 scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR);
825
826 scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
827 } while (scan_post_time != scan_prev_time);
828
829 scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
830 clock), 1000 * htotal);
831 scanline = min(scanline, vtotal - 1);
832 scanline = (scanline + vblank_start) % vtotal;
833
834 return scanline;
835}
836
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300837/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300838static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
839{
840 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100841 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200842 const struct drm_display_mode *mode;
843 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300844 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300845 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300846
Ville Syrjälä72259532017-03-02 19:15:05 +0200847 if (!crtc->active)
848 return -1;
849
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200850 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
851 mode = &vblank->hwmode;
852
Uma Shankaraec02462017-09-25 19:26:01 +0530853 if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
854 return __intel_get_crtc_scanline_from_timestamp(crtc);
855
Ville Syrjälä80715b22014-05-15 20:23:23 +0300856 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300857 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
858 vtotal /= 2;
859
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100860 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300861 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300862 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300863 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300864
865 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700866 * On HSW, the DSL reg (0x70000) appears to return 0 if we
867 * read it just before the start of vblank. So try it again
868 * so we don't accidentally end up spanning a vblank frame
869 * increment, causing the pipe_update_end() code to squak at us.
870 *
871 * The nature of this problem means we can't simply check the ISR
872 * bit and return the vblank start value; nor can we use the scanline
873 * debug register in the transcoder as it appears to have the same
874 * problem. We may need to extend this to include other platforms,
875 * but so far testing only shows the problem on HSW.
876 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100877 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700878 int i, temp;
879
880 for (i = 0; i < 100; i++) {
881 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200882 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700883 if (temp != position) {
884 position = temp;
885 break;
886 }
887 }
888 }
889
890 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300891 * See update_scanline_offset() for the details on the
892 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300893 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300894 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300895}
896
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200897static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
898 bool in_vblank_irq, int *vpos, int *hpos,
899 ktime_t *stime, ktime_t *etime,
900 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100901{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100902 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200903 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
904 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300905 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300906 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100907 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100908
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200909 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100910 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800911 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200912 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100913 }
914
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300915 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300916 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300917 vtotal = mode->crtc_vtotal;
918 vbl_start = mode->crtc_vblank_start;
919 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100920
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200921 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
922 vbl_start = DIV_ROUND_UP(vbl_start, 2);
923 vbl_end /= 2;
924 vtotal /= 2;
925 }
926
Mario Kleinerad3543e2013-10-30 05:13:08 +0100927 /*
928 * Lock uncore.lock, as we will do multiple timing critical raw
929 * register reads, potentially with preemption disabled, so the
930 * following code must not block on uncore.lock.
931 */
932 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300933
Mario Kleinerad3543e2013-10-30 05:13:08 +0100934 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
935
936 /* Get optional system timestamp before query. */
937 if (stime)
938 *stime = ktime_get();
939
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100940 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100941 /* No obvious pixelcount register. Only query vertical
942 * scanout position from Display scan line register.
943 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300944 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100945 } else {
946 /* Have access to pixelcount since start of frame.
947 * We can split this into vertical and horizontal
948 * scanout position.
949 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300950 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100951
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300952 /* convert to pixel counts */
953 vbl_start *= htotal;
954 vbl_end *= htotal;
955 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300956
957 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300958 * In interlaced modes, the pixel counter counts all pixels,
959 * so one field will have htotal more pixels. In order to avoid
960 * the reported position from jumping backwards when the pixel
961 * counter is beyond the length of the shorter field, just
962 * clamp the position the length of the shorter field. This
963 * matches how the scanline counter based position works since
964 * the scanline counter doesn't count the two half lines.
965 */
966 if (position >= vtotal)
967 position = vtotal - 1;
968
969 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300970 * Start of vblank interrupt is triggered at start of hsync,
971 * just prior to the first active line of vblank. However we
972 * consider lines to start at the leading edge of horizontal
973 * active. So, should we get here before we've crossed into
974 * the horizontal active of the first line in vblank, we would
975 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
976 * always add htotal-hsync_start to the current pixel position.
977 */
978 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300979 }
980
Mario Kleinerad3543e2013-10-30 05:13:08 +0100981 /* Get optional system timestamp after query. */
982 if (etime)
983 *etime = ktime_get();
984
985 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
986
987 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
988
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300989 /*
990 * While in vblank, position will be negative
991 * counting up towards 0 at vbl_end. And outside
992 * vblank, position will be positive counting
993 * up since vbl_end.
994 */
995 if (position >= vbl_start)
996 position -= vbl_end;
997 else
998 position += vtotal - vbl_end;
999
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001000 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001001 *vpos = position;
1002 *hpos = 0;
1003 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001004 *vpos = position / htotal;
1005 *hpos = position - (*vpos * htotal);
1006 }
1007
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001008 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001009}
1010
Ville Syrjäläa225f072014-04-29 13:35:45 +03001011int intel_get_crtc_scanline(struct intel_crtc *crtc)
1012{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001013 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +03001014 unsigned long irqflags;
1015 int position;
1016
1017 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1018 position = __intel_get_crtc_scanline(crtc);
1019 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1020
1021 return position;
1022}
1023
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001024static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001025{
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001026 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001027 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001028
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001029 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001030
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001031 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1032
Daniel Vetter20e4d402012-08-08 23:35:39 +02001033 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001034
Jesse Barnes7648fa92010-05-20 14:28:11 -07001035 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001036 busy_up = I915_READ(RCPREVBSYTUPAVG);
1037 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001038 max_avg = I915_READ(RCBMAXAVG);
1039 min_avg = I915_READ(RCBMINAVG);
1040
1041 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001042 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001043 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1044 new_delay = dev_priv->ips.cur_delay - 1;
1045 if (new_delay < dev_priv->ips.max_delay)
1046 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001047 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001048 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1049 new_delay = dev_priv->ips.cur_delay + 1;
1050 if (new_delay > dev_priv->ips.min_delay)
1051 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001052 }
1053
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001054 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001055 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001056
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001057 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001058
Jesse Barnesf97108d2010-01-29 11:27:07 -08001059 return;
1060}
1061
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001062static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001063{
Chris Wilson56299fb2017-02-27 20:58:48 +00001064 struct drm_i915_gem_request *rq = NULL;
1065 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001066
Chris Wilson2246bea2017-02-17 15:13:00 +00001067 atomic_inc(&engine->irq_count);
Chris Wilson538b2572017-01-24 15:18:05 +00001068 set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson56299fb2017-02-27 20:58:48 +00001069
Chris Wilson61d3dc72017-03-03 19:08:24 +00001070 spin_lock(&engine->breadcrumbs.irq_lock);
1071 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001072 if (wait) {
Chris Wilson17b51ad2017-09-18 17:27:33 +01001073 bool wakeup = engine->irq_seqno_barrier;
1074
Chris Wilson56299fb2017-02-27 20:58:48 +00001075 /* We use a callback from the dma-fence to submit
1076 * requests after waiting on our own requests. To
1077 * ensure minimum delay in queuing the next request to
1078 * hardware, signal the fence now rather than wait for
1079 * the signaler to be woken up. We still wake up the
1080 * waiter in order to handle the irq-seqno coherency
1081 * issues (we may receive the interrupt before the
1082 * seqno is written, see __i915_request_irq_complete())
1083 * and to handle coalescing of multiple seqno updates
1084 * and many waiters.
1085 */
1086 if (i915_seqno_passed(intel_engine_get_seqno(engine),
Chris Wilson17b51ad2017-09-18 17:27:33 +01001087 wait->seqno)) {
Chris Wilsonde4d2102017-09-18 17:27:34 +01001088 struct drm_i915_gem_request *waiter = wait->request;
1089
Chris Wilson17b51ad2017-09-18 17:27:33 +01001090 wakeup = true;
1091 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Chris Wilsonde4d2102017-09-18 17:27:34 +01001092 &waiter->fence.flags) &&
1093 intel_wait_check_request(wait, waiter))
1094 rq = i915_gem_request_get(waiter);
Chris Wilson17b51ad2017-09-18 17:27:33 +01001095 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001096
Chris Wilson17b51ad2017-09-18 17:27:33 +01001097 if (wakeup)
1098 wake_up_process(wait->tsk);
Chris Wilson67b807a82017-02-27 20:58:50 +00001099 } else {
1100 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001101 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001102 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001103
Chris Wilson24754d72017-03-03 14:45:57 +00001104 if (rq) {
Chris Wilson56299fb2017-02-27 20:58:48 +00001105 dma_fence_signal(&rq->fence);
Chris Wilson24754d72017-03-03 14:45:57 +00001106 i915_gem_request_put(rq);
1107 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001108
1109 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001110}
1111
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001112static void vlv_c0_read(struct drm_i915_private *dev_priv,
1113 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001114{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001115 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001116 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1117 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001118}
1119
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001120void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1121{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001122 memset(&dev_priv->rps.ei, 0, sizeof(dev_priv->rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001123}
1124
1125static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1126{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001127 const struct intel_rps_ei *prev = &dev_priv->rps.ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001128 struct intel_rps_ei now;
1129 u32 events = 0;
1130
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001131 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001132 return 0;
1133
1134 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001135
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001136 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001137 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001138 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001139
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001140 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001141
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001142 time *= dev_priv->czclk_freq;
1143
1144 /* Workload can be split between render + media,
1145 * e.g. SwapBuffers being blitted in X after being rendered in
1146 * mesa. To account for this we need to combine both engines
1147 * into our activity counter.
1148 */
Chris Wilson569884e2017-03-09 21:12:31 +00001149 render = now.render_c0 - prev->render_c0;
1150 media = now.media_c0 - prev->media_c0;
1151 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001152 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001153
1154 if (c0 > time * dev_priv->rps.up_threshold)
1155 events = GEN6_PM_RP_UP_THRESHOLD;
1156 else if (c0 < time * dev_priv->rps.down_threshold)
1157 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001158 }
1159
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001160 dev_priv->rps.ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001161 return events;
Deepak S31685c22014-07-03 17:33:01 -04001162}
1163
Ben Widawsky4912d042011-04-25 11:25:20 -07001164static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001165{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001166 struct drm_i915_private *dev_priv =
1167 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001168 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001169 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001170 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001171
Daniel Vetter59cdb632013-07-04 23:35:28 +02001172 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001173 if (dev_priv->rps.interrupts_enabled) {
1174 pm_iir = fetch_and_zero(&dev_priv->rps.pm_iir);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001175 client_boost = atomic_read(&dev_priv->rps.num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001176 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001177 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001178
Paulo Zanoni60611c12013-08-15 11:50:01 -03001179 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301180 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001181 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001182 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001183
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001184 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001185
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001186 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1187
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001188 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001189 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001190 min = dev_priv->rps.min_freq_softlimit;
1191 max = dev_priv->rps.max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001192 if (client_boost)
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001193 max = dev_priv->rps.max_freq;
1194 if (client_boost && new_delay < dev_priv->rps.boost_freq) {
1195 new_delay = dev_priv->rps.boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001196 adj = 0;
1197 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001198 if (adj > 0)
1199 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001200 else /* CHV needs even encode values */
1201 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301202
1203 if (new_delay >= dev_priv->rps.max_freq_softlimit)
1204 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001205 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001206 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001207 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001208 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1209 new_delay = dev_priv->rps.efficient_freq;
Chris Wilson17136d52017-02-10 15:03:47 +00001210 else if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
Ben Widawskyb39fb292014-03-19 18:31:11 -07001211 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001212 adj = 0;
1213 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1214 if (adj < 0)
1215 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001216 else /* CHV needs even encode values */
1217 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301218
1219 if (new_delay <= dev_priv->rps.min_freq_softlimit)
1220 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001221 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001222 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001223 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001224
Chris Wilsonedcf2842015-04-07 16:20:29 +01001225 dev_priv->rps.last_adj = adj;
1226
Ben Widawsky79249632012-09-07 19:43:42 -07001227 /* sysfs frequency interfaces may have snuck in while servicing the
1228 * interrupt
1229 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001230 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001231 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301232
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001233 if (intel_set_rps(dev_priv, new_delay)) {
1234 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
1235 dev_priv->rps.last_adj = 0;
1236 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001237
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001238 mutex_unlock(&dev_priv->rps.hw_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001239
1240out:
1241 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1242 spin_lock_irq(&dev_priv->irq_lock);
1243 if (dev_priv->rps.interrupts_enabled)
1244 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1245 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001246}
1247
Ben Widawskye3689192012-05-25 16:56:22 -07001248
1249/**
1250 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1251 * occurred.
1252 * @work: workqueue struct
1253 *
1254 * Doesn't actually do anything except notify userspace. As a consequence of
1255 * this event, userspace should try to remap the bad rows since statistically
1256 * it is likely the same row is more likely to go bad again.
1257 */
1258static void ivybridge_parity_work(struct work_struct *work)
1259{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001260 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001261 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001262 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001263 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001264 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001265 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001266
1267 /* We must turn off DOP level clock gating to access the L3 registers.
1268 * In order to prevent a get/put style interface, acquire struct mutex
1269 * any time we access those registers.
1270 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001271 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001272
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001273 /* If we've screwed up tracking, just let the interrupt fire again */
1274 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1275 goto out;
1276
Ben Widawskye3689192012-05-25 16:56:22 -07001277 misccpctl = I915_READ(GEN7_MISCCPCTL);
1278 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1279 POSTING_READ(GEN7_MISCCPCTL);
1280
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001281 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001282 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001283
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001284 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001285 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001286 break;
1287
1288 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1289
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001290 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001291
1292 error_status = I915_READ(reg);
1293 row = GEN7_PARITY_ERROR_ROW(error_status);
1294 bank = GEN7_PARITY_ERROR_BANK(error_status);
1295 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1296
1297 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1298 POSTING_READ(reg);
1299
1300 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1301 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1302 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1303 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1304 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1305 parity_event[5] = NULL;
1306
Chris Wilson91c8a322016-07-05 10:40:23 +01001307 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001308 KOBJ_CHANGE, parity_event);
1309
1310 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1311 slice, row, bank, subbank);
1312
1313 kfree(parity_event[4]);
1314 kfree(parity_event[3]);
1315 kfree(parity_event[2]);
1316 kfree(parity_event[1]);
1317 }
Ben Widawskye3689192012-05-25 16:56:22 -07001318
1319 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1320
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001321out:
1322 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001323 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001324 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001325 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001326
Chris Wilson91c8a322016-07-05 10:40:23 +01001327 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001328}
1329
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001330static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1331 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001332{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001333 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001334 return;
1335
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001336 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001337 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001338 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001339
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001340 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001341 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1342 dev_priv->l3_parity.which_slice |= 1 << 1;
1343
1344 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1345 dev_priv->l3_parity.which_slice |= 1 << 0;
1346
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001347 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001348}
1349
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001350static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001351 u32 gt_iir)
1352{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001353 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301354 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001355 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301356 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001357}
1358
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001359static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001360 u32 gt_iir)
1361{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001362 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301363 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001364 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301365 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001366 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301367 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001368
Ben Widawskycc609d52013-05-28 19:22:29 -07001369 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1370 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001371 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1372 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001373
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001374 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1375 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001376}
1377
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001378static void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001379gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001380{
Mika Kuoppalab620e872017-09-22 15:43:03 +03001381 struct intel_engine_execlists * const execlists = &engine->execlists;
Chris Wilson31de7352017-03-16 12:56:18 +00001382 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001383
1384 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) {
Mika Kuoppalab620e872017-09-22 15:43:03 +03001385 if (port_count(&execlists->port[0])) {
Chris Wilson955a4b82017-05-17 13:10:07 +01001386 __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted);
Chris Wilsona4b2b012017-05-17 13:10:01 +01001387 tasklet = true;
1388 }
Chris Wilsonf7470262017-01-24 15:20:21 +00001389 }
Chris Wilson31de7352017-03-16 12:56:18 +00001390
1391 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) {
1392 notify_ring(engine);
Michal Wajdeczko4f044a82017-09-19 19:38:44 +00001393 tasklet |= i915_modparams.enable_guc_submission;
Chris Wilson31de7352017-03-16 12:56:18 +00001394 }
1395
1396 if (tasklet)
Mika Kuoppalab620e872017-09-22 15:43:03 +03001397 tasklet_hi_schedule(&execlists->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001398}
1399
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001400static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1401 u32 master_ctl,
1402 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001403{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001404 irqreturn_t ret = IRQ_NONE;
1405
1406 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001407 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1408 if (gt_iir[0]) {
1409 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001410 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001411 } else
1412 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1413 }
1414
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001415 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001416 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1417 if (gt_iir[1]) {
1418 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001419 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001420 } else
1421 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1422 }
1423
Chris Wilson74cdb332015-04-07 16:21:05 +01001424 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001425 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1426 if (gt_iir[3]) {
1427 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001428 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001429 } else
1430 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1431 }
1432
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301433 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001434 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301435 if (gt_iir[2] & (dev_priv->pm_rps_events |
1436 dev_priv->pm_guc_events)) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001437 I915_WRITE_FW(GEN8_GT_IIR(2),
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301438 gt_iir[2] & (dev_priv->pm_rps_events |
1439 dev_priv->pm_guc_events));
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001440 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001441 } else
1442 DRM_ERROR("The master control interrupt lied (PM)!\n");
1443 }
1444
Ben Widawskyabd58f02013-11-02 21:07:09 -07001445 return ret;
1446}
1447
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001448static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1449 u32 gt_iir[4])
1450{
1451 if (gt_iir[0]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301452 gen8_cs_irq_handler(dev_priv->engine[RCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001453 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301454 gen8_cs_irq_handler(dev_priv->engine[BCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001455 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1456 }
1457
1458 if (gt_iir[1]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301459 gen8_cs_irq_handler(dev_priv->engine[VCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001460 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301461 gen8_cs_irq_handler(dev_priv->engine[VCS2],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001462 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1463 }
1464
1465 if (gt_iir[3])
Akash Goel3b3f1652016-10-13 22:44:48 +05301466 gen8_cs_irq_handler(dev_priv->engine[VECS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001467 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1468
1469 if (gt_iir[2] & dev_priv->pm_rps_events)
1470 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301471
1472 if (gt_iir[2] & dev_priv->pm_guc_events)
1473 gen9_guc_irq_handler(dev_priv, gt_iir[2]);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001474}
1475
Imre Deak63c88d22015-07-20 14:43:39 -07001476static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1477{
1478 switch (port) {
1479 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001480 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001481 case PORT_B:
1482 return val & PORTB_HOTPLUG_LONG_DETECT;
1483 case PORT_C:
1484 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001485 default:
1486 return false;
1487 }
1488}
1489
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001490static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1491{
1492 switch (port) {
1493 case PORT_E:
1494 return val & PORTE_HOTPLUG_LONG_DETECT;
1495 default:
1496 return false;
1497 }
1498}
1499
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001500static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1501{
1502 switch (port) {
1503 case PORT_A:
1504 return val & PORTA_HOTPLUG_LONG_DETECT;
1505 case PORT_B:
1506 return val & PORTB_HOTPLUG_LONG_DETECT;
1507 case PORT_C:
1508 return val & PORTC_HOTPLUG_LONG_DETECT;
1509 case PORT_D:
1510 return val & PORTD_HOTPLUG_LONG_DETECT;
1511 default:
1512 return false;
1513 }
1514}
1515
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001516static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1517{
1518 switch (port) {
1519 case PORT_A:
1520 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1521 default:
1522 return false;
1523 }
1524}
1525
Jani Nikula676574d2015-05-28 15:43:53 +03001526static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001527{
1528 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001529 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001530 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001531 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001532 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001533 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001534 return val & PORTD_HOTPLUG_LONG_DETECT;
1535 default:
1536 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001537 }
1538}
1539
Jani Nikula676574d2015-05-28 15:43:53 +03001540static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001541{
1542 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001543 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001544 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001545 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001546 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001547 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001548 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1549 default:
1550 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001551 }
1552}
1553
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001554/*
1555 * Get a bit mask of pins that have triggered, and which ones may be long.
1556 * This can be called multiple times with the same masks to accumulate
1557 * hotplug detection results from several registers.
1558 *
1559 * Note that the caller is expected to zero out the masks initially.
1560 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001561static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001562 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001563 const u32 hpd[HPD_NUM_PINS],
1564 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001565{
Jani Nikula8c841e52015-06-18 13:06:17 +03001566 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001567 int i;
1568
Jani Nikula676574d2015-05-28 15:43:53 +03001569 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001570 if ((hpd[i] & hotplug_trigger) == 0)
1571 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001572
Jani Nikula8c841e52015-06-18 13:06:17 +03001573 *pin_mask |= BIT(i);
1574
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07001575 port = intel_hpd_pin_to_port(i);
1576 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001577 continue;
1578
Imre Deakfd63e2a2015-07-21 15:32:44 -07001579 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001580 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001581 }
1582
1583 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1584 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1585
1586}
1587
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001588static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001589{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001590 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001591}
1592
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001593static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001594{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001595 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001596}
1597
Shuang He8bf1e9f2013-10-15 18:55:27 +01001598#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001599static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1600 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001601 uint32_t crc0, uint32_t crc1,
1602 uint32_t crc2, uint32_t crc3,
1603 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001604{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001605 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1606 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001607 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1608 struct drm_driver *driver = dev_priv->drm.driver;
1609 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001610 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001611
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001612 spin_lock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001613 if (pipe_crc->source) {
1614 if (!pipe_crc->entries) {
1615 spin_unlock(&pipe_crc->lock);
1616 DRM_DEBUG_KMS("spurious interrupt\n");
1617 return;
1618 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001619
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001620 head = pipe_crc->head;
1621 tail = pipe_crc->tail;
1622
1623 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1624 spin_unlock(&pipe_crc->lock);
1625 DRM_ERROR("CRC buffer overflowing\n");
1626 return;
1627 }
1628
1629 entry = &pipe_crc->entries[head];
1630
1631 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1632 entry->crc[0] = crc0;
1633 entry->crc[1] = crc1;
1634 entry->crc[2] = crc2;
1635 entry->crc[3] = crc3;
1636 entry->crc[4] = crc4;
1637
1638 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1639 pipe_crc->head = head;
1640
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001641 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001642
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001643 wake_up_interruptible(&pipe_crc->wq);
1644 } else {
1645 /*
1646 * For some not yet identified reason, the first CRC is
1647 * bonkers. So let's just wait for the next vblank and read
1648 * out the buggy result.
1649 *
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001650 * On GEN8+ sometimes the second CRC is bonkers as well, so
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001651 * don't trust that one either.
1652 */
1653 if (pipe_crc->skipped == 0 ||
Rodrigo Vivi163e8ae2017-09-27 17:20:40 -07001654 (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001655 pipe_crc->skipped++;
1656 spin_unlock(&pipe_crc->lock);
1657 return;
1658 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001659 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001660 crcs[0] = crc0;
1661 crcs[1] = crc1;
1662 crcs[2] = crc2;
1663 crcs[3] = crc3;
1664 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001665 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001666 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001667 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001668 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001669}
Daniel Vetter277de952013-10-18 16:37:07 +02001670#else
1671static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001672display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1673 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001674 uint32_t crc0, uint32_t crc1,
1675 uint32_t crc2, uint32_t crc3,
1676 uint32_t crc4) {}
1677#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001678
Daniel Vetter277de952013-10-18 16:37:07 +02001679
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001680static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1681 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001682{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001683 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001684 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1685 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001686}
1687
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001688static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1689 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001690{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001691 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001692 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1693 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1694 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1695 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1696 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001697}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001698
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001699static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1700 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001701{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001702 uint32_t res1, res2;
1703
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001704 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001705 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1706 else
1707 res1 = 0;
1708
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001709 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001710 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1711 else
1712 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001713
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001714 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001715 I915_READ(PIPE_CRC_RES_RED(pipe)),
1716 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1717 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1718 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001719}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001720
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001721/* The RPS events need forcewake, so we add them to a work queue and mask their
1722 * IMR bits until the work is done. Other interrupts can be processed without
1723 * the work queue. */
1724static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001725{
Deepak Sa6706b42014-03-15 20:23:22 +05301726 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001727 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301728 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001729 if (dev_priv->rps.interrupts_enabled) {
1730 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001731 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001732 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001733 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001734 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001735
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001736 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001737 return;
1738
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001739 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001740 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301741 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001742
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001743 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1744 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001745 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001746}
1747
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301748static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1749{
1750 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) {
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301751 /* Sample the log buffer flush related bits & clear them out now
1752 * itself from the message identity register to minimize the
1753 * probability of losing a flush interrupt, when there are back
1754 * to back flush interrupts.
1755 * There can be a new flush interrupt, for different log buffer
1756 * type (like for ISR), whilst Host is handling one (for DPC).
1757 * Since same bit is used in message register for ISR & DPC, it
1758 * could happen that GuC sets the bit for 2nd interrupt but Host
1759 * clears out the bit on handling the 1st interrupt.
1760 */
1761 u32 msg, flush;
1762
1763 msg = I915_READ(SOFT_SCRATCH(15));
Arkadiusz Hilera80bc452016-11-25 18:59:34 +01001764 flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED |
1765 INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER);
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301766 if (flush) {
1767 /* Clear the message bits that are handled */
1768 I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
1769
1770 /* Handle flush interrupt in bottom half */
Oscar Mateoe7465472017-03-22 10:39:48 -07001771 queue_work(dev_priv->guc.log.runtime.flush_wq,
1772 &dev_priv->guc.log.runtime.flush_work);
Akash Goel5aa1ee42016-10-12 21:54:36 +05301773
1774 dev_priv->guc.log.flush_interrupt_count++;
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301775 } else {
1776 /* Not clearing of unhandled event bits won't result in
1777 * re-triggering of the interrupt.
1778 */
1779 }
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301780 }
1781}
1782
Ville Syrjälä44d92412017-08-18 21:36:51 +03001783static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1784{
1785 enum pipe pipe;
1786
1787 for_each_pipe(dev_priv, pipe) {
1788 I915_WRITE(PIPESTAT(pipe),
1789 PIPESTAT_INT_STATUS_MASK |
1790 PIPE_FIFO_UNDERRUN_STATUS);
1791
1792 dev_priv->pipestat_irq_mask[pipe] = 0;
1793 }
1794}
1795
Ville Syrjäläeb643432017-08-18 21:36:59 +03001796static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1797 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001798{
Imre Deakc1874ed2014-02-04 21:35:46 +02001799 int pipe;
1800
Imre Deak58ead0d2014-02-04 21:35:47 +02001801 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001802
1803 if (!dev_priv->display_irqs_enabled) {
1804 spin_unlock(&dev_priv->irq_lock);
1805 return;
1806 }
1807
Damien Lespiau055e3932014-08-18 13:49:10 +01001808 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001809 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001810 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001811
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001812 /*
1813 * PIPESTAT bits get signalled even when the interrupt is
1814 * disabled with the mask bits, and some of the status bits do
1815 * not generate interrupts at all (like the underrun bit). Hence
1816 * we need to be careful that we only handle what we want to
1817 * handle.
1818 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001819
1820 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001821 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001822
1823 switch (pipe) {
1824 case PIPE_A:
1825 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1826 break;
1827 case PIPE_B:
1828 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1829 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001830 case PIPE_C:
1831 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1832 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001833 }
1834 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001835 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001836
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001837 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001838 continue;
1839
1840 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001841 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1842 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001843
1844 /*
1845 * Clear the PIPE*STAT regs before the IIR
1846 */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001847 if (pipe_stats[pipe])
1848 I915_WRITE(reg, enable_mask | pipe_stats[pipe]);
Imre Deakc1874ed2014-02-04 21:35:46 +02001849 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001850 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001851}
1852
Ville Syrjäläeb643432017-08-18 21:36:59 +03001853static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1854 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1855{
1856 enum pipe pipe;
1857
1858 for_each_pipe(dev_priv, pipe) {
1859 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1860 drm_handle_vblank(&dev_priv->drm, pipe);
1861
1862 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1863 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1864
1865 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1866 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1867 }
1868}
1869
1870static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1871 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1872{
1873 bool blc_event = false;
1874 enum pipe pipe;
1875
1876 for_each_pipe(dev_priv, pipe) {
1877 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1878 drm_handle_vblank(&dev_priv->drm, pipe);
1879
1880 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1881 blc_event = true;
1882
1883 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1884 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1885
1886 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1887 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1888 }
1889
1890 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1891 intel_opregion_asle_intr(dev_priv);
1892}
1893
1894static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1895 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1896{
1897 bool blc_event = false;
1898 enum pipe pipe;
1899
1900 for_each_pipe(dev_priv, pipe) {
1901 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1902 drm_handle_vblank(&dev_priv->drm, pipe);
1903
1904 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1905 blc_event = true;
1906
1907 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1908 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1909
1910 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1911 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1912 }
1913
1914 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1915 intel_opregion_asle_intr(dev_priv);
1916
1917 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1918 gmbus_irq_handler(dev_priv);
1919}
1920
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001921static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001922 u32 pipe_stats[I915_MAX_PIPES])
1923{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001924 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001925
Damien Lespiau055e3932014-08-18 13:49:10 +01001926 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001927 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1928 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001929
1930 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001931 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001932
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001933 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1934 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001935 }
1936
1937 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001938 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001939}
1940
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001941static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001942{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001943 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001944
1945 if (hotplug_status)
1946 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1947
1948 return hotplug_status;
1949}
1950
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001951static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001952 u32 hotplug_status)
1953{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001954 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001955
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001956 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1957 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001958 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001959
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001960 if (hotplug_trigger) {
1961 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1962 hotplug_trigger, hpd_status_g4x,
1963 i9xx_port_hotplug_long_detect);
1964
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001965 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001966 }
Jani Nikula369712e2015-05-27 15:03:40 +03001967
1968 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001969 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001970 } else {
1971 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001972
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001973 if (hotplug_trigger) {
1974 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001975 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001976 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001977 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001978 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001979 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001980}
1981
Daniel Vetterff1f5252012-10-02 15:10:55 +02001982static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001983{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001984 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001985 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001986 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001987
Imre Deak2dd2a882015-02-24 11:14:30 +02001988 if (!intel_irqs_enabled(dev_priv))
1989 return IRQ_NONE;
1990
Imre Deak1f814da2015-12-16 02:52:19 +02001991 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1992 disable_rpm_wakeref_asserts(dev_priv);
1993
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001994 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001995 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001996 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001997 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001998 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001999
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002000 gt_iir = I915_READ(GTIIR);
2001 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002002 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002003
2004 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002005 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002006
2007 ret = IRQ_HANDLED;
2008
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002009 /*
2010 * Theory on interrupt generation, based on empirical evidence:
2011 *
2012 * x = ((VLV_IIR & VLV_IER) ||
2013 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2014 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2015 *
2016 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2017 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2018 * guarantee the CPU interrupt will be raised again even if we
2019 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2020 * bits this time around.
2021 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002022 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002023 ier = I915_READ(VLV_IER);
2024 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002025
2026 if (gt_iir)
2027 I915_WRITE(GTIIR, gt_iir);
2028 if (pm_iir)
2029 I915_WRITE(GEN6_PMIIR, pm_iir);
2030
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002031 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002032 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002033
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002034 /* Call regardless, as some status bits might not be
2035 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002036 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002037
Jerome Anandeef57322017-01-25 04:27:49 +05302038 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2039 I915_LPE_PIPE_B_INTERRUPT))
2040 intel_lpe_audio_irq_handler(dev_priv);
2041
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002042 /*
2043 * VLV_IIR is single buffered, and reflects the level
2044 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2045 */
2046 if (iir)
2047 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002048
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002049 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002050 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2051 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002052
Ville Syrjälä52894872016-04-13 21:19:56 +03002053 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002054 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002055 if (pm_iir)
2056 gen6_rps_irq_handler(dev_priv, pm_iir);
2057
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002058 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002059 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002060
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002061 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002062 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002063
Imre Deak1f814da2015-12-16 02:52:19 +02002064 enable_rpm_wakeref_asserts(dev_priv);
2065
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002066 return ret;
2067}
2068
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002069static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2070{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002071 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002072 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002073 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002074
Imre Deak2dd2a882015-02-24 11:14:30 +02002075 if (!intel_irqs_enabled(dev_priv))
2076 return IRQ_NONE;
2077
Imre Deak1f814da2015-12-16 02:52:19 +02002078 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2079 disable_rpm_wakeref_asserts(dev_priv);
2080
Chris Wilson579de732016-03-14 09:01:57 +00002081 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002082 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002083 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002084 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002085 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002086 u32 ier = 0;
2087
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002088 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2089 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002090
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002091 if (master_ctl == 0 && iir == 0)
2092 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002093
Oscar Mateo27b6c122014-06-16 16:11:00 +01002094 ret = IRQ_HANDLED;
2095
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002096 /*
2097 * Theory on interrupt generation, based on empirical evidence:
2098 *
2099 * x = ((VLV_IIR & VLV_IER) ||
2100 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2101 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2102 *
2103 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2104 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2105 * guarantee the CPU interrupt will be raised again even if we
2106 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2107 * bits this time around.
2108 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002109 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002110 ier = I915_READ(VLV_IER);
2111 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002112
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002113 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002114
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002115 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002116 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002117
Oscar Mateo27b6c122014-06-16 16:11:00 +01002118 /* Call regardless, as some status bits might not be
2119 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002120 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002121
Jerome Anandeef57322017-01-25 04:27:49 +05302122 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2123 I915_LPE_PIPE_B_INTERRUPT |
2124 I915_LPE_PIPE_C_INTERRUPT))
2125 intel_lpe_audio_irq_handler(dev_priv);
2126
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002127 /*
2128 * VLV_IIR is single buffered, and reflects the level
2129 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2130 */
2131 if (iir)
2132 I915_WRITE(VLV_IIR, iir);
2133
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002134 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002135 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002136 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002137
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002138 gen8_gt_irq_handler(dev_priv, gt_iir);
2139
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002140 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002141 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002142
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002143 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002144 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002145
Imre Deak1f814da2015-12-16 02:52:19 +02002146 enable_rpm_wakeref_asserts(dev_priv);
2147
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002148 return ret;
2149}
2150
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002151static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2152 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002153 const u32 hpd[HPD_NUM_PINS])
2154{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002155 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2156
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002157 /*
2158 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2159 * unless we touch the hotplug register, even if hotplug_trigger is
2160 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2161 * errors.
2162 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002163 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002164 if (!hotplug_trigger) {
2165 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2166 PORTD_HOTPLUG_STATUS_MASK |
2167 PORTC_HOTPLUG_STATUS_MASK |
2168 PORTB_HOTPLUG_STATUS_MASK;
2169 dig_hotplug_reg &= ~mask;
2170 }
2171
Ville Syrjälä40e56412015-08-27 23:56:10 +03002172 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002173 if (!hotplug_trigger)
2174 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002175
2176 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2177 dig_hotplug_reg, hpd,
2178 pch_port_hotplug_long_detect);
2179
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002180 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002181}
2182
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002183static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002184{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002185 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002186 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002187
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002188 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002189
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002190 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2191 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2192 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002193 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002194 port_name(port));
2195 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002196
Daniel Vetterce99c252012-12-01 13:53:47 +01002197 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002198 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002199
Jesse Barnes776ad802011-01-04 15:09:39 -08002200 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002201 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002202
2203 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2204 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2205
2206 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2207 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2208
2209 if (pch_iir & SDE_POISON)
2210 DRM_ERROR("PCH poison interrupt\n");
2211
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002212 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002213 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002214 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2215 pipe_name(pipe),
2216 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002217
2218 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2219 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2220
2221 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2222 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2223
Jesse Barnes776ad802011-01-04 15:09:39 -08002224 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002225 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002226
2227 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002228 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002229}
2230
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002231static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002232{
Paulo Zanoni86642812013-04-12 17:57:57 -03002233 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002234 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002235
Paulo Zanonide032bf2013-04-12 17:57:58 -03002236 if (err_int & ERR_INT_POISON)
2237 DRM_ERROR("Poison interrupt\n");
2238
Damien Lespiau055e3932014-08-18 13:49:10 +01002239 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002240 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2241 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002242
Daniel Vetter5a69b892013-10-16 22:55:52 +02002243 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002244 if (IS_IVYBRIDGE(dev_priv))
2245 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002246 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002247 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002248 }
2249 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002250
Paulo Zanoni86642812013-04-12 17:57:57 -03002251 I915_WRITE(GEN7_ERR_INT, err_int);
2252}
2253
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002254static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002255{
Paulo Zanoni86642812013-04-12 17:57:57 -03002256 u32 serr_int = I915_READ(SERR_INT);
2257
Paulo Zanonide032bf2013-04-12 17:57:58 -03002258 if (serr_int & SERR_INT_POISON)
2259 DRM_ERROR("PCH poison interrupt\n");
2260
Paulo Zanoni86642812013-04-12 17:57:57 -03002261 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002262 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002263
2264 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002265 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002266
2267 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002268 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002269
2270 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002271}
2272
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002273static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002274{
Adam Jackson23e81d62012-06-06 15:45:44 -04002275 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002276 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002277
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002278 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002279
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002280 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2281 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2282 SDE_AUDIO_POWER_SHIFT_CPT);
2283 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2284 port_name(port));
2285 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002286
2287 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002288 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002289
2290 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002291 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002292
2293 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2294 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2295
2296 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2297 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2298
2299 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002300 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002301 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2302 pipe_name(pipe),
2303 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002304
2305 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002306 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002307}
2308
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002309static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002310{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002311 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2312 ~SDE_PORTE_HOTPLUG_SPT;
2313 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2314 u32 pin_mask = 0, long_mask = 0;
2315
2316 if (hotplug_trigger) {
2317 u32 dig_hotplug_reg;
2318
2319 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2320 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2321
2322 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2323 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002324 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002325 }
2326
2327 if (hotplug2_trigger) {
2328 u32 dig_hotplug_reg;
2329
2330 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2331 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2332
2333 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2334 dig_hotplug_reg, hpd_spt,
2335 spt_port_hotplug2_long_detect);
2336 }
2337
2338 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002339 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002340
2341 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002342 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002343}
2344
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002345static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2346 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002347 const u32 hpd[HPD_NUM_PINS])
2348{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002349 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2350
2351 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2352 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2353
2354 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2355 dig_hotplug_reg, hpd,
2356 ilk_port_hotplug_long_detect);
2357
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002358 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002359}
2360
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002361static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2362 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002363{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002364 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002365 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2366
Ville Syrjälä40e56412015-08-27 23:56:10 +03002367 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002368 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002369
2370 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002371 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002372
2373 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002374 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002375
Paulo Zanonic008bc62013-07-12 16:35:10 -03002376 if (de_iir & DE_POISON)
2377 DRM_ERROR("Poison interrupt\n");
2378
Damien Lespiau055e3932014-08-18 13:49:10 +01002379 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002380 if (de_iir & DE_PIPE_VBLANK(pipe))
2381 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002382
Daniel Vetter40da17c22013-10-21 18:04:36 +02002383 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002384 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002385
Daniel Vetter40da17c22013-10-21 18:04:36 +02002386 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002387 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002388 }
2389
2390 /* check event from PCH */
2391 if (de_iir & DE_PCH_EVENT) {
2392 u32 pch_iir = I915_READ(SDEIIR);
2393
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002394 if (HAS_PCH_CPT(dev_priv))
2395 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002396 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002397 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002398
2399 /* should clear PCH hotplug event before clear CPU irq */
2400 I915_WRITE(SDEIIR, pch_iir);
2401 }
2402
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002403 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2404 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002405}
2406
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002407static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2408 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002409{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002410 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002411 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2412
Ville Syrjälä40e56412015-08-27 23:56:10 +03002413 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002414 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002415
2416 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002417 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002418
2419 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002420 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002421
2422 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002423 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002424
Damien Lespiau055e3932014-08-18 13:49:10 +01002425 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002426 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2427 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002428 }
2429
2430 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002431 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002432 u32 pch_iir = I915_READ(SDEIIR);
2433
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002434 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002435
2436 /* clear PCH hotplug event before clear CPU irq */
2437 I915_WRITE(SDEIIR, pch_iir);
2438 }
2439}
2440
Oscar Mateo72c90f62014-06-16 16:10:57 +01002441/*
2442 * To handle irqs with the minimum potential races with fresh interrupts, we:
2443 * 1 - Disable Master Interrupt Control.
2444 * 2 - Find the source(s) of the interrupt.
2445 * 3 - Clear the Interrupt Identity bits (IIR).
2446 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2447 * 5 - Re-enable Master Interrupt Control.
2448 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002449static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002450{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002451 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002452 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002453 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002454 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002455
Imre Deak2dd2a882015-02-24 11:14:30 +02002456 if (!intel_irqs_enabled(dev_priv))
2457 return IRQ_NONE;
2458
Imre Deak1f814da2015-12-16 02:52:19 +02002459 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2460 disable_rpm_wakeref_asserts(dev_priv);
2461
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002462 /* disable master interrupt before clearing iir */
2463 de_ier = I915_READ(DEIER);
2464 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002465 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002466
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002467 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2468 * interrupts will will be stored on its back queue, and then we'll be
2469 * able to process them after we restore SDEIER (as soon as we restore
2470 * it, we'll get an interrupt if SDEIIR still has something to process
2471 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002472 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002473 sde_ier = I915_READ(SDEIER);
2474 I915_WRITE(SDEIER, 0);
2475 POSTING_READ(SDEIER);
2476 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002477
Oscar Mateo72c90f62014-06-16 16:10:57 +01002478 /* Find, clear, then process each source of interrupt */
2479
Chris Wilson0e434062012-05-09 21:45:44 +01002480 gt_iir = I915_READ(GTIIR);
2481 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002482 I915_WRITE(GTIIR, gt_iir);
2483 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002484 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002485 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002486 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002487 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002488 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002489
2490 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002491 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002492 I915_WRITE(DEIIR, de_iir);
2493 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002494 if (INTEL_GEN(dev_priv) >= 7)
2495 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002496 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002497 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002498 }
2499
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002500 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002501 u32 pm_iir = I915_READ(GEN6_PMIIR);
2502 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002503 I915_WRITE(GEN6_PMIIR, pm_iir);
2504 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002505 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002506 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002507 }
2508
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002509 I915_WRITE(DEIER, de_ier);
2510 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002511 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002512 I915_WRITE(SDEIER, sde_ier);
2513 POSTING_READ(SDEIER);
2514 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002515
Imre Deak1f814da2015-12-16 02:52:19 +02002516 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2517 enable_rpm_wakeref_asserts(dev_priv);
2518
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002519 return ret;
2520}
2521
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002522static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2523 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002524 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302525{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002526 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302527
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002528 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2529 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302530
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002531 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002532 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002533 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002534
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002535 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302536}
2537
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002538static irqreturn_t
2539gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002540{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002541 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002542 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002543 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002544
Ben Widawskyabd58f02013-11-02 21:07:09 -07002545 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002546 iir = I915_READ(GEN8_DE_MISC_IIR);
2547 if (iir) {
2548 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002549 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002550 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002551 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002552 else
2553 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002554 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002555 else
2556 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002557 }
2558
Daniel Vetter6d766f02013-11-07 14:49:55 +01002559 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002560 iir = I915_READ(GEN8_DE_PORT_IIR);
2561 if (iir) {
2562 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302563 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002564
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002565 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002566 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002567
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002568 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002569 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002570 tmp_mask |= GEN9_AUX_CHANNEL_B |
2571 GEN9_AUX_CHANNEL_C |
2572 GEN9_AUX_CHANNEL_D;
2573
2574 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002575 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302576 found = true;
2577 }
2578
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002579 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002580 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2581 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002582 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2583 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002584 found = true;
2585 }
2586 } else if (IS_BROADWELL(dev_priv)) {
2587 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2588 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002589 ilk_hpd_irq_handler(dev_priv,
2590 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002591 found = true;
2592 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302593 }
2594
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002595 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002596 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302597 found = true;
2598 }
2599
Shashank Sharmad04a4922014-08-22 17:40:41 +05302600 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002601 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002602 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002603 else
2604 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002605 }
2606
Damien Lespiau055e3932014-08-18 13:49:10 +01002607 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002608 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002609
Daniel Vetterc42664c2013-11-07 11:05:40 +01002610 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2611 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002612
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002613 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2614 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002615 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002616 continue;
2617 }
2618
2619 ret = IRQ_HANDLED;
2620 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2621
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002622 if (iir & GEN8_PIPE_VBLANK)
2623 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002624
2625 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002626 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002627
2628 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2629 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2630
2631 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002632 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002633 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2634 else
2635 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2636
2637 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002638 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002639 pipe_name(pipe),
2640 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002641 }
2642
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002643 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302644 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002645 /*
2646 * FIXME(BDW): Assume for now that the new interrupt handling
2647 * scheme also closed the SDE interrupt handling race we've seen
2648 * on older pch-split platforms. But this needs testing.
2649 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002650 iir = I915_READ(SDEIIR);
2651 if (iir) {
2652 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002653 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002654
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002655 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2656 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002657 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002658 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002659 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002660 } else {
2661 /*
2662 * Like on previous PCH there seems to be something
2663 * fishy going on with forwarding PCH interrupts.
2664 */
2665 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2666 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002667 }
2668
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002669 return ret;
2670}
2671
2672static irqreturn_t gen8_irq_handler(int irq, void *arg)
2673{
2674 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002675 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002676 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002677 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002678 irqreturn_t ret;
2679
2680 if (!intel_irqs_enabled(dev_priv))
2681 return IRQ_NONE;
2682
2683 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2684 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2685 if (!master_ctl)
2686 return IRQ_NONE;
2687
2688 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2689
2690 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2691 disable_rpm_wakeref_asserts(dev_priv);
2692
2693 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002694 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2695 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002696 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2697
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002698 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2699 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002700
Imre Deak1f814da2015-12-16 02:52:19 +02002701 enable_rpm_wakeref_asserts(dev_priv);
2702
Ben Widawskyabd58f02013-11-02 21:07:09 -07002703 return ret;
2704}
2705
Chris Wilson36703e72017-06-22 11:56:25 +01002706struct wedge_me {
2707 struct delayed_work work;
2708 struct drm_i915_private *i915;
2709 const char *name;
2710};
2711
2712static void wedge_me(struct work_struct *work)
2713{
2714 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2715
2716 dev_err(w->i915->drm.dev,
2717 "%s timed out, cancelling all in-flight rendering.\n",
2718 w->name);
2719 i915_gem_set_wedged(w->i915);
2720}
2721
2722static void __init_wedge(struct wedge_me *w,
2723 struct drm_i915_private *i915,
2724 long timeout,
2725 const char *name)
2726{
2727 w->i915 = i915;
2728 w->name = name;
2729
2730 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2731 schedule_delayed_work(&w->work, timeout);
2732}
2733
2734static void __fini_wedge(struct wedge_me *w)
2735{
2736 cancel_delayed_work_sync(&w->work);
2737 destroy_delayed_work_on_stack(&w->work);
2738 w->i915 = NULL;
2739}
2740
2741#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2742 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2743 (W)->i915; \
2744 __fini_wedge((W)))
2745
Jesse Barnes8a905232009-07-11 16:48:03 -04002746/**
Chris Wilsond5367302017-06-20 10:57:43 +01002747 * i915_reset_device - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002748 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002749 *
2750 * Fire an error uevent so userspace can see that a hang or error
2751 * was detected.
2752 */
Chris Wilsond5367302017-06-20 10:57:43 +01002753static void i915_reset_device(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002754{
Chris Wilson91c8a322016-07-05 10:40:23 +01002755 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002756 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2757 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2758 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002759 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002760
Chris Wilsonc0336662016-05-06 15:40:21 +01002761 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002762
Chris Wilson8af29b02016-09-09 14:11:47 +01002763 DRM_DEBUG_DRIVER("resetting chip\n");
2764 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2765
Chris Wilson36703e72017-06-22 11:56:25 +01002766 /* Use a watchdog to ensure that our reset completes */
2767 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
2768 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002769
Chris Wilson36703e72017-06-22 11:56:25 +01002770 /* Signal that locked waiters should reset the GPU */
2771 set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags);
2772 wake_up_all(&dev_priv->gpu_error.wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00002773
Chris Wilson36703e72017-06-22 11:56:25 +01002774 /* Wait for anyone holding the lock to wakeup, without
2775 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01002776 */
Chris Wilson36703e72017-06-22 11:56:25 +01002777 do {
2778 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilson535275d2017-07-21 13:32:37 +01002779 i915_reset(dev_priv, 0);
Chris Wilson36703e72017-06-22 11:56:25 +01002780 mutex_unlock(&dev_priv->drm.struct_mutex);
2781 }
2782 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2783 I915_RESET_HANDOFF,
2784 TASK_UNINTERRUPTIBLE,
2785 1));
Chris Wilson780f2622016-09-09 14:11:52 +01002786
Chris Wilson36703e72017-06-22 11:56:25 +01002787 intel_finish_reset(dev_priv);
2788 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02002789
Chris Wilson780f2622016-09-09 14:11:52 +01002790 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002791 kobject_uevent_env(kobj,
2792 KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002793}
2794
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002795static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002796{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002797 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04002798
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002799 if (!IS_GEN2(dev_priv))
2800 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04002801
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002802 if (INTEL_GEN(dev_priv) < 4)
2803 I915_WRITE(IPEIR, I915_READ(IPEIR));
2804 else
2805 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002806
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002807 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04002808 eir = I915_READ(EIR);
2809 if (eir) {
2810 /*
2811 * some errors might have become stuck,
2812 * mask them.
2813 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002814 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002815 I915_WRITE(EMR, I915_READ(EMR) | eir);
2816 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2817 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002818}
2819
2820/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002821 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002822 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002823 * @engine_mask: mask representing engines that are hung
Michel Thierry87c390b2017-01-11 20:18:08 -08002824 * @fmt: Error message format string
2825 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002826 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002827 * dump it to the syslog. Also call i915_capture_error_state() to make
2828 * sure we get a record and make it available in debugfs. Fire a uevent
2829 * so userspace knows something bad happened (should trigger collection
2830 * of a ring dump etc.).
2831 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002832void i915_handle_error(struct drm_i915_private *dev_priv,
2833 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002834 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002835{
Michel Thierry142bc7d2017-06-20 10:57:46 +01002836 struct intel_engine_cs *engine;
2837 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02002838 va_list args;
2839 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002840
Mika Kuoppala58174462014-02-25 17:11:26 +02002841 va_start(args, fmt);
2842 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2843 va_end(args);
2844
Chris Wilson1604a862017-03-14 17:18:40 +00002845 /*
2846 * In most cases it's guaranteed that we get here with an RPM
2847 * reference held, for example because there is a pending GPU
2848 * request that won't finish until the reset is done. This
2849 * isn't the case at least when we get here by doing a
2850 * simulated reset via debugfs, so get an RPM reference.
2851 */
2852 intel_runtime_pm_get(dev_priv);
2853
Chris Wilsonc0336662016-05-06 15:40:21 +01002854 i915_capture_error_state(dev_priv, engine_mask, error_msg);
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002855 i915_clear_error_registers(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002856
Michel Thierry142bc7d2017-06-20 10:57:46 +01002857 /*
2858 * Try engine reset when available. We fall back to full reset if
2859 * single reset fails.
2860 */
2861 if (intel_has_reset_engine(dev_priv)) {
2862 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02002863 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01002864 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2865 &dev_priv->gpu_error.flags))
2866 continue;
2867
Chris Wilson535275d2017-07-21 13:32:37 +01002868 if (i915_reset_engine(engine, 0) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01002869 engine_mask &= ~intel_engine_flag(engine);
2870
2871 clear_bit(I915_RESET_ENGINE + engine->id,
2872 &dev_priv->gpu_error.flags);
2873 wake_up_bit(&dev_priv->gpu_error.flags,
2874 I915_RESET_ENGINE + engine->id);
2875 }
2876 }
2877
Chris Wilson8af29b02016-09-09 14:11:47 +01002878 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00002879 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04002880
Michel Thierry142bc7d2017-06-20 10:57:46 +01002881 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01002882 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
2883 wait_event(dev_priv->gpu_error.reset_queue,
2884 !test_bit(I915_RESET_BACKOFF,
2885 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00002886 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01002887 }
Chris Wilson8af29b02016-09-09 14:11:47 +01002888
Michel Thierry142bc7d2017-06-20 10:57:46 +01002889 /* Prevent any other reset-engine attempt. */
2890 for_each_engine(engine, dev_priv, tmp) {
2891 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2892 &dev_priv->gpu_error.flags))
2893 wait_on_bit(&dev_priv->gpu_error.flags,
2894 I915_RESET_ENGINE + engine->id,
2895 TASK_UNINTERRUPTIBLE);
2896 }
2897
Chris Wilsond5367302017-06-20 10:57:43 +01002898 i915_reset_device(dev_priv);
2899
Michel Thierry142bc7d2017-06-20 10:57:46 +01002900 for_each_engine(engine, dev_priv, tmp) {
2901 clear_bit(I915_RESET_ENGINE + engine->id,
2902 &dev_priv->gpu_error.flags);
2903 }
2904
Chris Wilsond5367302017-06-20 10:57:43 +01002905 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
2906 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00002907
2908out:
2909 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002910}
2911
Keith Packard42f52ef2008-10-18 19:39:29 -07002912/* Called from drm generic code, passed 'crtc' which
2913 * we use as a pipe index
2914 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002915static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002916{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002917 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002918 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002919
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002920 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01002921 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2922 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2923
2924 return 0;
2925}
2926
2927static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
2928{
2929 struct drm_i915_private *dev_priv = to_i915(dev);
2930 unsigned long irqflags;
2931
2932 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2933 i915_enable_pipestat(dev_priv, pipe,
2934 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002935 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002936
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002937 return 0;
2938}
2939
Thierry Reding88e72712015-09-24 18:35:31 +02002940static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002941{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002942 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002943 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002944 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002945 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002946
Jesse Barnesf796cf82011-04-07 13:58:17 -07002947 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002948 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002949 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2950
2951 return 0;
2952}
2953
Thierry Reding88e72712015-09-24 18:35:31 +02002954static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002955{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002956 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002957 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002958
Ben Widawskyabd58f02013-11-02 21:07:09 -07002959 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002960 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002961 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002962
Ben Widawskyabd58f02013-11-02 21:07:09 -07002963 return 0;
2964}
2965
Keith Packard42f52ef2008-10-18 19:39:29 -07002966/* Called from drm generic code, passed 'crtc' which
2967 * we use as a pipe index
2968 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002969static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
2970{
2971 struct drm_i915_private *dev_priv = to_i915(dev);
2972 unsigned long irqflags;
2973
2974 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2975 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2976 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2977}
2978
2979static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002980{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002981 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002982 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002983
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002984 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002985 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002986 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002987 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2988}
2989
Thierry Reding88e72712015-09-24 18:35:31 +02002990static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002991{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002992 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002993 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002994 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002995 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002996
2997 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002998 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002999 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3000}
3001
Thierry Reding88e72712015-09-24 18:35:31 +02003002static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003003{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003004 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003005 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003006
Ben Widawskyabd58f02013-11-02 21:07:09 -07003007 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003008 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003009 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3010}
3011
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003012static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003013{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003014 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003015 return;
3016
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003017 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003018
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003019 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003020 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003021}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003022
Paulo Zanoni622364b2014-04-01 15:37:22 -03003023/*
3024 * SDEIER is also touched by the interrupt handler to work around missed PCH
3025 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3026 * instead we unconditionally enable all PCH interrupt sources here, but then
3027 * only unmask them as needed with SDEIMR.
3028 *
3029 * This function needs to be called before interrupts are enabled.
3030 */
3031static void ibx_irq_pre_postinstall(struct drm_device *dev)
3032{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003033 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003034
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003035 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003036 return;
3037
3038 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003039 I915_WRITE(SDEIER, 0xffffffff);
3040 POSTING_READ(SDEIER);
3041}
3042
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003043static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003044{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003045 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003046 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003047 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003048}
3049
Ville Syrjälä70591a42014-10-30 19:42:58 +02003050static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3051{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003052 if (IS_CHERRYVIEW(dev_priv))
3053 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3054 else
3055 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3056
Ville Syrjäläad22d102016-04-12 18:56:14 +03003057 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003058 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3059
Ville Syrjälä44d92412017-08-18 21:36:51 +03003060 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003061
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003062 GEN3_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003063 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003064}
3065
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003066static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3067{
3068 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003069 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003070 enum pipe pipe;
3071
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003072 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003073
3074 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3075 for_each_pipe(dev_priv, pipe)
3076 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3077
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003078 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3079 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003080 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3081 I915_LPE_PIPE_A_INTERRUPT |
3082 I915_LPE_PIPE_B_INTERRUPT;
3083
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003084 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003085 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3086 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003087
3088 WARN_ON(dev_priv->irq_mask != ~0);
3089
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003090 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003091
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003092 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003093}
3094
3095/* drm_dma.h hooks
3096*/
3097static void ironlake_irq_reset(struct drm_device *dev)
3098{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003099 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003100
Ville Syrjäläd420a502017-08-18 21:37:03 +03003101 if (IS_GEN5(dev_priv))
3102 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003103
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003104 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003105 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003106 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3107
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003108 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003109
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003110 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003111}
3112
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003113static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003114{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003115 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003116
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003117 I915_WRITE(VLV_MASTER_IER, 0);
3118 POSTING_READ(VLV_MASTER_IER);
3119
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003120 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003121
Ville Syrjäläad22d102016-04-12 18:56:14 +03003122 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003123 if (dev_priv->display_irqs_enabled)
3124 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003125 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003126}
3127
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003128static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3129{
3130 GEN8_IRQ_RESET_NDX(GT, 0);
3131 GEN8_IRQ_RESET_NDX(GT, 1);
3132 GEN8_IRQ_RESET_NDX(GT, 2);
3133 GEN8_IRQ_RESET_NDX(GT, 3);
3134}
3135
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003136static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003137{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003138 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003139 int pipe;
3140
Ben Widawskyabd58f02013-11-02 21:07:09 -07003141 I915_WRITE(GEN8_MASTER_IRQ, 0);
3142 POSTING_READ(GEN8_MASTER_IRQ);
3143
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003144 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003145
Damien Lespiau055e3932014-08-18 13:49:10 +01003146 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003147 if (intel_display_power_is_enabled(dev_priv,
3148 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003149 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003150
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003151 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3152 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3153 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003154
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003155 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003156 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003157}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003158
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003159void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003160 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003161{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003162 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003163 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003164
Daniel Vetter13321782014-09-15 14:55:29 +02003165 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003166 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3167 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3168 dev_priv->de_irq_mask[pipe],
3169 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003170 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003171}
3172
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003173void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003174 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003175{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003176 enum pipe pipe;
3177
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003178 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003179 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3180 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003181 spin_unlock_irq(&dev_priv->irq_lock);
3182
3183 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003184 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003185}
3186
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003187static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003188{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003189 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003190
3191 I915_WRITE(GEN8_MASTER_IRQ, 0);
3192 POSTING_READ(GEN8_MASTER_IRQ);
3193
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003194 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003195
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003196 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003197
Ville Syrjäläad22d102016-04-12 18:56:14 +03003198 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003199 if (dev_priv->display_irqs_enabled)
3200 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003201 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003202}
3203
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003204static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003205 const u32 hpd[HPD_NUM_PINS])
3206{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003207 struct intel_encoder *encoder;
3208 u32 enabled_irqs = 0;
3209
Chris Wilson91c8a322016-07-05 10:40:23 +01003210 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003211 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3212 enabled_irqs |= hpd[encoder->hpd_pin];
3213
3214 return enabled_irqs;
3215}
3216
Imre Deak1a56b1a2017-01-27 11:39:21 +02003217static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3218{
3219 u32 hotplug;
3220
3221 /*
3222 * Enable digital hotplug on the PCH, and configure the DP short pulse
3223 * duration to 2ms (which is the minimum in the Display Port spec).
3224 * The pulse duration bits are reserved on LPT+.
3225 */
3226 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3227 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3228 PORTC_PULSE_DURATION_MASK |
3229 PORTD_PULSE_DURATION_MASK);
3230 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3231 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3232 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3233 /*
3234 * When CPU and PCH are on the same package, port A
3235 * HPD must be enabled in both north and south.
3236 */
3237 if (HAS_PCH_LPT_LP(dev_priv))
3238 hotplug |= PORTA_HOTPLUG_ENABLE;
3239 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3240}
3241
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003242static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003243{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003244 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003245
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003246 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003247 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003248 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003249 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003250 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003251 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003252 }
3253
Daniel Vetterfee884e2013-07-04 23:35:21 +02003254 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003255
Imre Deak1a56b1a2017-01-27 11:39:21 +02003256 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003257}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003258
Imre Deak2a57d9c2017-01-27 11:39:18 +02003259static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3260{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003261 u32 val, hotplug;
3262
3263 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3264 if (HAS_PCH_CNP(dev_priv)) {
3265 val = I915_READ(SOUTH_CHICKEN1);
3266 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3267 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3268 I915_WRITE(SOUTH_CHICKEN1, val);
3269 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003270
3271 /* Enable digital hotplug on the PCH */
3272 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3273 hotplug |= PORTA_HOTPLUG_ENABLE |
3274 PORTB_HOTPLUG_ENABLE |
3275 PORTC_HOTPLUG_ENABLE |
3276 PORTD_HOTPLUG_ENABLE;
3277 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3278
3279 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3280 hotplug |= PORTE_HOTPLUG_ENABLE;
3281 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3282}
3283
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003284static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003285{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003286 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003287
3288 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003289 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003290
3291 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3292
Imre Deak2a57d9c2017-01-27 11:39:18 +02003293 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003294}
3295
Imre Deak1a56b1a2017-01-27 11:39:21 +02003296static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3297{
3298 u32 hotplug;
3299
3300 /*
3301 * Enable digital hotplug on the CPU, and configure the DP short pulse
3302 * duration to 2ms (which is the minimum in the Display Port spec)
3303 * The pulse duration bits are reserved on HSW+.
3304 */
3305 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3306 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3307 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3308 DIGITAL_PORTA_PULSE_DURATION_2ms;
3309 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3310}
3311
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003312static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003313{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003314 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003315
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003316 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003317 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003318 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003319
3320 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003321 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003322 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003323 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003324
3325 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003326 } else {
3327 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003328 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003329
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003330 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3331 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003332
Imre Deak1a56b1a2017-01-27 11:39:21 +02003333 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003334
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003335 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003336}
3337
Imre Deak2a57d9c2017-01-27 11:39:18 +02003338static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3339 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003340{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003341 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003342
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003343 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003344 hotplug |= PORTA_HOTPLUG_ENABLE |
3345 PORTB_HOTPLUG_ENABLE |
3346 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303347
3348 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3349 hotplug, enabled_irqs);
3350 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3351
3352 /*
3353 * For BXT invert bit has to be set based on AOB design
3354 * for HPD detection logic, update it based on VBT fields.
3355 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303356 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3357 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3358 hotplug |= BXT_DDIA_HPD_INVERT;
3359 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3360 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3361 hotplug |= BXT_DDIB_HPD_INVERT;
3362 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3363 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3364 hotplug |= BXT_DDIC_HPD_INVERT;
3365
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003366 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003367}
3368
Imre Deak2a57d9c2017-01-27 11:39:18 +02003369static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3370{
3371 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3372}
3373
3374static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3375{
3376 u32 hotplug_irqs, enabled_irqs;
3377
3378 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3379 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3380
3381 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3382
3383 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3384}
3385
Paulo Zanonid46da432013-02-08 17:35:15 -02003386static void ibx_irq_postinstall(struct drm_device *dev)
3387{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003388 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003389 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003390
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003391 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003392 return;
3393
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003394 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003395 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003396 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003397 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003398 else
3399 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003400
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003401 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003402 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003403
3404 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3405 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003406 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003407 else
3408 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003409}
3410
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003411static void gen5_gt_irq_postinstall(struct drm_device *dev)
3412{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003413 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003414 u32 pm_irqs, gt_irqs;
3415
3416 pm_irqs = gt_irqs = 0;
3417
3418 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003419 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003420 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003421 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3422 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003423 }
3424
3425 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003426 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003427 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003428 } else {
3429 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3430 }
3431
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003432 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003433
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003434 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003435 /*
3436 * RPS interrupts will get enabled/disabled on demand when RPS
3437 * itself is enabled/disabled.
3438 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303439 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003440 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303441 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3442 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003443
Akash Goelf4e9af42016-10-12 21:54:30 +05303444 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003445 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003446 }
3447}
3448
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003449static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003450{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003451 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003452 u32 display_mask, extra_mask;
3453
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003454 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003455 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003456 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003457 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003458 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3459 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003460 } else {
3461 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003462 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3463 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003464 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3465 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3466 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003467 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003468
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003469 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003470
Paulo Zanoni622364b2014-04-01 15:37:22 -03003471 ibx_irq_pre_postinstall(dev);
3472
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003473 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003474
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003475 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003476
Imre Deak1a56b1a2017-01-27 11:39:21 +02003477 ilk_hpd_detection_setup(dev_priv);
3478
Paulo Zanonid46da432013-02-08 17:35:15 -02003479 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003480
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003481 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003482 /* Enable PCU event interrupts
3483 *
3484 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003485 * setup is guaranteed to run in single-threaded context. But we
3486 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003487 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003488 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003489 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003490 }
3491
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003492 return 0;
3493}
3494
Imre Deakf8b79e52014-03-04 19:23:07 +02003495void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3496{
Chris Wilson67520412017-03-02 13:28:01 +00003497 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003498
3499 if (dev_priv->display_irqs_enabled)
3500 return;
3501
3502 dev_priv->display_irqs_enabled = true;
3503
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003504 if (intel_irqs_enabled(dev_priv)) {
3505 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003506 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003507 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003508}
3509
3510void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3511{
Chris Wilson67520412017-03-02 13:28:01 +00003512 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003513
3514 if (!dev_priv->display_irqs_enabled)
3515 return;
3516
3517 dev_priv->display_irqs_enabled = false;
3518
Imre Deak950eaba2014-09-08 15:21:09 +03003519 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003520 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003521}
3522
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003523
3524static int valleyview_irq_postinstall(struct drm_device *dev)
3525{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003526 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003527
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003528 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003529
Ville Syrjäläad22d102016-04-12 18:56:14 +03003530 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003531 if (dev_priv->display_irqs_enabled)
3532 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003533 spin_unlock_irq(&dev_priv->irq_lock);
3534
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003535 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003536 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003537
3538 return 0;
3539}
3540
Ben Widawskyabd58f02013-11-02 21:07:09 -07003541static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3542{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003543 /* These are interrupts we'll toggle with the ring mask register */
3544 uint32_t gt_interrupts[] = {
3545 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003546 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003547 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3548 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003549 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003550 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3551 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3552 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003553 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003554 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3555 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003556 };
3557
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003558 if (HAS_L3_DPF(dev_priv))
3559 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3560
Akash Goelf4e9af42016-10-12 21:54:30 +05303561 dev_priv->pm_ier = 0x0;
3562 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303563 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3564 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003565 /*
3566 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303567 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003568 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303569 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303570 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003571}
3572
3573static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3574{
Damien Lespiau770de832014-03-20 20:45:01 +00003575 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3576 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003577 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3578 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003579 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003580 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003581
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003582 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003583 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003584 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3585 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003586 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003587 de_port_masked |= BXT_DE_PORT_GMBUS;
3588 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003589 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003590 }
Damien Lespiau770de832014-03-20 20:45:01 +00003591
3592 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3593 GEN8_PIPE_FIFO_UNDERRUN;
3594
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003595 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003596 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003597 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3598 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003599 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3600
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003601 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3602 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3603 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003604
Damien Lespiau055e3932014-08-18 13:49:10 +01003605 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003606 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003607 POWER_DOMAIN_PIPE(pipe)))
3608 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3609 dev_priv->de_irq_mask[pipe],
3610 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003611
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003612 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3613 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003614
3615 if (IS_GEN9_LP(dev_priv))
3616 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003617 else if (IS_BROADWELL(dev_priv))
3618 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003619}
3620
3621static int gen8_irq_postinstall(struct drm_device *dev)
3622{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003623 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003624
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003625 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303626 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003627
Ben Widawskyabd58f02013-11-02 21:07:09 -07003628 gen8_gt_irq_postinstall(dev_priv);
3629 gen8_de_irq_postinstall(dev_priv);
3630
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003631 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303632 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003633
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003634 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003635 POSTING_READ(GEN8_MASTER_IRQ);
3636
3637 return 0;
3638}
3639
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003640static int cherryview_irq_postinstall(struct drm_device *dev)
3641{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003642 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003643
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003644 gen8_gt_irq_postinstall(dev_priv);
3645
Ville Syrjäläad22d102016-04-12 18:56:14 +03003646 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003647 if (dev_priv->display_irqs_enabled)
3648 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003649 spin_unlock_irq(&dev_priv->irq_lock);
3650
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003651 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003652 POSTING_READ(GEN8_MASTER_IRQ);
3653
3654 return 0;
3655}
3656
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003657static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003658{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003659 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003660
Ville Syrjälä44d92412017-08-18 21:36:51 +03003661 i9xx_pipestat_irq_reset(dev_priv);
3662
Ville Syrjäläd420a502017-08-18 21:37:03 +03003663 I915_WRITE16(HWSTAM, 0xffff);
3664
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003665 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01003666}
3667
3668static int i8xx_irq_postinstall(struct drm_device *dev)
3669{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003670 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003671 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003672
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003673 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
3674 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01003675
3676 /* Unmask the interrupts that we always want on. */
3677 dev_priv->irq_mask =
3678 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003679 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003680
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003681 enable_mask =
3682 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3683 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3684 I915_USER_INTERRUPT;
3685
3686 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003687
Daniel Vetter379ef822013-10-16 22:55:56 +02003688 /* Interrupt setup is already guaranteed to be single-threaded, this is
3689 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003690 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003691 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3692 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003693 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003694
Chris Wilsonc2798b12012-04-22 21:13:57 +01003695 return 0;
3696}
3697
Daniel Vetterff1f5252012-10-02 15:10:55 +02003698static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003699{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003700 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003701 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003702 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003703
Imre Deak2dd2a882015-02-24 11:14:30 +02003704 if (!intel_irqs_enabled(dev_priv))
3705 return IRQ_NONE;
3706
Imre Deak1f814da2015-12-16 02:52:19 +02003707 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3708 disable_rpm_wakeref_asserts(dev_priv);
3709
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003710 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003711 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003712 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03003713
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003714 iir = I915_READ16(IIR);
3715 if (iir == 0)
3716 break;
3717
3718 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003719
Ville Syrjäläeb643432017-08-18 21:36:59 +03003720 /* Call regardless, as some status bits might not be
3721 * signalled in iir */
3722 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003723
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003724 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003725
Chris Wilsonc2798b12012-04-22 21:13:57 +01003726 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303727 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003728
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003729 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3730 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3731
Ville Syrjäläeb643432017-08-18 21:36:59 +03003732 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003733 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003734
Imre Deak1f814da2015-12-16 02:52:19 +02003735 enable_rpm_wakeref_asserts(dev_priv);
3736
3737 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003738}
3739
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003740static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003741{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003742 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003743
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003744 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003745 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003746 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3747 }
3748
Ville Syrjälä44d92412017-08-18 21:36:51 +03003749 i9xx_pipestat_irq_reset(dev_priv);
3750
Ville Syrjäläd420a502017-08-18 21:37:03 +03003751 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003752
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003753 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003754}
3755
3756static int i915_irq_postinstall(struct drm_device *dev)
3757{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003758 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01003759 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003760
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003761 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
3762 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01003763
3764 /* Unmask the interrupts that we always want on. */
3765 dev_priv->irq_mask =
3766 ~(I915_ASLE_INTERRUPT |
3767 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003768 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003769
3770 enable_mask =
3771 I915_ASLE_INTERRUPT |
3772 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3773 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003774 I915_USER_INTERRUPT;
3775
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003776 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003777 /* Enable in IER... */
3778 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3779 /* and unmask in IMR */
3780 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3781 }
3782
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003783 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003784
Daniel Vetter379ef822013-10-16 22:55:56 +02003785 /* Interrupt setup is already guaranteed to be single-threaded, this is
3786 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003787 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003788 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3789 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003790 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003791
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003792 i915_enable_asle_pipestat(dev_priv);
3793
Daniel Vetter20afbda2012-12-11 14:05:07 +01003794 return 0;
3795}
3796
Daniel Vetterff1f5252012-10-02 15:10:55 +02003797static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003798{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003799 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003800 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003801 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003802
Imre Deak2dd2a882015-02-24 11:14:30 +02003803 if (!intel_irqs_enabled(dev_priv))
3804 return IRQ_NONE;
3805
Imre Deak1f814da2015-12-16 02:52:19 +02003806 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3807 disable_rpm_wakeref_asserts(dev_priv);
3808
Chris Wilson38bde182012-04-24 22:59:50 +01003809 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003810 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003811 u32 hotplug_status = 0;
3812 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003813
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003814 iir = I915_READ(IIR);
3815 if (iir == 0)
3816 break;
3817
3818 ret = IRQ_HANDLED;
3819
3820 if (I915_HAS_HOTPLUG(dev_priv) &&
3821 iir & I915_DISPLAY_PORT_INTERRUPT)
3822 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003823
Ville Syrjäläeb643432017-08-18 21:36:59 +03003824 /* Call regardless, as some status bits might not be
3825 * signalled in iir */
3826 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003827
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003828 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003829
Chris Wilsona266c7d2012-04-24 22:59:44 +01003830 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303831 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003832
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003833 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3834 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003835
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003836 if (hotplug_status)
3837 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3838
3839 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3840 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003841
Imre Deak1f814da2015-12-16 02:52:19 +02003842 enable_rpm_wakeref_asserts(dev_priv);
3843
Chris Wilsona266c7d2012-04-24 22:59:44 +01003844 return ret;
3845}
3846
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003847static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003848{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003849 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003850
Egbert Eich0706f172015-09-23 16:15:27 +02003851 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01003852 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003853
Ville Syrjälä44d92412017-08-18 21:36:51 +03003854 i9xx_pipestat_irq_reset(dev_priv);
3855
Ville Syrjäläd420a502017-08-18 21:37:03 +03003856 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003857
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003858 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003859}
3860
3861static int i965_irq_postinstall(struct drm_device *dev)
3862{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003863 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003864 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003865 u32 error_mask;
3866
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003867 /*
3868 * Enable some error detection, note the instruction error mask
3869 * bit is reserved, so we leave it masked.
3870 */
3871 if (IS_G4X(dev_priv)) {
3872 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3873 GM45_ERROR_MEM_PRIV |
3874 GM45_ERROR_CP_PRIV |
3875 I915_ERROR_MEMORY_REFRESH);
3876 } else {
3877 error_mask = ~(I915_ERROR_PAGE_TABLE |
3878 I915_ERROR_MEMORY_REFRESH);
3879 }
3880 I915_WRITE(EMR, error_mask);
3881
Chris Wilsona266c7d2012-04-24 22:59:44 +01003882 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003883 dev_priv->irq_mask =
3884 ~(I915_ASLE_INTERRUPT |
3885 I915_DISPLAY_PORT_INTERRUPT |
3886 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3887 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3888 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003889
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003890 enable_mask =
3891 I915_ASLE_INTERRUPT |
3892 I915_DISPLAY_PORT_INTERRUPT |
3893 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3894 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3895 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3896 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003897
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003898 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003899 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003900
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003901 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
3902
Daniel Vetterb79480b2013-06-27 17:52:10 +02003903 /* Interrupt setup is already guaranteed to be single-threaded, this is
3904 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003905 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003906 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3907 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3908 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003909 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003910
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003911 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003912
3913 return 0;
3914}
3915
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003916static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003917{
Daniel Vetter20afbda2012-12-11 14:05:07 +01003918 u32 hotplug_en;
3919
Chris Wilson67520412017-03-02 13:28:01 +00003920 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003921
Ville Syrjälä778eb332015-01-09 14:21:13 +02003922 /* Note HDMI and DP share hotplug bits */
3923 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003924 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02003925 /* Programming the CRT detection parameters tends
3926 to generate a spurious hotplug event about three
3927 seconds later. So just do it once.
3928 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003929 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02003930 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02003931 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003932
Ville Syrjälä778eb332015-01-09 14:21:13 +02003933 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02003934 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03003935 HOTPLUG_INT_EN_MASK |
3936 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
3937 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
3938 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003939}
3940
Daniel Vetterff1f5252012-10-02 15:10:55 +02003941static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003942{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003943 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003944 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003945 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003946
Imre Deak2dd2a882015-02-24 11:14:30 +02003947 if (!intel_irqs_enabled(dev_priv))
3948 return IRQ_NONE;
3949
Imre Deak1f814da2015-12-16 02:52:19 +02003950 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3951 disable_rpm_wakeref_asserts(dev_priv);
3952
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003953 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003954 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003955 u32 hotplug_status = 0;
3956 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003957
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003958 iir = I915_READ(IIR);
3959 if (iir == 0)
3960 break;
3961
3962 ret = IRQ_HANDLED;
3963
3964 if (iir & I915_DISPLAY_PORT_INTERRUPT)
3965 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003966
Ville Syrjäläeb643432017-08-18 21:36:59 +03003967 /* Call regardless, as some status bits might not be
3968 * signalled in iir */
3969 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003970
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003971 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003972
Chris Wilsona266c7d2012-04-24 22:59:44 +01003973 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303974 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003975
Chris Wilsona266c7d2012-04-24 22:59:44 +01003976 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303977 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003978
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003979 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3980 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003981
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003982 if (hotplug_status)
3983 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3984
3985 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3986 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003987
Imre Deak1f814da2015-12-16 02:52:19 +02003988 enable_rpm_wakeref_asserts(dev_priv);
3989
Chris Wilsona266c7d2012-04-24 22:59:44 +01003990 return ret;
3991}
3992
Daniel Vetterfca52a52014-09-30 10:56:45 +02003993/**
3994 * intel_irq_init - initializes irq support
3995 * @dev_priv: i915 device instance
3996 *
3997 * This function initializes all the irq support including work items, timers
3998 * and all the vtables. It does not setup the interrupt itself though.
3999 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004000void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004001{
Chris Wilson91c8a322016-07-05 10:40:23 +01004002 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004003 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004004
Jani Nikula77913b32015-06-18 13:06:16 +03004005 intel_hpd_init_work(dev_priv);
4006
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004007 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004008
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004009 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004010 for (i = 0; i < MAX_L3_SLICES; ++i)
4011 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004012
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004013 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304014 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4015
Deepak Sa6706b42014-03-15 20:23:22 +05304016 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004017 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004018 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004019 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004020 else
4021 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304022
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05304023 dev_priv->rps.pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304024
4025 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004026 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304027 * if GEN6_PM_UP_EI_EXPIRED is masked.
4028 *
4029 * TODO: verify if this can be reproduced on VLV,CHV.
4030 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004031 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05304032 dev_priv->rps.pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304033
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004034 if (INTEL_GEN(dev_priv) >= 8)
Chris Wilson655d49e2017-03-12 13:27:45 +00004035 dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304036
Daniel Vetterb9632912014-09-30 10:56:44 +02004037 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004038 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004039 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004040 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004041 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004042 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004043 } else {
4044 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4045 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004046 }
4047
Ville Syrjälä21da2702014-08-06 14:49:55 +03004048 /*
4049 * Opt out of the vblank disable timer on everything except gen2.
4050 * Gen2 doesn't have a hardware frame counter and so depends on
4051 * vblank interrupts to produce sane vblank seuquence numbers.
4052 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004053 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004054 dev->vblank_disable_immediate = true;
4055
Chris Wilson262fd482017-02-15 13:15:47 +00004056 /* Most platforms treat the display irq block as an always-on
4057 * power domain. vlv/chv can disable it at runtime and need
4058 * special care to avoid writing any of the display block registers
4059 * outside of the power domain. We defer setting up the display irqs
4060 * in this case to the runtime pm.
4061 */
4062 dev_priv->display_irqs_enabled = true;
4063 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4064 dev_priv->display_irqs_enabled = false;
4065
Lyude317eaa92017-02-03 21:18:25 -05004066 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4067
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004068 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004069 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004070
Daniel Vetterb9632912014-09-30 10:56:44 +02004071 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004072 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004073 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004074 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004075 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004076 dev->driver->enable_vblank = i965_enable_vblank;
4077 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004078 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004079 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004080 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004081 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004082 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004083 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004084 dev->driver->enable_vblank = i965_enable_vblank;
4085 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004086 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004087 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004088 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004089 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004090 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004091 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004092 dev->driver->enable_vblank = gen8_enable_vblank;
4093 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004094 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004095 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004096 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4097 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004098 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4099 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004100 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004101 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004102 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004103 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004104 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004105 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004106 dev->driver->enable_vblank = ironlake_enable_vblank;
4107 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004108 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004109 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004110 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004111 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004112 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4113 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004114 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004115 dev->driver->enable_vblank = i8xx_enable_vblank;
4116 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004117 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004118 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004119 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004120 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004121 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004122 dev->driver->enable_vblank = i8xx_enable_vblank;
4123 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004124 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004125 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004126 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004127 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004128 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004129 dev->driver->enable_vblank = i965_enable_vblank;
4130 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004131 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004132 if (I915_HAS_HOTPLUG(dev_priv))
4133 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004134 }
4135}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004136
Daniel Vetterfca52a52014-09-30 10:56:45 +02004137/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004138 * intel_irq_fini - deinitializes IRQ support
4139 * @i915: i915 device instance
4140 *
4141 * This function deinitializes all the IRQ support.
4142 */
4143void intel_irq_fini(struct drm_i915_private *i915)
4144{
4145 int i;
4146
4147 for (i = 0; i < MAX_L3_SLICES; ++i)
4148 kfree(i915->l3_parity.remap_info[i]);
4149}
4150
4151/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004152 * intel_irq_install - enables the hardware interrupt
4153 * @dev_priv: i915 device instance
4154 *
4155 * This function enables the hardware interrupt handling, but leaves the hotplug
4156 * handling still disabled. It is called after intel_irq_init().
4157 *
4158 * In the driver load and resume code we need working interrupts in a few places
4159 * but don't want to deal with the hassle of concurrent probe and hotplug
4160 * workers. Hence the split into this two-stage approach.
4161 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004162int intel_irq_install(struct drm_i915_private *dev_priv)
4163{
4164 /*
4165 * We enable some interrupt sources in our postinstall hooks, so mark
4166 * interrupts as enabled _before_ actually enabling them to avoid
4167 * special cases in our ordering checks.
4168 */
4169 dev_priv->pm.irqs_enabled = true;
4170
Chris Wilson91c8a322016-07-05 10:40:23 +01004171 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004172}
4173
Daniel Vetterfca52a52014-09-30 10:56:45 +02004174/**
4175 * intel_irq_uninstall - finilizes all irq handling
4176 * @dev_priv: i915 device instance
4177 *
4178 * This stops interrupt and hotplug handling and unregisters and frees all
4179 * resources acquired in the init functions.
4180 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004181void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4182{
Chris Wilson91c8a322016-07-05 10:40:23 +01004183 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004184 intel_hpd_cancel_work(dev_priv);
4185 dev_priv->pm.irqs_enabled = false;
4186}
4187
Daniel Vetterfca52a52014-09-30 10:56:45 +02004188/**
4189 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4190 * @dev_priv: i915 device instance
4191 *
4192 * This function is used to disable interrupts at runtime, both in the runtime
4193 * pm and the system suspend/resume code.
4194 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004195void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004196{
Chris Wilson91c8a322016-07-05 10:40:23 +01004197 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004198 dev_priv->pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004199 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004200}
4201
Daniel Vetterfca52a52014-09-30 10:56:45 +02004202/**
4203 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4204 * @dev_priv: i915 device instance
4205 *
4206 * This function is used to enable interrupts at runtime, both in the runtime
4207 * pm and the system suspend/resume code.
4208 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004209void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004210{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004211 dev_priv->pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004212 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4213 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004214}