blob: bd38c6983eec7dcead1aa465f36bde9e0f9be239 [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
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100570static void
Imre Deak755e9012014-02-10 18:42:47 +0200571__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
572 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800573{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200574 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200575 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800576
Chris Wilson67520412017-03-02 13:28:01 +0000577 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200578 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200579
Ville Syrjälä04feced2014-04-03 13:28:33 +0300580 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
581 status_mask & ~PIPESTAT_INT_STATUS_MASK,
582 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
583 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200584 return;
585
586 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200587 return;
588
Imre Deak91d181d2014-02-10 18:42:49 +0200589 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
590
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200591 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200592 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200593 I915_WRITE(reg, pipestat);
594 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800595}
596
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100597static void
Imre Deak755e9012014-02-10 18:42:47 +0200598__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
599 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800600{
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200601 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200602 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800603
Chris Wilson67520412017-03-02 13:28:01 +0000604 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200605 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200606
Ville Syrjälä04feced2014-04-03 13:28:33 +0300607 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
608 status_mask & ~PIPESTAT_INT_STATUS_MASK,
609 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
610 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200611 return;
612
Imre Deak755e9012014-02-10 18:42:47 +0200613 if ((pipestat & enable_mask) == 0)
614 return;
615
Imre Deak91d181d2014-02-10 18:42:49 +0200616 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
617
Imre Deak755e9012014-02-10 18:42:47 +0200618 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200619 I915_WRITE(reg, pipestat);
620 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800621}
622
Imre Deak10c59c52014-02-10 18:42:48 +0200623static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
624{
625 u32 enable_mask = status_mask << 16;
626
627 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300628 * On pipe A we don't support the PSR interrupt yet,
629 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200630 */
631 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
632 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300633 /*
634 * On pipe B and C we don't support the PSR interrupt yet, on pipe
635 * A the same bit is for perf counters which we don't use either.
636 */
637 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
638 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200639
640 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
641 SPRITE0_FLIP_DONE_INT_EN_VLV |
642 SPRITE1_FLIP_DONE_INT_EN_VLV);
643 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
644 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
645 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
646 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
647
648 return enable_mask;
649}
650
Imre Deak755e9012014-02-10 18:42:47 +0200651void
652i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
653 u32 status_mask)
654{
655 u32 enable_mask;
656
Wayne Boyer666a4532015-12-09 12:29:35 -0800657 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100658 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200659 status_mask);
660 else
661 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200662 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
663}
664
665void
666i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
667 u32 status_mask)
668{
669 u32 enable_mask;
670
Wayne Boyer666a4532015-12-09 12:29:35 -0800671 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
Chris Wilson91c8a322016-07-05 10:40:23 +0100672 enable_mask = vlv_get_pipestat_enable_mask(&dev_priv->drm,
Imre Deak10c59c52014-02-10 18:42:48 +0200673 status_mask);
674 else
675 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200676 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
677}
678
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000679/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300680 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100681 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000682 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100683static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000684{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100685 if (!dev_priv->opregion.asle || !IS_MOBILE(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300686 return;
687
Daniel Vetter13321782014-09-15 14:55:29 +0200688 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000689
Imre Deak755e9012014-02-10 18:42:47 +0200690 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100691 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200692 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200693 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000694
Daniel Vetter13321782014-09-15 14:55:29 +0200695 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000696}
697
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300698/*
699 * This timing diagram depicts the video signal in and
700 * around the vertical blanking period.
701 *
702 * Assumptions about the fictitious mode used in this example:
703 * vblank_start >= 3
704 * vsync_start = vblank_start + 1
705 * vsync_end = vblank_start + 2
706 * vtotal = vblank_start + 3
707 *
708 * start of vblank:
709 * latch double buffered registers
710 * increment frame counter (ctg+)
711 * generate start of vblank interrupt (gen4+)
712 * |
713 * | frame start:
714 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
715 * | may be shifted forward 1-3 extra lines via PIPECONF
716 * | |
717 * | | start of vsync:
718 * | | generate vsync interrupt
719 * | | |
720 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
721 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
722 * ----va---> <-----------------vb--------------------> <--------va-------------
723 * | | <----vs-----> |
724 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
725 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
726 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
727 * | | |
728 * last visible pixel first visible pixel
729 * | increment frame counter (gen3/4)
730 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
731 *
732 * x = horizontal active
733 * _ = horizontal blanking
734 * hs = horizontal sync
735 * va = vertical active
736 * vb = vertical blanking
737 * vs = vertical sync
738 * vbs = vblank_start (number)
739 *
740 * Summary:
741 * - most events happen at the start of horizontal sync
742 * - frame start happens at the start of horizontal blank, 1-4 lines
743 * (depending on PIPECONF settings) after the start of vblank
744 * - gen3/4 pixel and frame counter are synchronized with the start
745 * of horizontal active on the first line of vertical active
746 */
747
Keith Packard42f52ef2008-10-18 19:39:29 -0700748/* Called from drm generic code, passed a 'crtc', which
749 * we use as a pipe index
750 */
Thierry Reding88e72712015-09-24 18:35:31 +0200751static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700752{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100753 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200754 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300755 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200756 const struct drm_display_mode *mode = &dev->vblank[pipe].hwmode;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200757 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700758
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100759 htotal = mode->crtc_htotal;
760 hsync_start = mode->crtc_hsync_start;
761 vbl_start = mode->crtc_vblank_start;
762 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
763 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300764
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300765 /* Convert to pixel count */
766 vbl_start *= htotal;
767
768 /* Start of vblank event occurs at start of hsync */
769 vbl_start -= htotal - hsync_start;
770
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800771 high_frame = PIPEFRAME(pipe);
772 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100773
Ville Syrjälä694e4092017-03-09 17:44:30 +0200774 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
775
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700776 /*
777 * High & low register fields aren't synchronized, so make sure
778 * we get a low value that's stable across two reads of the high
779 * register.
780 */
781 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200782 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
783 low = I915_READ_FW(low_frame);
784 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700785 } while (high1 != high2);
786
Ville Syrjälä694e4092017-03-09 17:44:30 +0200787 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
788
Chris Wilson5eddb702010-09-11 13:48:45 +0100789 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300790 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100791 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300792
793 /*
794 * The frame counter increments at beginning of active.
795 * Cook up a vblank counter by also checking the pixel
796 * counter against vblank start.
797 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200798 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700799}
800
Dave Airlie974e59b2015-10-30 09:45:33 +1000801static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800802{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100803 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800804
Ville Syrjälä649636e2015-09-22 19:50:01 +0300805 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800806}
807
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300808/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300809static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
810{
811 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +0100812 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200813 const struct drm_display_mode *mode;
814 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300815 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300816 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300817
Ville Syrjälä72259532017-03-02 19:15:05 +0200818 if (!crtc->active)
819 return -1;
820
Daniel Vetter5caa0fe2017-05-09 16:03:29 +0200821 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
822 mode = &vblank->hwmode;
823
Ville Syrjälä80715b22014-05-15 20:23:23 +0300824 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300825 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
826 vtotal /= 2;
827
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100828 if (IS_GEN2(dev_priv))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300829 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300830 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300831 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300832
833 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700834 * On HSW, the DSL reg (0x70000) appears to return 0 if we
835 * read it just before the start of vblank. So try it again
836 * so we don't accidentally end up spanning a vblank frame
837 * increment, causing the pipe_update_end() code to squak at us.
838 *
839 * The nature of this problem means we can't simply check the ISR
840 * bit and return the vblank start value; nor can we use the scanline
841 * debug register in the transcoder as it appears to have the same
842 * problem. We may need to extend this to include other platforms,
843 * but so far testing only shows the problem on HSW.
844 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100845 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -0700846 int i, temp;
847
848 for (i = 0; i < 100; i++) {
849 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +0200850 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -0700851 if (temp != position) {
852 position = temp;
853 break;
854 }
855 }
856 }
857
858 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300859 * See update_scanline_offset() for the details on the
860 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300861 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300862 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300863}
864
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200865static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
866 bool in_vblank_irq, int *vpos, int *hpos,
867 ktime_t *stime, ktime_t *etime,
868 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100869{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100870 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +0200871 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
872 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300873 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300874 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100875 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100876
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200877 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100878 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800879 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200880 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100881 }
882
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300883 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300884 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300885 vtotal = mode->crtc_vtotal;
886 vbl_start = mode->crtc_vblank_start;
887 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100888
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200889 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
890 vbl_start = DIV_ROUND_UP(vbl_start, 2);
891 vbl_end /= 2;
892 vtotal /= 2;
893 }
894
Mario Kleinerad3543e2013-10-30 05:13:08 +0100895 /*
896 * Lock uncore.lock, as we will do multiple timing critical raw
897 * register reads, potentially with preemption disabled, so the
898 * following code must not block on uncore.lock.
899 */
900 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300901
Mario Kleinerad3543e2013-10-30 05:13:08 +0100902 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
903
904 /* Get optional system timestamp before query. */
905 if (stime)
906 *stime = ktime_get();
907
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100908 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100909 /* No obvious pixelcount register. Only query vertical
910 * scanout position from Display scan line register.
911 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300912 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100913 } else {
914 /* Have access to pixelcount since start of frame.
915 * We can split this into vertical and horizontal
916 * scanout position.
917 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +0300918 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100919
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300920 /* convert to pixel counts */
921 vbl_start *= htotal;
922 vbl_end *= htotal;
923 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300924
925 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300926 * In interlaced modes, the pixel counter counts all pixels,
927 * so one field will have htotal more pixels. In order to avoid
928 * the reported position from jumping backwards when the pixel
929 * counter is beyond the length of the shorter field, just
930 * clamp the position the length of the shorter field. This
931 * matches how the scanline counter based position works since
932 * the scanline counter doesn't count the two half lines.
933 */
934 if (position >= vtotal)
935 position = vtotal - 1;
936
937 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300938 * Start of vblank interrupt is triggered at start of hsync,
939 * just prior to the first active line of vblank. However we
940 * consider lines to start at the leading edge of horizontal
941 * active. So, should we get here before we've crossed into
942 * the horizontal active of the first line in vblank, we would
943 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
944 * always add htotal-hsync_start to the current pixel position.
945 */
946 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300947 }
948
Mario Kleinerad3543e2013-10-30 05:13:08 +0100949 /* Get optional system timestamp after query. */
950 if (etime)
951 *etime = ktime_get();
952
953 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
954
955 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
956
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300957 /*
958 * While in vblank, position will be negative
959 * counting up towards 0 at vbl_end. And outside
960 * vblank, position will be positive counting
961 * up since vbl_end.
962 */
963 if (position >= vbl_start)
964 position -= vbl_end;
965 else
966 position += vtotal - vbl_end;
967
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100968 if (IS_GEN2(dev_priv) || IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300969 *vpos = position;
970 *hpos = 0;
971 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100972 *vpos = position / htotal;
973 *hpos = position - (*vpos * htotal);
974 }
975
Daniel Vetter1bf6ad62017-05-09 16:03:28 +0200976 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100977}
978
Ville Syrjäläa225f072014-04-29 13:35:45 +0300979int intel_get_crtc_scanline(struct intel_crtc *crtc)
980{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100981 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +0300982 unsigned long irqflags;
983 int position;
984
985 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
986 position = __intel_get_crtc_scanline(crtc);
987 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
988
989 return position;
990}
991
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100992static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800993{
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000994 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200995 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200996
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200997 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800998
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200999 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1000
Daniel Vetter20e4d402012-08-08 23:35:39 +02001001 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001002
Jesse Barnes7648fa92010-05-20 14:28:11 -07001003 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001004 busy_up = I915_READ(RCPREVBSYTUPAVG);
1005 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001006 max_avg = I915_READ(RCBMAXAVG);
1007 min_avg = I915_READ(RCBMINAVG);
1008
1009 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001010 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001011 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1012 new_delay = dev_priv->ips.cur_delay - 1;
1013 if (new_delay < dev_priv->ips.max_delay)
1014 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001015 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001016 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1017 new_delay = dev_priv->ips.cur_delay + 1;
1018 if (new_delay > dev_priv->ips.min_delay)
1019 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001020 }
1021
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001022 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001023 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001024
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001025 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001026
Jesse Barnesf97108d2010-01-29 11:27:07 -08001027 return;
1028}
1029
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001030static void notify_ring(struct intel_engine_cs *engine)
Chris Wilson549f7362010-10-19 11:19:32 +01001031{
Chris Wilson56299fb2017-02-27 20:58:48 +00001032 struct drm_i915_gem_request *rq = NULL;
1033 struct intel_wait *wait;
Tvrtko Ursulindffabc82017-02-21 09:13:48 +00001034
Chris Wilson2246bea2017-02-17 15:13:00 +00001035 atomic_inc(&engine->irq_count);
Chris Wilson538b2572017-01-24 15:18:05 +00001036 set_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted);
Chris Wilson56299fb2017-02-27 20:58:48 +00001037
Chris Wilson61d3dc72017-03-03 19:08:24 +00001038 spin_lock(&engine->breadcrumbs.irq_lock);
1039 wait = engine->breadcrumbs.irq_wait;
Chris Wilson56299fb2017-02-27 20:58:48 +00001040 if (wait) {
Chris Wilson17b51ad2017-09-18 17:27:33 +01001041 bool wakeup = engine->irq_seqno_barrier;
1042
Chris Wilson56299fb2017-02-27 20:58:48 +00001043 /* We use a callback from the dma-fence to submit
1044 * requests after waiting on our own requests. To
1045 * ensure minimum delay in queuing the next request to
1046 * hardware, signal the fence now rather than wait for
1047 * the signaler to be woken up. We still wake up the
1048 * waiter in order to handle the irq-seqno coherency
1049 * issues (we may receive the interrupt before the
1050 * seqno is written, see __i915_request_irq_complete())
1051 * and to handle coalescing of multiple seqno updates
1052 * and many waiters.
1053 */
1054 if (i915_seqno_passed(intel_engine_get_seqno(engine),
Chris Wilson17b51ad2017-09-18 17:27:33 +01001055 wait->seqno)) {
Chris Wilsonde4d2102017-09-18 17:27:34 +01001056 struct drm_i915_gem_request *waiter = wait->request;
1057
Chris Wilson17b51ad2017-09-18 17:27:33 +01001058 wakeup = true;
1059 if (!test_bit(DMA_FENCE_FLAG_SIGNALED_BIT,
Chris Wilsonde4d2102017-09-18 17:27:34 +01001060 &waiter->fence.flags) &&
1061 intel_wait_check_request(wait, waiter))
1062 rq = i915_gem_request_get(waiter);
Chris Wilson17b51ad2017-09-18 17:27:33 +01001063 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001064
Chris Wilson17b51ad2017-09-18 17:27:33 +01001065 if (wakeup)
1066 wake_up_process(wait->tsk);
Chris Wilson67b807a82017-02-27 20:58:50 +00001067 } else {
1068 __intel_engine_disarm_breadcrumbs(engine);
Chris Wilson56299fb2017-02-27 20:58:48 +00001069 }
Chris Wilson61d3dc72017-03-03 19:08:24 +00001070 spin_unlock(&engine->breadcrumbs.irq_lock);
Chris Wilson56299fb2017-02-27 20:58:48 +00001071
Chris Wilson24754d72017-03-03 14:45:57 +00001072 if (rq) {
Chris Wilson56299fb2017-02-27 20:58:48 +00001073 dma_fence_signal(&rq->fence);
Chris Wilson24754d72017-03-03 14:45:57 +00001074 i915_gem_request_put(rq);
1075 }
Chris Wilson56299fb2017-02-27 20:58:48 +00001076
1077 trace_intel_engine_notify(engine, wait);
Chris Wilson549f7362010-10-19 11:19:32 +01001078}
1079
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001080static void vlv_c0_read(struct drm_i915_private *dev_priv,
1081 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001082{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001083 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001084 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1085 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001086}
1087
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001088void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1089{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001090 memset(&dev_priv->rps.ei, 0, sizeof(dev_priv->rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001091}
1092
1093static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1094{
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001095 const struct intel_rps_ei *prev = &dev_priv->rps.ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001096 struct intel_rps_ei now;
1097 u32 events = 0;
1098
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001099 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001100 return 0;
1101
1102 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001103
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001104 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001105 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001106 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001107
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001108 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001109
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001110 time *= dev_priv->czclk_freq;
1111
1112 /* Workload can be split between render + media,
1113 * e.g. SwapBuffers being blitted in X after being rendered in
1114 * mesa. To account for this we need to combine both engines
1115 * into our activity counter.
1116 */
Chris Wilson569884e2017-03-09 21:12:31 +00001117 render = now.render_c0 - prev->render_c0;
1118 media = now.media_c0 - prev->media_c0;
1119 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001120 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001121
1122 if (c0 > time * dev_priv->rps.up_threshold)
1123 events = GEN6_PM_RP_UP_THRESHOLD;
1124 else if (c0 < time * dev_priv->rps.down_threshold)
1125 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001126 }
1127
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001128 dev_priv->rps.ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001129 return events;
Deepak S31685c22014-07-03 17:33:01 -04001130}
1131
Ben Widawsky4912d042011-04-25 11:25:20 -07001132static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001133{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001134 struct drm_i915_private *dev_priv =
1135 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001136 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001137 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001138 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001139
Daniel Vetter59cdb632013-07-04 23:35:28 +02001140 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001141 if (dev_priv->rps.interrupts_enabled) {
1142 pm_iir = fetch_and_zero(&dev_priv->rps.pm_iir);
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001143 client_boost = atomic_read(&dev_priv->rps.num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001144 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001145 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001146
Paulo Zanoni60611c12013-08-15 11:50:01 -03001147 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301148 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001149 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001150 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001151
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001152 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001153
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001154 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1155
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001156 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001157 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001158 min = dev_priv->rps.min_freq_softlimit;
1159 max = dev_priv->rps.max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001160 if (client_boost)
Chris Wilson29ecd78d2016-07-13 09:10:35 +01001161 max = dev_priv->rps.max_freq;
1162 if (client_boost && new_delay < dev_priv->rps.boost_freq) {
1163 new_delay = dev_priv->rps.boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001164 adj = 0;
1165 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001166 if (adj > 0)
1167 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001168 else /* CHV needs even encode values */
1169 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301170
1171 if (new_delay >= dev_priv->rps.max_freq_softlimit)
1172 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001173 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001174 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001175 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001176 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1177 new_delay = dev_priv->rps.efficient_freq;
Chris Wilson17136d52017-02-10 15:03:47 +00001178 else if (dev_priv->rps.cur_freq > dev_priv->rps.min_freq_softlimit)
Ben Widawskyb39fb292014-03-19 18:31:11 -07001179 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001180 adj = 0;
1181 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1182 if (adj < 0)
1183 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001184 else /* CHV needs even encode values */
1185 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301186
1187 if (new_delay <= dev_priv->rps.min_freq_softlimit)
1188 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001189 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001190 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001191 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001192
Chris Wilsonedcf2842015-04-07 16:20:29 +01001193 dev_priv->rps.last_adj = adj;
1194
Ben Widawsky79249632012-09-07 19:43:42 -07001195 /* sysfs frequency interfaces may have snuck in while servicing the
1196 * interrupt
1197 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001198 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001199 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301200
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001201 if (intel_set_rps(dev_priv, new_delay)) {
1202 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
1203 dev_priv->rps.last_adj = 0;
1204 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001205
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001206 mutex_unlock(&dev_priv->rps.hw_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001207
1208out:
1209 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1210 spin_lock_irq(&dev_priv->irq_lock);
1211 if (dev_priv->rps.interrupts_enabled)
1212 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1213 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001214}
1215
Ben Widawskye3689192012-05-25 16:56:22 -07001216
1217/**
1218 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1219 * occurred.
1220 * @work: workqueue struct
1221 *
1222 * Doesn't actually do anything except notify userspace. As a consequence of
1223 * this event, userspace should try to remap the bad rows since statistically
1224 * it is likely the same row is more likely to go bad again.
1225 */
1226static void ivybridge_parity_work(struct work_struct *work)
1227{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001228 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001229 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001230 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001231 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001232 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001233 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001234
1235 /* We must turn off DOP level clock gating to access the L3 registers.
1236 * In order to prevent a get/put style interface, acquire struct mutex
1237 * any time we access those registers.
1238 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001239 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001240
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001241 /* If we've screwed up tracking, just let the interrupt fire again */
1242 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1243 goto out;
1244
Ben Widawskye3689192012-05-25 16:56:22 -07001245 misccpctl = I915_READ(GEN7_MISCCPCTL);
1246 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1247 POSTING_READ(GEN7_MISCCPCTL);
1248
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001249 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001250 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001251
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001252 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001253 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001254 break;
1255
1256 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1257
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001258 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001259
1260 error_status = I915_READ(reg);
1261 row = GEN7_PARITY_ERROR_ROW(error_status);
1262 bank = GEN7_PARITY_ERROR_BANK(error_status);
1263 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1264
1265 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1266 POSTING_READ(reg);
1267
1268 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1269 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1270 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1271 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1272 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1273 parity_event[5] = NULL;
1274
Chris Wilson91c8a322016-07-05 10:40:23 +01001275 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001276 KOBJ_CHANGE, parity_event);
1277
1278 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1279 slice, row, bank, subbank);
1280
1281 kfree(parity_event[4]);
1282 kfree(parity_event[3]);
1283 kfree(parity_event[2]);
1284 kfree(parity_event[1]);
1285 }
Ben Widawskye3689192012-05-25 16:56:22 -07001286
1287 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1288
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001289out:
1290 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001291 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001292 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001293 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001294
Chris Wilson91c8a322016-07-05 10:40:23 +01001295 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001296}
1297
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001298static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1299 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001300{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001301 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001302 return;
1303
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001304 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001305 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001306 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001307
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001308 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001309 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1310 dev_priv->l3_parity.which_slice |= 1 << 1;
1311
1312 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1313 dev_priv->l3_parity.which_slice |= 1 << 0;
1314
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001315 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001316}
1317
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001318static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001319 u32 gt_iir)
1320{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001321 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301322 notify_ring(dev_priv->engine[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001323 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301324 notify_ring(dev_priv->engine[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001325}
1326
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001327static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001328 u32 gt_iir)
1329{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001330 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301331 notify_ring(dev_priv->engine[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001332 if (gt_iir & GT_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301333 notify_ring(dev_priv->engine[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001334 if (gt_iir & GT_BLT_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301335 notify_ring(dev_priv->engine[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001336
Ben Widawskycc609d52013-05-28 19:22:29 -07001337 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1338 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001339 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1340 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001341
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001342 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1343 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001344}
1345
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001346static void
Tvrtko Ursulin0bc40be2016-03-16 11:00:37 +00001347gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001348{
Chris Wilson31de7352017-03-16 12:56:18 +00001349 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001350
1351 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift)) {
Chris Wilsona4b2b012017-05-17 13:10:01 +01001352 if (port_count(&engine->execlist_port[0])) {
Chris Wilson955a4b82017-05-17 13:10:07 +01001353 __set_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted);
Chris Wilsona4b2b012017-05-17 13:10:01 +01001354 tasklet = true;
1355 }
Chris Wilsonf7470262017-01-24 15:20:21 +00001356 }
Chris Wilson31de7352017-03-16 12:56:18 +00001357
1358 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift)) {
1359 notify_ring(engine);
1360 tasklet |= i915.enable_guc_submission;
1361 }
1362
1363 if (tasklet)
1364 tasklet_hi_schedule(&engine->irq_tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001365}
1366
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001367static irqreturn_t gen8_gt_irq_ack(struct drm_i915_private *dev_priv,
1368 u32 master_ctl,
1369 u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001370{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001371 irqreturn_t ret = IRQ_NONE;
1372
1373 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001374 gt_iir[0] = I915_READ_FW(GEN8_GT_IIR(0));
1375 if (gt_iir[0]) {
1376 I915_WRITE_FW(GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001377 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001378 } else
1379 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1380 }
1381
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001382 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001383 gt_iir[1] = I915_READ_FW(GEN8_GT_IIR(1));
1384 if (gt_iir[1]) {
1385 I915_WRITE_FW(GEN8_GT_IIR(1), gt_iir[1]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001386 ret = IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07001387 } else
1388 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1389 }
1390
Chris Wilson74cdb332015-04-07 16:21:05 +01001391 if (master_ctl & GEN8_GT_VECS_IRQ) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001392 gt_iir[3] = I915_READ_FW(GEN8_GT_IIR(3));
1393 if (gt_iir[3]) {
1394 I915_WRITE_FW(GEN8_GT_IIR(3), gt_iir[3]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001395 ret = IRQ_HANDLED;
Chris Wilson74cdb332015-04-07 16:21:05 +01001396 } else
1397 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1398 }
1399
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301400 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001401 gt_iir[2] = I915_READ_FW(GEN8_GT_IIR(2));
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301402 if (gt_iir[2] & (dev_priv->pm_rps_events |
1403 dev_priv->pm_guc_events)) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001404 I915_WRITE_FW(GEN8_GT_IIR(2),
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301405 gt_iir[2] & (dev_priv->pm_rps_events |
1406 dev_priv->pm_guc_events));
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001407 ret = IRQ_HANDLED;
Ben Widawsky09610212014-05-15 20:58:08 +03001408 } else
1409 DRM_ERROR("The master control interrupt lied (PM)!\n");
1410 }
1411
Ben Widawskyabd58f02013-11-02 21:07:09 -07001412 return ret;
1413}
1414
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001415static void gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
1416 u32 gt_iir[4])
1417{
1418 if (gt_iir[0]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301419 gen8_cs_irq_handler(dev_priv->engine[RCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001420 gt_iir[0], GEN8_RCS_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301421 gen8_cs_irq_handler(dev_priv->engine[BCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001422 gt_iir[0], GEN8_BCS_IRQ_SHIFT);
1423 }
1424
1425 if (gt_iir[1]) {
Akash Goel3b3f1652016-10-13 22:44:48 +05301426 gen8_cs_irq_handler(dev_priv->engine[VCS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001427 gt_iir[1], GEN8_VCS1_IRQ_SHIFT);
Akash Goel3b3f1652016-10-13 22:44:48 +05301428 gen8_cs_irq_handler(dev_priv->engine[VCS2],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001429 gt_iir[1], GEN8_VCS2_IRQ_SHIFT);
1430 }
1431
1432 if (gt_iir[3])
Akash Goel3b3f1652016-10-13 22:44:48 +05301433 gen8_cs_irq_handler(dev_priv->engine[VECS],
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001434 gt_iir[3], GEN8_VECS_IRQ_SHIFT);
1435
1436 if (gt_iir[2] & dev_priv->pm_rps_events)
1437 gen6_rps_irq_handler(dev_priv, gt_iir[2]);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301438
1439 if (gt_iir[2] & dev_priv->pm_guc_events)
1440 gen9_guc_irq_handler(dev_priv, gt_iir[2]);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001441}
1442
Imre Deak63c88d22015-07-20 14:43:39 -07001443static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1444{
1445 switch (port) {
1446 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001447 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001448 case PORT_B:
1449 return val & PORTB_HOTPLUG_LONG_DETECT;
1450 case PORT_C:
1451 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001452 default:
1453 return false;
1454 }
1455}
1456
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001457static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1458{
1459 switch (port) {
1460 case PORT_E:
1461 return val & PORTE_HOTPLUG_LONG_DETECT;
1462 default:
1463 return false;
1464 }
1465}
1466
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001467static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1468{
1469 switch (port) {
1470 case PORT_A:
1471 return val & PORTA_HOTPLUG_LONG_DETECT;
1472 case PORT_B:
1473 return val & PORTB_HOTPLUG_LONG_DETECT;
1474 case PORT_C:
1475 return val & PORTC_HOTPLUG_LONG_DETECT;
1476 case PORT_D:
1477 return val & PORTD_HOTPLUG_LONG_DETECT;
1478 default:
1479 return false;
1480 }
1481}
1482
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001483static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1484{
1485 switch (port) {
1486 case PORT_A:
1487 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1488 default:
1489 return false;
1490 }
1491}
1492
Jani Nikula676574d2015-05-28 15:43:53 +03001493static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001494{
1495 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001496 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001497 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001498 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001499 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001500 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001501 return val & PORTD_HOTPLUG_LONG_DETECT;
1502 default:
1503 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001504 }
1505}
1506
Jani Nikula676574d2015-05-28 15:43:53 +03001507static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001508{
1509 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001510 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001511 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001512 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001513 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001514 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001515 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1516 default:
1517 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001518 }
1519}
1520
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001521/*
1522 * Get a bit mask of pins that have triggered, and which ones may be long.
1523 * This can be called multiple times with the same masks to accumulate
1524 * hotplug detection results from several registers.
1525 *
1526 * Note that the caller is expected to zero out the masks initially.
1527 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001528static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001529 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001530 const u32 hpd[HPD_NUM_PINS],
1531 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001532{
Jani Nikula8c841e52015-06-18 13:06:17 +03001533 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001534 int i;
1535
Jani Nikula676574d2015-05-28 15:43:53 +03001536 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001537 if ((hpd[i] & hotplug_trigger) == 0)
1538 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001539
Jani Nikula8c841e52015-06-18 13:06:17 +03001540 *pin_mask |= BIT(i);
1541
Rodrigo Vivi256cfdd2017-08-11 11:26:49 -07001542 port = intel_hpd_pin_to_port(i);
1543 if (port == PORT_NONE)
Imre Deakcc24fcd2015-07-21 15:32:45 -07001544 continue;
1545
Imre Deakfd63e2a2015-07-21 15:32:44 -07001546 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001547 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001548 }
1549
1550 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1551 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1552
1553}
1554
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001555static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001556{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001557 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001558}
1559
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001560static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001561{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001562 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001563}
1564
Shuang He8bf1e9f2013-10-15 18:55:27 +01001565#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001566static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1567 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001568 uint32_t crc0, uint32_t crc1,
1569 uint32_t crc2, uint32_t crc3,
1570 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001571{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001572 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1573 struct intel_pipe_crc_entry *entry;
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001574 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
1575 struct drm_driver *driver = dev_priv->drm.driver;
1576 uint32_t crcs[5];
Damien Lespiauac2300d2013-10-15 18:55:30 +01001577 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001578
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001579 spin_lock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001580 if (pipe_crc->source) {
1581 if (!pipe_crc->entries) {
1582 spin_unlock(&pipe_crc->lock);
1583 DRM_DEBUG_KMS("spurious interrupt\n");
1584 return;
1585 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001586
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001587 head = pipe_crc->head;
1588 tail = pipe_crc->tail;
1589
1590 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
1591 spin_unlock(&pipe_crc->lock);
1592 DRM_ERROR("CRC buffer overflowing\n");
1593 return;
1594 }
1595
1596 entry = &pipe_crc->entries[head];
1597
1598 entry->frame = driver->get_vblank_counter(&dev_priv->drm, pipe);
1599 entry->crc[0] = crc0;
1600 entry->crc[1] = crc1;
1601 entry->crc[2] = crc2;
1602 entry->crc[3] = crc3;
1603 entry->crc[4] = crc4;
1604
1605 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
1606 pipe_crc->head = head;
1607
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001608 spin_unlock(&pipe_crc->lock);
Damien Lespiau0c912c72013-10-15 18:55:37 +01001609
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001610 wake_up_interruptible(&pipe_crc->wq);
1611 } else {
1612 /*
1613 * For some not yet identified reason, the first CRC is
1614 * bonkers. So let's just wait for the next vblank and read
1615 * out the buggy result.
1616 *
1617 * On CHV sometimes the second CRC is bonkers as well, so
1618 * don't trust that one either.
1619 */
1620 if (pipe_crc->skipped == 0 ||
1621 (IS_CHERRYVIEW(dev_priv) && pipe_crc->skipped == 1)) {
1622 pipe_crc->skipped++;
1623 spin_unlock(&pipe_crc->lock);
1624 return;
1625 }
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001626 spin_unlock(&pipe_crc->lock);
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001627 crcs[0] = crc0;
1628 crcs[1] = crc1;
1629 crcs[2] = crc2;
1630 crcs[3] = crc3;
1631 crcs[4] = crc4;
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001632 drm_crtc_add_crc_entry(&crtc->base, true,
Daniel Vetterca814b22017-05-24 16:51:47 +02001633 drm_crtc_accurate_vblank_count(&crtc->base),
Tomeu Vizoso246ee522017-01-10 14:43:05 +01001634 crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001635 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001636}
Daniel Vetter277de952013-10-18 16:37:07 +02001637#else
1638static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001639display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1640 enum pipe pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001641 uint32_t crc0, uint32_t crc1,
1642 uint32_t crc2, uint32_t crc3,
1643 uint32_t crc4) {}
1644#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001645
Daniel Vetter277de952013-10-18 16:37:07 +02001646
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001647static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1648 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001649{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001650 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001651 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1652 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001653}
1654
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001655static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1656 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001657{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001658 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001659 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1660 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1661 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1662 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1663 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001664}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001665
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001666static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1667 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001668{
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001669 uint32_t res1, res2;
1670
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001671 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001672 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1673 else
1674 res1 = 0;
1675
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001676 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001677 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1678 else
1679 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001680
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001681 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001682 I915_READ(PIPE_CRC_RES_RED(pipe)),
1683 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1684 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1685 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001686}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001687
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001688/* The RPS events need forcewake, so we add them to a work queue and mask their
1689 * IMR bits until the work is done. Other interrupts can be processed without
1690 * the work queue. */
1691static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001692{
Deepak Sa6706b42014-03-15 20:23:22 +05301693 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001694 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301695 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001696 if (dev_priv->rps.interrupts_enabled) {
1697 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
Chris Wilsonc33d2472016-07-04 08:08:36 +01001698 schedule_work(&dev_priv->rps.work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001699 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001700 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001701 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001702
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001703 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001704 return;
1705
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001706 if (HAS_VEBOX(dev_priv)) {
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001707 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05301708 notify_ring(dev_priv->engine[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001709
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001710 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1711 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001712 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001713}
1714
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301715static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1716{
1717 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT) {
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301718 /* Sample the log buffer flush related bits & clear them out now
1719 * itself from the message identity register to minimize the
1720 * probability of losing a flush interrupt, when there are back
1721 * to back flush interrupts.
1722 * There can be a new flush interrupt, for different log buffer
1723 * type (like for ISR), whilst Host is handling one (for DPC).
1724 * Since same bit is used in message register for ISR & DPC, it
1725 * could happen that GuC sets the bit for 2nd interrupt but Host
1726 * clears out the bit on handling the 1st interrupt.
1727 */
1728 u32 msg, flush;
1729
1730 msg = I915_READ(SOFT_SCRATCH(15));
Arkadiusz Hilera80bc452016-11-25 18:59:34 +01001731 flush = msg & (INTEL_GUC_RECV_MSG_CRASH_DUMP_POSTED |
1732 INTEL_GUC_RECV_MSG_FLUSH_LOG_BUFFER);
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301733 if (flush) {
1734 /* Clear the message bits that are handled */
1735 I915_WRITE(SOFT_SCRATCH(15), msg & ~flush);
1736
1737 /* Handle flush interrupt in bottom half */
Oscar Mateoe7465472017-03-22 10:39:48 -07001738 queue_work(dev_priv->guc.log.runtime.flush_wq,
1739 &dev_priv->guc.log.runtime.flush_work);
Akash Goel5aa1ee42016-10-12 21:54:36 +05301740
1741 dev_priv->guc.log.flush_interrupt_count++;
Sagar Arun Kamble4100b2a2016-10-12 21:54:32 +05301742 } else {
1743 /* Not clearing of unhandled event bits won't result in
1744 * re-triggering of the interrupt.
1745 */
1746 }
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301747 }
1748}
1749
Ville Syrjälä44d92412017-08-18 21:36:51 +03001750static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1751{
1752 enum pipe pipe;
1753
1754 for_each_pipe(dev_priv, pipe) {
1755 I915_WRITE(PIPESTAT(pipe),
1756 PIPESTAT_INT_STATUS_MASK |
1757 PIPE_FIFO_UNDERRUN_STATUS);
1758
1759 dev_priv->pipestat_irq_mask[pipe] = 0;
1760 }
1761}
1762
Ville Syrjäläeb643432017-08-18 21:36:59 +03001763static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1764 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001765{
Imre Deakc1874ed2014-02-04 21:35:46 +02001766 int pipe;
1767
Imre Deak58ead0d2014-02-04 21:35:47 +02001768 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001769
1770 if (!dev_priv->display_irqs_enabled) {
1771 spin_unlock(&dev_priv->irq_lock);
1772 return;
1773 }
1774
Damien Lespiau055e3932014-08-18 13:49:10 +01001775 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001776 i915_reg_t reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001777 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001778
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001779 /*
1780 * PIPESTAT bits get signalled even when the interrupt is
1781 * disabled with the mask bits, and some of the status bits do
1782 * not generate interrupts at all (like the underrun bit). Hence
1783 * we need to be careful that we only handle what we want to
1784 * handle.
1785 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001786
1787 /* fifo underruns are filterered in the underrun handler. */
1788 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001789
1790 switch (pipe) {
1791 case PIPE_A:
1792 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1793 break;
1794 case PIPE_B:
1795 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1796 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001797 case PIPE_C:
1798 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1799 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001800 }
1801 if (iir & iir_bit)
1802 mask |= dev_priv->pipestat_irq_mask[pipe];
1803
1804 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001805 continue;
1806
1807 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001808 mask |= PIPESTAT_INT_ENABLE_MASK;
1809 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001810
1811 /*
1812 * Clear the PIPE*STAT regs before the IIR
1813 */
Imre Deak91d181d2014-02-10 18:42:49 +02001814 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1815 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001816 I915_WRITE(reg, pipe_stats[pipe]);
1817 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001818 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001819}
1820
Ville Syrjäläeb643432017-08-18 21:36:59 +03001821static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1822 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1823{
1824 enum pipe pipe;
1825
1826 for_each_pipe(dev_priv, pipe) {
1827 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1828 drm_handle_vblank(&dev_priv->drm, pipe);
1829
1830 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1831 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1832
1833 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1834 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1835 }
1836}
1837
1838static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1839 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1840{
1841 bool blc_event = false;
1842 enum pipe pipe;
1843
1844 for_each_pipe(dev_priv, pipe) {
1845 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1846 drm_handle_vblank(&dev_priv->drm, pipe);
1847
1848 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1849 blc_event = true;
1850
1851 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1852 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1853
1854 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1855 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1856 }
1857
1858 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1859 intel_opregion_asle_intr(dev_priv);
1860}
1861
1862static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1863 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1864{
1865 bool blc_event = false;
1866 enum pipe pipe;
1867
1868 for_each_pipe(dev_priv, pipe) {
1869 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1870 drm_handle_vblank(&dev_priv->drm, pipe);
1871
1872 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1873 blc_event = true;
1874
1875 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1876 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1877
1878 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1879 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1880 }
1881
1882 if (blc_event || (iir & I915_ASLE_INTERRUPT))
1883 intel_opregion_asle_intr(dev_priv);
1884
1885 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1886 gmbus_irq_handler(dev_priv);
1887}
1888
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001889static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001890 u32 pipe_stats[I915_MAX_PIPES])
1891{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001892 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02001893
Damien Lespiau055e3932014-08-18 13:49:10 +01001894 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02001895 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
1896 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001897
1898 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001899 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001900
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001901 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1902 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001903 }
1904
1905 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001906 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02001907}
1908
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001909static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001910{
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001911 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001912
1913 if (hotplug_status)
1914 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1915
1916 return hotplug_status;
1917}
1918
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001919static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001920 u32 hotplug_status)
1921{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001922 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001923
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001924 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
1925 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03001926 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001927
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001928 if (hotplug_trigger) {
1929 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1930 hotplug_trigger, hpd_status_g4x,
1931 i9xx_port_hotplug_long_detect);
1932
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001933 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001934 }
Jani Nikula369712e2015-05-27 15:03:40 +03001935
1936 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001937 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001938 } else {
1939 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001940
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001941 if (hotplug_trigger) {
1942 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001943 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001944 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001945 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001946 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001947 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001948}
1949
Daniel Vetterff1f5252012-10-02 15:10:55 +02001950static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001951{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001952 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001953 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001954 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001955
Imre Deak2dd2a882015-02-24 11:14:30 +02001956 if (!intel_irqs_enabled(dev_priv))
1957 return IRQ_NONE;
1958
Imre Deak1f814da2015-12-16 02:52:19 +02001959 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
1960 disable_rpm_wakeref_asserts(dev_priv);
1961
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001962 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03001963 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001964 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03001965 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001966 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001967
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001968 gt_iir = I915_READ(GTIIR);
1969 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001970 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001971
1972 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03001973 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001974
1975 ret = IRQ_HANDLED;
1976
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001977 /*
1978 * Theory on interrupt generation, based on empirical evidence:
1979 *
1980 * x = ((VLV_IIR & VLV_IER) ||
1981 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
1982 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
1983 *
1984 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
1985 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
1986 * guarantee the CPU interrupt will be raised again even if we
1987 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
1988 * bits this time around.
1989 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001990 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03001991 ier = I915_READ(VLV_IER);
1992 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03001993
1994 if (gt_iir)
1995 I915_WRITE(GTIIR, gt_iir);
1996 if (pm_iir)
1997 I915_WRITE(GEN6_PMIIR, pm_iir);
1998
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03001999 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002000 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002001
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002002 /* Call regardless, as some status bits might not be
2003 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002004 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002005
Jerome Anandeef57322017-01-25 04:27:49 +05302006 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2007 I915_LPE_PIPE_B_INTERRUPT))
2008 intel_lpe_audio_irq_handler(dev_priv);
2009
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002010 /*
2011 * VLV_IIR is single buffered, and reflects the level
2012 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2013 */
2014 if (iir)
2015 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002016
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002017 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002018 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
2019 POSTING_READ(VLV_MASTER_IER);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002020
Ville Syrjälä52894872016-04-13 21:19:56 +03002021 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002022 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002023 if (pm_iir)
2024 gen6_rps_irq_handler(dev_priv, pm_iir);
2025
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002026 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002027 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002028
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002029 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002030 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002031
Imre Deak1f814da2015-12-16 02:52:19 +02002032 enable_rpm_wakeref_asserts(dev_priv);
2033
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002034 return ret;
2035}
2036
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002037static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2038{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002039 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002040 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002041 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002042
Imre Deak2dd2a882015-02-24 11:14:30 +02002043 if (!intel_irqs_enabled(dev_priv))
2044 return IRQ_NONE;
2045
Imre Deak1f814da2015-12-16 02:52:19 +02002046 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2047 disable_rpm_wakeref_asserts(dev_priv);
2048
Chris Wilson579de732016-03-14 09:01:57 +00002049 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002050 u32 master_ctl, iir;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002051 u32 gt_iir[4] = {};
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002052 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002053 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002054 u32 ier = 0;
2055
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002056 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2057 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002058
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002059 if (master_ctl == 0 && iir == 0)
2060 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002061
Oscar Mateo27b6c122014-06-16 16:11:00 +01002062 ret = IRQ_HANDLED;
2063
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002064 /*
2065 * Theory on interrupt generation, based on empirical evidence:
2066 *
2067 * x = ((VLV_IIR & VLV_IER) ||
2068 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2069 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2070 *
2071 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2072 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2073 * guarantee the CPU interrupt will be raised again even if we
2074 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2075 * bits this time around.
2076 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002077 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002078 ier = I915_READ(VLV_IER);
2079 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002080
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002081 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002082
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002083 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002084 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002085
Oscar Mateo27b6c122014-06-16 16:11:00 +01002086 /* Call regardless, as some status bits might not be
2087 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002088 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002089
Jerome Anandeef57322017-01-25 04:27:49 +05302090 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2091 I915_LPE_PIPE_B_INTERRUPT |
2092 I915_LPE_PIPE_C_INTERRUPT))
2093 intel_lpe_audio_irq_handler(dev_priv);
2094
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002095 /*
2096 * VLV_IIR is single buffered, and reflects the level
2097 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2098 */
2099 if (iir)
2100 I915_WRITE(VLV_IIR, iir);
2101
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002102 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002103 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002104 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002105
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002106 gen8_gt_irq_handler(dev_priv, gt_iir);
2107
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002108 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002109 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002110
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002111 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002112 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002113
Imre Deak1f814da2015-12-16 02:52:19 +02002114 enable_rpm_wakeref_asserts(dev_priv);
2115
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002116 return ret;
2117}
2118
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002119static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2120 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002121 const u32 hpd[HPD_NUM_PINS])
2122{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002123 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2124
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002125 /*
2126 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2127 * unless we touch the hotplug register, even if hotplug_trigger is
2128 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2129 * errors.
2130 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002131 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002132 if (!hotplug_trigger) {
2133 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2134 PORTD_HOTPLUG_STATUS_MASK |
2135 PORTC_HOTPLUG_STATUS_MASK |
2136 PORTB_HOTPLUG_STATUS_MASK;
2137 dig_hotplug_reg &= ~mask;
2138 }
2139
Ville Syrjälä40e56412015-08-27 23:56:10 +03002140 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002141 if (!hotplug_trigger)
2142 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002143
2144 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2145 dig_hotplug_reg, hpd,
2146 pch_port_hotplug_long_detect);
2147
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002148 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002149}
2150
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002151static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002152{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002153 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002154 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002155
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002156 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002157
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002158 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2159 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2160 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002161 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002162 port_name(port));
2163 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002164
Daniel Vetterce99c252012-12-01 13:53:47 +01002165 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002166 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002167
Jesse Barnes776ad802011-01-04 15:09:39 -08002168 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002169 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002170
2171 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2172 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2173
2174 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2175 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2176
2177 if (pch_iir & SDE_POISON)
2178 DRM_ERROR("PCH poison interrupt\n");
2179
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002180 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002181 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002182 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2183 pipe_name(pipe),
2184 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002185
2186 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2187 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2188
2189 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2190 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2191
Jesse Barnes776ad802011-01-04 15:09:39 -08002192 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002193 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002194
2195 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002196 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002197}
2198
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002199static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002200{
Paulo Zanoni86642812013-04-12 17:57:57 -03002201 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002202 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002203
Paulo Zanonide032bf2013-04-12 17:57:58 -03002204 if (err_int & ERR_INT_POISON)
2205 DRM_ERROR("Poison interrupt\n");
2206
Damien Lespiau055e3932014-08-18 13:49:10 +01002207 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002208 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2209 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002210
Daniel Vetter5a69b892013-10-16 22:55:52 +02002211 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002212 if (IS_IVYBRIDGE(dev_priv))
2213 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002214 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002215 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002216 }
2217 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002218
Paulo Zanoni86642812013-04-12 17:57:57 -03002219 I915_WRITE(GEN7_ERR_INT, err_int);
2220}
2221
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002222static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002223{
Paulo Zanoni86642812013-04-12 17:57:57 -03002224 u32 serr_int = I915_READ(SERR_INT);
2225
Paulo Zanonide032bf2013-04-12 17:57:58 -03002226 if (serr_int & SERR_INT_POISON)
2227 DRM_ERROR("PCH poison interrupt\n");
2228
Paulo Zanoni86642812013-04-12 17:57:57 -03002229 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002230 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002231
2232 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002233 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002234
2235 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002236 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03002237
2238 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002239}
2240
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002241static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002242{
Adam Jackson23e81d62012-06-06 15:45:44 -04002243 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002244 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002245
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002246 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002247
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002248 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2249 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2250 SDE_AUDIO_POWER_SHIFT_CPT);
2251 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2252 port_name(port));
2253 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002254
2255 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002256 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002257
2258 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002259 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002260
2261 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2262 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2263
2264 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2265 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2266
2267 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002268 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002269 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2270 pipe_name(pipe),
2271 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002272
2273 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002274 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002275}
2276
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002277static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002278{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002279 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2280 ~SDE_PORTE_HOTPLUG_SPT;
2281 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2282 u32 pin_mask = 0, long_mask = 0;
2283
2284 if (hotplug_trigger) {
2285 u32 dig_hotplug_reg;
2286
2287 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2288 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2289
2290 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2291 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002292 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002293 }
2294
2295 if (hotplug2_trigger) {
2296 u32 dig_hotplug_reg;
2297
2298 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2299 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2300
2301 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
2302 dig_hotplug_reg, hpd_spt,
2303 spt_port_hotplug2_long_detect);
2304 }
2305
2306 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002307 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002308
2309 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002310 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002311}
2312
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002313static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2314 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002315 const u32 hpd[HPD_NUM_PINS])
2316{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002317 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2318
2319 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2320 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2321
2322 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2323 dig_hotplug_reg, hpd,
2324 ilk_port_hotplug_long_detect);
2325
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002326 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002327}
2328
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002329static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2330 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002331{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002332 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002333 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2334
Ville Syrjälä40e56412015-08-27 23:56:10 +03002335 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002336 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002337
2338 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002339 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002340
2341 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002342 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002343
Paulo Zanonic008bc62013-07-12 16:35:10 -03002344 if (de_iir & DE_POISON)
2345 DRM_ERROR("Poison interrupt\n");
2346
Damien Lespiau055e3932014-08-18 13:49:10 +01002347 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002348 if (de_iir & DE_PIPE_VBLANK(pipe))
2349 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002350
Daniel Vetter40da17c22013-10-21 18:04:36 +02002351 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002352 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002353
Daniel Vetter40da17c22013-10-21 18:04:36 +02002354 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002355 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002356 }
2357
2358 /* check event from PCH */
2359 if (de_iir & DE_PCH_EVENT) {
2360 u32 pch_iir = I915_READ(SDEIIR);
2361
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002362 if (HAS_PCH_CPT(dev_priv))
2363 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002364 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002365 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002366
2367 /* should clear PCH hotplug event before clear CPU irq */
2368 I915_WRITE(SDEIIR, pch_iir);
2369 }
2370
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002371 if (IS_GEN5(dev_priv) && de_iir & DE_PCU_EVENT)
2372 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002373}
2374
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002375static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2376 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002377{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002378 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002379 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2380
Ville Syrjälä40e56412015-08-27 23:56:10 +03002381 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002382 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002383
2384 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002385 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002386
2387 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002388 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002389
2390 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002391 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002392
Damien Lespiau055e3932014-08-18 13:49:10 +01002393 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002394 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2395 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002396 }
2397
2398 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002399 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002400 u32 pch_iir = I915_READ(SDEIIR);
2401
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002402 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002403
2404 /* clear PCH hotplug event before clear CPU irq */
2405 I915_WRITE(SDEIIR, pch_iir);
2406 }
2407}
2408
Oscar Mateo72c90f62014-06-16 16:10:57 +01002409/*
2410 * To handle irqs with the minimum potential races with fresh interrupts, we:
2411 * 1 - Disable Master Interrupt Control.
2412 * 2 - Find the source(s) of the interrupt.
2413 * 3 - Clear the Interrupt Identity bits (IIR).
2414 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2415 * 5 - Re-enable Master Interrupt Control.
2416 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002417static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002418{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002419 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002420 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002421 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002422 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002423
Imre Deak2dd2a882015-02-24 11:14:30 +02002424 if (!intel_irqs_enabled(dev_priv))
2425 return IRQ_NONE;
2426
Imre Deak1f814da2015-12-16 02:52:19 +02002427 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2428 disable_rpm_wakeref_asserts(dev_priv);
2429
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002430 /* disable master interrupt before clearing iir */
2431 de_ier = I915_READ(DEIER);
2432 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002433 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002434
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002435 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2436 * interrupts will will be stored on its back queue, and then we'll be
2437 * able to process them after we restore SDEIER (as soon as we restore
2438 * it, we'll get an interrupt if SDEIIR still has something to process
2439 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002440 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002441 sde_ier = I915_READ(SDEIER);
2442 I915_WRITE(SDEIER, 0);
2443 POSTING_READ(SDEIER);
2444 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002445
Oscar Mateo72c90f62014-06-16 16:10:57 +01002446 /* Find, clear, then process each source of interrupt */
2447
Chris Wilson0e434062012-05-09 21:45:44 +01002448 gt_iir = I915_READ(GTIIR);
2449 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002450 I915_WRITE(GTIIR, gt_iir);
2451 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002452 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002453 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002454 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002455 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002456 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002457
2458 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002459 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002460 I915_WRITE(DEIIR, de_iir);
2461 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002462 if (INTEL_GEN(dev_priv) >= 7)
2463 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002464 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002465 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002466 }
2467
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002468 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002469 u32 pm_iir = I915_READ(GEN6_PMIIR);
2470 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002471 I915_WRITE(GEN6_PMIIR, pm_iir);
2472 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002473 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002474 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002475 }
2476
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002477 I915_WRITE(DEIER, de_ier);
2478 POSTING_READ(DEIER);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002479 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002480 I915_WRITE(SDEIER, sde_ier);
2481 POSTING_READ(SDEIER);
2482 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002483
Imre Deak1f814da2015-12-16 02:52:19 +02002484 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2485 enable_rpm_wakeref_asserts(dev_priv);
2486
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002487 return ret;
2488}
2489
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002490static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2491 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002492 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302493{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002494 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302495
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002496 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2497 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302498
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002499 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002500 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002501 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002502
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002503 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302504}
2505
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002506static irqreturn_t
2507gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002508{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002509 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002510 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002511 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002512
Ben Widawskyabd58f02013-11-02 21:07:09 -07002513 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002514 iir = I915_READ(GEN8_DE_MISC_IIR);
2515 if (iir) {
2516 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002517 ret = IRQ_HANDLED;
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002518 if (iir & GEN8_DE_MISC_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002519 intel_opregion_asle_intr(dev_priv);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002520 else
2521 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002522 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002523 else
2524 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002525 }
2526
Daniel Vetter6d766f02013-11-07 14:49:55 +01002527 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002528 iir = I915_READ(GEN8_DE_PORT_IIR);
2529 if (iir) {
2530 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302531 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002532
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002533 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002534 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002535
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002536 tmp_mask = GEN8_AUX_CHANNEL_A;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002537 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002538 tmp_mask |= GEN9_AUX_CHANNEL_B |
2539 GEN9_AUX_CHANNEL_C |
2540 GEN9_AUX_CHANNEL_D;
2541
2542 if (iir & tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002543 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302544 found = true;
2545 }
2546
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002547 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002548 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2549 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002550 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2551 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002552 found = true;
2553 }
2554 } else if (IS_BROADWELL(dev_priv)) {
2555 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2556 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002557 ilk_hpd_irq_handler(dev_priv,
2558 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002559 found = true;
2560 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302561 }
2562
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002563 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002564 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302565 found = true;
2566 }
2567
Shashank Sharmad04a4922014-08-22 17:40:41 +05302568 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002569 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002570 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002571 else
2572 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002573 }
2574
Damien Lespiau055e3932014-08-18 13:49:10 +01002575 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002576 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002577
Daniel Vetterc42664c2013-11-07 11:05:40 +01002578 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2579 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002580
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002581 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2582 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002583 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002584 continue;
2585 }
2586
2587 ret = IRQ_HANDLED;
2588 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2589
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002590 if (iir & GEN8_PIPE_VBLANK)
2591 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002592
2593 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002594 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002595
2596 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2597 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2598
2599 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002600 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002601 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2602 else
2603 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2604
2605 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002606 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002607 pipe_name(pipe),
2608 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002609 }
2610
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002611 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302612 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002613 /*
2614 * FIXME(BDW): Assume for now that the new interrupt handling
2615 * scheme also closed the SDE interrupt handling race we've seen
2616 * on older pch-split platforms. But this needs testing.
2617 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002618 iir = I915_READ(SDEIIR);
2619 if (iir) {
2620 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002621 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002622
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07002623 if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
2624 HAS_PCH_CNP(dev_priv))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002625 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002626 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002627 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002628 } else {
2629 /*
2630 * Like on previous PCH there seems to be something
2631 * fishy going on with forwarding PCH interrupts.
2632 */
2633 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2634 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002635 }
2636
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002637 return ret;
2638}
2639
2640static irqreturn_t gen8_irq_handler(int irq, void *arg)
2641{
2642 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002643 struct drm_i915_private *dev_priv = to_i915(dev);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002644 u32 master_ctl;
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002645 u32 gt_iir[4] = {};
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002646 irqreturn_t ret;
2647
2648 if (!intel_irqs_enabled(dev_priv))
2649 return IRQ_NONE;
2650
2651 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
2652 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2653 if (!master_ctl)
2654 return IRQ_NONE;
2655
2656 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
2657
2658 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2659 disable_rpm_wakeref_asserts(dev_priv);
2660
2661 /* Find, clear, then process each source of interrupt */
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002662 ret = gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
2663 gen8_gt_irq_handler(dev_priv, gt_iir);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002664 ret |= gen8_de_irq_handler(dev_priv, master_ctl);
2665
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002666 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2667 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002668
Imre Deak1f814da2015-12-16 02:52:19 +02002669 enable_rpm_wakeref_asserts(dev_priv);
2670
Ben Widawskyabd58f02013-11-02 21:07:09 -07002671 return ret;
2672}
2673
Chris Wilson36703e72017-06-22 11:56:25 +01002674struct wedge_me {
2675 struct delayed_work work;
2676 struct drm_i915_private *i915;
2677 const char *name;
2678};
2679
2680static void wedge_me(struct work_struct *work)
2681{
2682 struct wedge_me *w = container_of(work, typeof(*w), work.work);
2683
2684 dev_err(w->i915->drm.dev,
2685 "%s timed out, cancelling all in-flight rendering.\n",
2686 w->name);
2687 i915_gem_set_wedged(w->i915);
2688}
2689
2690static void __init_wedge(struct wedge_me *w,
2691 struct drm_i915_private *i915,
2692 long timeout,
2693 const char *name)
2694{
2695 w->i915 = i915;
2696 w->name = name;
2697
2698 INIT_DELAYED_WORK_ONSTACK(&w->work, wedge_me);
2699 schedule_delayed_work(&w->work, timeout);
2700}
2701
2702static void __fini_wedge(struct wedge_me *w)
2703{
2704 cancel_delayed_work_sync(&w->work);
2705 destroy_delayed_work_on_stack(&w->work);
2706 w->i915 = NULL;
2707}
2708
2709#define i915_wedge_on_timeout(W, DEV, TIMEOUT) \
2710 for (__init_wedge((W), (DEV), (TIMEOUT), __func__); \
2711 (W)->i915; \
2712 __fini_wedge((W)))
2713
Jesse Barnes8a905232009-07-11 16:48:03 -04002714/**
Chris Wilsond5367302017-06-20 10:57:43 +01002715 * i915_reset_device - do process context error handling work
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002716 * @dev_priv: i915 device private
Jesse Barnes8a905232009-07-11 16:48:03 -04002717 *
2718 * Fire an error uevent so userspace can see that a hang or error
2719 * was detected.
2720 */
Chris Wilsond5367302017-06-20 10:57:43 +01002721static void i915_reset_device(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002722{
Chris Wilson91c8a322016-07-05 10:40:23 +01002723 struct kobject *kobj = &dev_priv->drm.primary->kdev->kobj;
Ben Widawskycce723e2013-07-19 09:16:42 -07002724 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2725 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2726 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Chris Wilson36703e72017-06-22 11:56:25 +01002727 struct wedge_me w;
Jesse Barnes8a905232009-07-11 16:48:03 -04002728
Chris Wilsonc0336662016-05-06 15:40:21 +01002729 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002730
Chris Wilson8af29b02016-09-09 14:11:47 +01002731 DRM_DEBUG_DRIVER("resetting chip\n");
2732 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event);
2733
Chris Wilson36703e72017-06-22 11:56:25 +01002734 /* Use a watchdog to ensure that our reset completes */
2735 i915_wedge_on_timeout(&w, dev_priv, 5*HZ) {
2736 intel_prepare_reset(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002737
Chris Wilson36703e72017-06-22 11:56:25 +01002738 /* Signal that locked waiters should reset the GPU */
2739 set_bit(I915_RESET_HANDOFF, &dev_priv->gpu_error.flags);
2740 wake_up_all(&dev_priv->gpu_error.wait_queue);
Chris Wilson8c185ec2017-03-16 17:13:02 +00002741
Chris Wilson36703e72017-06-22 11:56:25 +01002742 /* Wait for anyone holding the lock to wakeup, without
2743 * blocking indefinitely on struct_mutex.
Chris Wilson780f2622016-09-09 14:11:52 +01002744 */
Chris Wilson36703e72017-06-22 11:56:25 +01002745 do {
2746 if (mutex_trylock(&dev_priv->drm.struct_mutex)) {
Chris Wilson535275d2017-07-21 13:32:37 +01002747 i915_reset(dev_priv, 0);
Chris Wilson36703e72017-06-22 11:56:25 +01002748 mutex_unlock(&dev_priv->drm.struct_mutex);
2749 }
2750 } while (wait_on_bit_timeout(&dev_priv->gpu_error.flags,
2751 I915_RESET_HANDOFF,
2752 TASK_UNINTERRUPTIBLE,
2753 1));
Chris Wilson780f2622016-09-09 14:11:52 +01002754
Chris Wilson36703e72017-06-22 11:56:25 +01002755 intel_finish_reset(dev_priv);
2756 }
Daniel Vetter17e1df02013-09-08 21:57:13 +02002757
Chris Wilson780f2622016-09-09 14:11:52 +01002758 if (!test_bit(I915_WEDGED, &dev_priv->gpu_error.flags))
Chris Wilson8af29b02016-09-09 14:11:47 +01002759 kobject_uevent_env(kobj,
2760 KOBJ_CHANGE, reset_done_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002761}
2762
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002763static void i915_clear_error_registers(struct drm_i915_private *dev_priv)
Jesse Barnes8a905232009-07-11 16:48:03 -04002764{
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002765 u32 eir;
Jesse Barnes8a905232009-07-11 16:48:03 -04002766
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002767 if (!IS_GEN2(dev_priv))
2768 I915_WRITE(PGTBL_ER, I915_READ(PGTBL_ER));
Jesse Barnes8a905232009-07-11 16:48:03 -04002769
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002770 if (INTEL_GEN(dev_priv) < 4)
2771 I915_WRITE(IPEIR, I915_READ(IPEIR));
2772 else
2773 I915_WRITE(IPEIR_I965, I915_READ(IPEIR_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002774
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002775 I915_WRITE(EIR, I915_READ(EIR));
Jesse Barnes8a905232009-07-11 16:48:03 -04002776 eir = I915_READ(EIR);
2777 if (eir) {
2778 /*
2779 * some errors might have become stuck,
2780 * mask them.
2781 */
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002782 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masking\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002783 I915_WRITE(EMR, I915_READ(EMR) | eir);
2784 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2785 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002786}
2787
2788/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002789 * i915_handle_error - handle a gpu error
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +01002790 * @dev_priv: i915 device private
arun.siluvery@linux.intel.com14b730f2016-03-18 20:07:55 +00002791 * @engine_mask: mask representing engines that are hung
Michel Thierry87c390b2017-01-11 20:18:08 -08002792 * @fmt: Error message format string
2793 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002794 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002795 * dump it to the syslog. Also call i915_capture_error_state() to make
2796 * sure we get a record and make it available in debugfs. Fire a uevent
2797 * so userspace knows something bad happened (should trigger collection
2798 * of a ring dump etc.).
2799 */
Chris Wilsonc0336662016-05-06 15:40:21 +01002800void i915_handle_error(struct drm_i915_private *dev_priv,
2801 u32 engine_mask,
Mika Kuoppala58174462014-02-25 17:11:26 +02002802 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002803{
Michel Thierry142bc7d2017-06-20 10:57:46 +01002804 struct intel_engine_cs *engine;
2805 unsigned int tmp;
Mika Kuoppala58174462014-02-25 17:11:26 +02002806 va_list args;
2807 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002808
Mika Kuoppala58174462014-02-25 17:11:26 +02002809 va_start(args, fmt);
2810 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2811 va_end(args);
2812
Chris Wilson1604a862017-03-14 17:18:40 +00002813 /*
2814 * In most cases it's guaranteed that we get here with an RPM
2815 * reference held, for example because there is a pending GPU
2816 * request that won't finish until the reset is done. This
2817 * isn't the case at least when we get here by doing a
2818 * simulated reset via debugfs, so get an RPM reference.
2819 */
2820 intel_runtime_pm_get(dev_priv);
2821
Chris Wilsonc0336662016-05-06 15:40:21 +01002822 i915_capture_error_state(dev_priv, engine_mask, error_msg);
Chris Wilsoneaa14c22016-10-19 13:52:03 +01002823 i915_clear_error_registers(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002824
Michel Thierry142bc7d2017-06-20 10:57:46 +01002825 /*
2826 * Try engine reset when available. We fall back to full reset if
2827 * single reset fails.
2828 */
2829 if (intel_has_reset_engine(dev_priv)) {
2830 for_each_engine_masked(engine, dev_priv, engine_mask, tmp) {
Daniel Vetter9db529a2017-08-08 10:08:28 +02002831 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE);
Michel Thierry142bc7d2017-06-20 10:57:46 +01002832 if (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2833 &dev_priv->gpu_error.flags))
2834 continue;
2835
Chris Wilson535275d2017-07-21 13:32:37 +01002836 if (i915_reset_engine(engine, 0) == 0)
Michel Thierry142bc7d2017-06-20 10:57:46 +01002837 engine_mask &= ~intel_engine_flag(engine);
2838
2839 clear_bit(I915_RESET_ENGINE + engine->id,
2840 &dev_priv->gpu_error.flags);
2841 wake_up_bit(&dev_priv->gpu_error.flags,
2842 I915_RESET_ENGINE + engine->id);
2843 }
2844 }
2845
Chris Wilson8af29b02016-09-09 14:11:47 +01002846 if (!engine_mask)
Chris Wilson1604a862017-03-14 17:18:40 +00002847 goto out;
Ben Gamariba1234d2009-09-14 17:48:47 -04002848
Michel Thierry142bc7d2017-06-20 10:57:46 +01002849 /* Full reset needs the mutex, stop any other user trying to do so. */
Chris Wilsond5367302017-06-20 10:57:43 +01002850 if (test_and_set_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags)) {
2851 wait_event(dev_priv->gpu_error.reset_queue,
2852 !test_bit(I915_RESET_BACKOFF,
2853 &dev_priv->gpu_error.flags));
Chris Wilson1604a862017-03-14 17:18:40 +00002854 goto out;
Chris Wilsond5367302017-06-20 10:57:43 +01002855 }
Chris Wilson8af29b02016-09-09 14:11:47 +01002856
Michel Thierry142bc7d2017-06-20 10:57:46 +01002857 /* Prevent any other reset-engine attempt. */
2858 for_each_engine(engine, dev_priv, tmp) {
2859 while (test_and_set_bit(I915_RESET_ENGINE + engine->id,
2860 &dev_priv->gpu_error.flags))
2861 wait_on_bit(&dev_priv->gpu_error.flags,
2862 I915_RESET_ENGINE + engine->id,
2863 TASK_UNINTERRUPTIBLE);
2864 }
2865
Chris Wilsond5367302017-06-20 10:57:43 +01002866 i915_reset_device(dev_priv);
2867
Michel Thierry142bc7d2017-06-20 10:57:46 +01002868 for_each_engine(engine, dev_priv, tmp) {
2869 clear_bit(I915_RESET_ENGINE + engine->id,
2870 &dev_priv->gpu_error.flags);
2871 }
2872
Chris Wilsond5367302017-06-20 10:57:43 +01002873 clear_bit(I915_RESET_BACKOFF, &dev_priv->gpu_error.flags);
2874 wake_up_all(&dev_priv->gpu_error.reset_queue);
Chris Wilson1604a862017-03-14 17:18:40 +00002875
2876out:
2877 intel_runtime_pm_put(dev_priv);
Jesse Barnes8a905232009-07-11 16:48:03 -04002878}
2879
Keith Packard42f52ef2008-10-18 19:39:29 -07002880/* Called from drm generic code, passed 'crtc' which
2881 * we use as a pipe index
2882 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002883static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002884{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002885 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002886 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002887
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002888 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01002889 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2890 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2891
2892 return 0;
2893}
2894
2895static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
2896{
2897 struct drm_i915_private *dev_priv = to_i915(dev);
2898 unsigned long irqflags;
2899
2900 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2901 i915_enable_pipestat(dev_priv, pipe,
2902 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002903 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002904
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002905 return 0;
2906}
2907
Thierry Reding88e72712015-09-24 18:35:31 +02002908static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002909{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002910 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002911 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002912 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002913 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002914
Jesse Barnesf796cf82011-04-07 13:58:17 -07002915 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002916 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002917 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2918
2919 return 0;
2920}
2921
Thierry Reding88e72712015-09-24 18:35:31 +02002922static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002923{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002924 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002925 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002926
Ben Widawskyabd58f02013-11-02 21:07:09 -07002927 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002928 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002929 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002930
Ben Widawskyabd58f02013-11-02 21:07:09 -07002931 return 0;
2932}
2933
Keith Packard42f52ef2008-10-18 19:39:29 -07002934/* Called from drm generic code, passed 'crtc' which
2935 * we use as a pipe index
2936 */
Chris Wilson86e83e32016-10-07 20:49:52 +01002937static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
2938{
2939 struct drm_i915_private *dev_priv = to_i915(dev);
2940 unsigned long irqflags;
2941
2942 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
2943 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
2944 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2945}
2946
2947static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002948{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002949 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07002950 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002951
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002952 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002953 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002954 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002955 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2956}
2957
Thierry Reding88e72712015-09-24 18:35:31 +02002958static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002959{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002960 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002961 unsigned long irqflags;
Tvrtko Ursulin55b8f2a2016-10-14 09:17:22 +01002962 uint32_t bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01002963 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002964
2965 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02002966 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002967 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2968}
2969
Thierry Reding88e72712015-09-24 18:35:31 +02002970static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002971{
Chris Wilsonfac5e232016-07-04 11:34:36 +01002972 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002973 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002974
Ben Widawskyabd58f02013-11-02 21:07:09 -07002975 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02002976 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002977 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2978}
2979
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00002980static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03002981{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002982 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03002983 return;
2984
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03002985 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03002986
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01002987 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03002988 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03002989}
Paulo Zanoni105b1222014-04-01 15:37:17 -03002990
Paulo Zanoni622364b2014-04-01 15:37:22 -03002991/*
2992 * SDEIER is also touched by the interrupt handler to work around missed PCH
2993 * interrupts. Hence we can't update it after the interrupt handler is enabled -
2994 * instead we unconditionally enable all PCH interrupt sources here, but then
2995 * only unmask them as needed with SDEIMR.
2996 *
2997 * This function needs to be called before interrupts are enabled.
2998 */
2999static void ibx_irq_pre_postinstall(struct drm_device *dev)
3000{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003001 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003002
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003003 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003004 return;
3005
3006 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003007 I915_WRITE(SDEIER, 0xffffffff);
3008 POSTING_READ(SDEIER);
3009}
3010
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003011static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003012{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003013 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003014 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003015 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003016}
3017
Ville Syrjälä70591a42014-10-30 19:42:58 +02003018static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3019{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003020 if (IS_CHERRYVIEW(dev_priv))
3021 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3022 else
3023 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3024
Ville Syrjäläad22d102016-04-12 18:56:14 +03003025 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003026 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3027
Ville Syrjälä44d92412017-08-18 21:36:51 +03003028 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003029
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003030 GEN3_IRQ_RESET(VLV_);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003031 dev_priv->irq_mask = ~0;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003032}
3033
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003034static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3035{
3036 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003037 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003038 enum pipe pipe;
3039
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003040 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003041
3042 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3043 for_each_pipe(dev_priv, pipe)
3044 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3045
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003046 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3047 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003048 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3049 I915_LPE_PIPE_A_INTERRUPT |
3050 I915_LPE_PIPE_B_INTERRUPT;
3051
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003052 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003053 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3054 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003055
3056 WARN_ON(dev_priv->irq_mask != ~0);
3057
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003058 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003059
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003060 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003061}
3062
3063/* drm_dma.h hooks
3064*/
3065static void ironlake_irq_reset(struct drm_device *dev)
3066{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003067 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003068
Ville Syrjäläd420a502017-08-18 21:37:03 +03003069 if (IS_GEN5(dev_priv))
3070 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003071
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003072 GEN3_IRQ_RESET(DE);
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003073 if (IS_GEN7(dev_priv))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003074 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3075
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003076 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003077
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003078 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003079}
3080
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003081static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003082{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003083 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003084
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003085 I915_WRITE(VLV_MASTER_IER, 0);
3086 POSTING_READ(VLV_MASTER_IER);
3087
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003088 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003089
Ville Syrjäläad22d102016-04-12 18:56:14 +03003090 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003091 if (dev_priv->display_irqs_enabled)
3092 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003093 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003094}
3095
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003096static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3097{
3098 GEN8_IRQ_RESET_NDX(GT, 0);
3099 GEN8_IRQ_RESET_NDX(GT, 1);
3100 GEN8_IRQ_RESET_NDX(GT, 2);
3101 GEN8_IRQ_RESET_NDX(GT, 3);
3102}
3103
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003104static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003105{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003106 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003107 int pipe;
3108
Ben Widawskyabd58f02013-11-02 21:07:09 -07003109 I915_WRITE(GEN8_MASTER_IRQ, 0);
3110 POSTING_READ(GEN8_MASTER_IRQ);
3111
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003112 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003113
Damien Lespiau055e3932014-08-18 13:49:10 +01003114 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003115 if (intel_display_power_is_enabled(dev_priv,
3116 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003117 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003118
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003119 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3120 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3121 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003122
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003123 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003124 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003125}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003126
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003127void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003128 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003129{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003130 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003131 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003132
Daniel Vetter13321782014-09-15 14:55:29 +02003133 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003134 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3135 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3136 dev_priv->de_irq_mask[pipe],
3137 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003138 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003139}
3140
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003141void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003142 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003143{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003144 enum pipe pipe;
3145
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003146 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003147 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3148 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003149 spin_unlock_irq(&dev_priv->irq_lock);
3150
3151 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003152 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003153}
3154
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003155static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003156{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003157 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003158
3159 I915_WRITE(GEN8_MASTER_IRQ, 0);
3160 POSTING_READ(GEN8_MASTER_IRQ);
3161
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003162 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003163
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003164 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003165
Ville Syrjäläad22d102016-04-12 18:56:14 +03003166 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003167 if (dev_priv->display_irqs_enabled)
3168 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003169 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003170}
3171
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003172static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003173 const u32 hpd[HPD_NUM_PINS])
3174{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003175 struct intel_encoder *encoder;
3176 u32 enabled_irqs = 0;
3177
Chris Wilson91c8a322016-07-05 10:40:23 +01003178 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003179 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3180 enabled_irqs |= hpd[encoder->hpd_pin];
3181
3182 return enabled_irqs;
3183}
3184
Imre Deak1a56b1a2017-01-27 11:39:21 +02003185static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3186{
3187 u32 hotplug;
3188
3189 /*
3190 * Enable digital hotplug on the PCH, and configure the DP short pulse
3191 * duration to 2ms (which is the minimum in the Display Port spec).
3192 * The pulse duration bits are reserved on LPT+.
3193 */
3194 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3195 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3196 PORTC_PULSE_DURATION_MASK |
3197 PORTD_PULSE_DURATION_MASK);
3198 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3199 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3200 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3201 /*
3202 * When CPU and PCH are on the same package, port A
3203 * HPD must be enabled in both north and south.
3204 */
3205 if (HAS_PCH_LPT_LP(dev_priv))
3206 hotplug |= PORTA_HOTPLUG_ENABLE;
3207 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3208}
3209
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003210static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003211{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003212 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003213
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003214 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003215 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003216 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003217 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003218 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003219 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003220 }
3221
Daniel Vetterfee884e2013-07-04 23:35:21 +02003222 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003223
Imre Deak1a56b1a2017-01-27 11:39:21 +02003224 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003225}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003226
Imre Deak2a57d9c2017-01-27 11:39:18 +02003227static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3228{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003229 u32 val, hotplug;
3230
3231 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3232 if (HAS_PCH_CNP(dev_priv)) {
3233 val = I915_READ(SOUTH_CHICKEN1);
3234 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3235 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3236 I915_WRITE(SOUTH_CHICKEN1, val);
3237 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003238
3239 /* Enable digital hotplug on the PCH */
3240 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3241 hotplug |= PORTA_HOTPLUG_ENABLE |
3242 PORTB_HOTPLUG_ENABLE |
3243 PORTC_HOTPLUG_ENABLE |
3244 PORTD_HOTPLUG_ENABLE;
3245 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3246
3247 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3248 hotplug |= PORTE_HOTPLUG_ENABLE;
3249 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3250}
3251
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003252static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003253{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003254 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003255
3256 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003257 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003258
3259 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3260
Imre Deak2a57d9c2017-01-27 11:39:18 +02003261 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003262}
3263
Imre Deak1a56b1a2017-01-27 11:39:21 +02003264static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3265{
3266 u32 hotplug;
3267
3268 /*
3269 * Enable digital hotplug on the CPU, and configure the DP short pulse
3270 * duration to 2ms (which is the minimum in the Display Port spec)
3271 * The pulse duration bits are reserved on HSW+.
3272 */
3273 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3274 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3275 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3276 DIGITAL_PORTA_PULSE_DURATION_2ms;
3277 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3278}
3279
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003280static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003281{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003282 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003283
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003284 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003285 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003286 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003287
3288 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003289 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003290 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003291 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003292
3293 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003294 } else {
3295 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003296 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003297
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003298 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3299 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003300
Imre Deak1a56b1a2017-01-27 11:39:21 +02003301 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003302
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003303 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003304}
3305
Imre Deak2a57d9c2017-01-27 11:39:18 +02003306static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3307 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003308{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003309 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003310
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003311 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003312 hotplug |= PORTA_HOTPLUG_ENABLE |
3313 PORTB_HOTPLUG_ENABLE |
3314 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303315
3316 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3317 hotplug, enabled_irqs);
3318 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3319
3320 /*
3321 * For BXT invert bit has to be set based on AOB design
3322 * for HPD detection logic, update it based on VBT fields.
3323 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303324 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3325 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3326 hotplug |= BXT_DDIA_HPD_INVERT;
3327 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3328 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3329 hotplug |= BXT_DDIB_HPD_INVERT;
3330 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3331 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3332 hotplug |= BXT_DDIC_HPD_INVERT;
3333
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003334 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003335}
3336
Imre Deak2a57d9c2017-01-27 11:39:18 +02003337static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3338{
3339 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3340}
3341
3342static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3343{
3344 u32 hotplug_irqs, enabled_irqs;
3345
3346 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3347 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3348
3349 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3350
3351 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3352}
3353
Paulo Zanonid46da432013-02-08 17:35:15 -02003354static void ibx_irq_postinstall(struct drm_device *dev)
3355{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003356 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003357 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003358
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003359 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003360 return;
3361
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003362 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003363 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003364 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003365 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003366 else
3367 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003368
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003369 gen3_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003370 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003371
3372 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3373 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003374 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003375 else
3376 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003377}
3378
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003379static void gen5_gt_irq_postinstall(struct drm_device *dev)
3380{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003381 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003382 u32 pm_irqs, gt_irqs;
3383
3384 pm_irqs = gt_irqs = 0;
3385
3386 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003387 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003388 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003389 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3390 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003391 }
3392
3393 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Tvrtko Ursulin5db94012016-10-13 11:03:10 +01003394 if (IS_GEN5(dev_priv)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003395 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003396 } else {
3397 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3398 }
3399
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003400 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003401
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003402 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003403 /*
3404 * RPS interrupts will get enabled/disabled on demand when RPS
3405 * itself is enabled/disabled.
3406 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303407 if (HAS_VEBOX(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003408 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303409 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3410 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003411
Akash Goelf4e9af42016-10-12 21:54:30 +05303412 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003413 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003414 }
3415}
3416
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003417static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003418{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003419 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003420 u32 display_mask, extra_mask;
3421
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003422 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003423 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003424 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003425 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003426 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3427 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003428 } else {
3429 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003430 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3431 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003432 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3433 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3434 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003435 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003436
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003437 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003438
Paulo Zanoni622364b2014-04-01 15:37:22 -03003439 ibx_irq_pre_postinstall(dev);
3440
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003441 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003442
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003443 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003444
Imre Deak1a56b1a2017-01-27 11:39:21 +02003445 ilk_hpd_detection_setup(dev_priv);
3446
Paulo Zanonid46da432013-02-08 17:35:15 -02003447 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003448
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003449 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003450 /* Enable PCU event interrupts
3451 *
3452 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003453 * setup is guaranteed to run in single-threaded context. But we
3454 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003455 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003456 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003457 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003458 }
3459
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003460 return 0;
3461}
3462
Imre Deakf8b79e52014-03-04 19:23:07 +02003463void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3464{
Chris Wilson67520412017-03-02 13:28:01 +00003465 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003466
3467 if (dev_priv->display_irqs_enabled)
3468 return;
3469
3470 dev_priv->display_irqs_enabled = true;
3471
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003472 if (intel_irqs_enabled(dev_priv)) {
3473 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003474 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003475 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003476}
3477
3478void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3479{
Chris Wilson67520412017-03-02 13:28:01 +00003480 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003481
3482 if (!dev_priv->display_irqs_enabled)
3483 return;
3484
3485 dev_priv->display_irqs_enabled = false;
3486
Imre Deak950eaba2014-09-08 15:21:09 +03003487 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03003488 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02003489}
3490
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003491
3492static int valleyview_irq_postinstall(struct drm_device *dev)
3493{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003494 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003495
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003496 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003497
Ville Syrjäläad22d102016-04-12 18:56:14 +03003498 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003499 if (dev_priv->display_irqs_enabled)
3500 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003501 spin_unlock_irq(&dev_priv->irq_lock);
3502
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003503 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003504 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003505
3506 return 0;
3507}
3508
Ben Widawskyabd58f02013-11-02 21:07:09 -07003509static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3510{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003511 /* These are interrupts we'll toggle with the ring mask register */
3512 uint32_t gt_interrupts[] = {
3513 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003514 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003515 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3516 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003517 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003518 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3519 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3520 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003521 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003522 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3523 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003524 };
3525
Tvrtko Ursulin98735732016-04-19 16:46:08 +01003526 if (HAS_L3_DPF(dev_priv))
3527 gt_interrupts[0] |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
3528
Akash Goelf4e9af42016-10-12 21:54:30 +05303529 dev_priv->pm_ier = 0x0;
3530 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05303531 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3532 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003533 /*
3534 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303535 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02003536 */
Akash Goelf4e9af42016-10-12 21:54:30 +05303537 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05303538 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003539}
3540
3541static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3542{
Damien Lespiau770de832014-03-20 20:45:01 +00003543 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3544 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003545 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3546 u32 de_port_enables;
Ville Syrjälä11825b02016-05-19 12:14:43 +03003547 u32 de_misc_masked = GEN8_DE_MISC_GSE;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003548 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003549
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003550 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003551 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003552 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3553 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003554 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003555 de_port_masked |= BXT_DE_PORT_GMBUS;
3556 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003557 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003558 }
Damien Lespiau770de832014-03-20 20:45:01 +00003559
3560 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3561 GEN8_PIPE_FIFO_UNDERRUN;
3562
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003563 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02003564 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003565 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3566 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003567 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3568
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003569 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3570 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3571 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003572
Damien Lespiau055e3932014-08-18 13:49:10 +01003573 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003574 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003575 POWER_DOMAIN_PIPE(pipe)))
3576 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3577 dev_priv->de_irq_mask[pipe],
3578 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003579
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003580 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
3581 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003582
3583 if (IS_GEN9_LP(dev_priv))
3584 bxt_hpd_detection_setup(dev_priv);
Imre Deak1a56b1a2017-01-27 11:39:21 +02003585 else if (IS_BROADWELL(dev_priv))
3586 ilk_hpd_detection_setup(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003587}
3588
3589static int gen8_irq_postinstall(struct drm_device *dev)
3590{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003591 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003592
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003593 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303594 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003595
Ben Widawskyabd58f02013-11-02 21:07:09 -07003596 gen8_gt_irq_postinstall(dev_priv);
3597 gen8_de_irq_postinstall(dev_priv);
3598
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003599 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303600 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003601
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003602 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003603 POSTING_READ(GEN8_MASTER_IRQ);
3604
3605 return 0;
3606}
3607
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003608static int cherryview_irq_postinstall(struct drm_device *dev)
3609{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003610 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003611
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003612 gen8_gt_irq_postinstall(dev_priv);
3613
Ville Syrjäläad22d102016-04-12 18:56:14 +03003614 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003615 if (dev_priv->display_irqs_enabled)
3616 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003617 spin_unlock_irq(&dev_priv->irq_lock);
3618
Ville Syrjäläe5328c42016-04-13 21:19:47 +03003619 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003620 POSTING_READ(GEN8_MASTER_IRQ);
3621
3622 return 0;
3623}
3624
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003625static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003626{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003627 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003628
Ville Syrjälä44d92412017-08-18 21:36:51 +03003629 i9xx_pipestat_irq_reset(dev_priv);
3630
Ville Syrjäläd420a502017-08-18 21:37:03 +03003631 I915_WRITE16(HWSTAM, 0xffff);
3632
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003633 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01003634}
3635
3636static int i8xx_irq_postinstall(struct drm_device *dev)
3637{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003638 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003639 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003640
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003641 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
3642 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01003643
3644 /* Unmask the interrupts that we always want on. */
3645 dev_priv->irq_mask =
3646 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003647 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003648
Ville Syrjäläe9e98482017-08-18 21:36:54 +03003649 enable_mask =
3650 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3651 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3652 I915_USER_INTERRUPT;
3653
3654 GEN2_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003655
Daniel Vetter379ef822013-10-16 22:55:56 +02003656 /* Interrupt setup is already guaranteed to be single-threaded, this is
3657 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003658 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003659 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3660 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003661 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003662
Chris Wilsonc2798b12012-04-22 21:13:57 +01003663 return 0;
3664}
3665
Daniel Vetterff1f5252012-10-02 15:10:55 +02003666static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003667{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003668 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003669 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003670 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003671
Imre Deak2dd2a882015-02-24 11:14:30 +02003672 if (!intel_irqs_enabled(dev_priv))
3673 return IRQ_NONE;
3674
Imre Deak1f814da2015-12-16 02:52:19 +02003675 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3676 disable_rpm_wakeref_asserts(dev_priv);
3677
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003678 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003679 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003680 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03003681
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003682 iir = I915_READ16(IIR);
3683 if (iir == 0)
3684 break;
3685
3686 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003687
Ville Syrjäläeb643432017-08-18 21:36:59 +03003688 /* Call regardless, as some status bits might not be
3689 * signalled in iir */
3690 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003691
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003692 I915_WRITE16(IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003693
Chris Wilsonc2798b12012-04-22 21:13:57 +01003694 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303695 notify_ring(dev_priv->engine[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003696
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003697 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3698 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
3699
Ville Syrjäläeb643432017-08-18 21:36:59 +03003700 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003701 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003702
Imre Deak1f814da2015-12-16 02:52:19 +02003703 enable_rpm_wakeref_asserts(dev_priv);
3704
3705 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003706}
3707
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003708static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003709{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003710 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003711
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003712 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003713 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003714 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3715 }
3716
Ville Syrjälä44d92412017-08-18 21:36:51 +03003717 i9xx_pipestat_irq_reset(dev_priv);
3718
Ville Syrjäläd420a502017-08-18 21:37:03 +03003719 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003720
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003721 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003722}
3723
3724static int i915_irq_postinstall(struct drm_device *dev)
3725{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003726 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01003727 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003728
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003729 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
3730 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01003731
3732 /* Unmask the interrupts that we always want on. */
3733 dev_priv->irq_mask =
3734 ~(I915_ASLE_INTERRUPT |
3735 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003736 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003737
3738 enable_mask =
3739 I915_ASLE_INTERRUPT |
3740 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3741 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003742 I915_USER_INTERRUPT;
3743
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00003744 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003745 /* Enable in IER... */
3746 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3747 /* and unmask in IMR */
3748 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3749 }
3750
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003751 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003752
Daniel Vetter379ef822013-10-16 22:55:56 +02003753 /* Interrupt setup is already guaranteed to be single-threaded, this is
3754 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003755 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003756 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3757 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003758 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003759
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003760 i915_enable_asle_pipestat(dev_priv);
3761
Daniel Vetter20afbda2012-12-11 14:05:07 +01003762 return 0;
3763}
3764
Daniel Vetterff1f5252012-10-02 15:10:55 +02003765static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003766{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003767 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003768 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003769 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003770
Imre Deak2dd2a882015-02-24 11:14:30 +02003771 if (!intel_irqs_enabled(dev_priv))
3772 return IRQ_NONE;
3773
Imre Deak1f814da2015-12-16 02:52:19 +02003774 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3775 disable_rpm_wakeref_asserts(dev_priv);
3776
Chris Wilson38bde182012-04-24 22:59:50 +01003777 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003778 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003779 u32 hotplug_status = 0;
3780 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003781
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003782 iir = I915_READ(IIR);
3783 if (iir == 0)
3784 break;
3785
3786 ret = IRQ_HANDLED;
3787
3788 if (I915_HAS_HOTPLUG(dev_priv) &&
3789 iir & I915_DISPLAY_PORT_INTERRUPT)
3790 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003791
Ville Syrjäläeb643432017-08-18 21:36:59 +03003792 /* Call regardless, as some status bits might not be
3793 * signalled in iir */
3794 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003795
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003796 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003797
Chris Wilsona266c7d2012-04-24 22:59:44 +01003798 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303799 notify_ring(dev_priv->engine[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003800
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003801 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3802 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003803
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003804 if (hotplug_status)
3805 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3806
3807 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3808 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003809
Imre Deak1f814da2015-12-16 02:52:19 +02003810 enable_rpm_wakeref_asserts(dev_priv);
3811
Chris Wilsona266c7d2012-04-24 22:59:44 +01003812 return ret;
3813}
3814
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003815static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003816{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003817 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003818
Egbert Eich0706f172015-09-23 16:15:27 +02003819 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01003820 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003821
Ville Syrjälä44d92412017-08-18 21:36:51 +03003822 i9xx_pipestat_irq_reset(dev_priv);
3823
Ville Syrjäläd420a502017-08-18 21:37:03 +03003824 I915_WRITE(HWSTAM, 0xffffffff);
Ville Syrjälä44d92412017-08-18 21:36:51 +03003825
Ville Syrjäläba7eb782017-08-18 21:36:53 +03003826 GEN3_IRQ_RESET();
Chris Wilsona266c7d2012-04-24 22:59:44 +01003827}
3828
3829static int i965_irq_postinstall(struct drm_device *dev)
3830{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003831 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003832 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003833 u32 error_mask;
3834
Ville Syrjälä045cebd2017-08-18 21:36:55 +03003835 /*
3836 * Enable some error detection, note the instruction error mask
3837 * bit is reserved, so we leave it masked.
3838 */
3839 if (IS_G4X(dev_priv)) {
3840 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3841 GM45_ERROR_MEM_PRIV |
3842 GM45_ERROR_CP_PRIV |
3843 I915_ERROR_MEMORY_REFRESH);
3844 } else {
3845 error_mask = ~(I915_ERROR_PAGE_TABLE |
3846 I915_ERROR_MEMORY_REFRESH);
3847 }
3848 I915_WRITE(EMR, error_mask);
3849
Chris Wilsona266c7d2012-04-24 22:59:44 +01003850 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003851 dev_priv->irq_mask =
3852 ~(I915_ASLE_INTERRUPT |
3853 I915_DISPLAY_PORT_INTERRUPT |
3854 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3855 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3856 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003857
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003858 enable_mask =
3859 I915_ASLE_INTERRUPT |
3860 I915_DISPLAY_PORT_INTERRUPT |
3861 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3862 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3863 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT |
3864 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003865
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003866 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003867 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003868
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03003869 GEN3_IRQ_INIT(, dev_priv->irq_mask, enable_mask);
3870
Daniel Vetterb79480b2013-06-27 17:52:10 +02003871 /* Interrupt setup is already guaranteed to be single-threaded, this is
3872 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003873 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003874 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3875 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3876 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003877 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003878
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003879 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003880
3881 return 0;
3882}
3883
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003884static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003885{
Daniel Vetter20afbda2012-12-11 14:05:07 +01003886 u32 hotplug_en;
3887
Chris Wilson67520412017-03-02 13:28:01 +00003888 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003889
Ville Syrjälä778eb332015-01-09 14:21:13 +02003890 /* Note HDMI and DP share hotplug bits */
3891 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003892 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02003893 /* Programming the CRT detection parameters tends
3894 to generate a spurious hotplug event about three
3895 seconds later. So just do it once.
3896 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003897 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02003898 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02003899 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003900
Ville Syrjälä778eb332015-01-09 14:21:13 +02003901 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02003902 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03003903 HOTPLUG_INT_EN_MASK |
3904 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
3905 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
3906 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003907}
3908
Daniel Vetterff1f5252012-10-02 15:10:55 +02003909static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003910{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003911 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01003912 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003913 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003914
Imre Deak2dd2a882015-02-24 11:14:30 +02003915 if (!intel_irqs_enabled(dev_priv))
3916 return IRQ_NONE;
3917
Imre Deak1f814da2015-12-16 02:52:19 +02003918 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3919 disable_rpm_wakeref_asserts(dev_priv);
3920
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003921 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03003922 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003923 u32 hotplug_status = 0;
3924 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01003925
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003926 iir = I915_READ(IIR);
3927 if (iir == 0)
3928 break;
3929
3930 ret = IRQ_HANDLED;
3931
3932 if (iir & I915_DISPLAY_PORT_INTERRUPT)
3933 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003934
Ville Syrjäläeb643432017-08-18 21:36:59 +03003935 /* Call regardless, as some status bits might not be
3936 * signalled in iir */
3937 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003938
Daniel Vetterfd3a4022017-07-20 19:57:51 +02003939 I915_WRITE(IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003940
Chris Wilsona266c7d2012-04-24 22:59:44 +01003941 if (iir & I915_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303942 notify_ring(dev_priv->engine[RCS]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003943
Chris Wilsona266c7d2012-04-24 22:59:44 +01003944 if (iir & I915_BSD_USER_INTERRUPT)
Akash Goel3b3f1652016-10-13 22:44:48 +05303945 notify_ring(dev_priv->engine[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003946
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003947 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
3948 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01003949
Ville Syrjäläaf722d22017-08-18 21:37:00 +03003950 if (hotplug_status)
3951 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
3952
3953 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
3954 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003955
Imre Deak1f814da2015-12-16 02:52:19 +02003956 enable_rpm_wakeref_asserts(dev_priv);
3957
Chris Wilsona266c7d2012-04-24 22:59:44 +01003958 return ret;
3959}
3960
Daniel Vetterfca52a52014-09-30 10:56:45 +02003961/**
3962 * intel_irq_init - initializes irq support
3963 * @dev_priv: i915 device instance
3964 *
3965 * This function initializes all the irq support including work items, timers
3966 * and all the vtables. It does not setup the interrupt itself though.
3967 */
Daniel Vetterb9632912014-09-30 10:56:44 +02003968void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003969{
Chris Wilson91c8a322016-07-05 10:40:23 +01003970 struct drm_device *dev = &dev_priv->drm;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003971 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01003972
Jani Nikula77913b32015-06-18 13:06:16 +03003973 intel_hpd_init_work(dev_priv);
3974
Daniel Vetterc6a828d2012-08-08 23:35:35 +02003975 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003976
Daniel Vettera4da4fa2012-11-02 19:55:07 +01003977 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03003978 for (i = 0; i < MAX_L3_SLICES; ++i)
3979 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01003980
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00003981 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05303982 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
3983
Deepak Sa6706b42014-03-15 20:23:22 +05303984 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08003985 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03003986 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00003987 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04003988 else
3989 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05303990
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05303991 dev_priv->rps.pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303992
3993 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03003994 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05303995 * if GEN6_PM_UP_EI_EXPIRED is masked.
3996 *
3997 * TODO: verify if this can be reproduced on VLV,CHV.
3998 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07003999 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble5dd04552017-03-11 08:07:00 +05304000 dev_priv->rps.pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304001
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004002 if (INTEL_GEN(dev_priv) >= 8)
Chris Wilson655d49e2017-03-12 13:27:45 +00004003 dev_priv->rps.pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304004
Daniel Vetterb9632912014-09-30 10:56:44 +02004005 if (IS_GEN2(dev_priv)) {
Rodrigo Vivi4194c082016-08-03 10:00:56 -07004006 /* Gen2 doesn't have a hardware frame counter */
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004007 dev->max_vblank_count = 0;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004008 } else if (IS_G4X(dev_priv) || INTEL_GEN(dev_priv) >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004009 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004010 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004011 } else {
4012 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4013 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004014 }
4015
Ville Syrjälä21da2702014-08-06 14:49:55 +03004016 /*
4017 * Opt out of the vblank disable timer on everything except gen2.
4018 * Gen2 doesn't have a hardware frame counter and so depends on
4019 * vblank interrupts to produce sane vblank seuquence numbers.
4020 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004021 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004022 dev->vblank_disable_immediate = true;
4023
Chris Wilson262fd482017-02-15 13:15:47 +00004024 /* Most platforms treat the display irq block as an always-on
4025 * power domain. vlv/chv can disable it at runtime and need
4026 * special care to avoid writing any of the display block registers
4027 * outside of the power domain. We defer setting up the display irqs
4028 * in this case to the runtime pm.
4029 */
4030 dev_priv->display_irqs_enabled = true;
4031 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4032 dev_priv->display_irqs_enabled = false;
4033
Lyude317eaa92017-02-03 21:18:25 -05004034 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
4035
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004036 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004037 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004038
Daniel Vetterb9632912014-09-30 10:56:44 +02004039 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004040 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004041 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004042 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004043 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004044 dev->driver->enable_vblank = i965_enable_vblank;
4045 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004046 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004047 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004048 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004049 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004050 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004051 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004052 dev->driver->enable_vblank = i965_enable_vblank;
4053 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004054 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004055 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004056 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004057 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004058 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004059 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004060 dev->driver->enable_vblank = gen8_enable_vblank;
4061 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004062 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004063 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivi7b22b8c2017-06-02 13:06:39 -07004064 else if (HAS_PCH_SPT(dev_priv) || HAS_PCH_KBP(dev_priv) ||
4065 HAS_PCH_CNP(dev_priv))
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004066 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4067 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004068 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004069 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004070 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004071 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004072 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004073 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004074 dev->driver->enable_vblank = ironlake_enable_vblank;
4075 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004076 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004077 } else {
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004078 if (IS_GEN2(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004079 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004080 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4081 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004082 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004083 dev->driver->enable_vblank = i8xx_enable_vblank;
4084 dev->driver->disable_vblank = i8xx_disable_vblank;
Tvrtko Ursulin7e22dbb2016-05-10 10:57:06 +01004085 } else if (IS_GEN3(dev_priv)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004086 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004087 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004088 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004089 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004090 dev->driver->enable_vblank = i8xx_enable_vblank;
4091 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004092 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004093 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004094 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004095 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004096 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004097 dev->driver->enable_vblank = i965_enable_vblank;
4098 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004099 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004100 if (I915_HAS_HOTPLUG(dev_priv))
4101 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004102 }
4103}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004104
Daniel Vetterfca52a52014-09-30 10:56:45 +02004105/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004106 * intel_irq_fini - deinitializes IRQ support
4107 * @i915: i915 device instance
4108 *
4109 * This function deinitializes all the IRQ support.
4110 */
4111void intel_irq_fini(struct drm_i915_private *i915)
4112{
4113 int i;
4114
4115 for (i = 0; i < MAX_L3_SLICES; ++i)
4116 kfree(i915->l3_parity.remap_info[i]);
4117}
4118
4119/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004120 * intel_irq_install - enables the hardware interrupt
4121 * @dev_priv: i915 device instance
4122 *
4123 * This function enables the hardware interrupt handling, but leaves the hotplug
4124 * handling still disabled. It is called after intel_irq_init().
4125 *
4126 * In the driver load and resume code we need working interrupts in a few places
4127 * but don't want to deal with the hassle of concurrent probe and hotplug
4128 * workers. Hence the split into this two-stage approach.
4129 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004130int intel_irq_install(struct drm_i915_private *dev_priv)
4131{
4132 /*
4133 * We enable some interrupt sources in our postinstall hooks, so mark
4134 * interrupts as enabled _before_ actually enabling them to avoid
4135 * special cases in our ordering checks.
4136 */
4137 dev_priv->pm.irqs_enabled = true;
4138
Chris Wilson91c8a322016-07-05 10:40:23 +01004139 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004140}
4141
Daniel Vetterfca52a52014-09-30 10:56:45 +02004142/**
4143 * intel_irq_uninstall - finilizes all irq handling
4144 * @dev_priv: i915 device instance
4145 *
4146 * This stops interrupt and hotplug handling and unregisters and frees all
4147 * resources acquired in the init functions.
4148 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004149void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4150{
Chris Wilson91c8a322016-07-05 10:40:23 +01004151 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004152 intel_hpd_cancel_work(dev_priv);
4153 dev_priv->pm.irqs_enabled = false;
4154}
4155
Daniel Vetterfca52a52014-09-30 10:56:45 +02004156/**
4157 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4158 * @dev_priv: i915 device instance
4159 *
4160 * This function is used to disable interrupts at runtime, both in the runtime
4161 * pm and the system suspend/resume code.
4162 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004163void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004164{
Chris Wilson91c8a322016-07-05 10:40:23 +01004165 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004166 dev_priv->pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004167 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004168}
4169
Daniel Vetterfca52a52014-09-30 10:56:45 +02004170/**
4171 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4172 * @dev_priv: i915 device instance
4173 *
4174 * This function is used to enable interrupts at runtime, both in the runtime
4175 * pm and the system suspend/resume code.
4176 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004177void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004178{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004179 dev_priv->pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004180 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4181 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004182}