blob: ca6d806a195ab50a0ea67236d5b218cf31bb840c [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 */
142#define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
143 u32 val = I915_READ(reg); \
144 if (val) { \
145 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
146 (reg), val); \
147 I915_WRITE((reg), 0xffffffff); \
148 POSTING_READ(reg); \
149 I915_WRITE((reg), 0xffffffff); \
150 POSTING_READ(reg); \
151 } \
152} while (0)
153
Paulo Zanoni35079892014-04-01 15:37:15 -0300154#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300155 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300156 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200157 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
158 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300159} while (0)
160
161#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300162 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300163 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200164 I915_WRITE(type##IMR, (imr_val)); \
165 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300166} while (0)
167
Imre Deakc9a9a262014-11-05 20:48:37 +0200168static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
169
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300170/**
171 * ilk_update_display_irq - update DEIMR
172 * @dev_priv: driver private
173 * @interrupt_mask: mask of interrupt bits to update
174 * @enabled_irq_mask: mask of interrupt bits to enable
175 */
176static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
177 uint32_t interrupt_mask,
178 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800179{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300180 uint32_t new_val;
181
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200182 assert_spin_locked(&dev_priv->irq_lock);
183
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300184 WARN_ON(enabled_irq_mask & ~interrupt_mask);
185
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700186 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300187 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300188
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300189 new_val = dev_priv->irq_mask;
190 new_val &= ~interrupt_mask;
191 new_val |= (~enabled_irq_mask & interrupt_mask);
192
193 if (new_val != dev_priv->irq_mask) {
194 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000195 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000196 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800197 }
198}
199
Daniel Vetter47339cd2014-09-30 10:56:46 +0200200void
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300201ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
202{
203 ilk_update_display_irq(dev_priv, mask, mask);
204}
205
206void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300207ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800208{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300209 ilk_update_display_irq(dev_priv, mask, 0);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800210}
211
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300212/**
213 * ilk_update_gt_irq - update GTIMR
214 * @dev_priv: driver private
215 * @interrupt_mask: mask of interrupt bits to update
216 * @enabled_irq_mask: mask of interrupt bits to enable
217 */
218static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
219 uint32_t interrupt_mask,
220 uint32_t enabled_irq_mask)
221{
222 assert_spin_locked(&dev_priv->irq_lock);
223
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100224 WARN_ON(enabled_irq_mask & ~interrupt_mask);
225
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700226 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300227 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300228
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300229 dev_priv->gt_irq_mask &= ~interrupt_mask;
230 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
231 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
232 POSTING_READ(GTIMR);
233}
234
Daniel Vetter480c8032014-07-16 09:49:40 +0200235void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300236{
237 ilk_update_gt_irq(dev_priv, mask, mask);
238}
239
Daniel Vetter480c8032014-07-16 09:49:40 +0200240void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300241{
242 ilk_update_gt_irq(dev_priv, mask, 0);
243}
244
Imre Deakb900b942014-11-05 20:48:48 +0200245static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
246{
247 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
248}
249
Imre Deaka72fbc32014-11-05 20:48:31 +0200250static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
251{
252 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
253}
254
Imre Deakb900b942014-11-05 20:48:48 +0200255static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
256{
257 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
258}
259
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300260/**
261 * snb_update_pm_irq - update GEN6_PMIMR
262 * @dev_priv: driver private
263 * @interrupt_mask: mask of interrupt bits to update
264 * @enabled_irq_mask: mask of interrupt bits to enable
265 */
266static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
267 uint32_t interrupt_mask,
268 uint32_t enabled_irq_mask)
269{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300270 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300271
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100272 WARN_ON(enabled_irq_mask & ~interrupt_mask);
273
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300274 assert_spin_locked(&dev_priv->irq_lock);
275
Paulo Zanoni605cd252013-08-06 18:57:15 -0300276 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300277 new_val &= ~interrupt_mask;
278 new_val |= (~enabled_irq_mask & interrupt_mask);
279
Paulo Zanoni605cd252013-08-06 18:57:15 -0300280 if (new_val != dev_priv->pm_irq_mask) {
281 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200282 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
283 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300284 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300285}
286
Daniel Vetter480c8032014-07-16 09:49:40 +0200287void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300288{
Imre Deak9939fba2014-11-20 23:01:47 +0200289 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
290 return;
291
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300292 snb_update_pm_irq(dev_priv, mask, mask);
293}
294
Imre Deak9939fba2014-11-20 23:01:47 +0200295static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
296 uint32_t mask)
297{
298 snb_update_pm_irq(dev_priv, mask, 0);
299}
300
Daniel Vetter480c8032014-07-16 09:49:40 +0200301void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300302{
Imre Deak9939fba2014-11-20 23:01:47 +0200303 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
304 return;
305
306 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300307}
308
Imre Deak3cc134e2014-11-19 15:30:03 +0200309void gen6_reset_rps_interrupts(struct drm_device *dev)
310{
311 struct drm_i915_private *dev_priv = dev->dev_private;
312 uint32_t reg = gen6_pm_iir(dev_priv);
313
314 spin_lock_irq(&dev_priv->irq_lock);
315 I915_WRITE(reg, dev_priv->pm_rps_events);
316 I915_WRITE(reg, dev_priv->pm_rps_events);
317 POSTING_READ(reg);
Imre Deak096fad92015-03-23 19:11:35 +0200318 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200319 spin_unlock_irq(&dev_priv->irq_lock);
320}
321
Imre Deakb900b942014-11-05 20:48:48 +0200322void gen6_enable_rps_interrupts(struct drm_device *dev)
323{
324 struct drm_i915_private *dev_priv = dev->dev_private;
325
326 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak78e68d32014-12-15 18:59:27 +0200327
Imre Deakb900b942014-11-05 20:48:48 +0200328 WARN_ON(dev_priv->rps.pm_iir);
Imre Deak3cc134e2014-11-19 15:30:03 +0200329 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200330 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200331 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
332 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200333 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200334
Imre Deakb900b942014-11-05 20:48:48 +0200335 spin_unlock_irq(&dev_priv->irq_lock);
336}
337
Imre Deak59d02a12014-12-19 19:33:26 +0200338u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
339{
340 /*
Imre Deakf24eeb12014-12-19 19:33:27 +0200341 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
Imre Deak59d02a12014-12-19 19:33:26 +0200342 * if GEN6_PM_UP_EI_EXPIRED is masked.
Imre Deakf24eeb12014-12-19 19:33:27 +0200343 *
344 * TODO: verify if this can be reproduced on VLV,CHV.
Imre Deak59d02a12014-12-19 19:33:26 +0200345 */
346 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
347 mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
348
349 if (INTEL_INFO(dev_priv)->gen >= 8)
350 mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
351
352 return mask;
353}
354
Imre Deakb900b942014-11-05 20:48:48 +0200355void gen6_disable_rps_interrupts(struct drm_device *dev)
356{
357 struct drm_i915_private *dev_priv = dev->dev_private;
358
Imre Deakd4d70aa2014-11-19 15:30:04 +0200359 spin_lock_irq(&dev_priv->irq_lock);
360 dev_priv->rps.interrupts_enabled = false;
361 spin_unlock_irq(&dev_priv->irq_lock);
362
363 cancel_work_sync(&dev_priv->rps.work);
364
Imre Deak9939fba2014-11-20 23:01:47 +0200365 spin_lock_irq(&dev_priv->irq_lock);
366
Imre Deak59d02a12014-12-19 19:33:26 +0200367 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200368
369 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200370 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
371 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200372
373 spin_unlock_irq(&dev_priv->irq_lock);
374
375 synchronize_irq(dev->irq);
Imre Deakb900b942014-11-05 20:48:48 +0200376}
377
Ben Widawsky09610212014-05-15 20:58:08 +0300378/**
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300379 * bdw_update_port_irq - update DE port interrupt
380 * @dev_priv: driver private
381 * @interrupt_mask: mask of interrupt bits to update
382 * @enabled_irq_mask: mask of interrupt bits to enable
383 */
384static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
385 uint32_t interrupt_mask,
386 uint32_t enabled_irq_mask)
387{
388 uint32_t new_val;
389 uint32_t old_val;
390
391 assert_spin_locked(&dev_priv->irq_lock);
392
393 WARN_ON(enabled_irq_mask & ~interrupt_mask);
394
395 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
396 return;
397
398 old_val = I915_READ(GEN8_DE_PORT_IMR);
399
400 new_val = old_val;
401 new_val &= ~interrupt_mask;
402 new_val |= (~enabled_irq_mask & interrupt_mask);
403
404 if (new_val != old_val) {
405 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
406 POSTING_READ(GEN8_DE_PORT_IMR);
407 }
408}
409
410/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200411 * ibx_display_interrupt_update - update SDEIMR
412 * @dev_priv: driver private
413 * @interrupt_mask: mask of interrupt bits to update
414 * @enabled_irq_mask: mask of interrupt bits to enable
415 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200416void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
417 uint32_t interrupt_mask,
418 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200419{
420 uint32_t sdeimr = I915_READ(SDEIMR);
421 sdeimr &= ~interrupt_mask;
422 sdeimr |= (~enabled_irq_mask & interrupt_mask);
423
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100424 WARN_ON(enabled_irq_mask & ~interrupt_mask);
425
Daniel Vetterfee884e2013-07-04 23:35:21 +0200426 assert_spin_locked(&dev_priv->irq_lock);
427
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700428 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300429 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300430
Daniel Vetterfee884e2013-07-04 23:35:21 +0200431 I915_WRITE(SDEIMR, sdeimr);
432 POSTING_READ(SDEIMR);
433}
Paulo Zanoni86642812013-04-12 17:57:57 -0300434
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100435static void
Imre Deak755e9012014-02-10 18:42:47 +0200436__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
437 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800438{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200439 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200440 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800441
Daniel Vetterb79480b2013-06-27 17:52:10 +0200442 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200443 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200444
Ville Syrjälä04feced2014-04-03 13:28:33 +0300445 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
446 status_mask & ~PIPESTAT_INT_STATUS_MASK,
447 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
448 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200449 return;
450
451 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200452 return;
453
Imre Deak91d181d2014-02-10 18:42:49 +0200454 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
455
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200456 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200457 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200458 I915_WRITE(reg, pipestat);
459 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800460}
461
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100462static void
Imre Deak755e9012014-02-10 18:42:47 +0200463__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
464 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800465{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200466 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200467 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800468
Daniel Vetterb79480b2013-06-27 17:52:10 +0200469 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200470 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200471
Ville Syrjälä04feced2014-04-03 13:28:33 +0300472 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
473 status_mask & ~PIPESTAT_INT_STATUS_MASK,
474 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
475 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200476 return;
477
Imre Deak755e9012014-02-10 18:42:47 +0200478 if ((pipestat & enable_mask) == 0)
479 return;
480
Imre Deak91d181d2014-02-10 18:42:49 +0200481 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
482
Imre Deak755e9012014-02-10 18:42:47 +0200483 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200484 I915_WRITE(reg, pipestat);
485 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800486}
487
Imre Deak10c59c52014-02-10 18:42:48 +0200488static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
489{
490 u32 enable_mask = status_mask << 16;
491
492 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300493 * On pipe A we don't support the PSR interrupt yet,
494 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200495 */
496 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
497 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300498 /*
499 * On pipe B and C we don't support the PSR interrupt yet, on pipe
500 * A the same bit is for perf counters which we don't use either.
501 */
502 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
503 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200504
505 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
506 SPRITE0_FLIP_DONE_INT_EN_VLV |
507 SPRITE1_FLIP_DONE_INT_EN_VLV);
508 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
509 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
510 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
511 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
512
513 return enable_mask;
514}
515
Imre Deak755e9012014-02-10 18:42:47 +0200516void
517i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
518 u32 status_mask)
519{
520 u32 enable_mask;
521
Imre Deak10c59c52014-02-10 18:42:48 +0200522 if (IS_VALLEYVIEW(dev_priv->dev))
523 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
524 status_mask);
525 else
526 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200527 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
528}
529
530void
531i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
532 u32 status_mask)
533{
534 u32 enable_mask;
535
Imre Deak10c59c52014-02-10 18:42:48 +0200536 if (IS_VALLEYVIEW(dev_priv->dev))
537 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
538 status_mask);
539 else
540 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200541 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
542}
543
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000544/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300545 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000546 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300547static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000548{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300549 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000550
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300551 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
552 return;
553
Daniel Vetter13321782014-09-15 14:55:29 +0200554 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000555
Imre Deak755e9012014-02-10 18:42:47 +0200556 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300557 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200558 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200559 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000560
Daniel Vetter13321782014-09-15 14:55:29 +0200561 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000562}
563
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300564/*
565 * This timing diagram depicts the video signal in and
566 * around the vertical blanking period.
567 *
568 * Assumptions about the fictitious mode used in this example:
569 * vblank_start >= 3
570 * vsync_start = vblank_start + 1
571 * vsync_end = vblank_start + 2
572 * vtotal = vblank_start + 3
573 *
574 * start of vblank:
575 * latch double buffered registers
576 * increment frame counter (ctg+)
577 * generate start of vblank interrupt (gen4+)
578 * |
579 * | frame start:
580 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
581 * | may be shifted forward 1-3 extra lines via PIPECONF
582 * | |
583 * | | start of vsync:
584 * | | generate vsync interrupt
585 * | | |
586 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
587 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
588 * ----va---> <-----------------vb--------------------> <--------va-------------
589 * | | <----vs-----> |
590 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
591 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
592 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
593 * | | |
594 * last visible pixel first visible pixel
595 * | increment frame counter (gen3/4)
596 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
597 *
598 * x = horizontal active
599 * _ = horizontal blanking
600 * hs = horizontal sync
601 * va = vertical active
602 * vb = vertical blanking
603 * vs = vertical sync
604 * vbs = vblank_start (number)
605 *
606 * Summary:
607 * - most events happen at the start of horizontal sync
608 * - frame start happens at the start of horizontal blank, 1-4 lines
609 * (depending on PIPECONF settings) after the start of vblank
610 * - gen3/4 pixel and frame counter are synchronized with the start
611 * of horizontal active on the first line of vertical active
612 */
613
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300614static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
615{
616 /* Gen2 doesn't have a hardware frame counter */
617 return 0;
618}
619
Keith Packard42f52ef2008-10-18 19:39:29 -0700620/* Called from drm generic code, passed a 'crtc', which
621 * we use as a pipe index
622 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700623static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700624{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300625 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700626 unsigned long high_frame;
627 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300628 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100629 struct intel_crtc *intel_crtc =
630 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200631 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700632
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100633 htotal = mode->crtc_htotal;
634 hsync_start = mode->crtc_hsync_start;
635 vbl_start = mode->crtc_vblank_start;
636 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
637 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300638
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300639 /* Convert to pixel count */
640 vbl_start *= htotal;
641
642 /* Start of vblank event occurs at start of hsync */
643 vbl_start -= htotal - hsync_start;
644
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800645 high_frame = PIPEFRAME(pipe);
646 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100647
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700648 /*
649 * High & low register fields aren't synchronized, so make sure
650 * we get a low value that's stable across two reads of the high
651 * register.
652 */
653 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100654 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300655 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100656 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700657 } while (high1 != high2);
658
Chris Wilson5eddb702010-09-11 13:48:45 +0100659 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300660 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100661 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300662
663 /*
664 * The frame counter increments at beginning of active.
665 * Cook up a vblank counter by also checking the pixel
666 * counter against vblank start.
667 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200668 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700669}
670
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700671static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800672{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300673 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800674 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800675
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800676 return I915_READ(reg);
677}
678
Mario Kleinerad3543e2013-10-30 05:13:08 +0100679/* raw reads, only for fast reads of display block, no need for forcewake etc. */
680#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100681
Ville Syrjäläa225f072014-04-29 13:35:45 +0300682static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
683{
684 struct drm_device *dev = crtc->base.dev;
685 struct drm_i915_private *dev_priv = dev->dev_private;
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200686 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300687 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300688 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300689
Ville Syrjälä80715b22014-05-15 20:23:23 +0300690 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300691 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
692 vtotal /= 2;
693
694 if (IS_GEN2(dev))
695 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
696 else
697 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
698
699 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300700 * See update_scanline_offset() for the details on the
701 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300702 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300703 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300704}
705
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700706static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200707 unsigned int flags, int *vpos, int *hpos,
708 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100709{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300710 struct drm_i915_private *dev_priv = dev->dev_private;
711 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
712 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200713 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300714 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300715 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100716 bool in_vbl = true;
717 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100718 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100719
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200720 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100721 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800722 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100723 return 0;
724 }
725
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300726 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300727 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300728 vtotal = mode->crtc_vtotal;
729 vbl_start = mode->crtc_vblank_start;
730 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100731
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200732 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
733 vbl_start = DIV_ROUND_UP(vbl_start, 2);
734 vbl_end /= 2;
735 vtotal /= 2;
736 }
737
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300738 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
739
Mario Kleinerad3543e2013-10-30 05:13:08 +0100740 /*
741 * Lock uncore.lock, as we will do multiple timing critical raw
742 * register reads, potentially with preemption disabled, so the
743 * following code must not block on uncore.lock.
744 */
745 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300746
Mario Kleinerad3543e2013-10-30 05:13:08 +0100747 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
748
749 /* Get optional system timestamp before query. */
750 if (stime)
751 *stime = ktime_get();
752
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300753 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100754 /* No obvious pixelcount register. Only query vertical
755 * scanout position from Display scan line register.
756 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300757 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100758 } else {
759 /* Have access to pixelcount since start of frame.
760 * We can split this into vertical and horizontal
761 * scanout position.
762 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100763 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100764
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300765 /* convert to pixel counts */
766 vbl_start *= htotal;
767 vbl_end *= htotal;
768 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300769
770 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300771 * In interlaced modes, the pixel counter counts all pixels,
772 * so one field will have htotal more pixels. In order to avoid
773 * the reported position from jumping backwards when the pixel
774 * counter is beyond the length of the shorter field, just
775 * clamp the position the length of the shorter field. This
776 * matches how the scanline counter based position works since
777 * the scanline counter doesn't count the two half lines.
778 */
779 if (position >= vtotal)
780 position = vtotal - 1;
781
782 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300783 * Start of vblank interrupt is triggered at start of hsync,
784 * just prior to the first active line of vblank. However we
785 * consider lines to start at the leading edge of horizontal
786 * active. So, should we get here before we've crossed into
787 * the horizontal active of the first line in vblank, we would
788 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
789 * always add htotal-hsync_start to the current pixel position.
790 */
791 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300792 }
793
Mario Kleinerad3543e2013-10-30 05:13:08 +0100794 /* Get optional system timestamp after query. */
795 if (etime)
796 *etime = ktime_get();
797
798 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
799
800 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
801
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300802 in_vbl = position >= vbl_start && position < vbl_end;
803
804 /*
805 * While in vblank, position will be negative
806 * counting up towards 0 at vbl_end. And outside
807 * vblank, position will be positive counting
808 * up since vbl_end.
809 */
810 if (position >= vbl_start)
811 position -= vbl_end;
812 else
813 position += vtotal - vbl_end;
814
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300815 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300816 *vpos = position;
817 *hpos = 0;
818 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100819 *vpos = position / htotal;
820 *hpos = position - (*vpos * htotal);
821 }
822
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100823 /* In vblank? */
824 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200825 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100826
827 return ret;
828}
829
Ville Syrjäläa225f072014-04-29 13:35:45 +0300830int intel_get_crtc_scanline(struct intel_crtc *crtc)
831{
832 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
833 unsigned long irqflags;
834 int position;
835
836 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
837 position = __intel_get_crtc_scanline(crtc);
838 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
839
840 return position;
841}
842
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700843static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100844 int *max_error,
845 struct timeval *vblank_time,
846 unsigned flags)
847{
Chris Wilson4041b852011-01-22 10:07:56 +0000848 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100849
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700850 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000851 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100852 return -EINVAL;
853 }
854
855 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000856 crtc = intel_get_crtc_for_pipe(dev, pipe);
857 if (crtc == NULL) {
858 DRM_ERROR("Invalid crtc %d\n", pipe);
859 return -EINVAL;
860 }
861
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200862 if (!crtc->hwmode.crtc_clock) {
Chris Wilson4041b852011-01-22 10:07:56 +0000863 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
864 return -EBUSY;
865 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100866
867 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000868 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
869 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300870 crtc,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200871 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100872}
873
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200874static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800875{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300876 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000877 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200878 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200879
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200880 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800881
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200882 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
883
Daniel Vetter20e4d402012-08-08 23:35:39 +0200884 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200885
Jesse Barnes7648fa92010-05-20 14:28:11 -0700886 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000887 busy_up = I915_READ(RCPREVBSYTUPAVG);
888 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800889 max_avg = I915_READ(RCBMAXAVG);
890 min_avg = I915_READ(RCBMINAVG);
891
892 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000893 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200894 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
895 new_delay = dev_priv->ips.cur_delay - 1;
896 if (new_delay < dev_priv->ips.max_delay)
897 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000898 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200899 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
900 new_delay = dev_priv->ips.cur_delay + 1;
901 if (new_delay > dev_priv->ips.min_delay)
902 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800903 }
904
Jesse Barnes7648fa92010-05-20 14:28:11 -0700905 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200906 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800907
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200908 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200909
Jesse Barnesf97108d2010-01-29 11:27:07 -0800910 return;
911}
912
Chris Wilson74cdb332015-04-07 16:21:05 +0100913static void notify_ring(struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +0100914{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +0100915 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +0000916 return;
917
John Harrisonbcfcc8b2014-12-05 13:49:36 +0000918 trace_i915_gem_request_notify(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000919
Chris Wilson549f7362010-10-19 11:19:32 +0100920 wake_up_all(&ring->irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +0100921}
922
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000923static void vlv_c0_read(struct drm_i915_private *dev_priv,
924 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400925{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000926 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
927 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
928 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400929}
930
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000931static bool vlv_c0_above(struct drm_i915_private *dev_priv,
932 const struct intel_rps_ei *old,
933 const struct intel_rps_ei *now,
934 int threshold)
Deepak S31685c22014-07-03 17:33:01 -0400935{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000936 u64 time, c0;
Deepak S31685c22014-07-03 17:33:01 -0400937
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000938 if (old->cz_clock == 0)
939 return false;
Deepak S31685c22014-07-03 17:33:01 -0400940
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000941 time = now->cz_clock - old->cz_clock;
942 time *= threshold * dev_priv->mem_freq;
Deepak S31685c22014-07-03 17:33:01 -0400943
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000944 /* Workload can be split between render + media, e.g. SwapBuffers
945 * being blitted in X after being rendered in mesa. To account for
946 * this we need to combine both engines into our activity counter.
947 */
948 c0 = now->render_c0 - old->render_c0;
949 c0 += now->media_c0 - old->media_c0;
950 c0 *= 100 * VLV_CZ_CLOCK_TO_MILLI_SEC * 4 / 1000;
Deepak S31685c22014-07-03 17:33:01 -0400951
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000952 return c0 >= time;
953}
Deepak S31685c22014-07-03 17:33:01 -0400954
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000955void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
956{
957 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
958 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000959}
960
961static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
962{
963 struct intel_rps_ei now;
964 u32 events = 0;
965
Chris Wilson6f4b12f82015-03-18 09:48:23 +0000966 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000967 return 0;
968
969 vlv_c0_read(dev_priv, &now);
970 if (now.cz_clock == 0)
971 return 0;
Deepak S31685c22014-07-03 17:33:01 -0400972
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000973 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
974 if (!vlv_c0_above(dev_priv,
975 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +0100976 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000977 events |= GEN6_PM_RP_DOWN_THRESHOLD;
978 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -0400979 }
980
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000981 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
982 if (vlv_c0_above(dev_priv,
983 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +0100984 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000985 events |= GEN6_PM_RP_UP_THRESHOLD;
986 dev_priv->rps.up_ei = now;
987 }
988
989 return events;
Deepak S31685c22014-07-03 17:33:01 -0400990}
991
Chris Wilsonf5a4c672015-04-27 13:41:23 +0100992static bool any_waiters(struct drm_i915_private *dev_priv)
993{
994 struct intel_engine_cs *ring;
995 int i;
996
997 for_each_ring(ring, dev_priv, i)
998 if (ring->irq_refcount)
999 return true;
1000
1001 return false;
1002}
1003
Ben Widawsky4912d042011-04-25 11:25:20 -07001004static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001005{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001006 struct drm_i915_private *dev_priv =
1007 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001008 bool client_boost;
1009 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -03001010 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001011
Daniel Vetter59cdb632013-07-04 23:35:28 +02001012 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001013 /* Speed up work cancelation during disabling rps interrupts. */
1014 if (!dev_priv->rps.interrupts_enabled) {
1015 spin_unlock_irq(&dev_priv->irq_lock);
1016 return;
1017 }
Daniel Vetterc6a828d2012-08-08 23:35:35 +02001018 pm_iir = dev_priv->rps.pm_iir;
1019 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +02001020 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1021 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001022 client_boost = dev_priv->rps.client_boost;
1023 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +02001024 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001025
Paulo Zanoni60611c12013-08-15 11:50:01 -03001026 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301027 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001028
Chris Wilson8d3afd72015-05-21 21:01:47 +01001029 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001030 return;
1031
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001032 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001033
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001034 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1035
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001036 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001037 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001038 min = dev_priv->rps.min_freq_softlimit;
1039 max = dev_priv->rps.max_freq_softlimit;
1040
1041 if (client_boost) {
1042 new_delay = dev_priv->rps.max_freq_softlimit;
1043 adj = 0;
1044 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001045 if (adj > 0)
1046 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001047 else /* CHV needs even encode values */
1048 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001049 /*
1050 * For better performance, jump directly
1051 * to RPe if we're below it.
1052 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001053 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001054 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001055 adj = 0;
1056 }
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001057 } else if (any_waiters(dev_priv)) {
1058 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001059 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001060 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1061 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001062 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001063 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001064 adj = 0;
1065 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1066 if (adj < 0)
1067 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001068 else /* CHV needs even encode values */
1069 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001070 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001071 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001072 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001073
Chris Wilsonedcf2842015-04-07 16:20:29 +01001074 dev_priv->rps.last_adj = adj;
1075
Ben Widawsky79249632012-09-07 19:43:42 -07001076 /* sysfs frequency interfaces may have snuck in while servicing the
1077 * interrupt
1078 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001079 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001080 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301081
Ville Syrjäläffe02b42015-02-02 19:09:50 +02001082 intel_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001083
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001084 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001085}
1086
Ben Widawskye3689192012-05-25 16:56:22 -07001087
1088/**
1089 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1090 * occurred.
1091 * @work: workqueue struct
1092 *
1093 * Doesn't actually do anything except notify userspace. As a consequence of
1094 * this event, userspace should try to remap the bad rows since statistically
1095 * it is likely the same row is more likely to go bad again.
1096 */
1097static void ivybridge_parity_work(struct work_struct *work)
1098{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001099 struct drm_i915_private *dev_priv =
1100 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001101 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001102 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001103 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001104 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001105
1106 /* We must turn off DOP level clock gating to access the L3 registers.
1107 * In order to prevent a get/put style interface, acquire struct mutex
1108 * any time we access those registers.
1109 */
1110 mutex_lock(&dev_priv->dev->struct_mutex);
1111
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001112 /* If we've screwed up tracking, just let the interrupt fire again */
1113 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1114 goto out;
1115
Ben Widawskye3689192012-05-25 16:56:22 -07001116 misccpctl = I915_READ(GEN7_MISCCPCTL);
1117 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1118 POSTING_READ(GEN7_MISCCPCTL);
1119
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001120 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1121 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001122
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001123 slice--;
1124 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1125 break;
1126
1127 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1128
1129 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1130
1131 error_status = I915_READ(reg);
1132 row = GEN7_PARITY_ERROR_ROW(error_status);
1133 bank = GEN7_PARITY_ERROR_BANK(error_status);
1134 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1135
1136 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1137 POSTING_READ(reg);
1138
1139 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1140 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1141 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1142 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1143 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1144 parity_event[5] = NULL;
1145
Dave Airlie5bdebb12013-10-11 14:07:25 +10001146 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001147 KOBJ_CHANGE, parity_event);
1148
1149 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1150 slice, row, bank, subbank);
1151
1152 kfree(parity_event[4]);
1153 kfree(parity_event[3]);
1154 kfree(parity_event[2]);
1155 kfree(parity_event[1]);
1156 }
Ben Widawskye3689192012-05-25 16:56:22 -07001157
1158 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1159
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001160out:
1161 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001162 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001163 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001164 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001165
1166 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001167}
1168
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001169static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001170{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001171 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001172
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001173 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001174 return;
1175
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001176 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001177 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001178 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001179
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001180 iir &= GT_PARITY_ERROR(dev);
1181 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1182 dev_priv->l3_parity.which_slice |= 1 << 1;
1183
1184 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1185 dev_priv->l3_parity.which_slice |= 1 << 0;
1186
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001187 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001188}
1189
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001190static void ilk_gt_irq_handler(struct drm_device *dev,
1191 struct drm_i915_private *dev_priv,
1192 u32 gt_iir)
1193{
1194 if (gt_iir &
1195 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Chris Wilson74cdb332015-04-07 16:21:05 +01001196 notify_ring(&dev_priv->ring[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001197 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001198 notify_ring(&dev_priv->ring[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001199}
1200
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001201static void snb_gt_irq_handler(struct drm_device *dev,
1202 struct drm_i915_private *dev_priv,
1203 u32 gt_iir)
1204{
1205
Ben Widawskycc609d52013-05-28 19:22:29 -07001206 if (gt_iir &
1207 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Chris Wilson74cdb332015-04-07 16:21:05 +01001208 notify_ring(&dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001209 if (gt_iir & GT_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001210 notify_ring(&dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001211 if (gt_iir & GT_BLT_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001212 notify_ring(&dev_priv->ring[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001213
Ben Widawskycc609d52013-05-28 19:22:29 -07001214 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1215 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001216 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1217 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001218
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001219 if (gt_iir & GT_PARITY_ERROR(dev))
1220 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001221}
1222
Chris Wilson74cdb332015-04-07 16:21:05 +01001223static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
Ben Widawskyabd58f02013-11-02 21:07:09 -07001224 u32 master_ctl)
1225{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001226 irqreturn_t ret = IRQ_NONE;
1227
1228 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson74cdb332015-04-07 16:21:05 +01001229 u32 tmp = I915_READ_FW(GEN8_GT_IIR(0));
Ben Widawskyabd58f02013-11-02 21:07:09 -07001230 if (tmp) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001231 I915_WRITE_FW(GEN8_GT_IIR(0), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001232 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001233
Chris Wilson74cdb332015-04-07 16:21:05 +01001234 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
1235 intel_lrc_irq_handler(&dev_priv->ring[RCS]);
1236 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
1237 notify_ring(&dev_priv->ring[RCS]);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001238
Chris Wilson74cdb332015-04-07 16:21:05 +01001239 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
1240 intel_lrc_irq_handler(&dev_priv->ring[BCS]);
1241 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
1242 notify_ring(&dev_priv->ring[BCS]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001243 } else
1244 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1245 }
1246
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001247 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson74cdb332015-04-07 16:21:05 +01001248 u32 tmp = I915_READ_FW(GEN8_GT_IIR(1));
Ben Widawskyabd58f02013-11-02 21:07:09 -07001249 if (tmp) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001250 I915_WRITE_FW(GEN8_GT_IIR(1), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001251 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001252
Chris Wilson74cdb332015-04-07 16:21:05 +01001253 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
1254 intel_lrc_irq_handler(&dev_priv->ring[VCS]);
1255 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
1256 notify_ring(&dev_priv->ring[VCS]);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001257
Chris Wilson74cdb332015-04-07 16:21:05 +01001258 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
1259 intel_lrc_irq_handler(&dev_priv->ring[VCS2]);
1260 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
1261 notify_ring(&dev_priv->ring[VCS2]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001262 } else
1263 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1264 }
1265
Chris Wilson74cdb332015-04-07 16:21:05 +01001266 if (master_ctl & GEN8_GT_VECS_IRQ) {
1267 u32 tmp = I915_READ_FW(GEN8_GT_IIR(3));
1268 if (tmp) {
1269 I915_WRITE_FW(GEN8_GT_IIR(3), tmp);
1270 ret = IRQ_HANDLED;
1271
1272 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
1273 intel_lrc_irq_handler(&dev_priv->ring[VECS]);
1274 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
1275 notify_ring(&dev_priv->ring[VECS]);
1276 } else
1277 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1278 }
1279
Ben Widawsky09610212014-05-15 20:58:08 +03001280 if (master_ctl & GEN8_GT_PM_IRQ) {
Chris Wilson74cdb332015-04-07 16:21:05 +01001281 u32 tmp = I915_READ_FW(GEN8_GT_IIR(2));
Ben Widawsky09610212014-05-15 20:58:08 +03001282 if (tmp & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001283 I915_WRITE_FW(GEN8_GT_IIR(2),
1284 tmp & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001285 ret = IRQ_HANDLED;
Imre Deakc9a9a262014-11-05 20:48:37 +02001286 gen6_rps_irq_handler(dev_priv, tmp);
Ben Widawsky09610212014-05-15 20:58:08 +03001287 } else
1288 DRM_ERROR("The master control interrupt lied (PM)!\n");
1289 }
1290
Ben Widawskyabd58f02013-11-02 21:07:09 -07001291 return ret;
1292}
1293
Imre Deak63c88d22015-07-20 14:43:39 -07001294static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1295{
1296 switch (port) {
1297 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001298 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001299 case PORT_B:
1300 return val & PORTB_HOTPLUG_LONG_DETECT;
1301 case PORT_C:
1302 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001303 default:
1304 return false;
1305 }
1306}
1307
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001308static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1309{
1310 switch (port) {
1311 case PORT_E:
1312 return val & PORTE_HOTPLUG_LONG_DETECT;
1313 default:
1314 return false;
1315 }
1316}
1317
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001318static bool spt_port_hotplug_long_detect(enum port port, u32 val)
1319{
1320 switch (port) {
1321 case PORT_A:
1322 return val & PORTA_HOTPLUG_LONG_DETECT;
1323 case PORT_B:
1324 return val & PORTB_HOTPLUG_LONG_DETECT;
1325 case PORT_C:
1326 return val & PORTC_HOTPLUG_LONG_DETECT;
1327 case PORT_D:
1328 return val & PORTD_HOTPLUG_LONG_DETECT;
1329 default:
1330 return false;
1331 }
1332}
1333
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001334static bool ilk_port_hotplug_long_detect(enum port port, u32 val)
1335{
1336 switch (port) {
1337 case PORT_A:
1338 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1339 default:
1340 return false;
1341 }
1342}
1343
Jani Nikula676574d2015-05-28 15:43:53 +03001344static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001345{
1346 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001347 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001348 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001349 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001350 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001351 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001352 return val & PORTD_HOTPLUG_LONG_DETECT;
1353 default:
1354 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001355 }
1356}
1357
Jani Nikula676574d2015-05-28 15:43:53 +03001358static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001359{
1360 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001361 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001362 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001363 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001364 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001365 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001366 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1367 default:
1368 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001369 }
1370}
1371
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001372/*
1373 * Get a bit mask of pins that have triggered, and which ones may be long.
1374 * This can be called multiple times with the same masks to accumulate
1375 * hotplug detection results from several registers.
1376 *
1377 * Note that the caller is expected to zero out the masks initially.
1378 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001379static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001380 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001381 const u32 hpd[HPD_NUM_PINS],
1382 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001383{
Jani Nikula8c841e52015-06-18 13:06:17 +03001384 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001385 int i;
1386
Jani Nikula676574d2015-05-28 15:43:53 +03001387 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001388 if ((hpd[i] & hotplug_trigger) == 0)
1389 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001390
Jani Nikula8c841e52015-06-18 13:06:17 +03001391 *pin_mask |= BIT(i);
1392
Imre Deakcc24fcd2015-07-21 15:32:45 -07001393 if (!intel_hpd_pin_to_port(i, &port))
1394 continue;
1395
Imre Deakfd63e2a2015-07-21 15:32:44 -07001396 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001397 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001398 }
1399
1400 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1401 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1402
1403}
1404
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001405static void gmbus_irq_handler(struct drm_device *dev)
1406{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001407 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001408
Daniel Vetter28c70f12012-12-01 13:53:45 +01001409 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001410}
1411
Daniel Vetterce99c252012-12-01 13:53:47 +01001412static void dp_aux_irq_handler(struct drm_device *dev)
1413{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001414 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001415
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001416 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001417}
1418
Shuang He8bf1e9f2013-10-15 18:55:27 +01001419#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001420static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1421 uint32_t crc0, uint32_t crc1,
1422 uint32_t crc2, uint32_t crc3,
1423 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001424{
1425 struct drm_i915_private *dev_priv = dev->dev_private;
1426 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1427 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001428 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001429
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001430 spin_lock(&pipe_crc->lock);
1431
Damien Lespiau0c912c72013-10-15 18:55:37 +01001432 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001433 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001434 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001435 return;
1436 }
1437
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001438 head = pipe_crc->head;
1439 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001440
1441 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001442 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001443 DRM_ERROR("CRC buffer overflowing\n");
1444 return;
1445 }
1446
1447 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001448
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001449 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001450 entry->crc[0] = crc0;
1451 entry->crc[1] = crc1;
1452 entry->crc[2] = crc2;
1453 entry->crc[3] = crc3;
1454 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001455
1456 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001457 pipe_crc->head = head;
1458
1459 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001460
1461 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001462}
Daniel Vetter277de952013-10-18 16:37:07 +02001463#else
1464static inline void
1465display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1466 uint32_t crc0, uint32_t crc1,
1467 uint32_t crc2, uint32_t crc3,
1468 uint32_t crc4) {}
1469#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001470
Daniel Vetter277de952013-10-18 16:37:07 +02001471
1472static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001473{
1474 struct drm_i915_private *dev_priv = dev->dev_private;
1475
Daniel Vetter277de952013-10-18 16:37:07 +02001476 display_pipe_crc_irq_handler(dev, pipe,
1477 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1478 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001479}
1480
Daniel Vetter277de952013-10-18 16:37:07 +02001481static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001482{
1483 struct drm_i915_private *dev_priv = dev->dev_private;
1484
Daniel Vetter277de952013-10-18 16:37:07 +02001485 display_pipe_crc_irq_handler(dev, pipe,
1486 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1487 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1488 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1489 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1490 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001491}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001492
Daniel Vetter277de952013-10-18 16:37:07 +02001493static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001494{
1495 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001496 uint32_t res1, res2;
1497
1498 if (INTEL_INFO(dev)->gen >= 3)
1499 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1500 else
1501 res1 = 0;
1502
1503 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1504 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1505 else
1506 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001507
Daniel Vetter277de952013-10-18 16:37:07 +02001508 display_pipe_crc_irq_handler(dev, pipe,
1509 I915_READ(PIPE_CRC_RES_RED(pipe)),
1510 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1511 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1512 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001513}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001514
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001515/* The RPS events need forcewake, so we add them to a work queue and mask their
1516 * IMR bits until the work is done. Other interrupts can be processed without
1517 * the work queue. */
1518static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001519{
Deepak Sa6706b42014-03-15 20:23:22 +05301520 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001521 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001522 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001523 if (dev_priv->rps.interrupts_enabled) {
1524 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1525 queue_work(dev_priv->wq, &dev_priv->rps.work);
1526 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001527 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001528 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001529
Imre Deakc9a9a262014-11-05 20:48:37 +02001530 if (INTEL_INFO(dev_priv)->gen >= 8)
1531 return;
1532
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001533 if (HAS_VEBOX(dev_priv->dev)) {
1534 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001535 notify_ring(&dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001536
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001537 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1538 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001539 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001540}
1541
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001542static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1543{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001544 if (!drm_handle_vblank(dev, pipe))
1545 return false;
1546
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001547 return true;
1548}
1549
Imre Deakc1874ed2014-02-04 21:35:46 +02001550static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1551{
1552 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001553 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001554 int pipe;
1555
Imre Deak58ead0d2014-02-04 21:35:47 +02001556 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01001557 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001558 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001559 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001560
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001561 /*
1562 * PIPESTAT bits get signalled even when the interrupt is
1563 * disabled with the mask bits, and some of the status bits do
1564 * not generate interrupts at all (like the underrun bit). Hence
1565 * we need to be careful that we only handle what we want to
1566 * handle.
1567 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001568
1569 /* fifo underruns are filterered in the underrun handler. */
1570 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001571
1572 switch (pipe) {
1573 case PIPE_A:
1574 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1575 break;
1576 case PIPE_B:
1577 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1578 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001579 case PIPE_C:
1580 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1581 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001582 }
1583 if (iir & iir_bit)
1584 mask |= dev_priv->pipestat_irq_mask[pipe];
1585
1586 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001587 continue;
1588
1589 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001590 mask |= PIPESTAT_INT_ENABLE_MASK;
1591 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001592
1593 /*
1594 * Clear the PIPE*STAT regs before the IIR
1595 */
Imre Deak91d181d2014-02-10 18:42:49 +02001596 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1597 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001598 I915_WRITE(reg, pipe_stats[pipe]);
1599 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001600 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001601
Damien Lespiau055e3932014-08-18 13:49:10 +01001602 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001603 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1604 intel_pipe_handle_vblank(dev, pipe))
1605 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001606
Imre Deak579a9b02014-02-04 21:35:48 +02001607 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001608 intel_prepare_page_flip(dev, pipe);
1609 intel_finish_page_flip(dev, pipe);
1610 }
1611
1612 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1613 i9xx_pipe_crc_irq_handler(dev, pipe);
1614
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001615 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1616 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001617 }
1618
1619 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1620 gmbus_irq_handler(dev);
1621}
1622
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001623static void i9xx_hpd_irq_handler(struct drm_device *dev)
1624{
1625 struct drm_i915_private *dev_priv = dev->dev_private;
1626 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001627 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001628
Jani Nikula0d2e4292015-05-27 15:03:39 +03001629 if (!hotplug_status)
1630 return;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001631
Jani Nikula0d2e4292015-05-27 15:03:39 +03001632 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1633 /*
1634 * Make sure hotplug status is cleared before we clear IIR, or else we
1635 * may miss hotplug events.
1636 */
1637 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001638
Jani Nikula0d2e4292015-05-27 15:03:39 +03001639 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
1640 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001641
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001642 if (hotplug_trigger) {
1643 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1644 hotplug_trigger, hpd_status_g4x,
1645 i9xx_port_hotplug_long_detect);
1646
1647 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1648 }
Jani Nikula369712e2015-05-27 15:03:40 +03001649
1650 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1651 dp_aux_irq_handler(dev);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001652 } else {
1653 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001654
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03001655 if (hotplug_trigger) {
1656 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1657 hotplug_trigger, hpd_status_g4x,
1658 i9xx_port_hotplug_long_detect);
1659
1660 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1661 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001662 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001663}
1664
Daniel Vetterff1f5252012-10-02 15:10:55 +02001665static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001666{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001667 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001668 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001669 u32 iir, gt_iir, pm_iir;
1670 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001671
Imre Deak2dd2a882015-02-24 11:14:30 +02001672 if (!intel_irqs_enabled(dev_priv))
1673 return IRQ_NONE;
1674
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001675 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001676 /* Find, clear, then process each source of interrupt */
1677
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001678 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001679 if (gt_iir)
1680 I915_WRITE(GTIIR, gt_iir);
1681
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001682 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001683 if (pm_iir)
1684 I915_WRITE(GEN6_PMIIR, pm_iir);
1685
1686 iir = I915_READ(VLV_IIR);
1687 if (iir) {
1688 /* Consume port before clearing IIR or we'll miss events */
1689 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1690 i9xx_hpd_irq_handler(dev);
1691 I915_WRITE(VLV_IIR, iir);
1692 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001693
1694 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1695 goto out;
1696
1697 ret = IRQ_HANDLED;
1698
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001699 if (gt_iir)
1700 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001701 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001702 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001703 /* Call regardless, as some status bits might not be
1704 * signalled in iir */
1705 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001706 }
1707
1708out:
1709 return ret;
1710}
1711
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001712static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1713{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001714 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001715 struct drm_i915_private *dev_priv = dev->dev_private;
1716 u32 master_ctl, iir;
1717 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001718
Imre Deak2dd2a882015-02-24 11:14:30 +02001719 if (!intel_irqs_enabled(dev_priv))
1720 return IRQ_NONE;
1721
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001722 for (;;) {
1723 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1724 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001725
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001726 if (master_ctl == 0 && iir == 0)
1727 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001728
Oscar Mateo27b6c122014-06-16 16:11:00 +01001729 ret = IRQ_HANDLED;
1730
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001731 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001732
Oscar Mateo27b6c122014-06-16 16:11:00 +01001733 /* Find, clear, then process each source of interrupt */
1734
1735 if (iir) {
1736 /* Consume port before clearing IIR or we'll miss events */
1737 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1738 i9xx_hpd_irq_handler(dev);
1739 I915_WRITE(VLV_IIR, iir);
1740 }
1741
Chris Wilson74cdb332015-04-07 16:21:05 +01001742 gen8_gt_irq_handler(dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001743
Oscar Mateo27b6c122014-06-16 16:11:00 +01001744 /* Call regardless, as some status bits might not be
1745 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001746 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001747
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001748 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1749 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001750 }
1751
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001752 return ret;
1753}
1754
Ville Syrjälä40e56412015-08-27 23:56:10 +03001755static void ibx_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
1756 const u32 hpd[HPD_NUM_PINS])
1757{
1758 struct drm_i915_private *dev_priv = to_i915(dev);
1759 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1760
1761 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1762 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1763
1764 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1765 dig_hotplug_reg, hpd,
1766 pch_port_hotplug_long_detect);
1767
1768 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1769}
1770
Adam Jackson23e81d62012-06-06 15:45:44 -04001771static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001772{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001773 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001774 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001775 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001776
Ville Syrjälä40e56412015-08-27 23:56:10 +03001777 if (hotplug_trigger)
1778 ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001779
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001780 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1781 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1782 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001783 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001784 port_name(port));
1785 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001786
Daniel Vetterce99c252012-12-01 13:53:47 +01001787 if (pch_iir & SDE_AUX_MASK)
1788 dp_aux_irq_handler(dev);
1789
Jesse Barnes776ad802011-01-04 15:09:39 -08001790 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001791 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001792
1793 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1794 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1795
1796 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1797 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1798
1799 if (pch_iir & SDE_POISON)
1800 DRM_ERROR("PCH poison interrupt\n");
1801
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001802 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001803 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001804 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1805 pipe_name(pipe),
1806 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001807
1808 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1809 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1810
1811 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1812 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1813
Jesse Barnes776ad802011-01-04 15:09:39 -08001814 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001815 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001816
1817 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001818 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001819}
1820
1821static void ivb_err_int_handler(struct drm_device *dev)
1822{
1823 struct drm_i915_private *dev_priv = dev->dev_private;
1824 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001825 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001826
Paulo Zanonide032bf2013-04-12 17:57:58 -03001827 if (err_int & ERR_INT_POISON)
1828 DRM_ERROR("Poison interrupt\n");
1829
Damien Lespiau055e3932014-08-18 13:49:10 +01001830 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001831 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1832 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03001833
Daniel Vetter5a69b892013-10-16 22:55:52 +02001834 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1835 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001836 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001837 else
Daniel Vetter277de952013-10-18 16:37:07 +02001838 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001839 }
1840 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001841
Paulo Zanoni86642812013-04-12 17:57:57 -03001842 I915_WRITE(GEN7_ERR_INT, err_int);
1843}
1844
1845static void cpt_serr_int_handler(struct drm_device *dev)
1846{
1847 struct drm_i915_private *dev_priv = dev->dev_private;
1848 u32 serr_int = I915_READ(SERR_INT);
1849
Paulo Zanonide032bf2013-04-12 17:57:58 -03001850 if (serr_int & SERR_INT_POISON)
1851 DRM_ERROR("PCH poison interrupt\n");
1852
Paulo Zanoni86642812013-04-12 17:57:57 -03001853 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001854 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001855
1856 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001857 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001858
1859 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001860 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03001861
1862 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001863}
1864
Adam Jackson23e81d62012-06-06 15:45:44 -04001865static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1866{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001867 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04001868 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001869 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001870
Ville Syrjälä40e56412015-08-27 23:56:10 +03001871 if (hotplug_trigger)
1872 ibx_hpd_irq_handler(dev, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02001873
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001874 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1875 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1876 SDE_AUDIO_POWER_SHIFT_CPT);
1877 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1878 port_name(port));
1879 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001880
1881 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001882 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001883
1884 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001885 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001886
1887 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1888 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1889
1890 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1891 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1892
1893 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01001894 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04001895 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1896 pipe_name(pipe),
1897 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001898
1899 if (pch_iir & SDE_ERROR_CPT)
1900 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001901}
1902
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001903static void spt_irq_handler(struct drm_device *dev, u32 pch_iir)
1904{
1905 struct drm_i915_private *dev_priv = dev->dev_private;
1906 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
1907 ~SDE_PORTE_HOTPLUG_SPT;
1908 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
1909 u32 pin_mask = 0, long_mask = 0;
1910
1911 if (hotplug_trigger) {
1912 u32 dig_hotplug_reg;
1913
1914 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1915 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1916
1917 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1918 dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001919 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001920 }
1921
1922 if (hotplug2_trigger) {
1923 u32 dig_hotplug_reg;
1924
1925 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
1926 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
1927
1928 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
1929 dig_hotplug_reg, hpd_spt,
1930 spt_port_hotplug2_long_detect);
1931 }
1932
1933 if (pin_mask)
1934 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1935
1936 if (pch_iir & SDE_GMBUS_CPT)
1937 gmbus_irq_handler(dev);
1938}
1939
Ville Syrjälä40e56412015-08-27 23:56:10 +03001940static void ilk_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
1941 const u32 hpd[HPD_NUM_PINS])
1942{
1943 struct drm_i915_private *dev_priv = to_i915(dev);
1944 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
1945
1946 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
1947 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
1948
1949 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1950 dig_hotplug_reg, hpd,
1951 ilk_port_hotplug_long_detect);
1952
1953 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1954}
1955
Paulo Zanonic008bc62013-07-12 16:35:10 -03001956static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1957{
1958 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001959 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001960 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
1961
Ville Syrjälä40e56412015-08-27 23:56:10 +03001962 if (hotplug_trigger)
1963 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001964
1965 if (de_iir & DE_AUX_CHANNEL_A)
1966 dp_aux_irq_handler(dev);
1967
1968 if (de_iir & DE_GSE)
1969 intel_opregion_asle_intr(dev);
1970
Paulo Zanonic008bc62013-07-12 16:35:10 -03001971 if (de_iir & DE_POISON)
1972 DRM_ERROR("Poison interrupt\n");
1973
Damien Lespiau055e3932014-08-18 13:49:10 +01001974 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001975 if (de_iir & DE_PIPE_VBLANK(pipe) &&
1976 intel_pipe_handle_vblank(dev, pipe))
1977 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001978
Daniel Vetter40da17c2013-10-21 18:04:36 +02001979 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001980 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001981
Daniel Vetter40da17c2013-10-21 18:04:36 +02001982 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1983 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001984
Daniel Vetter40da17c2013-10-21 18:04:36 +02001985 /* plane/pipes map 1:1 on ilk+ */
1986 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1987 intel_prepare_page_flip(dev, pipe);
1988 intel_finish_page_flip_plane(dev, pipe);
1989 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001990 }
1991
1992 /* check event from PCH */
1993 if (de_iir & DE_PCH_EVENT) {
1994 u32 pch_iir = I915_READ(SDEIIR);
1995
1996 if (HAS_PCH_CPT(dev))
1997 cpt_irq_handler(dev, pch_iir);
1998 else
1999 ibx_irq_handler(dev, pch_iir);
2000
2001 /* should clear PCH hotplug event before clear CPU irq */
2002 I915_WRITE(SDEIIR, pch_iir);
2003 }
2004
2005 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
2006 ironlake_rps_change_irq_handler(dev);
2007}
2008
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002009static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
2010{
2011 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00002012 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002013 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2014
Ville Syrjälä40e56412015-08-27 23:56:10 +03002015 if (hotplug_trigger)
2016 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002017
2018 if (de_iir & DE_ERR_INT_IVB)
2019 ivb_err_int_handler(dev);
2020
2021 if (de_iir & DE_AUX_CHANNEL_A_IVB)
2022 dp_aux_irq_handler(dev);
2023
2024 if (de_iir & DE_GSE_IVB)
2025 intel_opregion_asle_intr(dev);
2026
Damien Lespiau055e3932014-08-18 13:49:10 +01002027 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002028 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
2029 intel_pipe_handle_vblank(dev, pipe))
2030 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02002031
2032 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00002033 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
2034 intel_prepare_page_flip(dev, pipe);
2035 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002036 }
2037 }
2038
2039 /* check event from PCH */
2040 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
2041 u32 pch_iir = I915_READ(SDEIIR);
2042
2043 cpt_irq_handler(dev, pch_iir);
2044
2045 /* clear PCH hotplug event before clear CPU irq */
2046 I915_WRITE(SDEIIR, pch_iir);
2047 }
2048}
2049
Oscar Mateo72c90f62014-06-16 16:10:57 +01002050/*
2051 * To handle irqs with the minimum potential races with fresh interrupts, we:
2052 * 1 - Disable Master Interrupt Control.
2053 * 2 - Find the source(s) of the interrupt.
2054 * 3 - Clear the Interrupt Identity bits (IIR).
2055 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2056 * 5 - Re-enable Master Interrupt Control.
2057 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002058static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002059{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002060 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03002061 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002062 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002063 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002064
Imre Deak2dd2a882015-02-24 11:14:30 +02002065 if (!intel_irqs_enabled(dev_priv))
2066 return IRQ_NONE;
2067
Paulo Zanoni86642812013-04-12 17:57:57 -03002068 /* We get interrupts on unclaimed registers, so check for this before we
2069 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01002070 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03002071
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002072 /* disable master interrupt before clearing iir */
2073 de_ier = I915_READ(DEIER);
2074 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03002075 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01002076
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002077 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2078 * interrupts will will be stored on its back queue, and then we'll be
2079 * able to process them after we restore SDEIER (as soon as we restore
2080 * it, we'll get an interrupt if SDEIIR still has something to process
2081 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07002082 if (!HAS_PCH_NOP(dev)) {
2083 sde_ier = I915_READ(SDEIER);
2084 I915_WRITE(SDEIER, 0);
2085 POSTING_READ(SDEIER);
2086 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002087
Oscar Mateo72c90f62014-06-16 16:10:57 +01002088 /* Find, clear, then process each source of interrupt */
2089
Chris Wilson0e434062012-05-09 21:45:44 +01002090 gt_iir = I915_READ(GTIIR);
2091 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002092 I915_WRITE(GTIIR, gt_iir);
2093 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002094 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002095 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002096 else
2097 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002098 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002099
2100 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002101 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002102 I915_WRITE(DEIIR, de_iir);
2103 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002104 if (INTEL_INFO(dev)->gen >= 7)
2105 ivb_display_irq_handler(dev, de_iir);
2106 else
2107 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002108 }
2109
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002110 if (INTEL_INFO(dev)->gen >= 6) {
2111 u32 pm_iir = I915_READ(GEN6_PMIIR);
2112 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002113 I915_WRITE(GEN6_PMIIR, pm_iir);
2114 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002115 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002116 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002117 }
2118
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002119 I915_WRITE(DEIER, de_ier);
2120 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002121 if (!HAS_PCH_NOP(dev)) {
2122 I915_WRITE(SDEIER, sde_ier);
2123 POSTING_READ(SDEIER);
2124 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002125
2126 return ret;
2127}
2128
Ville Syrjälä40e56412015-08-27 23:56:10 +03002129static void bxt_hpd_irq_handler(struct drm_device *dev, u32 hotplug_trigger,
2130 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302131{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002132 struct drm_i915_private *dev_priv = to_i915(dev);
2133 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302134
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002135 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2136 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302137
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002138 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002139 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002140 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002141
Jani Nikula475c2e32015-05-28 15:43:54 +03002142 intel_hpd_irq_handler(dev, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302143}
2144
Ben Widawskyabd58f02013-11-02 21:07:09 -07002145static irqreturn_t gen8_irq_handler(int irq, void *arg)
2146{
2147 struct drm_device *dev = arg;
2148 struct drm_i915_private *dev_priv = dev->dev_private;
2149 u32 master_ctl;
2150 irqreturn_t ret = IRQ_NONE;
2151 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002152 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002153 u32 aux_mask = GEN8_AUX_CHANNEL_A;
2154
Imre Deak2dd2a882015-02-24 11:14:30 +02002155 if (!intel_irqs_enabled(dev_priv))
2156 return IRQ_NONE;
2157
Rodrigo Vivib4834a52015-09-02 15:19:24 -07002158 if (INTEL_INFO(dev_priv)->gen >= 9)
Jesse Barnes88e04702014-11-13 17:51:48 +00002159 aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
2160 GEN9_AUX_CHANNEL_D;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002161
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002162 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002163 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2164 if (!master_ctl)
2165 return IRQ_NONE;
2166
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002167 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002168
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002169 /* Find, clear, then process each source of interrupt */
2170
Chris Wilson74cdb332015-04-07 16:21:05 +01002171 ret = gen8_gt_irq_handler(dev_priv, master_ctl);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002172
2173 if (master_ctl & GEN8_DE_MISC_IRQ) {
2174 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002175 if (tmp) {
2176 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2177 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002178 if (tmp & GEN8_DE_MISC_GSE)
2179 intel_opregion_asle_intr(dev);
2180 else
2181 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002182 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002183 else
2184 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002185 }
2186
Daniel Vetter6d766f02013-11-07 14:49:55 +01002187 if (master_ctl & GEN8_DE_PORT_IRQ) {
2188 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002189 if (tmp) {
Shashank Sharmad04a4922014-08-22 17:40:41 +05302190 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002191 u32 hotplug_trigger = 0;
2192
2193 if (IS_BROXTON(dev_priv))
2194 hotplug_trigger = tmp & BXT_DE_PORT_HOTPLUG_MASK;
2195 else if (IS_BROADWELL(dev_priv))
2196 hotplug_trigger = tmp & GEN8_PORT_DP_A_HOTPLUG;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302197
Daniel Vetter6d766f02013-11-07 14:49:55 +01002198 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2199 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002200
Shashank Sharmad04a4922014-08-22 17:40:41 +05302201 if (tmp & aux_mask) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002202 dp_aux_irq_handler(dev);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302203 found = true;
2204 }
2205
Ville Syrjälä40e56412015-08-27 23:56:10 +03002206 if (hotplug_trigger) {
2207 if (IS_BROXTON(dev))
2208 bxt_hpd_irq_handler(dev, hotplug_trigger, hpd_bxt);
2209 else
2210 ilk_hpd_irq_handler(dev, hotplug_trigger, hpd_bdw);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302211 found = true;
2212 }
2213
Shashank Sharma9e637432014-08-22 17:40:43 +05302214 if (IS_BROXTON(dev) && (tmp & BXT_DE_PORT_GMBUS)) {
2215 gmbus_irq_handler(dev);
2216 found = true;
2217 }
2218
Shashank Sharmad04a4922014-08-22 17:40:41 +05302219 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002220 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002221 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002222 else
2223 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002224 }
2225
Damien Lespiau055e3932014-08-18 13:49:10 +01002226 for_each_pipe(dev_priv, pipe) {
Damien Lespiau770de832014-03-20 20:45:01 +00002227 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002228
Daniel Vetterc42664c2013-11-07 11:05:40 +01002229 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2230 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002231
Daniel Vetterc42664c2013-11-07 11:05:40 +01002232 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002233 if (pipe_iir) {
2234 ret = IRQ_HANDLED;
2235 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Damien Lespiau770de832014-03-20 20:45:01 +00002236
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002237 if (pipe_iir & GEN8_PIPE_VBLANK &&
2238 intel_pipe_handle_vblank(dev, pipe))
2239 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002240
Rodrigo Vivib4834a52015-09-02 15:19:24 -07002241 if (INTEL_INFO(dev_priv)->gen >= 9)
Damien Lespiau770de832014-03-20 20:45:01 +00002242 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2243 else
2244 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2245
2246 if (flip_done) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002247 intel_prepare_page_flip(dev, pipe);
2248 intel_finish_page_flip_plane(dev, pipe);
2249 }
2250
2251 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2252 hsw_pipe_crc_irq_handler(dev, pipe);
2253
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002254 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
2255 intel_cpu_fifo_underrun_irq_handler(dev_priv,
2256 pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002257
Damien Lespiau770de832014-03-20 20:45:01 +00002258
Rodrigo Vivib4834a52015-09-02 15:19:24 -07002259 if (INTEL_INFO(dev_priv)->gen >= 9)
Damien Lespiau770de832014-03-20 20:45:01 +00002260 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2261 else
2262 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2263
2264 if (fault_errors)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002265 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2266 pipe_name(pipe),
2267 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
Daniel Vetterc42664c2013-11-07 11:05:40 +01002268 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002269 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2270 }
2271
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302272 if (HAS_PCH_SPLIT(dev) && !HAS_PCH_NOP(dev) &&
2273 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002274 /*
2275 * FIXME(BDW): Assume for now that the new interrupt handling
2276 * scheme also closed the SDE interrupt handling race we've seen
2277 * on older pch-split platforms. But this needs testing.
2278 */
2279 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002280 if (pch_iir) {
2281 I915_WRITE(SDEIIR, pch_iir);
2282 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002283
2284 if (HAS_PCH_SPT(dev_priv))
2285 spt_irq_handler(dev, pch_iir);
2286 else
2287 cpt_irq_handler(dev, pch_iir);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002288 } else
2289 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2290
Daniel Vetter92d03a82013-11-07 11:05:43 +01002291 }
2292
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002293 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2294 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002295
2296 return ret;
2297}
2298
Daniel Vetter17e1df02013-09-08 21:57:13 +02002299static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2300 bool reset_completed)
2301{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002302 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002303 int i;
2304
2305 /*
2306 * Notify all waiters for GPU completion events that reset state has
2307 * been changed, and that they need to restart their wait after
2308 * checking for potential errors (and bail out to drop locks if there is
2309 * a gpu reset pending so that i915_error_work_func can acquire them).
2310 */
2311
2312 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2313 for_each_ring(ring, dev_priv, i)
2314 wake_up_all(&ring->irq_queue);
2315
2316 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2317 wake_up_all(&dev_priv->pending_flip_queue);
2318
2319 /*
2320 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2321 * reset state is cleared.
2322 */
2323 if (reset_completed)
2324 wake_up_all(&dev_priv->gpu_error.reset_queue);
2325}
2326
Jesse Barnes8a905232009-07-11 16:48:03 -04002327/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002328 * i915_reset_and_wakeup - do process context error handling work
Jesse Barnes8a905232009-07-11 16:48:03 -04002329 *
2330 * Fire an error uevent so userspace can see that a hang or error
2331 * was detected.
2332 */
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002333static void i915_reset_and_wakeup(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002334{
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002335 struct drm_i915_private *dev_priv = to_i915(dev);
2336 struct i915_gpu_error *error = &dev_priv->gpu_error;
Ben Widawskycce723e2013-07-19 09:16:42 -07002337 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2338 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2339 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002340 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002341
Dave Airlie5bdebb12013-10-11 14:07:25 +10002342 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002343
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002344 /*
2345 * Note that there's only one work item which does gpu resets, so we
2346 * need not worry about concurrent gpu resets potentially incrementing
2347 * error->reset_counter twice. We only need to take care of another
2348 * racing irq/hangcheck declaring the gpu dead for a second time. A
2349 * quick check for that is good enough: schedule_work ensures the
2350 * correct ordering between hang detection and this work item, and since
2351 * the reset in-progress bit is only ever set by code outside of this
2352 * work we don't need to worry about any other races.
2353 */
2354 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002355 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002356 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002357 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002358
Daniel Vetter17e1df02013-09-08 21:57:13 +02002359 /*
Imre Deakf454c692014-04-23 01:09:04 +03002360 * In most cases it's guaranteed that we get here with an RPM
2361 * reference held, for example because there is a pending GPU
2362 * request that won't finish until the reset is done. This
2363 * isn't the case at least when we get here by doing a
2364 * simulated reset via debugs, so get an RPM reference.
2365 */
2366 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002367
2368 intel_prepare_reset(dev);
2369
Imre Deakf454c692014-04-23 01:09:04 +03002370 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002371 * All state reset _must_ be completed before we update the
2372 * reset counter, for otherwise waiters might miss the reset
2373 * pending state and not properly drop locks, resulting in
2374 * deadlocks with the reset work.
2375 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002376 ret = i915_reset(dev);
2377
Ville Syrjälä75147472014-11-24 18:28:11 +02002378 intel_finish_reset(dev);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002379
Imre Deakf454c692014-04-23 01:09:04 +03002380 intel_runtime_pm_put(dev_priv);
2381
Daniel Vetterf69061b2012-12-06 09:01:42 +01002382 if (ret == 0) {
2383 /*
2384 * After all the gem state is reset, increment the reset
2385 * counter and wake up everyone waiting for the reset to
2386 * complete.
2387 *
2388 * Since unlock operations are a one-sided barrier only,
2389 * we need to insert a barrier here to order any seqno
2390 * updates before
2391 * the counter increment.
2392 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002393 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002394 atomic_inc(&dev_priv->gpu_error.reset_counter);
2395
Dave Airlie5bdebb12013-10-11 14:07:25 +10002396 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002397 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002398 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002399 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002400 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002401
Daniel Vetter17e1df02013-09-08 21:57:13 +02002402 /*
2403 * Note: The wake_up also serves as a memory barrier so that
2404 * waiters see the update value of the reset counter atomic_t.
2405 */
2406 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002407 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002408}
2409
Chris Wilson35aed2e2010-05-27 13:18:12 +01002410static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002411{
2412 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002413 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002414 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002415 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002416
Chris Wilson35aed2e2010-05-27 13:18:12 +01002417 if (!eir)
2418 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002419
Joe Perchesa70491c2012-03-18 13:00:11 -07002420 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002421
Ben Widawskybd9854f2012-08-23 15:18:09 -07002422 i915_get_extra_instdone(dev, instdone);
2423
Jesse Barnes8a905232009-07-11 16:48:03 -04002424 if (IS_G4X(dev)) {
2425 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2426 u32 ipeir = I915_READ(IPEIR_I965);
2427
Joe Perchesa70491c2012-03-18 13:00:11 -07002428 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2429 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002430 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2431 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002432 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002433 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002434 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002435 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002436 }
2437 if (eir & GM45_ERROR_PAGE_TABLE) {
2438 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002439 pr_err("page table error\n");
2440 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002441 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002442 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002443 }
2444 }
2445
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002446 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002447 if (eir & I915_ERROR_PAGE_TABLE) {
2448 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002449 pr_err("page table error\n");
2450 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002451 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002452 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002453 }
2454 }
2455
2456 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002457 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002458 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002459 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002460 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002461 /* pipestat has already been acked */
2462 }
2463 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002464 pr_err("instruction error\n");
2465 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002466 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2467 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002468 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002469 u32 ipeir = I915_READ(IPEIR);
2470
Joe Perchesa70491c2012-03-18 13:00:11 -07002471 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2472 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002473 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002474 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002475 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002476 } else {
2477 u32 ipeir = I915_READ(IPEIR_I965);
2478
Joe Perchesa70491c2012-03-18 13:00:11 -07002479 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2480 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002481 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002482 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002483 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002484 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002485 }
2486 }
2487
2488 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002489 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002490 eir = I915_READ(EIR);
2491 if (eir) {
2492 /*
2493 * some errors might have become stuck,
2494 * mask them.
2495 */
2496 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2497 I915_WRITE(EMR, I915_READ(EMR) | eir);
2498 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2499 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002500}
2501
2502/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002503 * i915_handle_error - handle a gpu error
Chris Wilson35aed2e2010-05-27 13:18:12 +01002504 * @dev: drm device
2505 *
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002506 * Do some basic checking of regsiter state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002507 * dump it to the syslog. Also call i915_capture_error_state() to make
2508 * sure we get a record and make it available in debugfs. Fire a uevent
2509 * so userspace knows something bad happened (should trigger collection
2510 * of a ring dump etc.).
2511 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002512void i915_handle_error(struct drm_device *dev, bool wedged,
2513 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002514{
2515 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002516 va_list args;
2517 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002518
Mika Kuoppala58174462014-02-25 17:11:26 +02002519 va_start(args, fmt);
2520 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2521 va_end(args);
2522
2523 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002524 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002525
Ben Gamariba1234d2009-09-14 17:48:47 -04002526 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002527 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2528 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002529
Ben Gamari11ed50e2009-09-14 17:48:45 -04002530 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002531 * Wakeup waiting processes so that the reset function
2532 * i915_reset_and_wakeup doesn't deadlock trying to grab
2533 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002534 * processes will see a reset in progress and back off,
2535 * releasing their locks and then wait for the reset completion.
2536 * We must do this for _all_ gpu waiters that might hold locks
2537 * that the reset work needs to acquire.
2538 *
2539 * Note: The wake_up serves as the required memory barrier to
2540 * ensure that the waiters see the updated value of the reset
2541 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002542 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002543 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002544 }
2545
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002546 i915_reset_and_wakeup(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002547}
2548
Keith Packard42f52ef2008-10-18 19:39:29 -07002549/* Called from drm generic code, passed 'crtc' which
2550 * we use as a pipe index
2551 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002552static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002553{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002554 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002555 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002556
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002557 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002558 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002559 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002560 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002561 else
Keith Packard7c463582008-11-04 02:03:27 -08002562 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002563 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002564 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002565
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002566 return 0;
2567}
2568
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002569static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002570{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002571 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002572 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002573 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002574 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002575
Jesse Barnesf796cf82011-04-07 13:58:17 -07002576 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002577 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002578 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2579
2580 return 0;
2581}
2582
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002583static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2584{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002585 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002586 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002587
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002588 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002589 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002590 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002591 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2592
2593 return 0;
2594}
2595
Ben Widawskyabd58f02013-11-02 21:07:09 -07002596static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2597{
2598 struct drm_i915_private *dev_priv = dev->dev_private;
2599 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002600
Ben Widawskyabd58f02013-11-02 21:07:09 -07002601 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002602 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2603 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2604 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002605 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2606 return 0;
2607}
2608
Keith Packard42f52ef2008-10-18 19:39:29 -07002609/* Called from drm generic code, passed 'crtc' which
2610 * we use as a pipe index
2611 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002612static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002613{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002614 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002615 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002616
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002617 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002618 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002619 PIPE_VBLANK_INTERRUPT_STATUS |
2620 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002621 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2622}
2623
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002624static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002625{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002626 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002627 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002628 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002629 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002630
2631 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002632 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002633 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2634}
2635
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002636static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2637{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002638 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002639 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002640
2641 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002642 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002643 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002644 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2645}
2646
Ben Widawskyabd58f02013-11-02 21:07:09 -07002647static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2648{
2649 struct drm_i915_private *dev_priv = dev->dev_private;
2650 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002651
Ben Widawskyabd58f02013-11-02 21:07:09 -07002652 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002653 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2654 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2655 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002656 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2657}
2658
Chris Wilson9107e9d2013-06-10 11:20:20 +01002659static bool
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002660ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002661{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002662 return (list_empty(&ring->request_list) ||
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002663 i915_seqno_passed(seqno, ring->last_submitted_seqno));
Ben Gamarif65d9422009-09-14 17:48:44 -04002664}
2665
Daniel Vettera028c4b2014-03-15 00:08:56 +01002666static bool
2667ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2668{
2669 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002670 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002671 } else {
2672 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2673 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2674 MI_SEMAPHORE_REGISTER);
2675 }
2676}
2677
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002678static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002679semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002680{
2681 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002682 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002683 int i;
2684
2685 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002686 for_each_ring(signaller, dev_priv, i) {
2687 if (ring == signaller)
2688 continue;
2689
2690 if (offset == signaller->semaphore.signal_ggtt[ring->id])
2691 return signaller;
2692 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002693 } else {
2694 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2695
2696 for_each_ring(signaller, dev_priv, i) {
2697 if(ring == signaller)
2698 continue;
2699
Ben Widawskyebc348b2014-04-29 14:52:28 -07002700 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002701 return signaller;
2702 }
2703 }
2704
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002705 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
2706 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002707
2708 return NULL;
2709}
2710
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002711static struct intel_engine_cs *
2712semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002713{
2714 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002715 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002716 u64 offset = 0;
2717 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002718
2719 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002720 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002721 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002722
Daniel Vetter88fe4292014-03-15 00:08:55 +01002723 /*
2724 * HEAD is likely pointing to the dword after the actual command,
2725 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002726 * or 4 dwords depending on the semaphore wait command size.
2727 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002728 * point at at batch, and semaphores are always emitted into the
2729 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002730 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002731 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002732 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002733
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002734 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002735 /*
2736 * Be paranoid and presume the hw has gone off into the wild -
2737 * our ring is smaller than what the hardware (and hence
2738 * HEAD_ADDR) allows. Also handles wrap-around.
2739 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002740 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002741
2742 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002743 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002744 if (cmd == ipehr)
2745 break;
2746
Daniel Vetter88fe4292014-03-15 00:08:55 +01002747 head -= 4;
2748 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002749
Daniel Vetter88fe4292014-03-15 00:08:55 +01002750 if (!i)
2751 return NULL;
2752
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002753 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002754 if (INTEL_INFO(ring->dev)->gen >= 8) {
2755 offset = ioread32(ring->buffer->virtual_start + head + 12);
2756 offset <<= 32;
2757 offset = ioread32(ring->buffer->virtual_start + head + 8);
2758 }
2759 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002760}
2761
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002762static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01002763{
2764 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002765 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002766 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002767
Chris Wilson4be17382014-06-06 10:22:29 +01002768 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002769
2770 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002771 if (signaller == NULL)
2772 return -1;
2773
2774 /* Prevent pathological recursion due to driver bugs */
2775 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01002776 return -1;
2777
Chris Wilson4be17382014-06-06 10:22:29 +01002778 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
2779 return 1;
2780
Chris Wilsona0d036b2014-07-19 12:40:42 +01002781 /* cursory check for an unkickable deadlock */
2782 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2783 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002784 return -1;
2785
2786 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002787}
2788
2789static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2790{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002791 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01002792 int i;
2793
2794 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01002795 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002796}
2797
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002798static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002799ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002800{
2801 struct drm_device *dev = ring->dev;
2802 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002803 u32 tmp;
2804
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002805 if (acthd != ring->hangcheck.acthd) {
2806 if (acthd > ring->hangcheck.max_acthd) {
2807 ring->hangcheck.max_acthd = acthd;
2808 return HANGCHECK_ACTIVE;
2809 }
2810
2811 return HANGCHECK_ACTIVE_LOOP;
2812 }
Chris Wilson6274f212013-06-10 11:20:21 +01002813
Chris Wilson9107e9d2013-06-10 11:20:20 +01002814 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002815 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002816
2817 /* Is the chip hanging on a WAIT_FOR_EVENT?
2818 * If so we can simply poke the RB_WAIT bit
2819 * and break the hang. This should work on
2820 * all but the second generation chipsets.
2821 */
2822 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002823 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002824 i915_handle_error(dev, false,
2825 "Kicking stuck wait on %s",
2826 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002827 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002828 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002829 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002830
Chris Wilson6274f212013-06-10 11:20:21 +01002831 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2832 switch (semaphore_passed(ring)) {
2833 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002834 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002835 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002836 i915_handle_error(dev, false,
2837 "Kicking stuck semaphore on %s",
2838 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002839 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002840 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002841 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002842 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002843 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002844 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002845
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002846 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002847}
2848
Chris Wilson737b1502015-01-26 18:03:03 +02002849/*
Ben Gamarif65d9422009-09-14 17:48:44 -04002850 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002851 * batchbuffers in a long time. We keep track per ring seqno progress and
2852 * if there are no progress, hangcheck score for that ring is increased.
2853 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2854 * we kick the ring. If we see no progress on three subsequent calls
2855 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002856 */
Chris Wilson737b1502015-01-26 18:03:03 +02002857static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04002858{
Chris Wilson737b1502015-01-26 18:03:03 +02002859 struct drm_i915_private *dev_priv =
2860 container_of(work, typeof(*dev_priv),
2861 gpu_error.hangcheck_work.work);
2862 struct drm_device *dev = dev_priv->dev;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002863 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002864 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002865 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002866 bool stuck[I915_NUM_RINGS] = { 0 };
2867#define BUSY 1
2868#define KICK 5
2869#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002870
Jani Nikulad330a952014-01-21 11:24:25 +02002871 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002872 return;
2873
Chris Wilsonb4519512012-05-11 14:29:30 +01002874 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002875 u64 acthd;
2876 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002877 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002878
Chris Wilson6274f212013-06-10 11:20:21 +01002879 semaphore_clear_deadlocks(dev_priv);
2880
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002881 seqno = ring->get_seqno(ring, false);
2882 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002883
Chris Wilson9107e9d2013-06-10 11:20:20 +01002884 if (ring->hangcheck.seqno == seqno) {
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002885 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002886 ring->hangcheck.action = HANGCHECK_IDLE;
2887
Chris Wilson9107e9d2013-06-10 11:20:20 +01002888 if (waitqueue_active(&ring->irq_queue)) {
2889 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002890 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002891 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2892 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2893 ring->name);
2894 else
2895 DRM_INFO("Fake missed irq on %s\n",
2896 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002897 wake_up_all(&ring->irq_queue);
2898 }
2899 /* Safeguard against driver failure */
2900 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002901 } else
2902 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002903 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002904 /* We always increment the hangcheck score
2905 * if the ring is busy and still processing
2906 * the same request, so that no single request
2907 * can run indefinitely (such as a chain of
2908 * batches). The only time we do not increment
2909 * the hangcheck score on this ring, if this
2910 * ring is in a legitimate wait for another
2911 * ring. In that case the waiting ring is a
2912 * victim and we want to be sure we catch the
2913 * right culprit. Then every time we do kick
2914 * the ring, add a small increment to the
2915 * score so that we can catch a batch that is
2916 * being repeatedly kicked and so responsible
2917 * for stalling the machine.
2918 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002919 ring->hangcheck.action = ring_stuck(ring,
2920 acthd);
2921
2922 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002923 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002924 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002925 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002926 break;
2927 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002928 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002929 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002930 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002931 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002932 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002933 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002934 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002935 stuck[i] = true;
2936 break;
2937 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002938 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002939 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002940 ring->hangcheck.action = HANGCHECK_ACTIVE;
2941
Chris Wilson9107e9d2013-06-10 11:20:20 +01002942 /* Gradually reduce the count so that we catch DoS
2943 * attempts across multiple batches.
2944 */
2945 if (ring->hangcheck.score > 0)
2946 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002947
2948 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002949 }
2950
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002951 ring->hangcheck.seqno = seqno;
2952 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002953 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002954 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002955
Mika Kuoppala92cab732013-05-24 17:16:07 +03002956 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002957 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002958 DRM_INFO("%s on %s\n",
2959 stuck[i] ? "stuck" : "no progress",
2960 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002961 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002962 }
2963 }
2964
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002965 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02002966 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04002967
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002968 if (busy_count)
2969 /* Reset timer case chip hangs without another request
2970 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002971 i915_queue_hangcheck(dev);
2972}
2973
2974void i915_queue_hangcheck(struct drm_device *dev)
2975{
Chris Wilson737b1502015-01-26 18:03:03 +02002976 struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
Chris Wilson672e7b72014-11-19 09:47:19 +00002977
Jani Nikulad330a952014-01-21 11:24:25 +02002978 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002979 return;
2980
Chris Wilson737b1502015-01-26 18:03:03 +02002981 /* Don't continually defer the hangcheck so that it is always run at
2982 * least once after work has been scheduled on any ring. Otherwise,
2983 * we will ignore a hung ring if a second ring is kept busy.
2984 */
2985
2986 queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
2987 round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002988}
2989
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03002990static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03002991{
2992 struct drm_i915_private *dev_priv = dev->dev_private;
2993
2994 if (HAS_PCH_NOP(dev))
2995 return;
2996
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03002997 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03002998
2999 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
3000 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003001}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003002
Paulo Zanoni622364b2014-04-01 15:37:22 -03003003/*
3004 * SDEIER is also touched by the interrupt handler to work around missed PCH
3005 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3006 * instead we unconditionally enable all PCH interrupt sources here, but then
3007 * only unmask them as needed with SDEIMR.
3008 *
3009 * This function needs to be called before interrupts are enabled.
3010 */
3011static void ibx_irq_pre_postinstall(struct drm_device *dev)
3012{
3013 struct drm_i915_private *dev_priv = dev->dev_private;
3014
3015 if (HAS_PCH_NOP(dev))
3016 return;
3017
3018 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003019 I915_WRITE(SDEIER, 0xffffffff);
3020 POSTING_READ(SDEIER);
3021}
3022
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003023static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003024{
3025 struct drm_i915_private *dev_priv = dev->dev_private;
3026
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003027 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03003028 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003029 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003030}
3031
Linus Torvalds1da177e2005-04-16 15:20:36 -07003032/* drm_dma.h hooks
3033*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03003034static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003035{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003036 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003037
Paulo Zanoni0c841212014-04-01 15:37:27 -03003038 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01003039
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003040 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03003041 if (IS_GEN7(dev))
3042 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003043
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003044 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00003045
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03003046 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07003047}
3048
Ville Syrjälä70591a42014-10-30 19:42:58 +02003049static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3050{
3051 enum pipe pipe;
3052
3053 I915_WRITE(PORT_HOTPLUG_EN, 0);
3054 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3055
3056 for_each_pipe(dev_priv, pipe)
3057 I915_WRITE(PIPESTAT(pipe), 0xffff);
3058
3059 GEN5_IRQ_RESET(VLV_);
3060}
3061
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003062static void valleyview_irq_preinstall(struct drm_device *dev)
3063{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003064 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003065
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003066 /* VLV magic */
3067 I915_WRITE(VLV_IMR, 0);
3068 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
3069 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
3070 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
3071
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03003072 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003073
Ville Syrjälä7c4cde32014-10-30 19:42:51 +02003074 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003075
Ville Syrjälä70591a42014-10-30 19:42:58 +02003076 vlv_display_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003077}
3078
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003079static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3080{
3081 GEN8_IRQ_RESET_NDX(GT, 0);
3082 GEN8_IRQ_RESET_NDX(GT, 1);
3083 GEN8_IRQ_RESET_NDX(GT, 2);
3084 GEN8_IRQ_RESET_NDX(GT, 3);
3085}
3086
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003087static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003088{
3089 struct drm_i915_private *dev_priv = dev->dev_private;
3090 int pipe;
3091
Ben Widawskyabd58f02013-11-02 21:07:09 -07003092 I915_WRITE(GEN8_MASTER_IRQ, 0);
3093 POSTING_READ(GEN8_MASTER_IRQ);
3094
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003095 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003096
Damien Lespiau055e3932014-08-18 13:49:10 +01003097 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003098 if (intel_display_power_is_enabled(dev_priv,
3099 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003100 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003101
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003102 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3103 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3104 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003105
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303106 if (HAS_PCH_SPLIT(dev))
3107 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003108}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003109
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003110void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3111 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003112{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003113 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003114
Daniel Vetter13321782014-09-15 14:55:29 +02003115 spin_lock_irq(&dev_priv->irq_lock);
Damien Lespiaud14c0342015-03-06 18:50:51 +00003116 if (pipe_mask & 1 << PIPE_A)
3117 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
3118 dev_priv->de_irq_mask[PIPE_A],
3119 ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003120 if (pipe_mask & 1 << PIPE_B)
3121 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
3122 dev_priv->de_irq_mask[PIPE_B],
3123 ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
3124 if (pipe_mask & 1 << PIPE_C)
3125 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
3126 dev_priv->de_irq_mask[PIPE_C],
3127 ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003128 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003129}
3130
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003131static void cherryview_irq_preinstall(struct drm_device *dev)
3132{
3133 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003134
3135 I915_WRITE(GEN8_MASTER_IRQ, 0);
3136 POSTING_READ(GEN8_MASTER_IRQ);
3137
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003138 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003139
3140 GEN5_IRQ_RESET(GEN8_PCU_);
3141
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003142 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3143
Ville Syrjälä70591a42014-10-30 19:42:58 +02003144 vlv_display_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003145}
3146
Ville Syrjälä87a02102015-08-27 23:55:57 +03003147static u32 intel_hpd_enabled_irqs(struct drm_device *dev,
3148 const u32 hpd[HPD_NUM_PINS])
3149{
3150 struct drm_i915_private *dev_priv = to_i915(dev);
3151 struct intel_encoder *encoder;
3152 u32 enabled_irqs = 0;
3153
3154 for_each_intel_encoder(dev, encoder)
3155 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3156 enabled_irqs |= hpd[encoder->hpd_pin];
3157
3158 return enabled_irqs;
3159}
3160
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003161static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003162{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003163 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003164 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003165
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003166 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003167 hotplug_irqs = SDE_HOTPLUG_MASK;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003168 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003169 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003170 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003171 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003172 }
3173
Daniel Vetterfee884e2013-07-04 23:35:21 +02003174 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003175
3176 /*
3177 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003178 * duration to 2ms (which is the minimum in the Display Port spec).
3179 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003180 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003181 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3182 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3183 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3184 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3185 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
Ville Syrjälä0b2eb332015-08-27 23:56:05 +03003186 /*
3187 * When CPU and PCH are on the same package, port A
3188 * HPD must be enabled in both north and south.
3189 */
3190 if (HAS_PCH_LPT_LP(dev))
3191 hotplug |= PORTA_HOTPLUG_ENABLE;
Keith Packard7fe0b972011-09-19 13:31:02 -07003192 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003193}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003194
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003195static void spt_hpd_irq_setup(struct drm_device *dev)
3196{
3197 struct drm_i915_private *dev_priv = dev->dev_private;
3198 u32 hotplug_irqs, hotplug, enabled_irqs;
3199
3200 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
3201 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_spt);
3202
3203 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3204
3205 /* Enable digital hotplug on the PCH */
3206 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3207 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
Ville Syrjälä74c0b392015-08-27 23:56:07 +03003208 PORTB_HOTPLUG_ENABLE | PORTA_HOTPLUG_ENABLE;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003209 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3210
3211 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3212 hotplug |= PORTE_HOTPLUG_ENABLE;
3213 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003214}
3215
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003216static void ilk_hpd_irq_setup(struct drm_device *dev)
3217{
3218 struct drm_i915_private *dev_priv = dev->dev_private;
3219 u32 hotplug_irqs, hotplug, enabled_irqs;
3220
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003221 if (INTEL_INFO(dev)->gen >= 8) {
3222 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
3223 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bdw);
3224
3225 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3226 } else if (INTEL_INFO(dev)->gen >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003227 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
3228 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003229
3230 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003231 } else {
3232 hotplug_irqs = DE_DP_A_HOTPLUG;
3233 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003234
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003235 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3236 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003237
3238 /*
3239 * Enable digital hotplug on the CPU, and configure the DP short pulse
3240 * duration to 2ms (which is the minimum in the Display Port spec)
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003241 * The pulse duration bits are reserved on HSW+.
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003242 */
3243 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3244 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3245 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | DIGITAL_PORTA_PULSE_DURATION_2ms;
3246 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3247
3248 ibx_hpd_irq_setup(dev);
3249}
3250
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003251static void bxt_hpd_irq_setup(struct drm_device *dev)
3252{
3253 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003254 u32 hotplug_irqs, hotplug, enabled_irqs;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003255
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003256 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_bxt);
3257 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003258
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003259 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003260
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003261 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3262 hotplug |= PORTC_HOTPLUG_ENABLE | PORTB_HOTPLUG_ENABLE |
3263 PORTA_HOTPLUG_ENABLE;
3264 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003265}
3266
Paulo Zanonid46da432013-02-08 17:35:15 -02003267static void ibx_irq_postinstall(struct drm_device *dev)
3268{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003269 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003270 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003271
Daniel Vetter692a04c2013-05-29 21:43:05 +02003272 if (HAS_PCH_NOP(dev))
3273 return;
3274
Paulo Zanoni105b1222014-04-01 15:37:17 -03003275 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003276 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003277 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003278 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003279
Paulo Zanoni337ba012014-04-01 15:37:16 -03003280 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003281 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003282}
3283
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003284static void gen5_gt_irq_postinstall(struct drm_device *dev)
3285{
3286 struct drm_i915_private *dev_priv = dev->dev_private;
3287 u32 pm_irqs, gt_irqs;
3288
3289 pm_irqs = gt_irqs = 0;
3290
3291 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003292 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003293 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003294 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3295 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003296 }
3297
3298 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3299 if (IS_GEN5(dev)) {
3300 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3301 ILK_BSD_USER_INTERRUPT;
3302 } else {
3303 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3304 }
3305
Paulo Zanoni35079892014-04-01 15:37:15 -03003306 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003307
3308 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003309 /*
3310 * RPS interrupts will get enabled/disabled on demand when RPS
3311 * itself is enabled/disabled.
3312 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003313 if (HAS_VEBOX(dev))
3314 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3315
Paulo Zanoni605cd252013-08-06 18:57:15 -03003316 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003317 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003318 }
3319}
3320
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003321static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003322{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003323 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003324 u32 display_mask, extra_mask;
3325
3326 if (INTEL_INFO(dev)->gen >= 7) {
3327 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3328 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3329 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003330 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003331 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003332 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3333 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003334 } else {
3335 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3336 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003337 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003338 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3339 DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003340 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3341 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3342 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003343 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003344
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003345 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003346
Paulo Zanoni0c841212014-04-01 15:37:27 -03003347 I915_WRITE(HWSTAM, 0xeffe);
3348
Paulo Zanoni622364b2014-04-01 15:37:22 -03003349 ibx_irq_pre_postinstall(dev);
3350
Paulo Zanoni35079892014-04-01 15:37:15 -03003351 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003352
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003353 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003354
Paulo Zanonid46da432013-02-08 17:35:15 -02003355 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003356
Jesse Barnesf97108d2010-01-29 11:27:07 -08003357 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003358 /* Enable PCU event interrupts
3359 *
3360 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003361 * setup is guaranteed to run in single-threaded context. But we
3362 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003363 spin_lock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003364 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003365 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003366 }
3367
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003368 return 0;
3369}
3370
Imre Deakf8b79e52014-03-04 19:23:07 +02003371static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3372{
3373 u32 pipestat_mask;
3374 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003375 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003376
3377 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3378 PIPE_FIFO_UNDERRUN_STATUS;
3379
Ville Syrjälä120dda42014-10-30 19:42:57 +02003380 for_each_pipe(dev_priv, pipe)
3381 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003382 POSTING_READ(PIPESTAT(PIPE_A));
3383
3384 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3385 PIPE_CRC_DONE_INTERRUPT_STATUS;
3386
Ville Syrjälä120dda42014-10-30 19:42:57 +02003387 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3388 for_each_pipe(dev_priv, pipe)
3389 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003390
3391 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3392 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3393 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003394 if (IS_CHERRYVIEW(dev_priv))
3395 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003396 dev_priv->irq_mask &= ~iir_mask;
3397
3398 I915_WRITE(VLV_IIR, iir_mask);
3399 I915_WRITE(VLV_IIR, iir_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003400 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003401 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3402 POSTING_READ(VLV_IMR);
Imre Deakf8b79e52014-03-04 19:23:07 +02003403}
3404
3405static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3406{
3407 u32 pipestat_mask;
3408 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003409 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003410
3411 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3412 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003413 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003414 if (IS_CHERRYVIEW(dev_priv))
3415 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003416
3417 dev_priv->irq_mask |= iir_mask;
Imre Deakf8b79e52014-03-04 19:23:07 +02003418 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003419 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003420 I915_WRITE(VLV_IIR, iir_mask);
3421 I915_WRITE(VLV_IIR, iir_mask);
3422 POSTING_READ(VLV_IIR);
3423
3424 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3425 PIPE_CRC_DONE_INTERRUPT_STATUS;
3426
Ville Syrjälä120dda42014-10-30 19:42:57 +02003427 i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3428 for_each_pipe(dev_priv, pipe)
3429 i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003430
3431 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3432 PIPE_FIFO_UNDERRUN_STATUS;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003433
3434 for_each_pipe(dev_priv, pipe)
3435 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003436 POSTING_READ(PIPESTAT(PIPE_A));
3437}
3438
3439void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3440{
3441 assert_spin_locked(&dev_priv->irq_lock);
3442
3443 if (dev_priv->display_irqs_enabled)
3444 return;
3445
3446 dev_priv->display_irqs_enabled = true;
3447
Imre Deak950eaba2014-09-08 15:21:09 +03003448 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003449 valleyview_display_irqs_install(dev_priv);
3450}
3451
3452void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3453{
3454 assert_spin_locked(&dev_priv->irq_lock);
3455
3456 if (!dev_priv->display_irqs_enabled)
3457 return;
3458
3459 dev_priv->display_irqs_enabled = false;
3460
Imre Deak950eaba2014-09-08 15:21:09 +03003461 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003462 valleyview_display_irqs_uninstall(dev_priv);
3463}
3464
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003465static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003466{
Imre Deakf8b79e52014-03-04 19:23:07 +02003467 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003468
Daniel Vetter20afbda2012-12-11 14:05:07 +01003469 I915_WRITE(PORT_HOTPLUG_EN, 0);
3470 POSTING_READ(PORT_HOTPLUG_EN);
3471
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003472 I915_WRITE(VLV_IIR, 0xffffffff);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003473 I915_WRITE(VLV_IIR, 0xffffffff);
3474 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3475 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3476 POSTING_READ(VLV_IMR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003477
Daniel Vetterb79480b2013-06-27 17:52:10 +02003478 /* Interrupt setup is already guaranteed to be single-threaded, this is
3479 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003480 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003481 if (dev_priv->display_irqs_enabled)
3482 valleyview_display_irqs_install(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003483 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003484}
3485
3486static int valleyview_irq_postinstall(struct drm_device *dev)
3487{
3488 struct drm_i915_private *dev_priv = dev->dev_private;
3489
3490 vlv_display_irq_postinstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003491
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003492 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003493
3494 /* ack & enable invalid PTE error interrupts */
3495#if 0 /* FIXME: add support to irq handler for checking these bits */
3496 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3497 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3498#endif
3499
3500 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003501
3502 return 0;
3503}
3504
Ben Widawskyabd58f02013-11-02 21:07:09 -07003505static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3506{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003507 /* These are interrupts we'll toggle with the ring mask register */
3508 uint32_t gt_interrupts[] = {
3509 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003510 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003511 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003512 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3513 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003514 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003515 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3516 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3517 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003518 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003519 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3520 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003521 };
3522
Ben Widawsky09610212014-05-15 20:58:08 +03003523 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303524 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3525 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003526 /*
3527 * RPS interrupts will get enabled/disabled on demand when RPS itself
3528 * is enabled/disabled.
3529 */
3530 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303531 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003532}
3533
3534static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3535{
Damien Lespiau770de832014-03-20 20:45:01 +00003536 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3537 uint32_t de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003538 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
3539 u32 de_port_enables;
3540 enum pipe pipe;
Damien Lespiau770de832014-03-20 20:45:01 +00003541
Rodrigo Vivib4834a52015-09-02 15:19:24 -07003542 if (INTEL_INFO(dev_priv)->gen >= 9) {
Damien Lespiau770de832014-03-20 20:45:01 +00003543 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3544 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003545 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
3546 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303547 if (IS_BROXTON(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003548 de_port_masked |= BXT_DE_PORT_GMBUS;
3549 } else {
Damien Lespiau770de832014-03-20 20:45:01 +00003550 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3551 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003552 }
Damien Lespiau770de832014-03-20 20:45:01 +00003553
3554 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3555 GEN8_PIPE_FIFO_UNDERRUN;
3556
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003557 de_port_enables = de_port_masked;
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003558 if (IS_BROXTON(dev_priv))
3559 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
3560 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003561 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
3562
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003563 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3564 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3565 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003566
Damien Lespiau055e3932014-08-18 13:49:10 +01003567 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003568 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003569 POWER_DOMAIN_PIPE(pipe)))
3570 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3571 dev_priv->de_irq_mask[pipe],
3572 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003573
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003574 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003575}
3576
3577static int gen8_irq_postinstall(struct drm_device *dev)
3578{
3579 struct drm_i915_private *dev_priv = dev->dev_private;
3580
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303581 if (HAS_PCH_SPLIT(dev))
3582 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003583
Ben Widawskyabd58f02013-11-02 21:07:09 -07003584 gen8_gt_irq_postinstall(dev_priv);
3585 gen8_de_irq_postinstall(dev_priv);
3586
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303587 if (HAS_PCH_SPLIT(dev))
3588 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003589
3590 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3591 POSTING_READ(GEN8_MASTER_IRQ);
3592
3593 return 0;
3594}
3595
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003596static int cherryview_irq_postinstall(struct drm_device *dev)
3597{
3598 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003599
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003600 vlv_display_irq_postinstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003601
3602 gen8_gt_irq_postinstall(dev_priv);
3603
3604 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3605 POSTING_READ(GEN8_MASTER_IRQ);
3606
3607 return 0;
3608}
3609
Ben Widawskyabd58f02013-11-02 21:07:09 -07003610static void gen8_irq_uninstall(struct drm_device *dev)
3611{
3612 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003613
3614 if (!dev_priv)
3615 return;
3616
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003617 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003618}
3619
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003620static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
3621{
3622 /* Interrupt setup is already guaranteed to be single-threaded, this is
3623 * just to make the assert_spin_locked check happy. */
3624 spin_lock_irq(&dev_priv->irq_lock);
3625 if (dev_priv->display_irqs_enabled)
3626 valleyview_display_irqs_uninstall(dev_priv);
3627 spin_unlock_irq(&dev_priv->irq_lock);
3628
3629 vlv_display_irq_reset(dev_priv);
3630
Imre Deakc352d1b2014-11-20 16:05:55 +02003631 dev_priv->irq_mask = ~0;
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003632}
3633
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003634static void valleyview_irq_uninstall(struct drm_device *dev)
3635{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003636 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003637
3638 if (!dev_priv)
3639 return;
3640
Imre Deak843d0e72014-04-14 20:24:23 +03003641 I915_WRITE(VLV_MASTER_IER, 0);
3642
Ville Syrjälä893fce82014-10-30 19:42:56 +02003643 gen5_gt_irq_reset(dev);
3644
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003645 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003646
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003647 vlv_display_irq_uninstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003648}
3649
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003650static void cherryview_irq_uninstall(struct drm_device *dev)
3651{
3652 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003653
3654 if (!dev_priv)
3655 return;
3656
3657 I915_WRITE(GEN8_MASTER_IRQ, 0);
3658 POSTING_READ(GEN8_MASTER_IRQ);
3659
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003660 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003661
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003662 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003663
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003664 vlv_display_irq_uninstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003665}
3666
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003667static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003668{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003669 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003670
3671 if (!dev_priv)
3672 return;
3673
Paulo Zanonibe30b292014-04-01 15:37:25 -03003674 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003675}
3676
Chris Wilsonc2798b12012-04-22 21:13:57 +01003677static void i8xx_irq_preinstall(struct drm_device * dev)
3678{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003679 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003680 int pipe;
3681
Damien Lespiau055e3932014-08-18 13:49:10 +01003682 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003683 I915_WRITE(PIPESTAT(pipe), 0);
3684 I915_WRITE16(IMR, 0xffff);
3685 I915_WRITE16(IER, 0x0);
3686 POSTING_READ16(IER);
3687}
3688
3689static int i8xx_irq_postinstall(struct drm_device *dev)
3690{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003691 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003692
Chris Wilsonc2798b12012-04-22 21:13:57 +01003693 I915_WRITE16(EMR,
3694 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3695
3696 /* Unmask the interrupts that we always want on. */
3697 dev_priv->irq_mask =
3698 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3699 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3700 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003701 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003702 I915_WRITE16(IMR, dev_priv->irq_mask);
3703
3704 I915_WRITE16(IER,
3705 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3706 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003707 I915_USER_INTERRUPT);
3708 POSTING_READ16(IER);
3709
Daniel Vetter379ef822013-10-16 22:55:56 +02003710 /* Interrupt setup is already guaranteed to be single-threaded, this is
3711 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003712 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003713 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3714 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003715 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003716
Chris Wilsonc2798b12012-04-22 21:13:57 +01003717 return 0;
3718}
3719
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003720/*
3721 * Returns true when a page flip has completed.
3722 */
3723static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003724 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003725{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003726 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003727 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003728
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003729 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003730 return false;
3731
3732 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003733 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003734
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003735 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3736 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3737 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3738 * the flip is completed (no longer pending). Since this doesn't raise
3739 * an interrupt per se, we watch for the change at vblank.
3740 */
3741 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003742 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003743
Ville Syrjälä7d475592014-12-17 23:08:03 +02003744 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003745 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003746 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003747
3748check_page_flip:
3749 intel_check_page_flip(dev, pipe);
3750 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003751}
3752
Daniel Vetterff1f5252012-10-02 15:10:55 +02003753static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003754{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003755 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003756 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003757 u16 iir, new_iir;
3758 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003759 int pipe;
3760 u16 flip_mask =
3761 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3762 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3763
Imre Deak2dd2a882015-02-24 11:14:30 +02003764 if (!intel_irqs_enabled(dev_priv))
3765 return IRQ_NONE;
3766
Chris Wilsonc2798b12012-04-22 21:13:57 +01003767 iir = I915_READ16(IIR);
3768 if (iir == 0)
3769 return IRQ_NONE;
3770
3771 while (iir & ~flip_mask) {
3772 /* Can't rely on pipestat interrupt bit in iir as it might
3773 * have been cleared after the pipestat interrupt was received.
3774 * It doesn't set the bit in iir again, but it still produces
3775 * interrupts (for non-MSI).
3776 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003777 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003778 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003779 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003780
Damien Lespiau055e3932014-08-18 13:49:10 +01003781 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003782 int reg = PIPESTAT(pipe);
3783 pipe_stats[pipe] = I915_READ(reg);
3784
3785 /*
3786 * Clear the PIPE*STAT regs before the IIR
3787 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003788 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003789 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003790 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003791 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003792
3793 I915_WRITE16(IIR, iir & ~flip_mask);
3794 new_iir = I915_READ16(IIR); /* Flush posted writes */
3795
Chris Wilsonc2798b12012-04-22 21:13:57 +01003796 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01003797 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003798
Damien Lespiau055e3932014-08-18 13:49:10 +01003799 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003800 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003801 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003802 plane = !plane;
3803
Daniel Vetter4356d582013-10-16 22:55:55 +02003804 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003805 i8xx_handle_vblank(dev, plane, pipe, iir))
3806 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003807
Daniel Vetter4356d582013-10-16 22:55:55 +02003808 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003809 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003810
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003811 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3812 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3813 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003814 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003815
3816 iir = new_iir;
3817 }
3818
3819 return IRQ_HANDLED;
3820}
3821
3822static void i8xx_irq_uninstall(struct drm_device * dev)
3823{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003824 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003825 int pipe;
3826
Damien Lespiau055e3932014-08-18 13:49:10 +01003827 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003828 /* Clear enable bits; then clear status bits */
3829 I915_WRITE(PIPESTAT(pipe), 0);
3830 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3831 }
3832 I915_WRITE16(IMR, 0xffff);
3833 I915_WRITE16(IER, 0x0);
3834 I915_WRITE16(IIR, I915_READ16(IIR));
3835}
3836
Chris Wilsona266c7d2012-04-24 22:59:44 +01003837static void i915_irq_preinstall(struct drm_device * dev)
3838{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003839 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003840 int pipe;
3841
Chris Wilsona266c7d2012-04-24 22:59:44 +01003842 if (I915_HAS_HOTPLUG(dev)) {
3843 I915_WRITE(PORT_HOTPLUG_EN, 0);
3844 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3845 }
3846
Chris Wilson00d98eb2012-04-24 22:59:48 +01003847 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01003848 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003849 I915_WRITE(PIPESTAT(pipe), 0);
3850 I915_WRITE(IMR, 0xffffffff);
3851 I915_WRITE(IER, 0x0);
3852 POSTING_READ(IER);
3853}
3854
3855static int i915_irq_postinstall(struct drm_device *dev)
3856{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003857 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003858 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003859
Chris Wilson38bde182012-04-24 22:59:50 +01003860 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3861
3862 /* Unmask the interrupts that we always want on. */
3863 dev_priv->irq_mask =
3864 ~(I915_ASLE_INTERRUPT |
3865 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3866 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3867 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003868 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003869
3870 enable_mask =
3871 I915_ASLE_INTERRUPT |
3872 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3873 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003874 I915_USER_INTERRUPT;
3875
Chris Wilsona266c7d2012-04-24 22:59:44 +01003876 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003877 I915_WRITE(PORT_HOTPLUG_EN, 0);
3878 POSTING_READ(PORT_HOTPLUG_EN);
3879
Chris Wilsona266c7d2012-04-24 22:59:44 +01003880 /* Enable in IER... */
3881 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3882 /* and unmask in IMR */
3883 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3884 }
3885
Chris Wilsona266c7d2012-04-24 22:59:44 +01003886 I915_WRITE(IMR, dev_priv->irq_mask);
3887 I915_WRITE(IER, enable_mask);
3888 POSTING_READ(IER);
3889
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003890 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003891
Daniel Vetter379ef822013-10-16 22:55:56 +02003892 /* Interrupt setup is already guaranteed to be single-threaded, this is
3893 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003894 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003895 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3896 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003897 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003898
Daniel Vetter20afbda2012-12-11 14:05:07 +01003899 return 0;
3900}
3901
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003902/*
3903 * Returns true when a page flip has completed.
3904 */
3905static bool i915_handle_vblank(struct drm_device *dev,
3906 int plane, int pipe, u32 iir)
3907{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003908 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003909 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3910
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003911 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003912 return false;
3913
3914 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003915 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003916
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003917 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3918 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3919 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3920 * the flip is completed (no longer pending). Since this doesn't raise
3921 * an interrupt per se, we watch for the change at vblank.
3922 */
3923 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003924 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003925
Ville Syrjälä7d475592014-12-17 23:08:03 +02003926 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003927 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003928 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003929
3930check_page_flip:
3931 intel_check_page_flip(dev, pipe);
3932 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003933}
3934
Daniel Vetterff1f5252012-10-02 15:10:55 +02003935static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003936{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003937 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003938 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003939 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01003940 u32 flip_mask =
3941 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3942 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003943 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003944
Imre Deak2dd2a882015-02-24 11:14:30 +02003945 if (!intel_irqs_enabled(dev_priv))
3946 return IRQ_NONE;
3947
Chris Wilsona266c7d2012-04-24 22:59:44 +01003948 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003949 do {
3950 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003951 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003952
3953 /* Can't rely on pipestat interrupt bit in iir as it might
3954 * have been cleared after the pipestat interrupt was received.
3955 * It doesn't set the bit in iir again, but it still produces
3956 * interrupts (for non-MSI).
3957 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003958 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003959 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003960 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003961
Damien Lespiau055e3932014-08-18 13:49:10 +01003962 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003963 int reg = PIPESTAT(pipe);
3964 pipe_stats[pipe] = I915_READ(reg);
3965
Chris Wilson38bde182012-04-24 22:59:50 +01003966 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003967 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003968 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003969 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003970 }
3971 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003972 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003973
3974 if (!irq_received)
3975 break;
3976
Chris Wilsona266c7d2012-04-24 22:59:44 +01003977 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003978 if (I915_HAS_HOTPLUG(dev) &&
3979 iir & I915_DISPLAY_PORT_INTERRUPT)
3980 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003981
Chris Wilson38bde182012-04-24 22:59:50 +01003982 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003983 new_iir = I915_READ(IIR); /* Flush posted writes */
3984
Chris Wilsona266c7d2012-04-24 22:59:44 +01003985 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01003986 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003987
Damien Lespiau055e3932014-08-18 13:49:10 +01003988 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003989 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003990 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003991 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003992
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003993 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3994 i915_handle_vblank(dev, plane, pipe, iir))
3995 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003996
3997 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3998 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003999
4000 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004001 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004002
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004003 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4004 intel_cpu_fifo_underrun_irq_handler(dev_priv,
4005 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004006 }
4007
Chris Wilsona266c7d2012-04-24 22:59:44 +01004008 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4009 intel_opregion_asle_intr(dev);
4010
4011 /* With MSI, interrupts are only generated when iir
4012 * transitions from zero to nonzero. If another bit got
4013 * set while we were handling the existing iir bits, then
4014 * we would never get another interrupt.
4015 *
4016 * This is fine on non-MSI as well, as if we hit this path
4017 * we avoid exiting the interrupt handler only to generate
4018 * another one.
4019 *
4020 * Note that for MSI this could cause a stray interrupt report
4021 * if an interrupt landed in the time between writing IIR and
4022 * the posting read. This should be rare enough to never
4023 * trigger the 99% of 100,000 interrupts test for disabling
4024 * stray interrupts.
4025 */
Chris Wilson38bde182012-04-24 22:59:50 +01004026 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004027 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01004028 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004029
4030 return ret;
4031}
4032
4033static void i915_irq_uninstall(struct drm_device * dev)
4034{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004035 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004036 int pipe;
4037
Chris Wilsona266c7d2012-04-24 22:59:44 +01004038 if (I915_HAS_HOTPLUG(dev)) {
4039 I915_WRITE(PORT_HOTPLUG_EN, 0);
4040 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4041 }
4042
Chris Wilson00d98eb2012-04-24 22:59:48 +01004043 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004044 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01004045 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01004046 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01004047 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
4048 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004049 I915_WRITE(IMR, 0xffffffff);
4050 I915_WRITE(IER, 0x0);
4051
Chris Wilsona266c7d2012-04-24 22:59:44 +01004052 I915_WRITE(IIR, I915_READ(IIR));
4053}
4054
4055static void i965_irq_preinstall(struct drm_device * dev)
4056{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004057 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004058 int pipe;
4059
Chris Wilsonadca4732012-05-11 18:01:31 +01004060 I915_WRITE(PORT_HOTPLUG_EN, 0);
4061 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004062
4063 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01004064 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004065 I915_WRITE(PIPESTAT(pipe), 0);
4066 I915_WRITE(IMR, 0xffffffff);
4067 I915_WRITE(IER, 0x0);
4068 POSTING_READ(IER);
4069}
4070
4071static int i965_irq_postinstall(struct drm_device *dev)
4072{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004073 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004074 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004075 u32 error_mask;
4076
Chris Wilsona266c7d2012-04-24 22:59:44 +01004077 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004078 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01004079 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004080 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4081 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4082 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4083 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
4084 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
4085
4086 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004087 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4088 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004089 enable_mask |= I915_USER_INTERRUPT;
4090
4091 if (IS_G4X(dev))
4092 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004093
Daniel Vetterb79480b2013-06-27 17:52:10 +02004094 /* Interrupt setup is already guaranteed to be single-threaded, this is
4095 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004096 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004097 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4098 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4099 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004100 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004101
Chris Wilsona266c7d2012-04-24 22:59:44 +01004102 /*
4103 * Enable some error detection, note the instruction error mask
4104 * bit is reserved, so we leave it masked.
4105 */
4106 if (IS_G4X(dev)) {
4107 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4108 GM45_ERROR_MEM_PRIV |
4109 GM45_ERROR_CP_PRIV |
4110 I915_ERROR_MEMORY_REFRESH);
4111 } else {
4112 error_mask = ~(I915_ERROR_PAGE_TABLE |
4113 I915_ERROR_MEMORY_REFRESH);
4114 }
4115 I915_WRITE(EMR, error_mask);
4116
4117 I915_WRITE(IMR, dev_priv->irq_mask);
4118 I915_WRITE(IER, enable_mask);
4119 POSTING_READ(IER);
4120
Daniel Vetter20afbda2012-12-11 14:05:07 +01004121 I915_WRITE(PORT_HOTPLUG_EN, 0);
4122 POSTING_READ(PORT_HOTPLUG_EN);
4123
Jani Nikulaf49e38d2013-04-29 13:02:54 +03004124 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004125
4126 return 0;
4127}
4128
Egbert Eichbac56d52013-02-25 12:06:51 -05004129static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004130{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004131 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter20afbda2012-12-11 14:05:07 +01004132 u32 hotplug_en;
4133
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004134 assert_spin_locked(&dev_priv->irq_lock);
4135
Ville Syrjälä778eb332015-01-09 14:21:13 +02004136 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4137 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4138 /* Note HDMI and DP share hotplug bits */
4139 /* enable bits are the same for all generations */
Ville Syrjälä87a02102015-08-27 23:55:57 +03004140 hotplug_en |= intel_hpd_enabled_irqs(dev, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004141 /* Programming the CRT detection parameters tends
4142 to generate a spurious hotplug event about three
4143 seconds later. So just do it once.
4144 */
4145 if (IS_G4X(dev))
4146 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4147 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
4148 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004149
Ville Syrjälä778eb332015-01-09 14:21:13 +02004150 /* Ignore TV since it's buggy */
4151 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004152}
4153
Daniel Vetterff1f5252012-10-02 15:10:55 +02004154static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004155{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004156 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004157 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004158 u32 iir, new_iir;
4159 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004160 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004161 u32 flip_mask =
4162 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4163 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004164
Imre Deak2dd2a882015-02-24 11:14:30 +02004165 if (!intel_irqs_enabled(dev_priv))
4166 return IRQ_NONE;
4167
Chris Wilsona266c7d2012-04-24 22:59:44 +01004168 iir = I915_READ(IIR);
4169
Chris Wilsona266c7d2012-04-24 22:59:44 +01004170 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004171 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004172 bool blc_event = false;
4173
Chris Wilsona266c7d2012-04-24 22:59:44 +01004174 /* Can't rely on pipestat interrupt bit in iir as it might
4175 * have been cleared after the pipestat interrupt was received.
4176 * It doesn't set the bit in iir again, but it still produces
4177 * interrupts (for non-MSI).
4178 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004179 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004180 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004181 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004182
Damien Lespiau055e3932014-08-18 13:49:10 +01004183 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004184 int reg = PIPESTAT(pipe);
4185 pipe_stats[pipe] = I915_READ(reg);
4186
4187 /*
4188 * Clear the PIPE*STAT regs before the IIR
4189 */
4190 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004191 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004192 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004193 }
4194 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004195 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004196
4197 if (!irq_received)
4198 break;
4199
4200 ret = IRQ_HANDLED;
4201
4202 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004203 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4204 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004205
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004206 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004207 new_iir = I915_READ(IIR); /* Flush posted writes */
4208
Chris Wilsona266c7d2012-04-24 22:59:44 +01004209 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004210 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004211 if (iir & I915_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004212 notify_ring(&dev_priv->ring[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004213
Damien Lespiau055e3932014-08-18 13:49:10 +01004214 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004215 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004216 i915_handle_vblank(dev, pipe, pipe, iir))
4217 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004218
4219 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4220 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004221
4222 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004223 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004224
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004225 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4226 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004227 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004228
4229 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4230 intel_opregion_asle_intr(dev);
4231
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004232 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4233 gmbus_irq_handler(dev);
4234
Chris Wilsona266c7d2012-04-24 22:59:44 +01004235 /* With MSI, interrupts are only generated when iir
4236 * transitions from zero to nonzero. If another bit got
4237 * set while we were handling the existing iir bits, then
4238 * we would never get another interrupt.
4239 *
4240 * This is fine on non-MSI as well, as if we hit this path
4241 * we avoid exiting the interrupt handler only to generate
4242 * another one.
4243 *
4244 * Note that for MSI this could cause a stray interrupt report
4245 * if an interrupt landed in the time between writing IIR and
4246 * the posting read. This should be rare enough to never
4247 * trigger the 99% of 100,000 interrupts test for disabling
4248 * stray interrupts.
4249 */
4250 iir = new_iir;
4251 }
4252
4253 return ret;
4254}
4255
4256static void i965_irq_uninstall(struct drm_device * dev)
4257{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004258 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004259 int pipe;
4260
4261 if (!dev_priv)
4262 return;
4263
Chris Wilsonadca4732012-05-11 18:01:31 +01004264 I915_WRITE(PORT_HOTPLUG_EN, 0);
4265 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004266
4267 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004268 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004269 I915_WRITE(PIPESTAT(pipe), 0);
4270 I915_WRITE(IMR, 0xffffffff);
4271 I915_WRITE(IER, 0x0);
4272
Damien Lespiau055e3932014-08-18 13:49:10 +01004273 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004274 I915_WRITE(PIPESTAT(pipe),
4275 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4276 I915_WRITE(IIR, I915_READ(IIR));
4277}
4278
Daniel Vetterfca52a52014-09-30 10:56:45 +02004279/**
4280 * intel_irq_init - initializes irq support
4281 * @dev_priv: i915 device instance
4282 *
4283 * This function initializes all the irq support including work items, timers
4284 * and all the vtables. It does not setup the interrupt itself though.
4285 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004286void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004287{
Daniel Vetterb9632912014-09-30 10:56:44 +02004288 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004289
Jani Nikula77913b32015-06-18 13:06:16 +03004290 intel_hpd_init_work(dev_priv);
4291
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004292 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004293 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004294
Deepak Sa6706b42014-03-15 20:23:22 +05304295 /* Let's track the enabled rps events */
Daniel Vetterb9632912014-09-30 10:56:44 +02004296 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004297 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004298 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004299 else
4300 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304301
Chris Wilson737b1502015-01-26 18:03:03 +02004302 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4303 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004304
Tomas Janousek97a19a22012-12-08 13:48:13 +01004305 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004306
Daniel Vetterb9632912014-09-30 10:56:44 +02004307 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004308 dev->max_vblank_count = 0;
4309 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004310 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004311 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4312 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004313 } else {
4314 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4315 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004316 }
4317
Ville Syrjälä21da2702014-08-06 14:49:55 +03004318 /*
4319 * Opt out of the vblank disable timer on everything except gen2.
4320 * Gen2 doesn't have a hardware frame counter and so depends on
4321 * vblank interrupts to produce sane vblank seuquence numbers.
4322 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004323 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004324 dev->vblank_disable_immediate = true;
4325
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004326 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4327 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004328
Daniel Vetterb9632912014-09-30 10:56:44 +02004329 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004330 dev->driver->irq_handler = cherryview_irq_handler;
4331 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4332 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4333 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4334 dev->driver->enable_vblank = valleyview_enable_vblank;
4335 dev->driver->disable_vblank = valleyview_disable_vblank;
4336 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004337 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004338 dev->driver->irq_handler = valleyview_irq_handler;
4339 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4340 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4341 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4342 dev->driver->enable_vblank = valleyview_enable_vblank;
4343 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004344 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004345 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004346 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004347 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004348 dev->driver->irq_postinstall = gen8_irq_postinstall;
4349 dev->driver->irq_uninstall = gen8_irq_uninstall;
4350 dev->driver->enable_vblank = gen8_enable_vblank;
4351 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004352 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004353 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004354 else if (HAS_PCH_SPT(dev))
4355 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4356 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004357 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004358 } else if (HAS_PCH_SPLIT(dev)) {
4359 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004360 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004361 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4362 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4363 dev->driver->enable_vblank = ironlake_enable_vblank;
4364 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004365 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004366 } else {
Daniel Vetterb9632912014-09-30 10:56:44 +02004367 if (INTEL_INFO(dev_priv)->gen == 2) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004368 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4369 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4370 dev->driver->irq_handler = i8xx_irq_handler;
4371 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Daniel Vetterb9632912014-09-30 10:56:44 +02004372 } else if (INTEL_INFO(dev_priv)->gen == 3) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004373 dev->driver->irq_preinstall = i915_irq_preinstall;
4374 dev->driver->irq_postinstall = i915_irq_postinstall;
4375 dev->driver->irq_uninstall = i915_irq_uninstall;
4376 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004377 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004378 dev->driver->irq_preinstall = i965_irq_preinstall;
4379 dev->driver->irq_postinstall = i965_irq_postinstall;
4380 dev->driver->irq_uninstall = i965_irq_uninstall;
4381 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004382 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004383 if (I915_HAS_HOTPLUG(dev_priv))
4384 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004385 dev->driver->enable_vblank = i915_enable_vblank;
4386 dev->driver->disable_vblank = i915_disable_vblank;
4387 }
4388}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004389
Daniel Vetterfca52a52014-09-30 10:56:45 +02004390/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004391 * intel_irq_install - enables the hardware interrupt
4392 * @dev_priv: i915 device instance
4393 *
4394 * This function enables the hardware interrupt handling, but leaves the hotplug
4395 * handling still disabled. It is called after intel_irq_init().
4396 *
4397 * In the driver load and resume code we need working interrupts in a few places
4398 * but don't want to deal with the hassle of concurrent probe and hotplug
4399 * workers. Hence the split into this two-stage approach.
4400 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004401int intel_irq_install(struct drm_i915_private *dev_priv)
4402{
4403 /*
4404 * We enable some interrupt sources in our postinstall hooks, so mark
4405 * interrupts as enabled _before_ actually enabling them to avoid
4406 * special cases in our ordering checks.
4407 */
4408 dev_priv->pm.irqs_enabled = true;
4409
4410 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4411}
4412
Daniel Vetterfca52a52014-09-30 10:56:45 +02004413/**
4414 * intel_irq_uninstall - finilizes all irq handling
4415 * @dev_priv: i915 device instance
4416 *
4417 * This stops interrupt and hotplug handling and unregisters and frees all
4418 * resources acquired in the init functions.
4419 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004420void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4421{
4422 drm_irq_uninstall(dev_priv->dev);
4423 intel_hpd_cancel_work(dev_priv);
4424 dev_priv->pm.irqs_enabled = false;
4425}
4426
Daniel Vetterfca52a52014-09-30 10:56:45 +02004427/**
4428 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4429 * @dev_priv: i915 device instance
4430 *
4431 * This function is used to disable interrupts at runtime, both in the runtime
4432 * pm and the system suspend/resume code.
4433 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004434void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004435{
Daniel Vetterb9632912014-09-30 10:56:44 +02004436 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004437 dev_priv->pm.irqs_enabled = false;
Imre Deak2dd2a882015-02-24 11:14:30 +02004438 synchronize_irq(dev_priv->dev->irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004439}
4440
Daniel Vetterfca52a52014-09-30 10:56:45 +02004441/**
4442 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4443 * @dev_priv: i915 device instance
4444 *
4445 * This function is used to enable interrupts at runtime, both in the runtime
4446 * pm and the system suspend/resume code.
4447 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004448void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004449{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004450 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004451 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4452 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004453}