blob: bd196252768780a530183b84787fea3eb9d868b9 [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
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300129#define GEN5_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
Paulo Zanoni337ba012014-04-01 15:37:16 -0300139/*
140 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
141 */
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300142static void gen5_assert_iir_is_zero(struct drm_i915_private *dev_priv, u32 reg)
143{
144 u32 val = I915_READ(reg);
145
146 if (val == 0)
147 return;
148
149 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
150 reg, val);
151 I915_WRITE(reg, 0xffffffff);
152 POSTING_READ(reg);
153 I915_WRITE(reg, 0xffffffff);
154 POSTING_READ(reg);
155}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300156
Paulo Zanoni35079892014-04-01 15:37:15 -0300157#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300158 gen5_assert_iir_is_zero(dev_priv, GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300159 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200160 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
161 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300162} while (0)
163
164#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300165 gen5_assert_iir_is_zero(dev_priv, type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300166 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200167 I915_WRITE(type##IMR, (imr_val)); \
168 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300169} while (0)
170
Imre Deakc9a9a262014-11-05 20:48:37 +0200171static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
172
Egbert Eich0706f172015-09-23 16:15:27 +0200173/* For display hotplug interrupt */
174static inline void
175i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
176 uint32_t mask,
177 uint32_t bits)
178{
179 uint32_t val;
180
181 assert_spin_locked(&dev_priv->irq_lock);
182 WARN_ON(bits & ~mask);
183
184 val = I915_READ(PORT_HOTPLUG_EN);
185 val &= ~mask;
186 val |= bits;
187 I915_WRITE(PORT_HOTPLUG_EN, val);
188}
189
190/**
191 * i915_hotplug_interrupt_update - update hotplug interrupt enable
192 * @dev_priv: driver private
193 * @mask: bits to update
194 * @bits: bits to enable
195 * NOTE: the HPD enable bits are modified both inside and outside
196 * of an interrupt context. To avoid that read-modify-write cycles
197 * interfer, these bits are protected by a spinlock. Since this
198 * function is usually not called from a context where the lock is
199 * held already, this function acquires the lock itself. A non-locking
200 * version is also available.
201 */
202void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
203 uint32_t mask,
204 uint32_t bits)
205{
206 spin_lock_irq(&dev_priv->irq_lock);
207 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
208 spin_unlock_irq(&dev_priv->irq_lock);
209}
210
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300211/**
212 * ilk_update_display_irq - update DEIMR
213 * @dev_priv: driver private
214 * @interrupt_mask: mask of interrupt bits to update
215 * @enabled_irq_mask: mask of interrupt bits to enable
216 */
217static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
218 uint32_t interrupt_mask,
219 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800220{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300221 uint32_t new_val;
222
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200223 assert_spin_locked(&dev_priv->irq_lock);
224
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300225 WARN_ON(enabled_irq_mask & ~interrupt_mask);
226
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700227 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300228 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300229
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300230 new_val = dev_priv->irq_mask;
231 new_val &= ~interrupt_mask;
232 new_val |= (~enabled_irq_mask & interrupt_mask);
233
234 if (new_val != dev_priv->irq_mask) {
235 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000236 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000237 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800238 }
239}
240
Daniel Vetter47339cd2014-09-30 10:56:46 +0200241void
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300242ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
243{
244 ilk_update_display_irq(dev_priv, mask, mask);
245}
246
247void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300248ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800249{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300250 ilk_update_display_irq(dev_priv, mask, 0);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800251}
252
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300253/**
254 * ilk_update_gt_irq - update GTIMR
255 * @dev_priv: driver private
256 * @interrupt_mask: mask of interrupt bits to update
257 * @enabled_irq_mask: mask of interrupt bits to enable
258 */
259static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
260 uint32_t interrupt_mask,
261 uint32_t enabled_irq_mask)
262{
263 assert_spin_locked(&dev_priv->irq_lock);
264
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100265 WARN_ON(enabled_irq_mask & ~interrupt_mask);
266
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700267 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300268 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300269
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300270 dev_priv->gt_irq_mask &= ~interrupt_mask;
271 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
272 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
273 POSTING_READ(GTIMR);
274}
275
Daniel Vetter480c8032014-07-16 09:49:40 +0200276void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300277{
278 ilk_update_gt_irq(dev_priv, mask, mask);
279}
280
Daniel Vetter480c8032014-07-16 09:49:40 +0200281void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300282{
283 ilk_update_gt_irq(dev_priv, mask, 0);
284}
285
Imre Deakb900b942014-11-05 20:48:48 +0200286static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
287{
288 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
289}
290
Imre Deaka72fbc32014-11-05 20:48:31 +0200291static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
292{
293 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
294}
295
Imre Deakb900b942014-11-05 20:48:48 +0200296static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
297{
298 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
299}
300
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300301/**
302 * snb_update_pm_irq - update GEN6_PMIMR
303 * @dev_priv: driver private
304 * @interrupt_mask: mask of interrupt bits to update
305 * @enabled_irq_mask: mask of interrupt bits to enable
306 */
307static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
308 uint32_t interrupt_mask,
309 uint32_t enabled_irq_mask)
310{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300311 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300312
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100313 WARN_ON(enabled_irq_mask & ~interrupt_mask);
314
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300315 assert_spin_locked(&dev_priv->irq_lock);
316
Paulo Zanoni605cd252013-08-06 18:57:15 -0300317 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300318 new_val &= ~interrupt_mask;
319 new_val |= (~enabled_irq_mask & interrupt_mask);
320
Paulo Zanoni605cd252013-08-06 18:57:15 -0300321 if (new_val != dev_priv->pm_irq_mask) {
322 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200323 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
324 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300325 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300326}
327
Daniel Vetter480c8032014-07-16 09:49:40 +0200328void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300329{
Imre Deak9939fba2014-11-20 23:01:47 +0200330 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
331 return;
332
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300333 snb_update_pm_irq(dev_priv, mask, mask);
334}
335
Imre Deak9939fba2014-11-20 23:01:47 +0200336static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
337 uint32_t mask)
338{
339 snb_update_pm_irq(dev_priv, mask, 0);
340}
341
Daniel Vetter480c8032014-07-16 09:49:40 +0200342void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300343{
Imre Deak9939fba2014-11-20 23:01:47 +0200344 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
345 return;
346
347 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300348}
349
Imre Deak3cc134e2014-11-19 15:30:03 +0200350void gen6_reset_rps_interrupts(struct drm_device *dev)
351{
352 struct drm_i915_private *dev_priv = dev->dev_private;
353 uint32_t reg = gen6_pm_iir(dev_priv);
354
355 spin_lock_irq(&dev_priv->irq_lock);
356 I915_WRITE(reg, dev_priv->pm_rps_events);
357 I915_WRITE(reg, dev_priv->pm_rps_events);
358 POSTING_READ(reg);
Imre Deak096fad92015-03-23 19:11:35 +0200359 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200360 spin_unlock_irq(&dev_priv->irq_lock);
361}
362
Imre Deakb900b942014-11-05 20:48:48 +0200363void gen6_enable_rps_interrupts(struct drm_device *dev)
364{
365 struct drm_i915_private *dev_priv = dev->dev_private;
366
367 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak78e68d32014-12-15 18:59:27 +0200368
Imre Deakb900b942014-11-05 20:48:48 +0200369 WARN_ON(dev_priv->rps.pm_iir);
Imre Deak3cc134e2014-11-19 15:30:03 +0200370 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200371 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200372 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
373 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200374 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200375
Imre Deakb900b942014-11-05 20:48:48 +0200376 spin_unlock_irq(&dev_priv->irq_lock);
377}
378
Imre Deak59d02a12014-12-19 19:33:26 +0200379u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
380{
381 /*
Imre Deakf24eeb12014-12-19 19:33:27 +0200382 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
Imre Deak59d02a12014-12-19 19:33:26 +0200383 * if GEN6_PM_UP_EI_EXPIRED is masked.
Imre Deakf24eeb12014-12-19 19:33:27 +0200384 *
385 * TODO: verify if this can be reproduced on VLV,CHV.
Imre Deak59d02a12014-12-19 19:33:26 +0200386 */
387 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
388 mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
389
390 if (INTEL_INFO(dev_priv)->gen >= 8)
391 mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
392
393 return mask;
394}
395
Imre Deakb900b942014-11-05 20:48:48 +0200396void gen6_disable_rps_interrupts(struct drm_device *dev)
397{
398 struct drm_i915_private *dev_priv = dev->dev_private;
399
Imre Deakd4d70aa2014-11-19 15:30:04 +0200400 spin_lock_irq(&dev_priv->irq_lock);
401 dev_priv->rps.interrupts_enabled = false;
402 spin_unlock_irq(&dev_priv->irq_lock);
403
404 cancel_work_sync(&dev_priv->rps.work);
405
Imre Deak9939fba2014-11-20 23:01:47 +0200406 spin_lock_irq(&dev_priv->irq_lock);
407
Imre Deak59d02a12014-12-19 19:33:26 +0200408 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200409
410 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200411 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
412 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200413
414 spin_unlock_irq(&dev_priv->irq_lock);
415
416 synchronize_irq(dev->irq);
Imre Deakb900b942014-11-05 20:48:48 +0200417}
418
Ben Widawsky09610212014-05-15 20:58:08 +0300419/**
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300420 * bdw_update_port_irq - update DE port interrupt
421 * @dev_priv: driver private
422 * @interrupt_mask: mask of interrupt bits to update
423 * @enabled_irq_mask: mask of interrupt bits to enable
424 */
425static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
426 uint32_t interrupt_mask,
427 uint32_t enabled_irq_mask)
428{
429 uint32_t new_val;
430 uint32_t old_val;
431
432 assert_spin_locked(&dev_priv->irq_lock);
433
434 WARN_ON(enabled_irq_mask & ~interrupt_mask);
435
436 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
437 return;
438
439 old_val = I915_READ(GEN8_DE_PORT_IMR);
440
441 new_val = old_val;
442 new_val &= ~interrupt_mask;
443 new_val |= (~enabled_irq_mask & interrupt_mask);
444
445 if (new_val != old_val) {
446 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
447 POSTING_READ(GEN8_DE_PORT_IMR);
448 }
449}
450
451/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200452 * ibx_display_interrupt_update - update SDEIMR
453 * @dev_priv: driver private
454 * @interrupt_mask: mask of interrupt bits to update
455 * @enabled_irq_mask: mask of interrupt bits to enable
456 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200457void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
458 uint32_t interrupt_mask,
459 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200460{
461 uint32_t sdeimr = I915_READ(SDEIMR);
462 sdeimr &= ~interrupt_mask;
463 sdeimr |= (~enabled_irq_mask & interrupt_mask);
464
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100465 WARN_ON(enabled_irq_mask & ~interrupt_mask);
466
Daniel Vetterfee884e2013-07-04 23:35:21 +0200467 assert_spin_locked(&dev_priv->irq_lock);
468
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700469 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300470 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300471
Daniel Vetterfee884e2013-07-04 23:35:21 +0200472 I915_WRITE(SDEIMR, sdeimr);
473 POSTING_READ(SDEIMR);
474}
Paulo Zanoni86642812013-04-12 17:57:57 -0300475
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100476static void
Imre Deak755e9012014-02-10 18:42:47 +0200477__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
478 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800479{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200480 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200481 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800482
Daniel Vetterb79480b2013-06-27 17:52:10 +0200483 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200484 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200485
Ville Syrjälä04feced2014-04-03 13:28:33 +0300486 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
487 status_mask & ~PIPESTAT_INT_STATUS_MASK,
488 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
489 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200490 return;
491
492 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200493 return;
494
Imre Deak91d181d2014-02-10 18:42:49 +0200495 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
496
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200497 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200498 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200499 I915_WRITE(reg, pipestat);
500 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800501}
502
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100503static void
Imre Deak755e9012014-02-10 18:42:47 +0200504__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
505 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800506{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200507 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200508 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800509
Daniel Vetterb79480b2013-06-27 17:52:10 +0200510 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200511 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200512
Ville Syrjälä04feced2014-04-03 13:28:33 +0300513 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
514 status_mask & ~PIPESTAT_INT_STATUS_MASK,
515 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
516 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200517 return;
518
Imre Deak755e9012014-02-10 18:42:47 +0200519 if ((pipestat & enable_mask) == 0)
520 return;
521
Imre Deak91d181d2014-02-10 18:42:49 +0200522 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
523
Imre Deak755e9012014-02-10 18:42:47 +0200524 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200525 I915_WRITE(reg, pipestat);
526 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800527}
528
Imre Deak10c59c52014-02-10 18:42:48 +0200529static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
530{
531 u32 enable_mask = status_mask << 16;
532
533 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300534 * On pipe A we don't support the PSR interrupt yet,
535 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200536 */
537 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
538 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300539 /*
540 * On pipe B and C we don't support the PSR interrupt yet, on pipe
541 * A the same bit is for perf counters which we don't use either.
542 */
543 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
544 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200545
546 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
547 SPRITE0_FLIP_DONE_INT_EN_VLV |
548 SPRITE1_FLIP_DONE_INT_EN_VLV);
549 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
550 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
551 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
552 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
553
554 return enable_mask;
555}
556
Imre Deak755e9012014-02-10 18:42:47 +0200557void
558i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
559 u32 status_mask)
560{
561 u32 enable_mask;
562
Imre Deak10c59c52014-02-10 18:42:48 +0200563 if (IS_VALLEYVIEW(dev_priv->dev))
564 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
565 status_mask);
566 else
567 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200568 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
569}
570
571void
572i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
573 u32 status_mask)
574{
575 u32 enable_mask;
576
Imre Deak10c59c52014-02-10 18:42:48 +0200577 if (IS_VALLEYVIEW(dev_priv->dev))
578 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
579 status_mask);
580 else
581 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200582 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
583}
584
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000585/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300586 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Javier Martinez Canillas468f9d22015-10-08 09:54:44 +0200587 * @dev: drm device
Zhao Yakui01c66882009-10-28 05:10:00 +0000588 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300589static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000590{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300591 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000592
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300593 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
594 return;
595
Daniel Vetter13321782014-09-15 14:55:29 +0200596 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000597
Imre Deak755e9012014-02-10 18:42:47 +0200598 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300599 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200600 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200601 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000602
Daniel Vetter13321782014-09-15 14:55:29 +0200603 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000604}
605
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300606/*
607 * This timing diagram depicts the video signal in and
608 * around the vertical blanking period.
609 *
610 * Assumptions about the fictitious mode used in this example:
611 * vblank_start >= 3
612 * vsync_start = vblank_start + 1
613 * vsync_end = vblank_start + 2
614 * vtotal = vblank_start + 3
615 *
616 * start of vblank:
617 * latch double buffered registers
618 * increment frame counter (ctg+)
619 * generate start of vblank interrupt (gen4+)
620 * |
621 * | frame start:
622 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
623 * | may be shifted forward 1-3 extra lines via PIPECONF
624 * | |
625 * | | start of vsync:
626 * | | generate vsync interrupt
627 * | | |
628 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
629 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
630 * ----va---> <-----------------vb--------------------> <--------va-------------
631 * | | <----vs-----> |
632 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
633 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
634 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
635 * | | |
636 * last visible pixel first visible pixel
637 * | increment frame counter (gen3/4)
638 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
639 *
640 * x = horizontal active
641 * _ = horizontal blanking
642 * hs = horizontal sync
643 * va = vertical active
644 * vb = vertical blanking
645 * vs = vertical sync
646 * vbs = vblank_start (number)
647 *
648 * Summary:
649 * - most events happen at the start of horizontal sync
650 * - frame start happens at the start of horizontal blank, 1-4 lines
651 * (depending on PIPECONF settings) after the start of vblank
652 * - gen3/4 pixel and frame counter are synchronized with the start
653 * of horizontal active on the first line of vertical active
654 */
655
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300656static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
657{
658 /* Gen2 doesn't have a hardware frame counter */
659 return 0;
660}
661
Keith Packard42f52ef2008-10-18 19:39:29 -0700662/* Called from drm generic code, passed a 'crtc', which
663 * we use as a pipe index
664 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700665static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700666{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300667 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700668 unsigned long high_frame;
669 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300670 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100671 struct intel_crtc *intel_crtc =
672 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200673 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700674
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100675 htotal = mode->crtc_htotal;
676 hsync_start = mode->crtc_hsync_start;
677 vbl_start = mode->crtc_vblank_start;
678 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
679 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300680
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300681 /* Convert to pixel count */
682 vbl_start *= htotal;
683
684 /* Start of vblank event occurs at start of hsync */
685 vbl_start -= htotal - hsync_start;
686
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800687 high_frame = PIPEFRAME(pipe);
688 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100689
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700690 /*
691 * High & low register fields aren't synchronized, so make sure
692 * we get a low value that's stable across two reads of the high
693 * register.
694 */
695 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100696 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300697 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100698 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700699 } while (high1 != high2);
700
Chris Wilson5eddb702010-09-11 13:48:45 +0100701 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300702 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100703 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300704
705 /*
706 * The frame counter increments at beginning of active.
707 * Cook up a vblank counter by also checking the pixel
708 * counter against vblank start.
709 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200710 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700711}
712
Ville Syrjäläfd8f5072015-09-18 20:03:42 +0300713static u32 g4x_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800714{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300715 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800716
Ville Syrjälä649636e2015-09-22 19:50:01 +0300717 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800718}
719
Mario Kleinerad3543e2013-10-30 05:13:08 +0100720/* raw reads, only for fast reads of display block, no need for forcewake etc. */
721#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100722
Ville Syrjäläa225f072014-04-29 13:35:45 +0300723static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
724{
725 struct drm_device *dev = crtc->base.dev;
726 struct drm_i915_private *dev_priv = dev->dev_private;
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200727 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300728 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300729 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300730
Ville Syrjälä80715b22014-05-15 20:23:23 +0300731 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300732 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
733 vtotal /= 2;
734
735 if (IS_GEN2(dev))
736 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
737 else
738 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
739
740 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -0700741 * On HSW, the DSL reg (0x70000) appears to return 0 if we
742 * read it just before the start of vblank. So try it again
743 * so we don't accidentally end up spanning a vblank frame
744 * increment, causing the pipe_update_end() code to squak at us.
745 *
746 * The nature of this problem means we can't simply check the ISR
747 * bit and return the vblank start value; nor can we use the scanline
748 * debug register in the transcoder as it appears to have the same
749 * problem. We may need to extend this to include other platforms,
750 * but so far testing only shows the problem on HSW.
751 */
752 if (IS_HASWELL(dev) && !position) {
753 int i, temp;
754
755 for (i = 0; i < 100; i++) {
756 udelay(1);
757 temp = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) &
758 DSL_LINEMASK_GEN3;
759 if (temp != position) {
760 position = temp;
761 break;
762 }
763 }
764 }
765
766 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300767 * See update_scanline_offset() for the details on the
768 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300769 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300770 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300771}
772
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700773static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200774 unsigned int flags, int *vpos, int *hpos,
Ville Syrjälä3bb403b2015-09-14 22:43:44 +0300775 ktime_t *stime, ktime_t *etime,
776 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100777{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300778 struct drm_i915_private *dev_priv = dev->dev_private;
779 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
780 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300781 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300782 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100783 bool in_vbl = true;
784 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100785 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100786
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200787 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100788 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800789 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100790 return 0;
791 }
792
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300793 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300794 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300795 vtotal = mode->crtc_vtotal;
796 vbl_start = mode->crtc_vblank_start;
797 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100798
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200799 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
800 vbl_start = DIV_ROUND_UP(vbl_start, 2);
801 vbl_end /= 2;
802 vtotal /= 2;
803 }
804
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300805 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
806
Mario Kleinerad3543e2013-10-30 05:13:08 +0100807 /*
808 * Lock uncore.lock, as we will do multiple timing critical raw
809 * register reads, potentially with preemption disabled, so the
810 * following code must not block on uncore.lock.
811 */
812 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300813
Mario Kleinerad3543e2013-10-30 05:13:08 +0100814 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
815
816 /* Get optional system timestamp before query. */
817 if (stime)
818 *stime = ktime_get();
819
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300820 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100821 /* No obvious pixelcount register. Only query vertical
822 * scanout position from Display scan line register.
823 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300824 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100825 } else {
826 /* Have access to pixelcount since start of frame.
827 * We can split this into vertical and horizontal
828 * scanout position.
829 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100830 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100831
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300832 /* convert to pixel counts */
833 vbl_start *= htotal;
834 vbl_end *= htotal;
835 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300836
837 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300838 * In interlaced modes, the pixel counter counts all pixels,
839 * so one field will have htotal more pixels. In order to avoid
840 * the reported position from jumping backwards when the pixel
841 * counter is beyond the length of the shorter field, just
842 * clamp the position the length of the shorter field. This
843 * matches how the scanline counter based position works since
844 * the scanline counter doesn't count the two half lines.
845 */
846 if (position >= vtotal)
847 position = vtotal - 1;
848
849 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300850 * Start of vblank interrupt is triggered at start of hsync,
851 * just prior to the first active line of vblank. However we
852 * consider lines to start at the leading edge of horizontal
853 * active. So, should we get here before we've crossed into
854 * the horizontal active of the first line in vblank, we would
855 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
856 * always add htotal-hsync_start to the current pixel position.
857 */
858 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300859 }
860
Mario Kleinerad3543e2013-10-30 05:13:08 +0100861 /* Get optional system timestamp after query. */
862 if (etime)
863 *etime = ktime_get();
864
865 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
866
867 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
868
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300869 in_vbl = position >= vbl_start && position < vbl_end;
870
871 /*
872 * While in vblank, position will be negative
873 * counting up towards 0 at vbl_end. And outside
874 * vblank, position will be positive counting
875 * up since vbl_end.
876 */
877 if (position >= vbl_start)
878 position -= vbl_end;
879 else
880 position += vtotal - vbl_end;
881
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300882 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300883 *vpos = position;
884 *hpos = 0;
885 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100886 *vpos = position / htotal;
887 *hpos = position - (*vpos * htotal);
888 }
889
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100890 /* In vblank? */
891 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200892 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100893
894 return ret;
895}
896
Ville Syrjäläa225f072014-04-29 13:35:45 +0300897int intel_get_crtc_scanline(struct intel_crtc *crtc)
898{
899 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
900 unsigned long irqflags;
901 int position;
902
903 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
904 position = __intel_get_crtc_scanline(crtc);
905 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
906
907 return position;
908}
909
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700910static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100911 int *max_error,
912 struct timeval *vblank_time,
913 unsigned flags)
914{
Chris Wilson4041b852011-01-22 10:07:56 +0000915 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100916
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700917 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000918 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100919 return -EINVAL;
920 }
921
922 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000923 crtc = intel_get_crtc_for_pipe(dev, pipe);
924 if (crtc == NULL) {
925 DRM_ERROR("Invalid crtc %d\n", pipe);
926 return -EINVAL;
927 }
928
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200929 if (!crtc->hwmode.crtc_clock) {
Chris Wilson4041b852011-01-22 10:07:56 +0000930 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
931 return -EBUSY;
932 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100933
934 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000935 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
936 vblank_time, flags,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200937 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100938}
939
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200940static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800941{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300942 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000943 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200944 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200945
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200946 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800947
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200948 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
949
Daniel Vetter20e4d402012-08-08 23:35:39 +0200950 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200951
Jesse Barnes7648fa92010-05-20 14:28:11 -0700952 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000953 busy_up = I915_READ(RCPREVBSYTUPAVG);
954 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800955 max_avg = I915_READ(RCBMAXAVG);
956 min_avg = I915_READ(RCBMINAVG);
957
958 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000959 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200960 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
961 new_delay = dev_priv->ips.cur_delay - 1;
962 if (new_delay < dev_priv->ips.max_delay)
963 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000964 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200965 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
966 new_delay = dev_priv->ips.cur_delay + 1;
967 if (new_delay > dev_priv->ips.min_delay)
968 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800969 }
970
Jesse Barnes7648fa92010-05-20 14:28:11 -0700971 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200972 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800973
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200974 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200975
Jesse Barnesf97108d2010-01-29 11:27:07 -0800976 return;
977}
978
Chris Wilson74cdb332015-04-07 16:21:05 +0100979static void notify_ring(struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +0100980{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +0100981 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +0000982 return;
983
John Harrisonbcfcc8b2014-12-05 13:49:36 +0000984 trace_i915_gem_request_notify(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000985
Chris Wilson549f7362010-10-19 11:19:32 +0100986 wake_up_all(&ring->irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +0100987}
988
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000989static void vlv_c0_read(struct drm_i915_private *dev_priv,
990 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400991{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000992 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
993 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
994 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400995}
996
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000997static bool vlv_c0_above(struct drm_i915_private *dev_priv,
998 const struct intel_rps_ei *old,
999 const struct intel_rps_ei *now,
1000 int threshold)
Deepak S31685c22014-07-03 17:33:01 -04001001{
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001002 u64 time, c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001003 unsigned int mul = 100;
Deepak S31685c22014-07-03 17:33:01 -04001004
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001005 if (old->cz_clock == 0)
1006 return false;
Deepak S31685c22014-07-03 17:33:01 -04001007
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001008 if (I915_READ(VLV_COUNTER_CONTROL) & VLV_COUNT_RANGE_HIGH)
1009 mul <<= 8;
1010
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001011 time = now->cz_clock - old->cz_clock;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001012 time *= threshold * dev_priv->czclk_freq;
Deepak S31685c22014-07-03 17:33:01 -04001013
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001014 /* Workload can be split between render + media, e.g. SwapBuffers
1015 * being blitted in X after being rendered in mesa. To account for
1016 * this we need to combine both engines into our activity counter.
1017 */
1018 c0 = now->render_c0 - old->render_c0;
1019 c0 += now->media_c0 - old->media_c0;
Ville Syrjälä7bad74d2015-09-24 23:29:20 +03001020 c0 *= mul * VLV_CZ_CLOCK_TO_MILLI_SEC;
Deepak S31685c22014-07-03 17:33:01 -04001021
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001022 return c0 >= time;
1023}
Deepak S31685c22014-07-03 17:33:01 -04001024
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001025void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1026{
1027 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
1028 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001029}
1030
1031static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1032{
1033 struct intel_rps_ei now;
1034 u32 events = 0;
1035
Chris Wilson6f4b12f82015-03-18 09:48:23 +00001036 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001037 return 0;
1038
1039 vlv_c0_read(dev_priv, &now);
1040 if (now.cz_clock == 0)
1041 return 0;
Deepak S31685c22014-07-03 17:33:01 -04001042
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001043 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
1044 if (!vlv_c0_above(dev_priv,
1045 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001046 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001047 events |= GEN6_PM_RP_DOWN_THRESHOLD;
1048 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -04001049 }
1050
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001051 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
1052 if (vlv_c0_above(dev_priv,
1053 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +01001054 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001055 events |= GEN6_PM_RP_UP_THRESHOLD;
1056 dev_priv->rps.up_ei = now;
1057 }
1058
1059 return events;
Deepak S31685c22014-07-03 17:33:01 -04001060}
1061
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001062static bool any_waiters(struct drm_i915_private *dev_priv)
1063{
1064 struct intel_engine_cs *ring;
1065 int i;
1066
1067 for_each_ring(ring, dev_priv, i)
1068 if (ring->irq_refcount)
1069 return true;
1070
1071 return false;
1072}
1073
Ben Widawsky4912d042011-04-25 11:25:20 -07001074static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001075{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001076 struct drm_i915_private *dev_priv =
1077 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001078 bool client_boost;
1079 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001080 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001081
Daniel Vetter59cdb632013-07-04 23:35:28 +02001082 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001083 /* Speed up work cancelation during disabling rps interrupts. */
1084 if (!dev_priv->rps.interrupts_enabled) {
1085 spin_unlock_irq(&dev_priv->irq_lock);
1086 return;
1087 }
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001088 pm_iir = dev_priv->rps.pm_iir;
1089 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001090 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1091 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001092 client_boost = dev_priv->rps.client_boost;
1093 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001094 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001095
Paulo Zanoni60611c12013-08-15 11:50:01 -03001096 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301097 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001098
Chris Wilson8d3afd72015-05-21 21:01:47 +01001099 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001100 return;
1101
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001102 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001103
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001104 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1105
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001106 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001107 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001108 min = dev_priv->rps.min_freq_softlimit;
1109 max = dev_priv->rps.max_freq_softlimit;
1110
1111 if (client_boost) {
1112 new_delay = dev_priv->rps.max_freq_softlimit;
1113 adj = 0;
1114 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001115 if (adj > 0)
1116 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001117 else /* CHV needs even encode values */
1118 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001119 /*
1120 * For better performance, jump directly
1121 * to RPe if we're below it.
1122 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001123 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001124 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001125 adj = 0;
1126 }
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001127 } else if (any_waiters(dev_priv)) {
1128 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001129 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001130 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1131 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001132 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001133 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001134 adj = 0;
1135 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1136 if (adj < 0)
1137 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001138 else /* CHV needs even encode values */
1139 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001140 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001141 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001142 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001143
Chris Wilsonedcf2842015-04-07 16:20:29 +01001144 dev_priv->rps.last_adj = adj;
1145
Ben Widawsky79249632012-09-07 19:43:42 -07001146 /* sysfs frequency interfaces may have snuck in while servicing the
1147 * interrupt
1148 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001149 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001150 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301151
Ville Syrjäläffe02b42015-02-02 19:09:50 +02001152 intel_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001153
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001154 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001155}
1156
Ben Widawskye3689192012-05-25 16:56:22 -07001157
1158/**
1159 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1160 * occurred.
1161 * @work: workqueue struct
1162 *
1163 * Doesn't actually do anything except notify userspace. As a consequence of
1164 * this event, userspace should try to remap the bad rows since statistically
1165 * it is likely the same row is more likely to go bad again.
1166 */
1167static void ivybridge_parity_work(struct work_struct *work)
1168{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001169 struct drm_i915_private *dev_priv =
1170 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001171 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001172 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001173 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001174 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001175
1176 /* We must turn off DOP level clock gating to access the L3 registers.
1177 * In order to prevent a get/put style interface, acquire struct mutex
1178 * any time we access those registers.
1179 */
1180 mutex_lock(&dev_priv->dev->struct_mutex);
1181
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001182 /* If we've screwed up tracking, just let the interrupt fire again */
1183 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1184 goto out;
1185
Ben Widawskye3689192012-05-25 16:56:22 -07001186 misccpctl = I915_READ(GEN7_MISCCPCTL);
1187 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1188 POSTING_READ(GEN7_MISCCPCTL);
1189
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001190 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1191 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001192
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001193 slice--;
1194 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1195 break;
1196
1197 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1198
1199 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1200
1201 error_status = I915_READ(reg);
1202 row = GEN7_PARITY_ERROR_ROW(error_status);
1203 bank = GEN7_PARITY_ERROR_BANK(error_status);
1204 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1205
1206 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1207 POSTING_READ(reg);
1208
1209 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1210 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1211 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1212 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1213 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1214 parity_event[5] = NULL;
1215
Dave Airlie5bdebb12013-10-11 14:07:25 +10001216 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001217 KOBJ_CHANGE, parity_event);
1218
1219 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1220 slice, row, bank, subbank);
1221
1222 kfree(parity_event[4]);
1223 kfree(parity_event[3]);
1224 kfree(parity_event[2]);
1225 kfree(parity_event[1]);
1226 }
Ben Widawskye3689192012-05-25 16:56:22 -07001227
1228 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1229
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001230out:
1231 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001232 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001233 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001234 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001235
1236 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001237}
1238
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001239static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001240{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001241 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001242
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001243 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001244 return;
1245
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001246 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001247 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001248 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001249
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001250 iir &= GT_PARITY_ERROR(dev);
1251 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1252 dev_priv->l3_parity.which_slice |= 1 << 1;
1253
1254 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1255 dev_priv->l3_parity.which_slice |= 1 << 0;
1256
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001257 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001258}
1259
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001260static void ilk_gt_irq_handler(struct drm_device *dev,
1261 struct drm_i915_private *dev_priv,
1262 u32 gt_iir)
1263{
1264 if (gt_iir &
1265 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Chris Wilson74cdb332015-04-07 16:21:05 +01001266 notify_ring(&dev_priv->ring[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001267 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001268 notify_ring(&dev_priv->ring[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001269}
1270
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001271static void snb_gt_irq_handler(struct drm_device *dev,
1272 struct drm_i915_private *dev_priv,
1273 u32 gt_iir)
1274{
1275
Ben Widawskycc609d52013-05-28 19:22:29 -07001276 if (gt_iir &
1277 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Chris Wilson74cdb332015-04-07 16:21:05 +01001278 notify_ring(&dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001279 if (gt_iir & GT_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001280 notify_ring(&dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001281 if (gt_iir & GT_BLT_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001282 notify_ring(&dev_priv->ring[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001283
Ben Widawskycc609d52013-05-28 19:22:29 -07001284 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1285 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001286 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1287 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001288
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001289 if (gt_iir & GT_PARITY_ERROR(dev))
1290 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001291}
1292
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001293static __always_inline void
Daniel Vettere4ba99b2015-10-21 10:20:33 +02001294gen8_cs_irq_handler(struct intel_engine_cs *ring, u32 iir, int test_shift)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001295{
1296 if (iir & (GT_RENDER_USER_INTERRUPT << test_shift))
1297 notify_ring(ring);
1298 if (iir & (GT_CONTEXT_SWITCH_INTERRUPT << test_shift))
1299 intel_lrc_irq_handler(ring);
1300}
1301
Chris Wilson74cdb332015-04-07 16:21:05 +01001302static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
Ben Widawskyabd58f02013-11-02 21:07:09 -07001303 u32 master_ctl)
1304{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001305 irqreturn_t ret = IRQ_NONE;
1306
1307 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Nick Hoath5dd280b2015-10-20 10:23:51 +01001308 u32 iir = I915_READ_FW(GEN8_GT_IIR(0));
1309 if (iir) {
1310 I915_WRITE_FW(GEN8_GT_IIR(0), iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001311 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001312
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001313 gen8_cs_irq_handler(&dev_priv->ring[RCS],
1314 iir, GEN8_RCS_IRQ_SHIFT);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001315
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001316 gen8_cs_irq_handler(&dev_priv->ring[BCS],
1317 iir, GEN8_BCS_IRQ_SHIFT);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001318 } else
1319 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1320 }
1321
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001322 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Nick Hoath5dd280b2015-10-20 10:23:51 +01001323 u32 iir = I915_READ_FW(GEN8_GT_IIR(1));
1324 if (iir) {
1325 I915_WRITE_FW(GEN8_GT_IIR(1), iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001326 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001327
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001328 gen8_cs_irq_handler(&dev_priv->ring[VCS],
1329 iir, GEN8_VCS1_IRQ_SHIFT);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001330
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001331 gen8_cs_irq_handler(&dev_priv->ring[VCS2],
1332 iir, GEN8_VCS2_IRQ_SHIFT);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001333 } else
1334 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1335 }
1336
Chris Wilson74cdb332015-04-07 16:21:05 +01001337 if (master_ctl & GEN8_GT_VECS_IRQ) {
Nick Hoath5dd280b2015-10-20 10:23:51 +01001338 u32 iir = I915_READ_FW(GEN8_GT_IIR(3));
1339 if (iir) {
1340 I915_WRITE_FW(GEN8_GT_IIR(3), iir);
Chris Wilson74cdb332015-04-07 16:21:05 +01001341 ret = IRQ_HANDLED;
1342
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001343 gen8_cs_irq_handler(&dev_priv->ring[VECS],
1344 iir, GEN8_VECS_IRQ_SHIFT);
Chris Wilson74cdb332015-04-07 16:21:05 +01001345 } else
1346 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1347 }
1348
Ben Widawsky09610212014-05-15 20:58:08 +03001349 if (master_ctl & GEN8_GT_PM_IRQ) {
Nick Hoath5dd280b2015-10-20 10:23:51 +01001350 u32 iir = I915_READ_FW(GEN8_GT_IIR(2));
1351 if (iir & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001352 I915_WRITE_FW(GEN8_GT_IIR(2),
Nick Hoath5dd280b2015-10-20 10:23:51 +01001353 iir & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001354 ret = IRQ_HANDLED;
Nick Hoath5dd280b2015-10-20 10:23:51 +01001355 gen6_rps_irq_handler(dev_priv, iir);
Ben Widawsky09610212014-05-15 20:58:08 +03001356 } else
1357 DRM_ERROR("The master control interrupt lied (PM)!\n");
1358 }
1359
Ben Widawskyabd58f02013-11-02 21:07:09 -07001360 return ret;
1361}
1362
Imre Deak63c88d22015-07-20 14:43:39 -07001363static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1364{
1365 switch (port) {
1366 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001367 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001368 case PORT_B:
1369 return val & PORTB_HOTPLUG_LONG_DETECT;
1370 case PORT_C:
1371 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001372 default:
1373 return false;
1374 }
1375}
1376
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001377static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1378{
1379 switch (port) {
1380 case PORT_E:
1381 return val & PORTE_HOTPLUG_LONG_DETECT;
1382 default:
1383 return false;
1384 }
1385}
1386
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001387static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1388{
1389 switch (port) {
1390 case PORT_A:
1391 return val & PORTA_HOTPLUG_LONG_DETECT;
1392 case PORT_B:
1393 return val & PORTB_HOTPLUG_LONG_DETECT;
1394 case PORT_C:
1395 return val & PORTC_HOTPLUG_LONG_DETECT;
1396 case PORT_D:
1397 return val & PORTD_HOTPLUG_LONG_DETECT;
1398 default:
1399 return false;
1400 }
1401}
1402
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001403static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1404{
1405 switch (port) {
1406 case PORT_A:
1407 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1408 default:
1409 return false;
1410 }
1411}
1412
Jani Nikula676574d2015-05-28 15:43:53 +03001413static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001414{
1415 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001416 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001417 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001418 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001419 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001420 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001421 return val & PORTD_HOTPLUG_LONG_DETECT;
1422 default:
1423 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001424 }
1425}
1426
Jani Nikula676574d2015-05-28 15:43:53 +03001427static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001428{
1429 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001430 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001431 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001432 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001433 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001434 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001435 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1436 default:
1437 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001438 }
1439}
1440
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001441/*
1442 * Get a bit mask of pins that have triggered, and which ones may be long.
1443 * This can be called multiple times with the same masks to accumulate
1444 * hotplug detection results from several registers.
1445 *
1446 * Note that the caller is expected to zero out the masks initially.
1447 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001448static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001449 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001450 const u32 hpd[HPD_NUM_PINS],
1451 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001452{
Jani Nikula8c841e52015-06-18 13:06:17 +03001453 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001454 int i;
1455
Jani Nikula676574d2015-05-28 15:43:53 +03001456 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001457 if ((hpd[i] & hotplug_trigger) == 0)
1458 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001459
Jani Nikula8c841e52015-06-18 13:06:17 +03001460 *pin_mask |= BIT(i);
1461
Imre Deakcc24fcd2015-07-21 15:32:45 -07001462 if (!intel_hpd_pin_to_port(i, &port))
1463 continue;
1464
Imre Deakfd63e2a2015-07-21 15:32:44 -07001465 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001466 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001467 }
1468
1469 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1470 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1471
1472}
1473
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001474static void gmbus_irq_handler(struct drm_device *dev)
1475{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001476 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001477
Daniel Vetter28c70f12012-12-01 13:53:45 +01001478 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001479}
1480
Daniel Vetterce99c252012-12-01 13:53:47 +01001481static void dp_aux_irq_handler(struct drm_device *dev)
1482{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001483 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001484
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001485 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001486}
1487
Shuang He8bf1e9f2013-10-15 18:55:27 +01001488#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001489static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1490 uint32_t crc0, uint32_t crc1,
1491 uint32_t crc2, uint32_t crc3,
1492 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001493{
1494 struct drm_i915_private *dev_priv = dev->dev_private;
1495 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1496 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001497 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001498
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001499 spin_lock(&pipe_crc->lock);
1500
Damien Lespiau0c912c72013-10-15 18:55:37 +01001501 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001502 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001503 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001504 return;
1505 }
1506
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001507 head = pipe_crc->head;
1508 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001509
1510 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001511 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001512 DRM_ERROR("CRC buffer overflowing\n");
1513 return;
1514 }
1515
1516 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001517
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001518 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001519 entry->crc[0] = crc0;
1520 entry->crc[1] = crc1;
1521 entry->crc[2] = crc2;
1522 entry->crc[3] = crc3;
1523 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001524
1525 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001526 pipe_crc->head = head;
1527
1528 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001529
1530 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001531}
Daniel Vetter277de952013-10-18 16:37:07 +02001532#else
1533static inline void
1534display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1535 uint32_t crc0, uint32_t crc1,
1536 uint32_t crc2, uint32_t crc3,
1537 uint32_t crc4) {}
1538#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001539
Daniel Vetter277de952013-10-18 16:37:07 +02001540
1541static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001542{
1543 struct drm_i915_private *dev_priv = dev->dev_private;
1544
Daniel Vetter277de952013-10-18 16:37:07 +02001545 display_pipe_crc_irq_handler(dev, pipe,
1546 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1547 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001548}
1549
Daniel Vetter277de952013-10-18 16:37:07 +02001550static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001551{
1552 struct drm_i915_private *dev_priv = dev->dev_private;
1553
Daniel Vetter277de952013-10-18 16:37:07 +02001554 display_pipe_crc_irq_handler(dev, pipe,
1555 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1556 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1557 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1558 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1559 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001560}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001561
Daniel Vetter277de952013-10-18 16:37:07 +02001562static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001563{
1564 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001565 uint32_t res1, res2;
1566
1567 if (INTEL_INFO(dev)->gen >= 3)
1568 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1569 else
1570 res1 = 0;
1571
1572 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1573 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1574 else
1575 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001576
Daniel Vetter277de952013-10-18 16:37:07 +02001577 display_pipe_crc_irq_handler(dev, pipe,
1578 I915_READ(PIPE_CRC_RES_RED(pipe)),
1579 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1580 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1581 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001582}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001583
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001584/* The RPS events need forcewake, so we add them to a work queue and mask their
1585 * IMR bits until the work is done. Other interrupts can be processed without
1586 * the work queue. */
1587static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001588{
Deepak Sa6706b42014-03-15 20:23:22 +05301589 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001590 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001591 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001592 if (dev_priv->rps.interrupts_enabled) {
1593 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1594 queue_work(dev_priv->wq, &dev_priv->rps.work);
1595 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001596 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001597 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001598
Imre Deakc9a9a262014-11-05 20:48:37 +02001599 if (INTEL_INFO(dev_priv)->gen >= 8)
1600 return;
1601
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001602 if (HAS_VEBOX(dev_priv->dev)) {
1603 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001604 notify_ring(&dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001605
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001606 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1607 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001608 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001609}
1610
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001611static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1612{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001613 if (!drm_handle_vblank(dev, pipe))
1614 return false;
1615
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001616 return true;
1617}
1618
Imre Deakc1874ed2014-02-04 21:35:46 +02001619static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1620{
1621 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001622 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001623 int pipe;
1624
Imre Deak58ead0d2014-02-04 21:35:47 +02001625 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01001626 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001627 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001628 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001629
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001630 /*
1631 * PIPESTAT bits get signalled even when the interrupt is
1632 * disabled with the mask bits, and some of the status bits do
1633 * not generate interrupts at all (like the underrun bit). Hence
1634 * we need to be careful that we only handle what we want to
1635 * handle.
1636 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001637
1638 /* fifo underruns are filterered in the underrun handler. */
1639 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001640
1641 switch (pipe) {
1642 case PIPE_A:
1643 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1644 break;
1645 case PIPE_B:
1646 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1647 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001648 case PIPE_C:
1649 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1650 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001651 }
1652 if (iir & iir_bit)
1653 mask |= dev_priv->pipestat_irq_mask[pipe];
1654
1655 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001656 continue;
1657
1658 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001659 mask |= PIPESTAT_INT_ENABLE_MASK;
1660 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001661
1662 /*
1663 * Clear the PIPE*STAT regs before the IIR
1664 */
Imre Deak91d181d2014-02-10 18:42:49 +02001665 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1666 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001667 I915_WRITE(reg, pipe_stats[pipe]);
1668 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001669 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001670
Damien Lespiau055e3932014-08-18 13:49:10 +01001671 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001672 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1673 intel_pipe_handle_vblank(dev, pipe))
1674 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001675
Imre Deak579a9b02014-02-04 21:35:48 +02001676 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001677 intel_prepare_page_flip(dev, pipe);
1678 intel_finish_page_flip(dev, pipe);
1679 }
1680
1681 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1682 i9xx_pipe_crc_irq_handler(dev, pipe);
1683
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001684 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1685 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001686 }
1687
1688 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1689 gmbus_irq_handler(dev);
1690}
1691
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001692static void i9xx_hpd_irq_handler(struct drm_device *dev)
1693{
1694 struct drm_i915_private *dev_priv = dev->dev_private;
1695 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001696 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001697
Jani Nikula0d2e4292015-05-27 15:03:39 +03001698 if (!hotplug_status)
1699 return;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001700
Jani Nikula0d2e4292015-05-27 15:03:39 +03001701 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1702 /*
1703 * Make sure hotplug status is cleared before we clear IIR, or else we
1704 * may miss hotplug events.
1705 */
1706 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001707
Jani Nikula0d2e4292015-05-27 15:03:39 +03001708 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
1709 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001710
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001711 if (hotplug_trigger) {
1712 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1713 hotplug_trigger, hpd_status_g4x,
1714 i9xx_port_hotplug_long_detect);
1715
1716 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1717 }
Jani Nikula369712e2015-05-27 15:03:40 +03001718
1719 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1720 dp_aux_irq_handler(dev);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001721 } else {
1722 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001723
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001724 if (hotplug_trigger) {
1725 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Daniel Vetter44cc6c02015-09-30 08:47:41 +02001726 hotplug_trigger, hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001727 i9xx_port_hotplug_long_detect);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001728 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1729 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001730 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001731}
1732
Daniel Vetterff1f5252012-10-02 15:10:55 +02001733static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001734{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001735 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001736 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001737 u32 iir, gt_iir, pm_iir;
1738 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001739
Imre Deak2dd2a882015-02-24 11:14:30 +02001740 if (!intel_irqs_enabled(dev_priv))
1741 return IRQ_NONE;
1742
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001743 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001744 /* Find, clear, then process each source of interrupt */
1745
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001746 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001747 if (gt_iir)
1748 I915_WRITE(GTIIR, gt_iir);
1749
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001750 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001751 if (pm_iir)
1752 I915_WRITE(GEN6_PMIIR, pm_iir);
1753
1754 iir = I915_READ(VLV_IIR);
1755 if (iir) {
1756 /* Consume port before clearing IIR or we'll miss events */
1757 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1758 i9xx_hpd_irq_handler(dev);
1759 I915_WRITE(VLV_IIR, iir);
1760 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001761
1762 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1763 goto out;
1764
1765 ret = IRQ_HANDLED;
1766
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001767 if (gt_iir)
1768 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001769 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001770 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001771 /* Call regardless, as some status bits might not be
1772 * signalled in iir */
1773 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001774 }
1775
1776out:
1777 return ret;
1778}
1779
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001780static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1781{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001782 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001783 struct drm_i915_private *dev_priv = dev->dev_private;
1784 u32 master_ctl, iir;
1785 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001786
Imre Deak2dd2a882015-02-24 11:14:30 +02001787 if (!intel_irqs_enabled(dev_priv))
1788 return IRQ_NONE;
1789
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001790 for (;;) {
1791 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1792 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001793
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001794 if (master_ctl == 0 && iir == 0)
1795 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001796
Oscar Mateo27b6c122014-06-16 16:11:00 +01001797 ret = IRQ_HANDLED;
1798
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001799 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001800
Oscar Mateo27b6c122014-06-16 16:11:00 +01001801 /* Find, clear, then process each source of interrupt */
1802
1803 if (iir) {
1804 /* Consume port before clearing IIR or we'll miss events */
1805 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1806 i9xx_hpd_irq_handler(dev);
1807 I915_WRITE(VLV_IIR, iir);
1808 }
1809
Chris Wilson74cdb332015-04-07 16:21:05 +01001810 gen8_gt_irq_handler(dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001811
Oscar Mateo27b6c122014-06-16 16:11:00 +01001812 /* Call regardless, as some status bits might not be
1813 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001814 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001815
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001816 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1817 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001818 }
1819
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001820 return ret;
1821}
1822
Ville Syrjälä40e56412015-08-27 23:56:10 +03001823static void ibx_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
1824 const u32 hpd[HPD_NUM_PINS])
1825{
1826 struct drm_i915_private *dev_priv = to_i915(dev);
1827 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1828
1829 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1830 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1831
1832 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1833 dig_hotplug_reg, hpd,
1834 pch_port_hotplug_long_detect);
1835
1836 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1837}
1838
Adam Jackson23e81d62012-06-06 15:45:44 -04001839static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001840{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001841 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001842 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001843 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001844
Ville Syrjälä40e56412015-08-27 23:56:10 +03001845 if (hotplug_trigger)
1846 ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001847
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001848 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1849 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1850 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001851 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001852 port_name(port));
1853 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001854
Daniel Vetterce99c252012-12-01 13:53:47 +01001855 if (pch_iir & SDE_AUX_MASK)
1856 dp_aux_irq_handler(dev);
1857
Jesse Barnes776ad802011-01-04 15:09:39 -08001858 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001859 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001860
1861 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1862 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1863
1864 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1865 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1866
1867 if (pch_iir & SDE_POISON)
1868 DRM_ERROR("PCH poison interrupt\n");
1869
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001870 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001871 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001872 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1873 pipe_name(pipe),
1874 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001875
1876 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1877 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1878
1879 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1880 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1881
Jesse Barnes776ad802011-01-04 15:09:39 -08001882 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001883 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001884
1885 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001886 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001887}
1888
1889static void ivb_err_int_handler(struct drm_device *dev)
1890{
1891 struct drm_i915_private *dev_priv = dev->dev_private;
1892 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001893 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001894
Paulo Zanonide032bf2013-04-12 17:57:58 -03001895 if (err_int & ERR_INT_POISON)
1896 DRM_ERROR("Poison interrupt\n");
1897
Damien Lespiau055e3932014-08-18 13:49:10 +01001898 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001899 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1900 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03001901
Daniel Vetter5a69b892013-10-16 22:55:52 +02001902 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1903 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001904 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001905 else
Daniel Vetter277de952013-10-18 16:37:07 +02001906 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001907 }
1908 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001909
Paulo Zanoni86642812013-04-12 17:57:57 -03001910 I915_WRITE(GEN7_ERR_INT, err_int);
1911}
1912
1913static void cpt_serr_int_handler(struct drm_device *dev)
1914{
1915 struct drm_i915_private *dev_priv = dev->dev_private;
1916 u32 serr_int = I915_READ(SERR_INT);
1917
Paulo Zanonide032bf2013-04-12 17:57:58 -03001918 if (serr_int & SERR_INT_POISON)
1919 DRM_ERROR("PCH poison interrupt\n");
1920
Paulo Zanoni86642812013-04-12 17:57:57 -03001921 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001922 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001923
1924 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001925 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001926
1927 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001928 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03001929
1930 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001931}
1932
Adam Jackson23e81d62012-06-06 15:45:44 -04001933static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1934{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001935 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04001936 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001937 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001938
Ville Syrjälä40e56412015-08-27 23:56:10 +03001939 if (hotplug_trigger)
1940 ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001941
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001942 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1943 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1944 SDE_AUDIO_POWER_SHIFT_CPT);
1945 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1946 port_name(port));
1947 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001948
1949 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001950 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001951
1952 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001953 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001954
1955 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1956 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1957
1958 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1959 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1960
1961 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01001962 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04001963 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1964 pipe_name(pipe),
1965 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001966
1967 if (pch_iir & SDE_ERROR_CPT)
1968 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001969}
1970
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001971static void spt_irq_handler(struct drm_device *dev, u32 pch_iir)
1972{
1973 struct drm_i915_private *dev_priv = dev->dev_private;
1974 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
1975 ~SDE_PORTE_HOTPLUG_SPT;
1976 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
1977 u32 pin_mask = 0, long_mask = 0;
1978
1979 if (hotplug_trigger) {
1980 u32 dig_hotplug_reg;
1981
1982 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1983 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1984
1985 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1986 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001987 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001988 }
1989
1990 if (hotplug2_trigger) {
1991 u32 dig_hotplug_reg;
1992
1993 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
1994 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
1995
1996 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
1997 dig_hotplug_reg, hpd_spt,
1998 spt_port_hotplug2_long_detect);
1999 }
2000
2001 if (pin_mask)
2002 intel_hpd_irq_handler(dev, pin_mask, long_mask);
2003
2004 if (pch_iir & SDE_GMBUS_CPT)
2005 gmbus_irq_handler(dev);
2006}
2007
Ville Syrjälä40e56412015-08-27 23:56:10 +03002008static void ilk_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
2009 const u32 hpd[HPD_NUM_PINS])
2010{
2011 struct drm_i915_private *dev_priv = to_i915(dev);
2012 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2013
2014 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2015 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2016
2017 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
2018 dig_hotplug_reg, hpd,
2019 ilk_port_hotplug_long_detect);
2020
2021 intel_hpd_irq_handler(dev, pin_mask, long_mask);
2022}
2023
Paulo Zanonic008bc62013-07-12 16:35:10 -03002024static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
2025{
2026 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02002027 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002028 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2029
Ville Syrjälä40e56412015-08-27 23:56:10 +03002030 if (hotplug_trigger)
2031 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002032
2033 if (de_iir & DE_AUX_CHANNEL_A)
2034 dp_aux_irq_handler(dev);
2035
2036 if (de_iir & DE_GSE)
2037 intel_opregion_asle_intr(dev);
2038
Paulo Zanonic008bc62013-07-12 16:35:10 -03002039 if (de_iir & DE_POISON)
2040 DRM_ERROR("Poison interrupt\n");
2041
Damien Lespiau055e3932014-08-18 13:49:10 +01002042 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002043 if (de_iir & DE_PIPE_VBLANK(pipe) &&
2044 intel_pipe_handle_vblank(dev, pipe))
2045 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002046
Daniel Vetter40da17c2013-10-21 18:04:36 +02002047 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002048 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002049
Daniel Vetter40da17c2013-10-21 18:04:36 +02002050 if (de_iir & DE_PIPE_CRC_DONE(pipe))
2051 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02002052
Daniel Vetter40da17c2013-10-21 18:04:36 +02002053 /* plane/pipes map 1:1 on ilk+ */
2054 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
2055 intel_prepare_page_flip(dev, pipe);
2056 intel_finish_page_flip_plane(dev, pipe);
2057 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03002058 }
2059
2060 /* check event from PCH */
2061 if (de_iir & DE_PCH_EVENT) {
2062 u32 pch_iir = I915_READ(SDEIIR);
2063
2064 if (HAS_PCH_CPT(dev))
2065 cpt_irq_handler(dev, pch_iir);
2066 else
2067 ibx_irq_handler(dev, pch_iir);
2068
2069 /* should clear PCH hotplug event before clear CPU irq */
2070 I915_WRITE(SDEIIR, pch_iir);
2071 }
2072
2073 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2074 ironlake_rps_change_irq_handler(dev);
2075}
2076
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002077static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2078{
2079 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002080 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002081 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2082
Ville Syrjälä40e56412015-08-27 23:56:10 +03002083 if (hotplug_trigger)
2084 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002085
2086 if (de_iir & DE_ERR_INT_IVB)
2087 ivb_err_int_handler(dev);
2088
2089 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2090 dp_aux_irq_handler(dev);
2091
2092 if (de_iir & DE_GSE_IVB)
2093 intel_opregion_asle_intr(dev);
2094
Damien Lespiau055e3932014-08-18 13:49:10 +01002095 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002096 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2097 intel_pipe_handle_vblank(dev, pipe))
2098 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02002099
2100 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002101 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2102 intel_prepare_page_flip(dev, pipe);
2103 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002104 }
2105 }
2106
2107 /* check event from PCH */
2108 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2109 u32 pch_iir = I915_READ(SDEIIR);
2110
2111 cpt_irq_handler(dev, pch_iir);
2112
2113 /* clear PCH hotplug event before clear CPU irq */
2114 I915_WRITE(SDEIIR, pch_iir);
2115 }
2116}
2117
Oscar Mateo72c90f62014-06-16 16:10:57 +01002118/*
2119 * To handle irqs with the minimum potential races with fresh interrupts, we:
2120 * 1 - Disable Master Interrupt Control.
2121 * 2 - Find the source(s) of the interrupt.
2122 * 3 - Clear the Interrupt Identity bits (IIR).
2123 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2124 * 5 - Re-enable Master Interrupt Control.
2125 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002126static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002127{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002128 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002129 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002130 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002131 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002132
Imre Deak2dd2a882015-02-24 11:14:30 +02002133 if (!intel_irqs_enabled(dev_priv))
2134 return IRQ_NONE;
2135
Paulo Zanoni86642812013-04-12 17:57:57 -03002136 /* We get interrupts on unclaimed registers, so check for this before we
2137 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002138 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002139
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002140 /* disable master interrupt before clearing iir */
2141 de_ier = I915_READ(DEIER);
2142 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002143 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002144
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002145 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2146 * interrupts will will be stored on its back queue, and then we'll be
2147 * able to process them after we restore SDEIER (as soon as we restore
2148 * it, we'll get an interrupt if SDEIIR still has something to process
2149 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002150 if (!HAS_PCH_NOP(dev)) {
2151 sde_ier = I915_READ(SDEIER);
2152 I915_WRITE(SDEIER, 0);
2153 POSTING_READ(SDEIER);
2154 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002155
Oscar Mateo72c90f62014-06-16 16:10:57 +01002156 /* Find, clear, then process each source of interrupt */
2157
Chris Wilson0e434062012-05-09 21:45:44 +01002158 gt_iir = I915_READ(GTIIR);
2159 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002160 I915_WRITE(GTIIR, gt_iir);
2161 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002162 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002163 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002164 else
2165 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002166 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002167
2168 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002169 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002170 I915_WRITE(DEIIR, de_iir);
2171 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002172 if (INTEL_INFO(dev)->gen >= 7)
2173 ivb_display_irq_handler(dev, de_iir);
2174 else
2175 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002176 }
2177
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002178 if (INTEL_INFO(dev)->gen >= 6) {
2179 u32 pm_iir = I915_READ(GEN6_PMIIR);
2180 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002181 I915_WRITE(GEN6_PMIIR, pm_iir);
2182 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002183 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002184 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002185 }
2186
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002187 I915_WRITE(DEIER, de_ier);
2188 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002189 if (!HAS_PCH_NOP(dev)) {
2190 I915_WRITE(SDEIER, sde_ier);
2191 POSTING_READ(SDEIER);
2192 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002193
2194 return ret;
2195}
2196
Ville Syrjälä40e56412015-08-27 23:56:10 +03002197static void bxt_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
2198 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302199{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002200 struct drm_i915_private *dev_priv = to_i915(dev);
2201 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302202
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002203 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2204 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302205
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002206 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002207 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002208 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002209
Jani Nikula475c2e32015-05-28 15:43:54 +03002210 intel_hpd_irq_handler(dev, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302211}
2212
Ben Widawskyabd58f02013-11-02 21:07:09 -07002213static irqreturn_t gen8_irq_handler(int irq, void *arg)
2214{
2215 struct drm_device *dev = arg;
2216 struct drm_i915_private *dev_priv = dev->dev_private;
2217 u32 master_ctl;
2218 irqreturn_t ret = IRQ_NONE;
2219 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002220 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002221 u32 aux_mask = GEN8_AUX_CHANNEL_A;
2222
Imre Deak2dd2a882015-02-24 11:14:30 +02002223 if (!intel_irqs_enabled(dev_priv))
2224 return IRQ_NONE;
2225
Rodrigo Vivib4834a52015-09-02 15:19:24 -07002226 if (INTEL_INFO(dev_priv)->gen >= 9)
Jesse Barnes88e04702014-11-13 17:51:48 +00002227 aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
2228 GEN9_AUX_CHANNEL_D;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002229
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002230 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002231 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2232 if (!master_ctl)
2233 return IRQ_NONE;
2234
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002235 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002236
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002237 /* Find, clear, then process each source of interrupt */
2238
Chris Wilson74cdb332015-04-07 16:21:05 +01002239 ret = gen8_gt_irq_handler(dev_priv, master_ctl);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002240
2241 if (master_ctl & GEN8_DE_MISC_IRQ) {
2242 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002243 if (tmp) {
2244 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2245 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002246 if (tmp & GEN8_DE_MISC_GSE)
2247 intel_opregion_asle_intr(dev);
2248 else
2249 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002250 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002251 else
2252 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002253 }
2254
Daniel Vetter6d766f02013-11-07 14:49:55 +01002255 if (master_ctl & GEN8_DE_PORT_IRQ) {
2256 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002257 if (tmp) {
Shashank Sharmad04a4922014-08-22 17:40:41 +05302258 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002259 u32 hotplug_trigger = 0;
2260
2261 if (IS_BROXTON(dev_priv))
2262 hotplug_trigger = tmp & BXT_DE_PORT_HOTPLUG_MASK;
2263 else if (IS_BROADWELL(dev_priv))
2264 hotplug_trigger = tmp & GEN8_PORT_DP_A_HOTPLUG;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302265
Daniel Vetter6d766f02013-11-07 14:49:55 +01002266 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2267 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002268
Shashank Sharmad04a4922014-08-22 17:40:41 +05302269 if (tmp & aux_mask) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002270 dp_aux_irq_handler(dev);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302271 found = true;
2272 }
2273
Ville Syrjälä40e56412015-08-27 23:56:10 +03002274 if (hotplug_trigger) {
2275 if (IS_BROXTON(dev))
2276 bxt_hpd_irq_handler(dev, hotplug_trigger, hpd_bxt);
2277 else
2278 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_bdw);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302279 found = true;
2280 }
2281
Shashank Sharma9e637432014-08-22 17:40:43 +05302282 if (IS_BROXTON(dev) && (tmp & BXT_DE_PORT_GMBUS)) {
2283 gmbus_irq_handler(dev);
2284 found = true;
2285 }
2286
Shashank Sharmad04a4922014-08-22 17:40:41 +05302287 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002288 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002289 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002290 else
2291 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002292 }
2293
Damien Lespiau055e3932014-08-18 13:49:10 +01002294 for_each_pipe(dev_priv, pipe) {
Damien Lespiau770de832014-03-20 20:45:01 +00002295 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002296
Daniel Vetterc42664c2013-11-07 11:05:40 +01002297 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2298 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002299
Daniel Vetterc42664c2013-11-07 11:05:40 +01002300 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002301 if (pipe_iir) {
2302 ret = IRQ_HANDLED;
2303 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Damien Lespiau770de832014-03-20 20:45:01 +00002304
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002305 if (pipe_iir & GEN8_PIPE_VBLANK &&
2306 intel_pipe_handle_vblank(dev, pipe))
2307 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002308
Rodrigo Vivib4834a52015-09-02 15:19:24 -07002309 if (INTEL_INFO(dev_priv)->gen >= 9)
Damien Lespiau770de832014-03-20 20:45:01 +00002310 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2311 else
2312 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2313
2314 if (flip_done) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002315 intel_prepare_page_flip(dev, pipe);
2316 intel_finish_page_flip_plane(dev, pipe);
2317 }
2318
2319 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2320 hsw_pipe_crc_irq_handler(dev, pipe);
2321
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002322 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
2323 intel_cpu_fifo_underrun_irq_handler(dev_priv,
2324 pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002325
Damien Lespiau770de832014-03-20 20:45:01 +00002326
Rodrigo Vivib4834a52015-09-02 15:19:24 -07002327 if (INTEL_INFO(dev_priv)->gen >= 9)
Damien Lespiau770de832014-03-20 20:45:01 +00002328 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2329 else
2330 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2331
2332 if (fault_errors)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002333 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2334 pipe_name(pipe),
2335 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
Daniel Vetterc42664c2013-11-07 11:05:40 +01002336 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002337 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2338 }
2339
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302340 if (HAS_PCH_SPLIT(dev) && !HAS_PCH_NOP(dev) &&
2341 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002342 /*
2343 * FIXME(BDW): Assume for now that the new interrupt handling
2344 * scheme also closed the SDE interrupt handling race we've seen
2345 * on older pch-split platforms. But this needs testing.
2346 */
2347 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002348 if (pch_iir) {
2349 I915_WRITE(SDEIIR, pch_iir);
2350 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002351
2352 if (HAS_PCH_SPT(dev_priv))
2353 spt_irq_handler(dev, pch_iir);
2354 else
2355 cpt_irq_handler(dev, pch_iir);
Daniel Vetter97e5ed12015-10-23 10:56:12 +02002356 } else {
2357 /*
2358 * Like on previous PCH there seems to be something
2359 * fishy going on with forwarding PCH interrupts.
2360 */
2361 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2362 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002363 }
2364
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002365 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2366 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002367
2368 return ret;
2369}
2370
Daniel Vetter17e1df02013-09-08 21:57:13 +02002371static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2372 bool reset_completed)
2373{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002374 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002375 int i;
2376
2377 /*
2378 * Notify all waiters for GPU completion events that reset state has
2379 * been changed, and that they need to restart their wait after
2380 * checking for potential errors (and bail out to drop locks if there is
2381 * a gpu reset pending so that i915_error_work_func can acquire them).
2382 */
2383
2384 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2385 for_each_ring(ring, dev_priv, i)
2386 wake_up_all(&ring->irq_queue);
2387
2388 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2389 wake_up_all(&dev_priv->pending_flip_queue);
2390
2391 /*
2392 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2393 * reset state is cleared.
2394 */
2395 if (reset_completed)
2396 wake_up_all(&dev_priv->gpu_error.reset_queue);
2397}
2398
Jesse Barnes8a905232009-07-11 16:48:03 -04002399/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002400 * i915_reset_and_wakeup - do process context error handling work
Javier Martinez Canillas468f9d22015-10-08 09:54:44 +02002401 * @dev: drm device
Jesse Barnes8a905232009-07-11 16:48:03 -04002402 *
2403 * Fire an error uevent so userspace can see that a hang or error
2404 * was detected.
2405 */
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002406static void i915_reset_and_wakeup(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002407{
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002408 struct drm_i915_private *dev_priv = to_i915(dev);
2409 struct i915_gpu_error *error = &dev_priv->gpu_error;
Ben Widawskycce723e2013-07-19 09:16:42 -07002410 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2411 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2412 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002413 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002414
Dave Airlie5bdebb12013-10-11 14:07:25 +10002415 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002416
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002417 /*
2418 * Note that there's only one work item which does gpu resets, so we
2419 * need not worry about concurrent gpu resets potentially incrementing
2420 * error->reset_counter twice. We only need to take care of another
2421 * racing irq/hangcheck declaring the gpu dead for a second time. A
2422 * quick check for that is good enough: schedule_work ensures the
2423 * correct ordering between hang detection and this work item, and since
2424 * the reset in-progress bit is only ever set by code outside of this
2425 * work we don't need to worry about any other races.
2426 */
2427 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002428 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002429 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002430 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002431
Daniel Vetter17e1df02013-09-08 21:57:13 +02002432 /*
Imre Deakf454c692014-04-23 01:09:04 +03002433 * In most cases it's guaranteed that we get here with an RPM
2434 * reference held, for example because there is a pending GPU
2435 * request that won't finish until the reset is done. This
2436 * isn't the case at least when we get here by doing a
2437 * simulated reset via debugs, so get an RPM reference.
2438 */
2439 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002440
2441 intel_prepare_reset(dev);
2442
Imre Deakf454c692014-04-23 01:09:04 +03002443 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002444 * All state reset _must_ be completed before we update the
2445 * reset counter, for otherwise waiters might miss the reset
2446 * pending state and not properly drop locks, resulting in
2447 * deadlocks with the reset work.
2448 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002449 ret = i915_reset(dev);
2450
Ville Syrjälä75147472014-11-24 18:28:11 +02002451 intel_finish_reset(dev);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002452
Imre Deakf454c692014-04-23 01:09:04 +03002453 intel_runtime_pm_put(dev_priv);
2454
Daniel Vetterf69061b2012-12-06 09:01:42 +01002455 if (ret == 0) {
2456 /*
2457 * After all the gem state is reset, increment the reset
2458 * counter and wake up everyone waiting for the reset to
2459 * complete.
2460 *
2461 * Since unlock operations are a one-sided barrier only,
2462 * we need to insert a barrier here to order any seqno
2463 * updates before
2464 * the counter increment.
2465 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002466 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002467 atomic_inc(&dev_priv->gpu_error.reset_counter);
2468
Dave Airlie5bdebb12013-10-11 14:07:25 +10002469 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002470 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002471 } else {
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002472 atomic_or(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002473 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002474
Daniel Vetter17e1df02013-09-08 21:57:13 +02002475 /*
2476 * Note: The wake_up also serves as a memory barrier so that
2477 * waiters see the update value of the reset counter atomic_t.
2478 */
2479 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002480 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002481}
2482
Chris Wilson35aed2e2010-05-27 13:18:12 +01002483static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002484{
2485 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002486 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002487 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002488 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002489
Chris Wilson35aed2e2010-05-27 13:18:12 +01002490 if (!eir)
2491 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002492
Joe Perchesa70491c2012-03-18 13:00:11 -07002493 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002494
Ben Widawskybd9854f2012-08-23 15:18:09 -07002495 i915_get_extra_instdone(dev, instdone);
2496
Jesse Barnes8a905232009-07-11 16:48:03 -04002497 if (IS_G4X(dev)) {
2498 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2499 u32 ipeir = I915_READ(IPEIR_I965);
2500
Joe Perchesa70491c2012-03-18 13:00:11 -07002501 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2502 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002503 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2504 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002505 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002506 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002507 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002508 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002509 }
2510 if (eir & GM45_ERROR_PAGE_TABLE) {
2511 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002512 pr_err("page table error\n");
2513 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002514 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002515 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002516 }
2517 }
2518
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002519 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002520 if (eir & I915_ERROR_PAGE_TABLE) {
2521 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002522 pr_err("page table error\n");
2523 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002524 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002525 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002526 }
2527 }
2528
2529 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002530 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002531 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002532 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002533 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002534 /* pipestat has already been acked */
2535 }
2536 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002537 pr_err("instruction error\n");
2538 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002539 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2540 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002541 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002542 u32 ipeir = I915_READ(IPEIR);
2543
Joe Perchesa70491c2012-03-18 13:00:11 -07002544 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2545 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002546 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002547 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002548 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002549 } else {
2550 u32 ipeir = I915_READ(IPEIR_I965);
2551
Joe Perchesa70491c2012-03-18 13:00:11 -07002552 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2553 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002554 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002555 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002556 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002557 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002558 }
2559 }
2560
2561 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002562 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002563 eir = I915_READ(EIR);
2564 if (eir) {
2565 /*
2566 * some errors might have become stuck,
2567 * mask them.
2568 */
2569 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2570 I915_WRITE(EMR, I915_READ(EMR) | eir);
2571 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2572 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002573}
2574
2575/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002576 * i915_handle_error - handle a gpu error
Chris Wilson35aed2e2010-05-27 13:18:12 +01002577 * @dev: drm device
2578 *
Javier Martinez Canillasaafd8582015-10-08 09:57:49 +02002579 * Do some basic checking of register state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002580 * dump it to the syslog. Also call i915_capture_error_state() to make
2581 * sure we get a record and make it available in debugfs. Fire a uevent
2582 * so userspace knows something bad happened (should trigger collection
2583 * of a ring dump etc.).
2584 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002585void i915_handle_error(struct drm_device *dev, bool wedged,
2586 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002587{
2588 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002589 va_list args;
2590 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002591
Mika Kuoppala58174462014-02-25 17:11:26 +02002592 va_start(args, fmt);
2593 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2594 va_end(args);
2595
2596 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002597 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002598
Ben Gamariba1234d2009-09-14 17:48:47 -04002599 if (wedged) {
Peter Zijlstra805de8f42015-04-24 01:12:32 +02002600 atomic_or(I915_RESET_IN_PROGRESS_FLAG,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002601 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002602
Ben Gamari11ed50e2009-09-14 17:48:45 -04002603 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002604 * Wakeup waiting processes so that the reset function
2605 * i915_reset_and_wakeup doesn't deadlock trying to grab
2606 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002607 * processes will see a reset in progress and back off,
2608 * releasing their locks and then wait for the reset completion.
2609 * We must do this for _all_ gpu waiters that might hold locks
2610 * that the reset work needs to acquire.
2611 *
2612 * Note: The wake_up serves as the required memory barrier to
2613 * ensure that the waiters see the updated value of the reset
2614 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002615 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002616 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002617 }
2618
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002619 i915_reset_and_wakeup(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002620}
2621
Keith Packard42f52ef2008-10-18 19:39:29 -07002622/* Called from drm generic code, passed 'crtc' which
2623 * we use as a pipe index
2624 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002625static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002626{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002627 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002628 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002629
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002630 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002631 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002632 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002633 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002634 else
Keith Packard7c463582008-11-04 02:03:27 -08002635 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002636 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002637 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002638
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002639 return 0;
2640}
2641
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002642static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002643{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002644 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002645 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002646 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002647 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002648
Jesse Barnesf796cf82011-04-07 13:58:17 -07002649 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002650 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002651 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2652
2653 return 0;
2654}
2655
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002656static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2657{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002658 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002659 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002660
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002661 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002662 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002663 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002664 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2665
2666 return 0;
2667}
2668
Ben Widawskyabd58f02013-11-02 21:07:09 -07002669static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2670{
2671 struct drm_i915_private *dev_priv = dev->dev_private;
2672 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002673
Ben Widawskyabd58f02013-11-02 21:07:09 -07002674 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002675 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2676 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2677 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002678 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2679 return 0;
2680}
2681
Keith Packard42f52ef2008-10-18 19:39:29 -07002682/* Called from drm generic code, passed 'crtc' which
2683 * we use as a pipe index
2684 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002685static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002686{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002687 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002688 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002689
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002690 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002691 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002692 PIPE_VBLANK_INTERRUPT_STATUS |
2693 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002694 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2695}
2696
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002697static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002698{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002699 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002700 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002701 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002702 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002703
2704 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002705 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002706 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2707}
2708
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002709static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2710{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002711 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002712 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002713
2714 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002715 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002716 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002717 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2718}
2719
Ben Widawskyabd58f02013-11-02 21:07:09 -07002720static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2721{
2722 struct drm_i915_private *dev_priv = dev->dev_private;
2723 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002724
Ben Widawskyabd58f02013-11-02 21:07:09 -07002725 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002726 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2727 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2728 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002729 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2730}
2731
Chris Wilson9107e9d2013-06-10 11:20:20 +01002732static bool
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002733ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002734{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002735 return (list_empty(&ring->request_list) ||
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002736 i915_seqno_passed(seqno, ring->last_submitted_seqno));
Ben Gamarif65d9422009-09-14 17:48:44 -04002737}
2738
Daniel Vettera028c4b2014-03-15 00:08:56 +01002739static bool
2740ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2741{
2742 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002743 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002744 } else {
2745 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2746 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2747 MI_SEMAPHORE_REGISTER);
2748 }
2749}
2750
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002751static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002752semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002753{
2754 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002755 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002756 int i;
2757
2758 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002759 for_each_ring(signaller, dev_priv, i) {
2760 if (ring == signaller)
2761 continue;
2762
2763 if (offset == signaller->semaphore.signal_ggtt[ring->id])
2764 return signaller;
2765 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002766 } else {
2767 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2768
2769 for_each_ring(signaller, dev_priv, i) {
2770 if(ring == signaller)
2771 continue;
2772
Ben Widawskyebc348b2014-04-29 14:52:28 -07002773 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002774 return signaller;
2775 }
2776 }
2777
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002778 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
2779 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002780
2781 return NULL;
2782}
2783
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002784static struct intel_engine_cs *
2785semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002786{
2787 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002788 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002789 u64 offset = 0;
2790 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002791
Tomas Elf381e8ae2015-10-08 19:31:33 +01002792 /*
2793 * This function does not support execlist mode - any attempt to
2794 * proceed further into this function will result in a kernel panic
2795 * when dereferencing ring->buffer, which is not set up in execlist
2796 * mode.
2797 *
2798 * The correct way of doing it would be to derive the currently
2799 * executing ring buffer from the current context, which is derived
2800 * from the currently running request. Unfortunately, to get the
2801 * current request we would have to grab the struct_mutex before doing
2802 * anything else, which would be ill-advised since some other thread
2803 * might have grabbed it already and managed to hang itself, causing
2804 * the hang checker to deadlock.
2805 *
2806 * Therefore, this function does not support execlist mode in its
2807 * current form. Just return NULL and move on.
2808 */
2809 if (ring->buffer == NULL)
2810 return NULL;
2811
Chris Wilsona24a11e2013-03-14 17:52:05 +02002812 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002813 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002814 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002815
Daniel Vetter88fe4292014-03-15 00:08:55 +01002816 /*
2817 * HEAD is likely pointing to the dword after the actual command,
2818 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002819 * or 4 dwords depending on the semaphore wait command size.
2820 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002821 * point at at batch, and semaphores are always emitted into the
2822 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002823 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002824 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002825 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002826
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002827 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002828 /*
2829 * Be paranoid and presume the hw has gone off into the wild -
2830 * our ring is smaller than what the hardware (and hence
2831 * HEAD_ADDR) allows. Also handles wrap-around.
2832 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002833 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002834
2835 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002836 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002837 if (cmd == ipehr)
2838 break;
2839
Daniel Vetter88fe4292014-03-15 00:08:55 +01002840 head -= 4;
2841 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002842
Daniel Vetter88fe4292014-03-15 00:08:55 +01002843 if (!i)
2844 return NULL;
2845
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002846 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002847 if (INTEL_INFO(ring->dev)->gen >= 8) {
2848 offset = ioread32(ring->buffer->virtual_start + head + 12);
2849 offset <<= 32;
2850 offset = ioread32(ring->buffer->virtual_start + head + 8);
2851 }
2852 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002853}
2854
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002855static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01002856{
2857 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002858 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002859 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002860
Chris Wilson4be17382014-06-06 10:22:29 +01002861 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002862
2863 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002864 if (signaller == NULL)
2865 return -1;
2866
2867 /* Prevent pathological recursion due to driver bugs */
2868 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01002869 return -1;
2870
Chris Wilson4be17382014-06-06 10:22:29 +01002871 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
2872 return 1;
2873
Chris Wilsona0d036b2014-07-19 12:40:42 +01002874 /* cursory check for an unkickable deadlock */
2875 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2876 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002877 return -1;
2878
2879 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002880}
2881
2882static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2883{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002884 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01002885 int i;
2886
2887 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01002888 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002889}
2890
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002891static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002892ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002893{
2894 struct drm_device *dev = ring->dev;
2895 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002896 u32 tmp;
2897
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002898 if (acthd != ring->hangcheck.acthd) {
2899 if (acthd > ring->hangcheck.max_acthd) {
2900 ring->hangcheck.max_acthd = acthd;
2901 return HANGCHECK_ACTIVE;
2902 }
2903
2904 return HANGCHECK_ACTIVE_LOOP;
2905 }
Chris Wilson6274f212013-06-10 11:20:21 +01002906
Chris Wilson9107e9d2013-06-10 11:20:20 +01002907 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002908 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002909
2910 /* Is the chip hanging on a WAIT_FOR_EVENT?
2911 * If so we can simply poke the RB_WAIT bit
2912 * and break the hang. This should work on
2913 * all but the second generation chipsets.
2914 */
2915 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002916 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002917 i915_handle_error(dev, false,
2918 "Kicking stuck wait on %s",
2919 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002920 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002921 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002922 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002923
Chris Wilson6274f212013-06-10 11:20:21 +01002924 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2925 switch (semaphore_passed(ring)) {
2926 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002927 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002928 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002929 i915_handle_error(dev, false,
2930 "Kicking stuck semaphore on %s",
2931 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002932 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002933 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002934 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002935 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002936 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002937 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002938
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002939 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002940}
2941
Chris Wilson737b1502015-01-26 18:03:03 +02002942/*
Ben Gamarif65d9422009-09-14 17:48:44 -04002943 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002944 * batchbuffers in a long time. We keep track per ring seqno progress and
2945 * if there are no progress, hangcheck score for that ring is increased.
2946 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2947 * we kick the ring. If we see no progress on three subsequent calls
2948 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002949 */
Chris Wilson737b1502015-01-26 18:03:03 +02002950static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04002951{
Chris Wilson737b1502015-01-26 18:03:03 +02002952 struct drm_i915_private *dev_priv =
2953 container_of(work, typeof(*dev_priv),
2954 gpu_error.hangcheck_work.work);
2955 struct drm_device *dev = dev_priv->dev;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002956 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002957 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002958 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002959 bool stuck[I915_NUM_RINGS] = { 0 };
2960#define BUSY 1
2961#define KICK 5
2962#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002963
Jani Nikulad330a952014-01-21 11:24:25 +02002964 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002965 return;
2966
Chris Wilsonb4519512012-05-11 14:29:30 +01002967 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002968 u64 acthd;
2969 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002970 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002971
Chris Wilson6274f212013-06-10 11:20:21 +01002972 semaphore_clear_deadlocks(dev_priv);
2973
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002974 seqno = ring->get_seqno(ring, false);
2975 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002976
Chris Wilson9107e9d2013-06-10 11:20:20 +01002977 if (ring->hangcheck.seqno == seqno) {
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002978 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002979 ring->hangcheck.action = HANGCHECK_IDLE;
2980
Chris Wilson9107e9d2013-06-10 11:20:20 +01002981 if (waitqueue_active(&ring->irq_queue)) {
2982 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002983 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002984 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2985 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2986 ring->name);
2987 else
2988 DRM_INFO("Fake missed irq on %s\n",
2989 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002990 wake_up_all(&ring->irq_queue);
2991 }
2992 /* Safeguard against driver failure */
2993 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002994 } else
2995 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002996 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002997 /* We always increment the hangcheck score
2998 * if the ring is busy and still processing
2999 * the same request, so that no single request
3000 * can run indefinitely (such as a chain of
3001 * batches). The only time we do not increment
3002 * the hangcheck score on this ring, if this
3003 * ring is in a legitimate wait for another
3004 * ring. In that case the waiting ring is a
3005 * victim and we want to be sure we catch the
3006 * right culprit. Then every time we do kick
3007 * the ring, add a small increment to the
3008 * score so that we can catch a batch that is
3009 * being repeatedly kicked and so responsible
3010 * for stalling the machine.
3011 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03003012 ring->hangcheck.action = ring_stuck(ring,
3013 acthd);
3014
3015 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03003016 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003017 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003018 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003019 break;
3020 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003021 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01003022 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003023 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003024 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01003025 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03003026 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03003027 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01003028 stuck[i] = true;
3029 break;
3030 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003031 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01003032 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03003033 ring->hangcheck.action = HANGCHECK_ACTIVE;
3034
Chris Wilson9107e9d2013-06-10 11:20:20 +01003035 /* Gradually reduce the count so that we catch DoS
3036 * attempts across multiple batches.
3037 */
3038 if (ring->hangcheck.score > 0)
3039 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03003040
3041 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01003042 }
3043
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003044 ring->hangcheck.seqno = seqno;
3045 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01003046 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01003047 }
Eric Anholtb9201c12010-01-08 14:25:16 -08003048
Mika Kuoppala92cab732013-05-24 17:16:07 +03003049 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02003050 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02003051 DRM_INFO("%s on %s\n",
3052 stuck[i] ? "stuck" : "no progress",
3053 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01003054 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03003055 }
3056 }
3057
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003058 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02003059 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04003060
Mika Kuoppala05407ff2013-05-30 09:04:29 +03003061 if (busy_count)
3062 /* Reset timer case chip hangs without another request
3063 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003064 i915_queue_hangcheck(dev);
3065}
3066
3067void i915_queue_hangcheck(struct drm_device *dev)
3068{
Chris Wilson737b1502015-01-26 18:03:03 +02003069 struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
Chris Wilson672e7b72014-11-19 09:47:19 +00003070
Jani Nikulad330a952014-01-21 11:24:25 +02003071 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03003072 return;
3073
Chris Wilson737b1502015-01-26 18:03:03 +02003074 /* Don't continually defer the hangcheck so that it is always run at
3075 * least once after work has been scheduled on any ring. Otherwise,
3076 * we will ignore a hung ring if a second ring is kept busy.
3077 */
3078
3079 queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
3080 round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04003081}
3082
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003083static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003084{
3085 struct drm_i915_private *dev_priv = dev->dev_private;
3086
3087 if (HAS_PCH_NOP(dev))
3088 return;
3089
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003090 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003091
3092 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3093 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003094}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003095
Paulo Zanoni622364b2014-04-01 15:37:22 -03003096/*
3097 * SDEIER is also touched by the interrupt handler to work around missed PCH
3098 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3099 * instead we unconditionally enable all PCH interrupt sources here, but then
3100 * only unmask them as needed with SDEIMR.
3101 *
3102 * This function needs to be called before interrupts are enabled.
3103 */
3104static void ibx_irq_pre_postinstall(struct drm_device *dev)
3105{
3106 struct drm_i915_private *dev_priv = dev->dev_private;
3107
3108 if (HAS_PCH_NOP(dev))
3109 return;
3110
3111 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003112 I915_WRITE(SDEIER, 0xffffffff);
3113 POSTING_READ(SDEIER);
3114}
3115
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003116static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003117{
3118 struct drm_i915_private *dev_priv = dev->dev_private;
3119
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003120 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003121 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003122 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003123}
3124
Linus Torvalds1da177e2005-04-16 15:20:36 -07003125/* drm_dma.h hooks
3126*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003127static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003128{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003129 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003130
Paulo Zanoni0c841212014-04-01 15:37:27 -03003131 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003132
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003133 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003134 if (IS_GEN7(dev))
3135 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003136
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003137 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003138
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003139 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003140}
3141
Ville Syrjälä70591a42014-10-30 19:42:58 +02003142static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3143{
3144 enum pipe pipe;
3145
Egbert Eich0706f172015-09-23 16:15:27 +02003146 i915_hotplug_interrupt_update(dev_priv, 0xFFFFFFFF, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003147 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3148
3149 for_each_pipe(dev_priv, pipe)
3150 I915_WRITE(PIPESTAT(pipe), 0xffff);
3151
3152 GEN5_IRQ_RESET(VLV_);
3153}
3154
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003155static void valleyview_irq_preinstall(struct drm_device *dev)
3156{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003157 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003158
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003159 /* VLV magic */
3160 I915_WRITE(VLV_IMR, 0);
3161 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3162 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3163 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3164
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003165 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003166
Ville Syrjälä7c4cde32014-10-30 19:42:51 +02003167 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003168
Ville Syrjälä70591a42014-10-30 19:42:58 +02003169 vlv_display_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003170}
3171
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003172static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3173{
3174 GEN8_IRQ_RESET_NDX(GT, 0);
3175 GEN8_IRQ_RESET_NDX(GT, 1);
3176 GEN8_IRQ_RESET_NDX(GT, 2);
3177 GEN8_IRQ_RESET_NDX(GT, 3);
3178}
3179
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003180static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003181{
3182 struct drm_i915_private *dev_priv = dev->dev_private;
3183 int pipe;
3184
Ben Widawskyabd58f02013-11-02 21:07:09 -07003185 I915_WRITE(GEN8_MASTER_IRQ, 0);
3186 POSTING_READ(GEN8_MASTER_IRQ);
3187
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003188 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003189
Damien Lespiau055e3932014-08-18 13:49:10 +01003190 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003191 if (intel_display_power_is_enabled(dev_priv,
3192 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003193 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003194
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003195 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3196 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3197 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003198
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303199 if (HAS_PCH_SPLIT(dev))
3200 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003201}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003202
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003203void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3204 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003205{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003206 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003207
Daniel Vetter13321782014-09-15 14:55:29 +02003208 spin_lock_irq(&dev_priv->irq_lock);
Damien Lespiaud14c0342015-03-06 18:50:51 +00003209 if (pipe_mask & 1 << PIPE_A)
3210 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
3211 dev_priv->de_irq_mask[PIPE_A],
3212 ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003213 if (pipe_mask & 1 << PIPE_B)
3214 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
3215 dev_priv->de_irq_mask[PIPE_B],
3216 ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
3217 if (pipe_mask & 1 << PIPE_C)
3218 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
3219 dev_priv->de_irq_mask[PIPE_C],
3220 ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003221 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003222}
3223
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003224static void cherryview_irq_preinstall(struct drm_device *dev)
3225{
3226 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003227
3228 I915_WRITE(GEN8_MASTER_IRQ, 0);
3229 POSTING_READ(GEN8_MASTER_IRQ);
3230
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003231 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003232
3233 GEN5_IRQ_RESET(GEN8_PCU_);
3234
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003235 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3236
Ville Syrjälä70591a42014-10-30 19:42:58 +02003237 vlv_display_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003238}
3239
Ville Syrjälä87a02102015-08-27 23:55:57 +03003240static u32 intel_hpd_enabled_irqs(struct drm_device *dev,
3241 const u32 hpd[HPD_NUM_PINS])
3242{
3243 struct drm_i915_private *dev_priv = to_i915(dev);
3244 struct intel_encoder *encoder;
3245 u32 enabled_irqs = 0;
3246
3247 for_each_intel_encoder(dev, encoder)
3248 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3249 enabled_irqs |= hpd[encoder->hpd_pin];
3250
3251 return enabled_irqs;
3252}
3253
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003254static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003255{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003256 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003257 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003258
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003259 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003260 hotplug_irqs = SDE_HOTPLUG_MASK;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003261 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003262 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003263 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003264 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003265 }
3266
Daniel Vetterfee884e2013-07-04 23:35:21 +02003267 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003268
3269 /*
3270 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003271 * duration to 2ms (which is the minimum in the Display Port spec).
3272 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003273 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003274 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3275 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3276 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3277 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3278 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003279 /*
3280 * When CPU and PCH are on the same package, port A
3281 * HPD must be enabled in both north and south.
3282 */
3283 if (HAS_PCH_LPT_LP(dev))
3284 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003285 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003286}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003287
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003288static void spt_hpd_irq_setup(struct drm_device *dev)
3289{
3290 struct drm_i915_private *dev_priv = dev->dev_private;
3291 u32 hotplug_irqs, hotplug, enabled_irqs;
3292
3293 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
3294 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_spt);
3295
3296 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3297
3298 /* Enable digital hotplug on the PCH */
3299 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3300 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003301 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003302 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3303
3304 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3305 hotplug |= PORTE_HOTPLUG_ENABLE;
3306 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003307}
3308
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003309static void ilk_hpd_irq_setup(struct drm_device *dev)
3310{
3311 struct drm_i915_private *dev_priv = dev->dev_private;
3312 u32 hotplug_irqs, hotplug, enabled_irqs;
3313
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003314 if (INTEL_INFO(dev)->gen >= 8) {
3315 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
3316 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bdw);
3317
3318 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3319 } else if (INTEL_INFO(dev)->gen >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003320 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
3321 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003322
3323 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003324 } else {
3325 hotplug_irqs = DE_DP_A_HOTPLUG;
3326 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003327
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003328 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3329 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003330
3331 /*
3332 * Enable digital hotplug on the CPU, and configure the DP short pulse
3333 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003334 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003335 */
3336 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3337 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3338 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3339 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3340
3341 ibx_hpd_irq_setup(dev);
3342}
3343
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003344static void bxt_hpd_irq_setup(struct drm_device *dev)
3345{
3346 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003347 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003348
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003349 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bxt);
3350 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003351
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003352 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003353
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003354 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3355 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3356 PORTA_HOTPLUG_ENABLE;
3357 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003358}
3359
Paulo Zanonid46da432013-02-08 17:35:15 -02003360static void ibx_irq_postinstall(struct drm_device *dev)
3361{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003362 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003363 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003364
Daniel Vetter692a04c2013-05-29 21:43:05 +02003365 if (HAS_PCH_NOP(dev))
3366 return;
3367
Paulo Zanoni105b1222014-04-01 15:37:17 -03003368 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003369 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003370 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003371 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003372
Ville Syrjäläb51a2842015-09-18 20:03:41 +03003373 gen5_assert_iir_is_zero(dev_priv, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003374 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003375}
3376
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003377static void gen5_gt_irq_postinstall(struct drm_device *dev)
3378{
3379 struct drm_i915_private *dev_priv = dev->dev_private;
3380 u32 pm_irqs, gt_irqs;
3381
3382 pm_irqs = gt_irqs = 0;
3383
3384 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003385 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003386 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003387 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3388 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003389 }
3390
3391 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3392 if (IS_GEN5(dev)) {
3393 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3394 ILK_BSD_USER_INTERRUPT;
3395 } else {
3396 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3397 }
3398
Paulo Zanoni35079892014-04-01 15:37:15 -03003399 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003400
3401 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003402 /*
3403 * RPS interrupts will get enabled/disabled on demand when RPS
3404 * itself is enabled/disabled.
3405 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003406 if (HAS_VEBOX(dev))
3407 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3408
Paulo Zanoni605cd252013-08-06 18:57:15 -03003409 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003410 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003411 }
3412}
3413
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003414static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003415{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003416 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003417 u32 display_mask, extra_mask;
3418
3419 if (INTEL_INFO(dev)->gen >= 7) {
3420 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3421 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3422 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003423 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003424 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003425 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3426 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003427 } else {
3428 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3429 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003430 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003431 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3432 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003433 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3434 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3435 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003436 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003437
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003438 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003439
Paulo Zanoni0c841212014-04-01 15:37:27 -03003440 I915_WRITE(HWSTAM, 0xeffe);
3441
Paulo Zanoni622364b2014-04-01 15:37:22 -03003442 ibx_irq_pre_postinstall(dev);
3443
Paulo Zanoni35079892014-04-01 15:37:15 -03003444 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003445
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003446 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003447
Paulo Zanonid46da432013-02-08 17:35:15 -02003448 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003449
Jesse Barnesf97108d2010-01-29 11:27:07 -08003450 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003451 /* Enable PCU event interrupts
3452 *
3453 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003454 * setup is guaranteed to run in single-threaded context. But we
3455 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003456 spin_lock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003457 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003458 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003459 }
3460
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003461 return 0;
3462}
3463
Imre Deakf8b79e52014-03-04 19:23:07 +02003464static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3465{
3466 u32 pipestat_mask;
3467 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003468 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003469
3470 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3471 PIPE_FIFO_UNDERRUN_STATUS;
3472
Ville Syrjälä120dda42014-10-30 19:42:57 +02003473 for_each_pipe(dev_priv, pipe)
3474 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003475 POSTING_READ(PIPESTAT(PIPE_A));
3476
3477 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3478 PIPE_CRC_DONE_INTERRUPT_STATUS;
3479
Ville Syrjälä120dda42014-10-30 19:42:57 +02003480 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3481 for_each_pipe(dev_priv, pipe)
3482 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003483
3484 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3485 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3486 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003487 if (IS_CHERRYVIEW(dev_priv))
3488 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003489 dev_priv->irq_mask &= ~iir_mask;
3490
3491 I915_WRITE(VLV_IIR, iir_mask);
3492 I915_WRITE(VLV_IIR, iir_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003493 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003494 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3495 POSTING_READ(VLV_IMR);
Imre Deakf8b79e52014-03-04 19:23:07 +02003496}
3497
3498static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3499{
3500 u32 pipestat_mask;
3501 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003502 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003503
3504 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3505 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003506 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003507 if (IS_CHERRYVIEW(dev_priv))
3508 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003509
3510 dev_priv->irq_mask |= iir_mask;
Imre Deakf8b79e52014-03-04 19:23:07 +02003511 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003512 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003513 I915_WRITE(VLV_IIR, iir_mask);
3514 I915_WRITE(VLV_IIR, iir_mask);
3515 POSTING_READ(VLV_IIR);
3516
3517 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3518 PIPE_CRC_DONE_INTERRUPT_STATUS;
3519
Ville Syrjälä120dda42014-10-30 19:42:57 +02003520 i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3521 for_each_pipe(dev_priv, pipe)
3522 i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003523
3524 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3525 PIPE_FIFO_UNDERRUN_STATUS;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003526
3527 for_each_pipe(dev_priv, pipe)
3528 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003529 POSTING_READ(PIPESTAT(PIPE_A));
3530}
3531
3532void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3533{
3534 assert_spin_locked(&dev_priv->irq_lock);
3535
3536 if (dev_priv->display_irqs_enabled)
3537 return;
3538
3539 dev_priv->display_irqs_enabled = true;
3540
Imre Deak950eaba2014-09-08 15:21:09 +03003541 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003542 valleyview_display_irqs_install(dev_priv);
3543}
3544
3545void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3546{
3547 assert_spin_locked(&dev_priv->irq_lock);
3548
3549 if (!dev_priv->display_irqs_enabled)
3550 return;
3551
3552 dev_priv->display_irqs_enabled = false;
3553
Imre Deak950eaba2014-09-08 15:21:09 +03003554 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003555 valleyview_display_irqs_uninstall(dev_priv);
3556}
3557
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003558static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003559{
Imre Deakf8b79e52014-03-04 19:23:07 +02003560 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003561
Egbert Eich0706f172015-09-23 16:15:27 +02003562 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003563 POSTING_READ(PORT_HOTPLUG_EN);
3564
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003565 I915_WRITE(VLV_IIR, 0xffffffff);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003566 I915_WRITE(VLV_IIR, 0xffffffff);
3567 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3568 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3569 POSTING_READ(VLV_IMR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003570
Daniel Vetterb79480b2013-06-27 17:52:10 +02003571 /* Interrupt setup is already guaranteed to be single-threaded, this is
3572 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003573 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003574 if (dev_priv->display_irqs_enabled)
3575 valleyview_display_irqs_install(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003576 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003577}
3578
3579static int valleyview_irq_postinstall(struct drm_device *dev)
3580{
3581 struct drm_i915_private *dev_priv = dev->dev_private;
3582
3583 vlv_display_irq_postinstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003584
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003585 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003586
3587 /* ack & enable invalid PTE error interrupts */
3588#if 0 /* FIXME: add support to irq handler for checking these bits */
3589 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3590 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3591#endif
3592
3593 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003594
3595 return 0;
3596}
3597
Ben Widawskyabd58f02013-11-02 21:07:09 -07003598static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3599{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003600 /* These are interrupts we'll toggle with the ring mask register */
3601 uint32_t gt_interrupts[] = {
3602 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003603 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003604 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003605 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3606 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003607 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003608 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3609 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3610 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003611 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003612 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3613 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003614 };
3615
Ben Widawsky09610212014-05-15 20:58:08 +03003616 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303617 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3618 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003619 /*
3620 * RPS interrupts will get enabled/disabled on demand when RPS itself
3621 * is enabled/disabled.
3622 */
3623 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303624 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003625}
3626
3627static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3628{
Damien Lespiau770de832014-03-20 20:45:01 +00003629 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3630 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003631 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3632 u32 de_port_enables;
3633 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003634
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003635 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003636 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3637 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003638 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3639 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303640 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003641 de_port_masked |= BXT_DE_PORT_GMBUS;
3642 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003643 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3644 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003645 }
Damien Lespiau770de832014-03-20 20:45:01 +00003646
3647 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3648 GEN8_PIPE_FIFO_UNDERRUN;
3649
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003650 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003651 if (IS_BROXTON(dev_priv))
3652 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3653 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003654 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3655
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003656 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3657 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3658 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003659
Damien Lespiau055e3932014-08-18 13:49:10 +01003660 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003661 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003662 POWER_DOMAIN_PIPE(pipe)))
3663 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3664 dev_priv->de_irq_mask[pipe],
3665 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003666
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003667 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003668}
3669
3670static int gen8_irq_postinstall(struct drm_device *dev)
3671{
3672 struct drm_i915_private *dev_priv = dev->dev_private;
3673
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303674 if (HAS_PCH_SPLIT(dev))
3675 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003676
Ben Widawskyabd58f02013-11-02 21:07:09 -07003677 gen8_gt_irq_postinstall(dev_priv);
3678 gen8_de_irq_postinstall(dev_priv);
3679
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303680 if (HAS_PCH_SPLIT(dev))
3681 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003682
3683 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3684 POSTING_READ(GEN8_MASTER_IRQ);
3685
3686 return 0;
3687}
3688
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003689static int cherryview_irq_postinstall(struct drm_device *dev)
3690{
3691 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003692
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003693 vlv_display_irq_postinstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003694
3695 gen8_gt_irq_postinstall(dev_priv);
3696
3697 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3698 POSTING_READ(GEN8_MASTER_IRQ);
3699
3700 return 0;
3701}
3702
Ben Widawskyabd58f02013-11-02 21:07:09 -07003703static void gen8_irq_uninstall(struct drm_device *dev)
3704{
3705 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003706
3707 if (!dev_priv)
3708 return;
3709
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003710 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003711}
3712
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003713static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
3714{
3715 /* Interrupt setup is already guaranteed to be single-threaded, this is
3716 * just to make the assert_spin_locked check happy. */
3717 spin_lock_irq(&dev_priv->irq_lock);
3718 if (dev_priv->display_irqs_enabled)
3719 valleyview_display_irqs_uninstall(dev_priv);
3720 spin_unlock_irq(&dev_priv->irq_lock);
3721
3722 vlv_display_irq_reset(dev_priv);
3723
Imre Deakc352d1b2014-11-20 16:05:55 +02003724 dev_priv->irq_mask = ~0;
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003725}
3726
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003727static void valleyview_irq_uninstall(struct drm_device *dev)
3728{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003729 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003730
3731 if (!dev_priv)
3732 return;
3733
Imre Deak843d0e72014-04-14 20:24:23 +03003734 I915_WRITE(VLV_MASTER_IER, 0);
3735
Ville Syrjälä893fce82014-10-30 19:42:56 +02003736 gen5_gt_irq_reset(dev);
3737
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003738 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003739
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003740 vlv_display_irq_uninstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003741}
3742
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003743static void cherryview_irq_uninstall(struct drm_device *dev)
3744{
3745 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003746
3747 if (!dev_priv)
3748 return;
3749
3750 I915_WRITE(GEN8_MASTER_IRQ, 0);
3751 POSTING_READ(GEN8_MASTER_IRQ);
3752
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003753 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003754
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003755 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003756
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003757 vlv_display_irq_uninstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003758}
3759
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003760static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003761{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003762 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003763
3764 if (!dev_priv)
3765 return;
3766
Paulo Zanonibe30b292014-04-01 15:37:25 -03003767 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003768}
3769
Chris Wilsonc2798b12012-04-22 21:13:57 +01003770static void i8xx_irq_preinstall(struct drm_device * dev)
3771{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003772 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003773 int pipe;
3774
Damien Lespiau055e3932014-08-18 13:49:10 +01003775 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003776 I915_WRITE(PIPESTAT(pipe), 0);
3777 I915_WRITE16(IMR, 0xffff);
3778 I915_WRITE16(IER, 0x0);
3779 POSTING_READ16(IER);
3780}
3781
3782static int i8xx_irq_postinstall(struct drm_device *dev)
3783{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003784 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003785
Chris Wilsonc2798b12012-04-22 21:13:57 +01003786 I915_WRITE16(EMR,
3787 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3788
3789 /* Unmask the interrupts that we always want on. */
3790 dev_priv->irq_mask =
3791 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3792 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3793 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003794 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003795 I915_WRITE16(IMR, dev_priv->irq_mask);
3796
3797 I915_WRITE16(IER,
3798 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3799 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003800 I915_USER_INTERRUPT);
3801 POSTING_READ16(IER);
3802
Daniel Vetter379ef822013-10-16 22:55:56 +02003803 /* Interrupt setup is already guaranteed to be single-threaded, this is
3804 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003805 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003806 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3807 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003808 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003809
Chris Wilsonc2798b12012-04-22 21:13:57 +01003810 return 0;
3811}
3812
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003813/*
3814 * Returns true when a page flip has completed.
3815 */
3816static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003817 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003818{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003819 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003820 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003821
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003822 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003823 return false;
3824
3825 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003826 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003827
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003828 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3829 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3830 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3831 * the flip is completed (no longer pending). Since this doesn't raise
3832 * an interrupt per se, we watch for the change at vblank.
3833 */
3834 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003835 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003836
Ville Syrjälä7d475592014-12-17 23:08:03 +02003837 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003838 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003839 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003840
3841check_page_flip:
3842 intel_check_page_flip(dev, pipe);
3843 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003844}
3845
Daniel Vetterff1f5252012-10-02 15:10:55 +02003846static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003847{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003848 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003849 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003850 u16 iir, new_iir;
3851 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003852 int pipe;
3853 u16 flip_mask =
3854 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3855 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3856
Imre Deak2dd2a882015-02-24 11:14:30 +02003857 if (!intel_irqs_enabled(dev_priv))
3858 return IRQ_NONE;
3859
Chris Wilsonc2798b12012-04-22 21:13:57 +01003860 iir = I915_READ16(IIR);
3861 if (iir == 0)
3862 return IRQ_NONE;
3863
3864 while (iir & ~flip_mask) {
3865 /* Can't rely on pipestat interrupt bit in iir as it might
3866 * have been cleared after the pipestat interrupt was received.
3867 * It doesn't set the bit in iir again, but it still produces
3868 * interrupts (for non-MSI).
3869 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003870 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003871 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003872 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003873
Damien Lespiau055e3932014-08-18 13:49:10 +01003874 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003875 int reg = PIPESTAT(pipe);
3876 pipe_stats[pipe] = I915_READ(reg);
3877
3878 /*
3879 * Clear the PIPE*STAT regs before the IIR
3880 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003881 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003882 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003883 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003884 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003885
3886 I915_WRITE16(IIR, iir & ~flip_mask);
3887 new_iir = I915_READ16(IIR); /* Flush posted writes */
3888
Chris Wilsonc2798b12012-04-22 21:13:57 +01003889 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01003890 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003891
Damien Lespiau055e3932014-08-18 13:49:10 +01003892 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003893 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003894 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003895 plane = !plane;
3896
Daniel Vetter4356d582013-10-16 22:55:55 +02003897 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003898 i8xx_handle_vblank(dev, plane, pipe, iir))
3899 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003900
Daniel Vetter4356d582013-10-16 22:55:55 +02003901 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003902 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003903
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003904 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3905 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3906 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003907 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003908
3909 iir = new_iir;
3910 }
3911
3912 return IRQ_HANDLED;
3913}
3914
3915static void i8xx_irq_uninstall(struct drm_device * dev)
3916{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003917 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003918 int pipe;
3919
Damien Lespiau055e3932014-08-18 13:49:10 +01003920 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003921 /* Clear enable bits; then clear status bits */
3922 I915_WRITE(PIPESTAT(pipe), 0);
3923 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3924 }
3925 I915_WRITE16(IMR, 0xffff);
3926 I915_WRITE16(IER, 0x0);
3927 I915_WRITE16(IIR, I915_READ16(IIR));
3928}
3929
Chris Wilsona266c7d2012-04-24 22:59:44 +01003930static void i915_irq_preinstall(struct drm_device * dev)
3931{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003932 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003933 int pipe;
3934
Chris Wilsona266c7d2012-04-24 22:59:44 +01003935 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003936 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003937 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3938 }
3939
Chris Wilson00d98eb2012-04-24 22:59:48 +01003940 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01003941 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003942 I915_WRITE(PIPESTAT(pipe), 0);
3943 I915_WRITE(IMR, 0xffffffff);
3944 I915_WRITE(IER, 0x0);
3945 POSTING_READ(IER);
3946}
3947
3948static int i915_irq_postinstall(struct drm_device *dev)
3949{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003950 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003951 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003952
Chris Wilson38bde182012-04-24 22:59:50 +01003953 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3954
3955 /* Unmask the interrupts that we always want on. */
3956 dev_priv->irq_mask =
3957 ~(I915_ASLE_INTERRUPT |
3958 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3959 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3960 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003961 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003962
3963 enable_mask =
3964 I915_ASLE_INTERRUPT |
3965 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3966 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003967 I915_USER_INTERRUPT;
3968
Chris Wilsona266c7d2012-04-24 22:59:44 +01003969 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02003970 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003971 POSTING_READ(PORT_HOTPLUG_EN);
3972
Chris Wilsona266c7d2012-04-24 22:59:44 +01003973 /* Enable in IER... */
3974 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3975 /* and unmask in IMR */
3976 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3977 }
3978
Chris Wilsona266c7d2012-04-24 22:59:44 +01003979 I915_WRITE(IMR, dev_priv->irq_mask);
3980 I915_WRITE(IER, enable_mask);
3981 POSTING_READ(IER);
3982
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003983 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003984
Daniel Vetter379ef822013-10-16 22:55:56 +02003985 /* Interrupt setup is already guaranteed to be single-threaded, this is
3986 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003987 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003988 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3989 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003990 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003991
Daniel Vetter20afbda2012-12-11 14:05:07 +01003992 return 0;
3993}
3994
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003995/*
3996 * Returns true when a page flip has completed.
3997 */
3998static bool i915_handle_vblank(struct drm_device *dev,
3999 int plane, int pipe, u32 iir)
4000{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004001 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004002 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
4003
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03004004 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004005 return false;
4006
4007 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004008 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004009
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004010 /* We detect FlipDone by looking for the change in PendingFlip from '1'
4011 * to '0' on the following vblank, i.e. IIR has the Pendingflip
4012 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
4013 * the flip is completed (no longer pending). Since this doesn't raise
4014 * an interrupt per se, we watch for the change at vblank.
4015 */
4016 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004017 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004018
Ville Syrjälä7d475592014-12-17 23:08:03 +02004019 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004020 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004021 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01004022
4023check_page_flip:
4024 intel_check_page_flip(dev, pipe);
4025 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004026}
4027
Daniel Vetterff1f5252012-10-02 15:10:55 +02004028static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004029{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004030 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004031 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01004032 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01004033 u32 flip_mask =
4034 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4035 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01004036 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004037
Imre Deak2dd2a882015-02-24 11:14:30 +02004038 if (!intel_irqs_enabled(dev_priv))
4039 return IRQ_NONE;
4040
Chris Wilsona266c7d2012-04-24 22:59:44 +01004041 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01004042 do {
4043 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01004044 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004045
4046 /* Can't rely on pipestat interrupt bit in iir as it might
4047 * have been cleared after the pipestat interrupt was received.
4048 * It doesn't set the bit in iir again, but it still produces
4049 * interrupts (for non-MSI).
4050 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004051 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004052 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004053 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004054
Damien Lespiau055e3932014-08-18 13:49:10 +01004055 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004056 int reg = PIPESTAT(pipe);
4057 pipe_stats[pipe] = I915_READ(reg);
4058
Chris Wilson38bde182012-04-24 22:59:50 +01004059 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004060 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004061 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01004062 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004063 }
4064 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004065 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004066
4067 if (!irq_received)
4068 break;
4069
Chris Wilsona266c7d2012-04-24 22:59:44 +01004070 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004071 if (I915_HAS_HOTPLUG(dev) &&
4072 iir & I915_DISPLAY_PORT_INTERRUPT)
4073 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004074
Chris Wilson38bde182012-04-24 22:59:50 +01004075 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004076 new_iir = I915_READ(IIR); /* Flush posted writes */
4077
Chris Wilsona266c7d2012-04-24 22:59:44 +01004078 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004079 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004080
Damien Lespiau055e3932014-08-18 13:49:10 +01004081 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01004082 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01004083 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01004084 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02004085
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004086 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
4087 i915_handle_vblank(dev, plane, pipe, iir))
4088 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004089
4090 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4091 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004092
4093 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004094 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004095
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004096 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4097 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4098 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004099 }
4100
Chris Wilsona266c7d2012-04-24 22:59:44 +01004101 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4102 intel_opregion_asle_intr(dev);
4103
4104 /* With MSI, interrupts are only generated when iir
4105 * transitions from zero to nonzero. If another bit got
4106 * set while we were handling the existing iir bits, then
4107 * we would never get another interrupt.
4108 *
4109 * This is fine on non-MSI as well, as if we hit this path
4110 * we avoid exiting the interrupt handler only to generate
4111 * another one.
4112 *
4113 * Note that for MSI this could cause a stray interrupt report
4114 * if an interrupt landed in the time between writing IIR and
4115 * the posting read. This should be rare enough to never
4116 * trigger the 99% of 100,000 interrupts test for disabling
4117 * stray interrupts.
4118 */
Chris Wilson38bde182012-04-24 22:59:50 +01004119 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004120 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004121 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004122
4123 return ret;
4124}
4125
4126static void i915_irq_uninstall(struct drm_device * dev)
4127{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004128 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004129 int pipe;
4130
Chris Wilsona266c7d2012-04-24 22:59:44 +01004131 if (I915_HAS_HOTPLUG(dev)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004132 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004133 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4134 }
4135
Chris Wilson00d98eb2012-04-24 22:59:48 +01004136 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004137 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004138 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004139 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004140 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4141 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004142 I915_WRITE(IMR, 0xffffffff);
4143 I915_WRITE(IER, 0x0);
4144
Chris Wilsona266c7d2012-04-24 22:59:44 +01004145 I915_WRITE(IIR, I915_READ(IIR));
4146}
4147
4148static void i965_irq_preinstall(struct drm_device * dev)
4149{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004150 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004151 int pipe;
4152
Egbert Eich0706f172015-09-23 16:15:27 +02004153 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004154 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004155
4156 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004157 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004158 I915_WRITE(PIPESTAT(pipe), 0);
4159 I915_WRITE(IMR, 0xffffffff);
4160 I915_WRITE(IER, 0x0);
4161 POSTING_READ(IER);
4162}
4163
4164static int i965_irq_postinstall(struct drm_device *dev)
4165{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004166 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004167 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004168 u32 error_mask;
4169
Chris Wilsona266c7d2012-04-24 22:59:44 +01004170 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004171 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004172 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004173 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4174 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4175 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4176 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4177 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4178
4179 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004180 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4181 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004182 enable_mask |= I915_USER_INTERRUPT;
4183
4184 if (IS_G4X(dev))
4185 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004186
Daniel Vetterb79480b2013-06-27 17:52:10 +02004187 /* Interrupt setup is already guaranteed to be single-threaded, this is
4188 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004189 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004190 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4191 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4192 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004193 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004194
Chris Wilsona266c7d2012-04-24 22:59:44 +01004195 /*
4196 * Enable some error detection, note the instruction error mask
4197 * bit is reserved, so we leave it masked.
4198 */
4199 if (IS_G4X(dev)) {
4200 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4201 GM45_ERROR_MEM_PRIV |
4202 GM45_ERROR_CP_PRIV |
4203 I915_ERROR_MEMORY_REFRESH);
4204 } else {
4205 error_mask = ~(I915_ERROR_PAGE_TABLE |
4206 I915_ERROR_MEMORY_REFRESH);
4207 }
4208 I915_WRITE(EMR, error_mask);
4209
4210 I915_WRITE(IMR, dev_priv->irq_mask);
4211 I915_WRITE(IER, enable_mask);
4212 POSTING_READ(IER);
4213
Egbert Eich0706f172015-09-23 16:15:27 +02004214 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004215 POSTING_READ(PORT_HOTPLUG_EN);
4216
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004217 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004218
4219 return 0;
4220}
4221
Egbert Eichbac56d52013-02-25 12:06:51 -05004222static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004223{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004224 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004225 u32 hotplug_en;
4226
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004227 assert_spin_locked(&dev_priv->irq_lock);
4228
Ville Syrjälä778eb332015-01-09 14:21:13 +02004229 /* Note HDMI and DP share hotplug bits */
4230 /* enable bits are the same for all generations */
Egbert Eich0706f172015-09-23 16:15:27 +02004231 hotplug_en = intel_hpd_enabled_irqs(dev, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004232 /* Programming the CRT detection parameters tends
4233 to generate a spurious hotplug event about three
4234 seconds later. So just do it once.
4235 */
4236 if (IS_G4X(dev))
4237 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004238 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004239
Ville Syrjälä778eb332015-01-09 14:21:13 +02004240 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004241 i915_hotplug_interrupt_update_locked(dev_priv,
4242 (HOTPLUG_INT_EN_MASK
4243 | CRT_HOTPLUG_VOLTAGE_COMPARE_MASK),
4244 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004245}
4246
Daniel Vetterff1f5252012-10-02 15:10:55 +02004247static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004248{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004249 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004250 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004251 u32 iir, new_iir;
4252 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004253 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004254 u32 flip_mask =
4255 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4256 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004257
Imre Deak2dd2a882015-02-24 11:14:30 +02004258 if (!intel_irqs_enabled(dev_priv))
4259 return IRQ_NONE;
4260
Chris Wilsona266c7d2012-04-24 22:59:44 +01004261 iir = I915_READ(IIR);
4262
Chris Wilsona266c7d2012-04-24 22:59:44 +01004263 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004264 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004265 bool blc_event = false;
4266
Chris Wilsona266c7d2012-04-24 22:59:44 +01004267 /* Can't rely on pipestat interrupt bit in iir as it might
4268 * have been cleared after the pipestat interrupt was received.
4269 * It doesn't set the bit in iir again, but it still produces
4270 * interrupts (for non-MSI).
4271 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004272 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004273 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004274 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004275
Damien Lespiau055e3932014-08-18 13:49:10 +01004276 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004277 int reg = PIPESTAT(pipe);
4278 pipe_stats[pipe] = I915_READ(reg);
4279
4280 /*
4281 * Clear the PIPE*STAT regs before the IIR
4282 */
4283 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004284 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004285 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004286 }
4287 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004288 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004289
4290 if (!irq_received)
4291 break;
4292
4293 ret = IRQ_HANDLED;
4294
4295 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004296 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4297 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004298
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004299 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004300 new_iir = I915_READ(IIR); /* Flush posted writes */
4301
Chris Wilsona266c7d2012-04-24 22:59:44 +01004302 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004303 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004304 if (iir & I915_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004305 notify_ring(&dev_priv->ring[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004306
Damien Lespiau055e3932014-08-18 13:49:10 +01004307 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004308 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004309 i915_handle_vblank(dev, pipe, pipe, iir))
4310 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004311
4312 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4313 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004314
4315 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004316 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004317
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004318 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4319 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004320 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004321
4322 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4323 intel_opregion_asle_intr(dev);
4324
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004325 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4326 gmbus_irq_handler(dev);
4327
Chris Wilsona266c7d2012-04-24 22:59:44 +01004328 /* With MSI, interrupts are only generated when iir
4329 * transitions from zero to nonzero. If another bit got
4330 * set while we were handling the existing iir bits, then
4331 * we would never get another interrupt.
4332 *
4333 * This is fine on non-MSI as well, as if we hit this path
4334 * we avoid exiting the interrupt handler only to generate
4335 * another one.
4336 *
4337 * Note that for MSI this could cause a stray interrupt report
4338 * if an interrupt landed in the time between writing IIR and
4339 * the posting read. This should be rare enough to never
4340 * trigger the 99% of 100,000 interrupts test for disabling
4341 * stray interrupts.
4342 */
4343 iir = new_iir;
4344 }
4345
4346 return ret;
4347}
4348
4349static void i965_irq_uninstall(struct drm_device * dev)
4350{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004351 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004352 int pipe;
4353
4354 if (!dev_priv)
4355 return;
4356
Egbert Eich0706f172015-09-23 16:15:27 +02004357 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004358 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004359
4360 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004361 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004362 I915_WRITE(PIPESTAT(pipe), 0);
4363 I915_WRITE(IMR, 0xffffffff);
4364 I915_WRITE(IER, 0x0);
4365
Damien Lespiau055e3932014-08-18 13:49:10 +01004366 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004367 I915_WRITE(PIPESTAT(pipe),
4368 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4369 I915_WRITE(IIR, I915_READ(IIR));
4370}
4371
Daniel Vetterfca52a52014-09-30 10:56:45 +02004372/**
4373 * intel_irq_init - initializes irq support
4374 * @dev_priv: i915 device instance
4375 *
4376 * This function initializes all the irq support including work items, timers
4377 * and all the vtables. It does not setup the interrupt itself though.
4378 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004379void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004380{
Daniel Vetterb9632912014-09-30 10:56:44 +02004381 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004382
Jani Nikula77913b32015-06-18 13:06:16 +03004383 intel_hpd_init_work(dev_priv);
4384
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004385 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004386 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004387
Deepak Sa6706b42014-03-15 20:23:22 +05304388 /* Let's track the enabled rps events */
Daniel Vetterb9632912014-09-30 10:56:44 +02004389 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004390 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004391 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004392 else
4393 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304394
Chris Wilson737b1502015-01-26 18:03:03 +02004395 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4396 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004397
Tomas Janousek97a19a22012-12-08 13:48:13 +01004398 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004399
Daniel Vetterb9632912014-09-30 10:56:44 +02004400 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004401 dev->max_vblank_count = 0;
4402 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004403 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004404 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
Ville Syrjäläfd8f5072015-09-18 20:03:42 +03004405 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004406 } else {
4407 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4408 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004409 }
4410
Ville Syrjälä21da2702014-08-06 14:49:55 +03004411 /*
4412 * Opt out of the vblank disable timer on everything except gen2.
4413 * Gen2 doesn't have a hardware frame counter and so depends on
4414 * vblank interrupts to produce sane vblank seuquence numbers.
4415 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004416 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004417 dev->vblank_disable_immediate = true;
4418
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004419 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4420 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004421
Daniel Vetterb9632912014-09-30 10:56:44 +02004422 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004423 dev->driver->irq_handler = cherryview_irq_handler;
4424 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4425 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4426 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4427 dev->driver->enable_vblank = valleyview_enable_vblank;
4428 dev->driver->disable_vblank = valleyview_disable_vblank;
4429 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004430 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004431 dev->driver->irq_handler = valleyview_irq_handler;
4432 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4433 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4434 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4435 dev->driver->enable_vblank = valleyview_enable_vblank;
4436 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004437 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004438 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004439 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004440 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004441 dev->driver->irq_postinstall = gen8_irq_postinstall;
4442 dev->driver->irq_uninstall = gen8_irq_uninstall;
4443 dev->driver->enable_vblank = gen8_enable_vblank;
4444 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004445 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004446 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004447 else if (HAS_PCH_SPT(dev))
4448 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4449 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004450 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004451 } else if (HAS_PCH_SPLIT(dev)) {
4452 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004453 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004454 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4455 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4456 dev->driver->enable_vblank = ironlake_enable_vblank;
4457 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004458 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004459 } else {
Daniel Vetterb9632912014-09-30 10:56:44 +02004460 if (INTEL_INFO(dev_priv)->gen == 2) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004461 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4462 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4463 dev->driver->irq_handler = i8xx_irq_handler;
4464 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Daniel Vetterb9632912014-09-30 10:56:44 +02004465 } else if (INTEL_INFO(dev_priv)->gen == 3) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004466 dev->driver->irq_preinstall = i915_irq_preinstall;
4467 dev->driver->irq_postinstall = i915_irq_postinstall;
4468 dev->driver->irq_uninstall = i915_irq_uninstall;
4469 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004470 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004471 dev->driver->irq_preinstall = i965_irq_preinstall;
4472 dev->driver->irq_postinstall = i965_irq_postinstall;
4473 dev->driver->irq_uninstall = i965_irq_uninstall;
4474 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004475 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004476 if (I915_HAS_HOTPLUG(dev_priv))
4477 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004478 dev->driver->enable_vblank = i915_enable_vblank;
4479 dev->driver->disable_vblank = i915_disable_vblank;
4480 }
4481}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004482
Daniel Vetterfca52a52014-09-30 10:56:45 +02004483/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004484 * intel_irq_install - enables the hardware interrupt
4485 * @dev_priv: i915 device instance
4486 *
4487 * This function enables the hardware interrupt handling, but leaves the hotplug
4488 * handling still disabled. It is called after intel_irq_init().
4489 *
4490 * In the driver load and resume code we need working interrupts in a few places
4491 * but don't want to deal with the hassle of concurrent probe and hotplug
4492 * workers. Hence the split into this two-stage approach.
4493 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004494int intel_irq_install(struct drm_i915_private *dev_priv)
4495{
4496 /*
4497 * We enable some interrupt sources in our postinstall hooks, so mark
4498 * interrupts as enabled _before_ actually enabling them to avoid
4499 * special cases in our ordering checks.
4500 */
4501 dev_priv->pm.irqs_enabled = true;
4502
4503 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4504}
4505
Daniel Vetterfca52a52014-09-30 10:56:45 +02004506/**
4507 * intel_irq_uninstall - finilizes all irq handling
4508 * @dev_priv: i915 device instance
4509 *
4510 * This stops interrupt and hotplug handling and unregisters and frees all
4511 * resources acquired in the init functions.
4512 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004513void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4514{
4515 drm_irq_uninstall(dev_priv->dev);
4516 intel_hpd_cancel_work(dev_priv);
4517 dev_priv->pm.irqs_enabled = false;
4518}
4519
Daniel Vetterfca52a52014-09-30 10:56:45 +02004520/**
4521 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4522 * @dev_priv: i915 device instance
4523 *
4524 * This function is used to disable interrupts at runtime, both in the runtime
4525 * pm and the system suspend/resume code.
4526 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004527void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004528{
Daniel Vetterb9632912014-09-30 10:56:44 +02004529 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004530 dev_priv->pm.irqs_enabled = false;
Imre Deak2dd2a882015-02-24 11:14:30 +02004531 synchronize_irq(dev_priv->dev->irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004532}
4533
Daniel Vetterfca52a52014-09-30 10:56:45 +02004534/**
4535 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4536 * @dev_priv: i915 device instance
4537 *
4538 * This function is used to enable interrupts at runtime, both in the runtime
4539 * pm and the system suspend/resume code.
4540 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004541void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004542{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004543 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004544 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4545 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004546}