blob: 755d9ceb26a254cecc5e4b02018b613d419cfcfc [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ä7c7e10d2015-01-09 14:21:12 +020048static const u32 hpd_ibx[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050049 [HPD_CRT] = SDE_CRT_HOTPLUG,
50 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
51 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
52 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
53 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
54};
55
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020056static const u32 hpd_cpt[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050057 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010058 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050059 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
60 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
61 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
62};
63
Xiong Zhang26951ca2015-08-17 15:55:50 +080064static const u32 hpd_spt[HPD_NUM_PINS] = {
65 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
66 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
67 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
68 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
69};
70
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020071static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050072 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
73 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
74 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
75 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
76 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
77 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
78};
79
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020080static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050081 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
82 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
83 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
84 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
85 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
86 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
87};
88
Ville Syrjälä4bca26d2015-05-11 20:49:10 +030089static const u32 hpd_status_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050090 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
91 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
92 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
93 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
94 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
95 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
96};
97
Shashank Sharmae0a20ad2015-03-27 14:54:14 +020098/* BXT hpd list */
99static const u32 hpd_bxt[HPD_NUM_PINS] = {
Sonika Jindal7f3561b2015-08-10 10:35:35 +0530100 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200101 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
102 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
103};
104
Paulo Zanoni5c502442014-04-01 15:37:11 -0300105/* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300106#define GEN8_IRQ_RESET_NDX(type, which) do { \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300107 I915_WRITE(GEN8_##type##_IMR(which), 0xffffffff); \
108 POSTING_READ(GEN8_##type##_IMR(which)); \
109 I915_WRITE(GEN8_##type##_IER(which), 0); \
110 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
111 POSTING_READ(GEN8_##type##_IIR(which)); \
112 I915_WRITE(GEN8_##type##_IIR(which), 0xffffffff); \
113 POSTING_READ(GEN8_##type##_IIR(which)); \
114} while (0)
115
Paulo Zanonif86f3fb2014-04-01 15:37:14 -0300116#define GEN5_IRQ_RESET(type) do { \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300117 I915_WRITE(type##IMR, 0xffffffff); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300118 POSTING_READ(type##IMR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300119 I915_WRITE(type##IER, 0); \
Paulo Zanoni5c502442014-04-01 15:37:11 -0300120 I915_WRITE(type##IIR, 0xffffffff); \
121 POSTING_READ(type##IIR); \
122 I915_WRITE(type##IIR, 0xffffffff); \
123 POSTING_READ(type##IIR); \
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300124} while (0)
125
Paulo Zanoni337ba012014-04-01 15:37:16 -0300126/*
127 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
128 */
129#define GEN5_ASSERT_IIR_IS_ZERO(reg) do { \
130 u32 val = I915_READ(reg); \
131 if (val) { \
132 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", \
133 (reg), val); \
134 I915_WRITE((reg), 0xffffffff); \
135 POSTING_READ(reg); \
136 I915_WRITE((reg), 0xffffffff); \
137 POSTING_READ(reg); \
138 } \
139} while (0)
140
Paulo Zanoni35079892014-04-01 15:37:15 -0300141#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300142 GEN5_ASSERT_IIR_IS_ZERO(GEN8_##type##_IIR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300143 I915_WRITE(GEN8_##type##_IER(which), (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200144 I915_WRITE(GEN8_##type##_IMR(which), (imr_val)); \
145 POSTING_READ(GEN8_##type##_IMR(which)); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300146} while (0)
147
148#define GEN5_IRQ_INIT(type, imr_val, ier_val) do { \
Paulo Zanoni337ba012014-04-01 15:37:16 -0300149 GEN5_ASSERT_IIR_IS_ZERO(type##IIR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300150 I915_WRITE(type##IER, (ier_val)); \
Ville Syrjälä7d1bd5392014-10-30 19:42:50 +0200151 I915_WRITE(type##IMR, (imr_val)); \
152 POSTING_READ(type##IMR); \
Paulo Zanoni35079892014-04-01 15:37:15 -0300153} while (0)
154
Imre Deakc9a9a262014-11-05 20:48:37 +0200155static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
156
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300157/**
158 * ilk_update_display_irq - update DEIMR
159 * @dev_priv: driver private
160 * @interrupt_mask: mask of interrupt bits to update
161 * @enabled_irq_mask: mask of interrupt bits to enable
162 */
163static void ilk_update_display_irq(struct drm_i915_private *dev_priv,
164 uint32_t interrupt_mask,
165 uint32_t enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800166{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300167 uint32_t new_val;
168
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200169 assert_spin_locked(&dev_priv->irq_lock);
170
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300171 WARN_ON(enabled_irq_mask & ~interrupt_mask);
172
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700173 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300174 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300175
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300176 new_val = dev_priv->irq_mask;
177 new_val &= ~interrupt_mask;
178 new_val |= (~enabled_irq_mask & interrupt_mask);
179
180 if (new_val != dev_priv->irq_mask) {
181 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000182 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000183 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800184 }
185}
186
Daniel Vetter47339cd2014-09-30 10:56:46 +0200187void
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300188ironlake_enable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
189{
190 ilk_update_display_irq(dev_priv, mask, mask);
191}
192
193void
Jani Nikula2d1013d2014-03-31 14:27:17 +0300194ironlake_disable_display_irq(struct drm_i915_private *dev_priv, u32 mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800195{
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300196 ilk_update_display_irq(dev_priv, mask, 0);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800197}
198
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300199/**
200 * ilk_update_gt_irq - update GTIMR
201 * @dev_priv: driver private
202 * @interrupt_mask: mask of interrupt bits to update
203 * @enabled_irq_mask: mask of interrupt bits to enable
204 */
205static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
206 uint32_t interrupt_mask,
207 uint32_t enabled_irq_mask)
208{
209 assert_spin_locked(&dev_priv->irq_lock);
210
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100211 WARN_ON(enabled_irq_mask & ~interrupt_mask);
212
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700213 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300214 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300215
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300216 dev_priv->gt_irq_mask &= ~interrupt_mask;
217 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
218 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
219 POSTING_READ(GTIMR);
220}
221
Daniel Vetter480c8032014-07-16 09:49:40 +0200222void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300223{
224 ilk_update_gt_irq(dev_priv, mask, mask);
225}
226
Daniel Vetter480c8032014-07-16 09:49:40 +0200227void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300228{
229 ilk_update_gt_irq(dev_priv, mask, 0);
230}
231
Imre Deakb900b942014-11-05 20:48:48 +0200232static u32 gen6_pm_iir(struct drm_i915_private *dev_priv)
233{
234 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
235}
236
Imre Deaka72fbc32014-11-05 20:48:31 +0200237static u32 gen6_pm_imr(struct drm_i915_private *dev_priv)
238{
239 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IMR(2) : GEN6_PMIMR;
240}
241
Imre Deakb900b942014-11-05 20:48:48 +0200242static u32 gen6_pm_ier(struct drm_i915_private *dev_priv)
243{
244 return INTEL_INFO(dev_priv)->gen >= 8 ? GEN8_GT_IER(2) : GEN6_PMIER;
245}
246
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300247/**
248 * snb_update_pm_irq - update GEN6_PMIMR
249 * @dev_priv: driver private
250 * @interrupt_mask: mask of interrupt bits to update
251 * @enabled_irq_mask: mask of interrupt bits to enable
252 */
253static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
254 uint32_t interrupt_mask,
255 uint32_t enabled_irq_mask)
256{
Paulo Zanoni605cd252013-08-06 18:57:15 -0300257 uint32_t new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300258
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100259 WARN_ON(enabled_irq_mask & ~interrupt_mask);
260
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300261 assert_spin_locked(&dev_priv->irq_lock);
262
Paulo Zanoni605cd252013-08-06 18:57:15 -0300263 new_val = dev_priv->pm_irq_mask;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300264 new_val &= ~interrupt_mask;
265 new_val |= (~enabled_irq_mask & interrupt_mask);
266
Paulo Zanoni605cd252013-08-06 18:57:15 -0300267 if (new_val != dev_priv->pm_irq_mask) {
268 dev_priv->pm_irq_mask = new_val;
Imre Deaka72fbc32014-11-05 20:48:31 +0200269 I915_WRITE(gen6_pm_imr(dev_priv), dev_priv->pm_irq_mask);
270 POSTING_READ(gen6_pm_imr(dev_priv));
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300271 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300272}
273
Daniel Vetter480c8032014-07-16 09:49:40 +0200274void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300275{
Imre Deak9939fba2014-11-20 23:01:47 +0200276 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
277 return;
278
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300279 snb_update_pm_irq(dev_priv, mask, mask);
280}
281
Imre Deak9939fba2014-11-20 23:01:47 +0200282static void __gen6_disable_pm_irq(struct drm_i915_private *dev_priv,
283 uint32_t mask)
284{
285 snb_update_pm_irq(dev_priv, mask, 0);
286}
287
Daniel Vetter480c8032014-07-16 09:49:40 +0200288void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, uint32_t mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300289{
Imre Deak9939fba2014-11-20 23:01:47 +0200290 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
291 return;
292
293 __gen6_disable_pm_irq(dev_priv, mask);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300294}
295
Imre Deak3cc134e2014-11-19 15:30:03 +0200296void gen6_reset_rps_interrupts(struct drm_device *dev)
297{
298 struct drm_i915_private *dev_priv = dev->dev_private;
299 uint32_t reg = gen6_pm_iir(dev_priv);
300
301 spin_lock_irq(&dev_priv->irq_lock);
302 I915_WRITE(reg, dev_priv->pm_rps_events);
303 I915_WRITE(reg, dev_priv->pm_rps_events);
304 POSTING_READ(reg);
Imre Deak096fad92015-03-23 19:11:35 +0200305 dev_priv->rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200306 spin_unlock_irq(&dev_priv->irq_lock);
307}
308
Imre Deakb900b942014-11-05 20:48:48 +0200309void gen6_enable_rps_interrupts(struct drm_device *dev)
310{
311 struct drm_i915_private *dev_priv = dev->dev_private;
312
313 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak78e68d32014-12-15 18:59:27 +0200314
Imre Deakb900b942014-11-05 20:48:48 +0200315 WARN_ON(dev_priv->rps.pm_iir);
Imre Deak3cc134e2014-11-19 15:30:03 +0200316 WARN_ON(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200317 dev_priv->rps.interrupts_enabled = true;
Imre Deak78e68d32014-12-15 18:59:27 +0200318 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) |
319 dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200320 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200321
Imre Deakb900b942014-11-05 20:48:48 +0200322 spin_unlock_irq(&dev_priv->irq_lock);
323}
324
Imre Deak59d02a12014-12-19 19:33:26 +0200325u32 gen6_sanitize_rps_pm_mask(struct drm_i915_private *dev_priv, u32 mask)
326{
327 /*
Imre Deakf24eeb12014-12-19 19:33:27 +0200328 * SNB,IVB can while VLV,CHV may hard hang on looping batchbuffer
Imre Deak59d02a12014-12-19 19:33:26 +0200329 * if GEN6_PM_UP_EI_EXPIRED is masked.
Imre Deakf24eeb12014-12-19 19:33:27 +0200330 *
331 * TODO: verify if this can be reproduced on VLV,CHV.
Imre Deak59d02a12014-12-19 19:33:26 +0200332 */
333 if (INTEL_INFO(dev_priv)->gen <= 7 && !IS_HASWELL(dev_priv))
334 mask &= ~GEN6_PM_RP_UP_EI_EXPIRED;
335
336 if (INTEL_INFO(dev_priv)->gen >= 8)
337 mask &= ~GEN8_PMINTR_REDIRECT_TO_NON_DISP;
338
339 return mask;
340}
341
Imre Deakb900b942014-11-05 20:48:48 +0200342void gen6_disable_rps_interrupts(struct drm_device *dev)
343{
344 struct drm_i915_private *dev_priv = dev->dev_private;
345
Imre Deakd4d70aa2014-11-19 15:30:04 +0200346 spin_lock_irq(&dev_priv->irq_lock);
347 dev_priv->rps.interrupts_enabled = false;
348 spin_unlock_irq(&dev_priv->irq_lock);
349
350 cancel_work_sync(&dev_priv->rps.work);
351
Imre Deak9939fba2014-11-20 23:01:47 +0200352 spin_lock_irq(&dev_priv->irq_lock);
353
Imre Deak59d02a12014-12-19 19:33:26 +0200354 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0));
Imre Deak9939fba2014-11-20 23:01:47 +0200355
356 __gen6_disable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deakb900b942014-11-05 20:48:48 +0200357 I915_WRITE(gen6_pm_ier(dev_priv), I915_READ(gen6_pm_ier(dev_priv)) &
358 ~dev_priv->pm_rps_events);
Imre Deak58072cc2015-03-23 19:11:34 +0200359
360 spin_unlock_irq(&dev_priv->irq_lock);
361
362 synchronize_irq(dev->irq);
Imre Deakb900b942014-11-05 20:48:48 +0200363}
364
Ben Widawsky09610212014-05-15 20:58:08 +0300365/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200366 * ibx_display_interrupt_update - update SDEIMR
367 * @dev_priv: driver private
368 * @interrupt_mask: mask of interrupt bits to update
369 * @enabled_irq_mask: mask of interrupt bits to enable
370 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200371void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
372 uint32_t interrupt_mask,
373 uint32_t enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200374{
375 uint32_t sdeimr = I915_READ(SDEIMR);
376 sdeimr &= ~interrupt_mask;
377 sdeimr |= (~enabled_irq_mask & interrupt_mask);
378
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100379 WARN_ON(enabled_irq_mask & ~interrupt_mask);
380
Daniel Vetterfee884e2013-07-04 23:35:21 +0200381 assert_spin_locked(&dev_priv->irq_lock);
382
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700383 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300384 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300385
Daniel Vetterfee884e2013-07-04 23:35:21 +0200386 I915_WRITE(SDEIMR, sdeimr);
387 POSTING_READ(SDEIMR);
388}
Paulo Zanoni86642812013-04-12 17:57:57 -0300389
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100390static void
Imre Deak755e9012014-02-10 18:42:47 +0200391__i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
392 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800393{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200394 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200395 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800396
Daniel Vetterb79480b2013-06-27 17:52:10 +0200397 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200398 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200399
Ville Syrjälä04feced2014-04-03 13:28:33 +0300400 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
401 status_mask & ~PIPESTAT_INT_STATUS_MASK,
402 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
403 pipe_name(pipe), enable_mask, status_mask))
Imre Deak755e9012014-02-10 18:42:47 +0200404 return;
405
406 if ((pipestat & enable_mask) == enable_mask)
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200407 return;
408
Imre Deak91d181d2014-02-10 18:42:49 +0200409 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
410
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200411 /* Enable the interrupt, clear any pending status */
Imre Deak755e9012014-02-10 18:42:47 +0200412 pipestat |= enable_mask | status_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200413 I915_WRITE(reg, pipestat);
414 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800415}
416
Daniel Vetterb5ea6422014-03-02 21:18:00 +0100417static void
Imre Deak755e9012014-02-10 18:42:47 +0200418__i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
419 u32 enable_mask, u32 status_mask)
Keith Packard7c463582008-11-04 02:03:27 -0800420{
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200421 u32 reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200422 u32 pipestat = I915_READ(reg) & PIPESTAT_INT_ENABLE_MASK;
Keith Packard7c463582008-11-04 02:03:27 -0800423
Daniel Vetterb79480b2013-06-27 17:52:10 +0200424 assert_spin_locked(&dev_priv->irq_lock);
Daniel Vetterd518ce52014-08-27 10:43:37 +0200425 WARN_ON(!intel_irqs_enabled(dev_priv));
Daniel Vetterb79480b2013-06-27 17:52:10 +0200426
Ville Syrjälä04feced2014-04-03 13:28:33 +0300427 if (WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
428 status_mask & ~PIPESTAT_INT_STATUS_MASK,
429 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
430 pipe_name(pipe), enable_mask, status_mask))
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200431 return;
432
Imre Deak755e9012014-02-10 18:42:47 +0200433 if ((pipestat & enable_mask) == 0)
434 return;
435
Imre Deak91d181d2014-02-10 18:42:49 +0200436 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
437
Imre Deak755e9012014-02-10 18:42:47 +0200438 pipestat &= ~enable_mask;
Ville Syrjälä46c06a32013-02-20 21:16:18 +0200439 I915_WRITE(reg, pipestat);
440 POSTING_READ(reg);
Keith Packard7c463582008-11-04 02:03:27 -0800441}
442
Imre Deak10c59c52014-02-10 18:42:48 +0200443static u32 vlv_get_pipestat_enable_mask(struct drm_device *dev, u32 status_mask)
444{
445 u32 enable_mask = status_mask << 16;
446
447 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300448 * On pipe A we don't support the PSR interrupt yet,
449 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200450 */
451 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
452 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300453 /*
454 * On pipe B and C we don't support the PSR interrupt yet, on pipe
455 * A the same bit is for perf counters which we don't use either.
456 */
457 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
458 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200459
460 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
461 SPRITE0_FLIP_DONE_INT_EN_VLV |
462 SPRITE1_FLIP_DONE_INT_EN_VLV);
463 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
464 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
465 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
466 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
467
468 return enable_mask;
469}
470
Imre Deak755e9012014-02-10 18:42:47 +0200471void
472i915_enable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
473 u32 status_mask)
474{
475 u32 enable_mask;
476
Imre Deak10c59c52014-02-10 18:42:48 +0200477 if (IS_VALLEYVIEW(dev_priv->dev))
478 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
479 status_mask);
480 else
481 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200482 __i915_enable_pipestat(dev_priv, pipe, enable_mask, status_mask);
483}
484
485void
486i915_disable_pipestat(struct drm_i915_private *dev_priv, enum pipe pipe,
487 u32 status_mask)
488{
489 u32 enable_mask;
490
Imre Deak10c59c52014-02-10 18:42:48 +0200491 if (IS_VALLEYVIEW(dev_priv->dev))
492 enable_mask = vlv_get_pipestat_enable_mask(dev_priv->dev,
493 status_mask);
494 else
495 enable_mask = status_mask << 16;
Imre Deak755e9012014-02-10 18:42:47 +0200496 __i915_disable_pipestat(dev_priv, pipe, enable_mask, status_mask);
497}
498
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000499/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300500 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Zhao Yakui01c66882009-10-28 05:10:00 +0000501 */
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300502static void i915_enable_asle_pipestat(struct drm_device *dev)
Zhao Yakui01c66882009-10-28 05:10:00 +0000503{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300504 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000505
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300506 if (!dev_priv->opregion.asle || !IS_MOBILE(dev))
507 return;
508
Daniel Vetter13321782014-09-15 14:55:29 +0200509 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000510
Imre Deak755e9012014-02-10 18:42:47 +0200511 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Jani Nikulaf8987802013-04-29 13:02:53 +0300512 if (INTEL_INFO(dev)->gen >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200513 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200514 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000515
Daniel Vetter13321782014-09-15 14:55:29 +0200516 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000517}
518
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300519/*
520 * This timing diagram depicts the video signal in and
521 * around the vertical blanking period.
522 *
523 * Assumptions about the fictitious mode used in this example:
524 * vblank_start >= 3
525 * vsync_start = vblank_start + 1
526 * vsync_end = vblank_start + 2
527 * vtotal = vblank_start + 3
528 *
529 * start of vblank:
530 * latch double buffered registers
531 * increment frame counter (ctg+)
532 * generate start of vblank interrupt (gen4+)
533 * |
534 * | frame start:
535 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
536 * | may be shifted forward 1-3 extra lines via PIPECONF
537 * | |
538 * | | start of vsync:
539 * | | generate vsync interrupt
540 * | | |
541 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
542 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
543 * ----va---> <-----------------vb--------------------> <--------va-------------
544 * | | <----vs-----> |
545 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
546 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
547 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
548 * | | |
549 * last visible pixel first visible pixel
550 * | increment frame counter (gen3/4)
551 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
552 *
553 * x = horizontal active
554 * _ = horizontal blanking
555 * hs = horizontal sync
556 * va = vertical active
557 * vb = vertical blanking
558 * vs = vertical sync
559 * vbs = vblank_start (number)
560 *
561 * Summary:
562 * - most events happen at the start of horizontal sync
563 * - frame start happens at the start of horizontal blank, 1-4 lines
564 * (depending on PIPECONF settings) after the start of vblank
565 * - gen3/4 pixel and frame counter are synchronized with the start
566 * of horizontal active on the first line of vertical active
567 */
568
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +0300569static u32 i8xx_get_vblank_counter(struct drm_device *dev, int pipe)
570{
571 /* Gen2 doesn't have a hardware frame counter */
572 return 0;
573}
574
Keith Packard42f52ef2008-10-18 19:39:29 -0700575/* Called from drm generic code, passed a 'crtc', which
576 * we use as a pipe index
577 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700578static u32 i915_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700579{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300580 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700581 unsigned long high_frame;
582 unsigned long low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300583 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100584 struct intel_crtc *intel_crtc =
585 to_intel_crtc(dev_priv->pipe_to_crtc_mapping[pipe]);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200586 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700587
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100588 htotal = mode->crtc_htotal;
589 hsync_start = mode->crtc_hsync_start;
590 vbl_start = mode->crtc_vblank_start;
591 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
592 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300593
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300594 /* Convert to pixel count */
595 vbl_start *= htotal;
596
597 /* Start of vblank event occurs at start of hsync */
598 vbl_start -= htotal - hsync_start;
599
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800600 high_frame = PIPEFRAME(pipe);
601 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100602
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700603 /*
604 * High & low register fields aren't synchronized, so make sure
605 * we get a low value that's stable across two reads of the high
606 * register.
607 */
608 do {
Chris Wilson5eddb702010-09-11 13:48:45 +0100609 high1 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300610 low = I915_READ(low_frame);
Chris Wilson5eddb702010-09-11 13:48:45 +0100611 high2 = I915_READ(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700612 } while (high1 != high2);
613
Chris Wilson5eddb702010-09-11 13:48:45 +0100614 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300615 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100616 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300617
618 /*
619 * The frame counter increments at beginning of active.
620 * Cook up a vblank counter by also checking the pixel
621 * counter against vblank start.
622 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200623 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700624}
625
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700626static u32 gm45_get_vblank_counter(struct drm_device *dev, int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800627{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300628 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800629 int reg = PIPE_FRMCOUNT_GM45(pipe);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800630
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800631 return I915_READ(reg);
632}
633
Mario Kleinerad3543e2013-10-30 05:13:08 +0100634/* raw reads, only for fast reads of display block, no need for forcewake etc. */
635#define __raw_i915_read32(dev_priv__, reg__) readl((dev_priv__)->regs + (reg__))
Mario Kleinerad3543e2013-10-30 05:13:08 +0100636
Ville Syrjäläa225f072014-04-29 13:35:45 +0300637static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
638{
639 struct drm_device *dev = crtc->base.dev;
640 struct drm_i915_private *dev_priv = dev->dev_private;
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200641 const struct drm_display_mode *mode = &crtc->base.hwmode;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300642 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +0300643 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300644
Ville Syrjälä80715b22014-05-15 20:23:23 +0300645 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300646 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
647 vtotal /= 2;
648
649 if (IS_GEN2(dev))
650 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
651 else
652 position = __raw_i915_read32(dev_priv, PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
653
654 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +0300655 * See update_scanline_offset() for the details on the
656 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +0300657 */
Ville Syrjälä80715b22014-05-15 20:23:23 +0300658 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +0300659}
660
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700661static int i915_get_crtc_scanoutpos(struct drm_device *dev, int pipe,
Ville Syrjäläabca9e42013-10-28 20:50:48 +0200662 unsigned int flags, int *vpos, int *hpos,
663 ktime_t *stime, ktime_t *etime)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100664{
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300665 struct drm_i915_private *dev_priv = dev->dev_private;
666 struct drm_crtc *crtc = dev_priv->pipe_to_crtc_mapping[pipe];
667 struct intel_crtc *intel_crtc = to_intel_crtc(crtc);
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200668 const struct drm_display_mode *mode = &intel_crtc->base.hwmode;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300669 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300670 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100671 bool in_vbl = true;
672 int ret = 0;
Mario Kleinerad3543e2013-10-30 05:13:08 +0100673 unsigned long irqflags;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100674
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200675 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100676 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800677 "pipe %c\n", pipe_name(pipe));
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100678 return 0;
679 }
680
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300681 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300682 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300683 vtotal = mode->crtc_vtotal;
684 vbl_start = mode->crtc_vblank_start;
685 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100686
Ville Syrjäläd31faf62013-10-28 16:31:41 +0200687 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
688 vbl_start = DIV_ROUND_UP(vbl_start, 2);
689 vbl_end /= 2;
690 vtotal /= 2;
691 }
692
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +0300693 ret |= DRM_SCANOUTPOS_VALID | DRM_SCANOUTPOS_ACCURATE;
694
Mario Kleinerad3543e2013-10-30 05:13:08 +0100695 /*
696 * Lock uncore.lock, as we will do multiple timing critical raw
697 * register reads, potentially with preemption disabled, so the
698 * following code must not block on uncore.lock.
699 */
700 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300701
Mario Kleinerad3543e2013-10-30 05:13:08 +0100702 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
703
704 /* Get optional system timestamp before query. */
705 if (stime)
706 *stime = ktime_get();
707
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300708 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100709 /* No obvious pixelcount register. Only query vertical
710 * scanout position from Display scan line register.
711 */
Ville Syrjäläa225f072014-04-29 13:35:45 +0300712 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100713 } else {
714 /* Have access to pixelcount since start of frame.
715 * We can split this into vertical and horizontal
716 * scanout position.
717 */
Mario Kleinerad3543e2013-10-30 05:13:08 +0100718 position = (__raw_i915_read32(dev_priv, PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100719
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300720 /* convert to pixel counts */
721 vbl_start *= htotal;
722 vbl_end *= htotal;
723 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300724
725 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +0300726 * In interlaced modes, the pixel counter counts all pixels,
727 * so one field will have htotal more pixels. In order to avoid
728 * the reported position from jumping backwards when the pixel
729 * counter is beyond the length of the shorter field, just
730 * clamp the position the length of the shorter field. This
731 * matches how the scanline counter based position works since
732 * the scanline counter doesn't count the two half lines.
733 */
734 if (position >= vtotal)
735 position = vtotal - 1;
736
737 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +0300738 * Start of vblank interrupt is triggered at start of hsync,
739 * just prior to the first active line of vblank. However we
740 * consider lines to start at the leading edge of horizontal
741 * active. So, should we get here before we've crossed into
742 * the horizontal active of the first line in vblank, we would
743 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
744 * always add htotal-hsync_start to the current pixel position.
745 */
746 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300747 }
748
Mario Kleinerad3543e2013-10-30 05:13:08 +0100749 /* Get optional system timestamp after query. */
750 if (etime)
751 *etime = ktime_get();
752
753 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
754
755 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
756
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300757 in_vbl = position >= vbl_start && position < vbl_end;
758
759 /*
760 * While in vblank, position will be negative
761 * counting up towards 0 at vbl_end. And outside
762 * vblank, position will be positive counting
763 * up since vbl_end.
764 */
765 if (position >= vbl_start)
766 position -= vbl_end;
767 else
768 position += vtotal - vbl_end;
769
Ville Syrjälä7c06b082013-10-11 21:52:43 +0300770 if (IS_GEN2(dev) || IS_G4X(dev) || INTEL_INFO(dev)->gen >= 5) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +0300771 *vpos = position;
772 *hpos = 0;
773 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100774 *vpos = position / htotal;
775 *hpos = position - (*vpos * htotal);
776 }
777
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100778 /* In vblank? */
779 if (in_vbl)
Daniel Vetter3d3cbd82014-09-10 17:36:11 +0200780 ret |= DRM_SCANOUTPOS_IN_VBLANK;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100781
782 return ret;
783}
784
Ville Syrjäläa225f072014-04-29 13:35:45 +0300785int intel_get_crtc_scanline(struct intel_crtc *crtc)
786{
787 struct drm_i915_private *dev_priv = crtc->base.dev->dev_private;
788 unsigned long irqflags;
789 int position;
790
791 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
792 position = __intel_get_crtc_scanline(crtc);
793 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
794
795 return position;
796}
797
Jesse Barnesf71d4af2011-06-28 13:00:41 -0700798static int i915_get_vblank_timestamp(struct drm_device *dev, int pipe,
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100799 int *max_error,
800 struct timeval *vblank_time,
801 unsigned flags)
802{
Chris Wilson4041b852011-01-22 10:07:56 +0000803 struct drm_crtc *crtc;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100804
Ben Widawsky7eb552a2013-03-13 14:05:41 -0700805 if (pipe < 0 || pipe >= INTEL_INFO(dev)->num_pipes) {
Chris Wilson4041b852011-01-22 10:07:56 +0000806 DRM_ERROR("Invalid crtc %d\n", pipe);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100807 return -EINVAL;
808 }
809
810 /* Get drm_crtc to timestamp: */
Chris Wilson4041b852011-01-22 10:07:56 +0000811 crtc = intel_get_crtc_for_pipe(dev, pipe);
812 if (crtc == NULL) {
813 DRM_ERROR("Invalid crtc %d\n", pipe);
814 return -EINVAL;
815 }
816
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200817 if (!crtc->hwmode.crtc_clock) {
Chris Wilson4041b852011-01-22 10:07:56 +0000818 DRM_DEBUG_KMS("crtc %d is disabled\n", pipe);
819 return -EBUSY;
820 }
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100821
822 /* Helper routine in DRM core does all the work: */
Chris Wilson4041b852011-01-22 10:07:56 +0000823 return drm_calc_vbltimestamp_from_scanoutpos(dev, pipe, max_error,
824 vblank_time, flags,
Ville Syrjälä7da903e2013-10-26 17:57:31 +0300825 crtc,
Maarten Lankhorstfc467a222015-06-01 12:50:07 +0200826 &crtc->hwmode);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +0100827}
828
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200829static void ironlake_rps_change_irq_handler(struct drm_device *dev)
Jesse Barnesf97108d2010-01-29 11:27:07 -0800830{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300831 struct drm_i915_private *dev_priv = dev->dev_private;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000832 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +0200833 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200834
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200835 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800836
Daniel Vetter73edd18f2012-08-08 23:35:37 +0200837 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
838
Daniel Vetter20e4d402012-08-08 23:35:39 +0200839 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +0200840
Jesse Barnes7648fa92010-05-20 14:28:11 -0700841 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000842 busy_up = I915_READ(RCPREVBSYTUPAVG);
843 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -0800844 max_avg = I915_READ(RCBMAXAVG);
845 min_avg = I915_READ(RCBMINAVG);
846
847 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000848 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200849 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
850 new_delay = dev_priv->ips.cur_delay - 1;
851 if (new_delay < dev_priv->ips.max_delay)
852 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +0000853 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +0200854 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
855 new_delay = dev_priv->ips.cur_delay + 1;
856 if (new_delay > dev_priv->ips.min_delay)
857 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800858 }
859
Jesse Barnes7648fa92010-05-20 14:28:11 -0700860 if (ironlake_set_drps(dev, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +0200861 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -0800862
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +0200863 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +0200864
Jesse Barnesf97108d2010-01-29 11:27:07 -0800865 return;
866}
867
Chris Wilson74cdb332015-04-07 16:21:05 +0100868static void notify_ring(struct intel_engine_cs *ring)
Chris Wilson549f7362010-10-19 11:19:32 +0100869{
Oscar Mateo93b0a4e2014-05-22 14:13:36 +0100870 if (!intel_ring_initialized(ring))
Chris Wilson475553d2011-01-20 09:52:56 +0000871 return;
872
John Harrisonbcfcc8b2014-12-05 13:49:36 +0000873 trace_i915_gem_request_notify(ring);
Chris Wilson9862e602011-01-04 22:22:17 +0000874
Chris Wilson549f7362010-10-19 11:19:32 +0100875 wake_up_all(&ring->irq_queue);
Chris Wilson549f7362010-10-19 11:19:32 +0100876}
877
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000878static void vlv_c0_read(struct drm_i915_private *dev_priv,
879 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -0400880{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000881 ei->cz_clock = vlv_punit_read(dev_priv, PUNIT_REG_CZ_TIMESTAMP);
882 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
883 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -0400884}
885
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000886static bool vlv_c0_above(struct drm_i915_private *dev_priv,
887 const struct intel_rps_ei *old,
888 const struct intel_rps_ei *now,
889 int threshold)
Deepak S31685c22014-07-03 17:33:01 -0400890{
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000891 u64 time, c0;
Deepak S31685c22014-07-03 17:33:01 -0400892
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000893 if (old->cz_clock == 0)
894 return false;
Deepak S31685c22014-07-03 17:33:01 -0400895
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000896 time = now->cz_clock - old->cz_clock;
897 time *= threshold * dev_priv->mem_freq;
Deepak S31685c22014-07-03 17:33:01 -0400898
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000899 /* Workload can be split between render + media, e.g. SwapBuffers
900 * being blitted in X after being rendered in mesa. To account for
901 * this we need to combine both engines into our activity counter.
902 */
903 c0 = now->render_c0 - old->render_c0;
904 c0 += now->media_c0 - old->media_c0;
905 c0 *= 100 * VLV_CZ_CLOCK_TO_MILLI_SEC * 4 / 1000;
Deepak S31685c22014-07-03 17:33:01 -0400906
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000907 return c0 >= time;
908}
Deepak S31685c22014-07-03 17:33:01 -0400909
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000910void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
911{
912 vlv_c0_read(dev_priv, &dev_priv->rps.down_ei);
913 dev_priv->rps.up_ei = dev_priv->rps.down_ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000914}
915
916static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
917{
918 struct intel_rps_ei now;
919 u32 events = 0;
920
Chris Wilson6f4b12f82015-03-18 09:48:23 +0000921 if ((pm_iir & (GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED)) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000922 return 0;
923
924 vlv_c0_read(dev_priv, &now);
925 if (now.cz_clock == 0)
926 return 0;
Deepak S31685c22014-07-03 17:33:01 -0400927
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000928 if (pm_iir & GEN6_PM_RP_DOWN_EI_EXPIRED) {
929 if (!vlv_c0_above(dev_priv,
930 &dev_priv->rps.down_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +0100931 dev_priv->rps.down_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000932 events |= GEN6_PM_RP_DOWN_THRESHOLD;
933 dev_priv->rps.down_ei = now;
Deepak S31685c22014-07-03 17:33:01 -0400934 }
935
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000936 if (pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) {
937 if (vlv_c0_above(dev_priv,
938 &dev_priv->rps.up_ei, &now,
Chris Wilson8fb55192015-04-07 16:20:28 +0100939 dev_priv->rps.up_threshold))
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000940 events |= GEN6_PM_RP_UP_THRESHOLD;
941 dev_priv->rps.up_ei = now;
942 }
943
944 return events;
Deepak S31685c22014-07-03 17:33:01 -0400945}
946
Chris Wilsonf5a4c672015-04-27 13:41:23 +0100947static bool any_waiters(struct drm_i915_private *dev_priv)
948{
949 struct intel_engine_cs *ring;
950 int i;
951
952 for_each_ring(ring, dev_priv, i)
953 if (ring->irq_refcount)
954 return true;
955
956 return false;
957}
958
Ben Widawsky4912d042011-04-25 11:25:20 -0700959static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800960{
Jani Nikula2d1013d2014-03-31 14:27:17 +0300961 struct drm_i915_private *dev_priv =
962 container_of(work, struct drm_i915_private, rps.work);
Chris Wilson8d3afd72015-05-21 21:01:47 +0100963 bool client_boost;
964 int new_delay, adj, min, max;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300965 u32 pm_iir;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800966
Daniel Vetter59cdb632013-07-04 23:35:28 +0200967 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakd4d70aa2014-11-19 15:30:04 +0200968 /* Speed up work cancelation during disabling rps interrupts. */
969 if (!dev_priv->rps.interrupts_enabled) {
970 spin_unlock_irq(&dev_priv->irq_lock);
971 return;
972 }
Daniel Vetterc6a828d2012-08-08 23:35:35 +0200973 pm_iir = dev_priv->rps.pm_iir;
974 dev_priv->rps.pm_iir = 0;
Imre Deaka72fbc32014-11-05 20:48:31 +0200975 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
976 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +0100977 client_boost = dev_priv->rps.client_boost;
978 dev_priv->rps.client_boost = false;
Daniel Vetter59cdb632013-07-04 23:35:28 +0200979 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -0700980
Paulo Zanoni60611c12013-08-15 11:50:01 -0300981 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +0530982 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Paulo Zanoni60611c12013-08-15 11:50:01 -0300983
Chris Wilson8d3afd72015-05-21 21:01:47 +0100984 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -0800985 return;
986
Jesse Barnes4fc688c2012-11-02 11:14:01 -0700987 mutex_lock(&dev_priv->rps.hw_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +0100988
Chris Wilson43cf3bf2015-03-18 09:48:22 +0000989 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
990
Chris Wilsondd75fdc2013-09-25 17:34:57 +0100991 adj = dev_priv->rps.last_adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +0100992 new_delay = dev_priv->rps.cur_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +0100993 min = dev_priv->rps.min_freq_softlimit;
994 max = dev_priv->rps.max_freq_softlimit;
995
996 if (client_boost) {
997 new_delay = dev_priv->rps.max_freq_softlimit;
998 adj = 0;
999 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001000 if (adj > 0)
1001 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001002 else /* CHV needs even encode values */
1003 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Ville Syrjälä74250342013-06-25 21:38:11 +03001004 /*
1005 * For better performance, jump directly
1006 * to RPe if we're below it.
1007 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001008 if (new_delay < dev_priv->rps.efficient_freq - adj) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001009 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001010 adj = 0;
1011 }
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001012 } else if (any_waiters(dev_priv)) {
1013 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001014 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Ben Widawskyb39fb292014-03-19 18:31:11 -07001015 if (dev_priv->rps.cur_freq > dev_priv->rps.efficient_freq)
1016 new_delay = dev_priv->rps.efficient_freq;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001017 else
Ben Widawskyb39fb292014-03-19 18:31:11 -07001018 new_delay = dev_priv->rps.min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001019 adj = 0;
1020 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1021 if (adj < 0)
1022 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001023 else /* CHV needs even encode values */
1024 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001025 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001026 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001027 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001028
Chris Wilsonedcf2842015-04-07 16:20:29 +01001029 dev_priv->rps.last_adj = adj;
1030
Ben Widawsky79249632012-09-07 19:43:42 -07001031 /* sysfs frequency interfaces may have snuck in while servicing the
1032 * interrupt
1033 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001034 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001035 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301036
Ville Syrjäläffe02b42015-02-02 19:09:50 +02001037 intel_set_rps(dev_priv->dev, new_delay);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001038
Jesse Barnes4fc688c2012-11-02 11:14:01 -07001039 mutex_unlock(&dev_priv->rps.hw_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001040}
1041
Ben Widawskye3689192012-05-25 16:56:22 -07001042
1043/**
1044 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1045 * occurred.
1046 * @work: workqueue struct
1047 *
1048 * Doesn't actually do anything except notify userspace. As a consequence of
1049 * this event, userspace should try to remap the bad rows since statistically
1050 * it is likely the same row is more likely to go bad again.
1051 */
1052static void ivybridge_parity_work(struct work_struct *work)
1053{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001054 struct drm_i915_private *dev_priv =
1055 container_of(work, struct drm_i915_private, l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001056 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001057 char *parity_event[6];
Ben Widawskye3689192012-05-25 16:56:22 -07001058 uint32_t misccpctl;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001059 uint8_t slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001060
1061 /* We must turn off DOP level clock gating to access the L3 registers.
1062 * In order to prevent a get/put style interface, acquire struct mutex
1063 * any time we access those registers.
1064 */
1065 mutex_lock(&dev_priv->dev->struct_mutex);
1066
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001067 /* If we've screwed up tracking, just let the interrupt fire again */
1068 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1069 goto out;
1070
Ben Widawskye3689192012-05-25 16:56:22 -07001071 misccpctl = I915_READ(GEN7_MISCCPCTL);
1072 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1073 POSTING_READ(GEN7_MISCCPCTL);
1074
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001075 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
1076 u32 reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001077
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001078 slice--;
1079 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv->dev)))
1080 break;
1081
1082 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1083
1084 reg = GEN7_L3CDERRST1 + (slice * 0x200);
1085
1086 error_status = I915_READ(reg);
1087 row = GEN7_PARITY_ERROR_ROW(error_status);
1088 bank = GEN7_PARITY_ERROR_BANK(error_status);
1089 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1090
1091 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1092 POSTING_READ(reg);
1093
1094 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1095 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1096 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1097 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1098 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1099 parity_event[5] = NULL;
1100
Dave Airlie5bdebb12013-10-11 14:07:25 +10001101 kobject_uevent_env(&dev_priv->dev->primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001102 KOBJ_CHANGE, parity_event);
1103
1104 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1105 slice, row, bank, subbank);
1106
1107 kfree(parity_event[4]);
1108 kfree(parity_event[3]);
1109 kfree(parity_event[2]);
1110 kfree(parity_event[1]);
1111 }
Ben Widawskye3689192012-05-25 16:56:22 -07001112
1113 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1114
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001115out:
1116 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001117 spin_lock_irq(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001118 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv->dev));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001119 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001120
1121 mutex_unlock(&dev_priv->dev->struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001122}
1123
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001124static void ivybridge_parity_error_irq_handler(struct drm_device *dev, u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001125{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001126 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskye3689192012-05-25 16:56:22 -07001127
Ben Widawsky040d2ba2013-09-19 11:01:40 -07001128 if (!HAS_L3_DPF(dev))
Ben Widawskye3689192012-05-25 16:56:22 -07001129 return;
1130
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001131 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001132 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001133 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001134
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001135 iir &= GT_PARITY_ERROR(dev);
1136 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1137 dev_priv->l3_parity.which_slice |= 1 << 1;
1138
1139 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1140 dev_priv->l3_parity.which_slice |= 1 << 0;
1141
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001142 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001143}
1144
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001145static void ilk_gt_irq_handler(struct drm_device *dev,
1146 struct drm_i915_private *dev_priv,
1147 u32 gt_iir)
1148{
1149 if (gt_iir &
1150 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Chris Wilson74cdb332015-04-07 16:21:05 +01001151 notify_ring(&dev_priv->ring[RCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001152 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001153 notify_ring(&dev_priv->ring[VCS]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001154}
1155
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001156static void snb_gt_irq_handler(struct drm_device *dev,
1157 struct drm_i915_private *dev_priv,
1158 u32 gt_iir)
1159{
1160
Ben Widawskycc609d52013-05-28 19:22:29 -07001161 if (gt_iir &
1162 (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT))
Chris Wilson74cdb332015-04-07 16:21:05 +01001163 notify_ring(&dev_priv->ring[RCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001164 if (gt_iir & GT_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001165 notify_ring(&dev_priv->ring[VCS]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001166 if (gt_iir & GT_BLT_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001167 notify_ring(&dev_priv->ring[BCS]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001168
Ben Widawskycc609d52013-05-28 19:22:29 -07001169 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1170 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001171 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1172 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001173
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001174 if (gt_iir & GT_PARITY_ERROR(dev))
1175 ivybridge_parity_error_irq_handler(dev, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001176}
1177
Chris Wilson74cdb332015-04-07 16:21:05 +01001178static irqreturn_t gen8_gt_irq_handler(struct drm_i915_private *dev_priv,
Ben Widawskyabd58f02013-11-02 21:07:09 -07001179 u32 master_ctl)
1180{
Ben Widawskyabd58f02013-11-02 21:07:09 -07001181 irqreturn_t ret = IRQ_NONE;
1182
1183 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson74cdb332015-04-07 16:21:05 +01001184 u32 tmp = I915_READ_FW(GEN8_GT_IIR(0));
Ben Widawskyabd58f02013-11-02 21:07:09 -07001185 if (tmp) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001186 I915_WRITE_FW(GEN8_GT_IIR(0), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001187 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001188
Chris Wilson74cdb332015-04-07 16:21:05 +01001189 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
1190 intel_lrc_irq_handler(&dev_priv->ring[RCS]);
1191 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT))
1192 notify_ring(&dev_priv->ring[RCS]);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001193
Chris Wilson74cdb332015-04-07 16:21:05 +01001194 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
1195 intel_lrc_irq_handler(&dev_priv->ring[BCS]);
1196 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT))
1197 notify_ring(&dev_priv->ring[BCS]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001198 } else
1199 DRM_ERROR("The master control interrupt lied (GT0)!\n");
1200 }
1201
Zhao Yakui85f9b5f2014-04-17 10:37:38 +08001202 if (master_ctl & (GEN8_GT_VCS1_IRQ | GEN8_GT_VCS2_IRQ)) {
Chris Wilson74cdb332015-04-07 16:21:05 +01001203 u32 tmp = I915_READ_FW(GEN8_GT_IIR(1));
Ben Widawskyabd58f02013-11-02 21:07:09 -07001204 if (tmp) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001205 I915_WRITE_FW(GEN8_GT_IIR(1), tmp);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001206 ret = IRQ_HANDLED;
Thomas Daniele981e7b2014-07-24 17:04:39 +01001207
Chris Wilson74cdb332015-04-07 16:21:05 +01001208 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
1209 intel_lrc_irq_handler(&dev_priv->ring[VCS]);
1210 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT))
1211 notify_ring(&dev_priv->ring[VCS]);
Thomas Daniele981e7b2014-07-24 17:04:39 +01001212
Chris Wilson74cdb332015-04-07 16:21:05 +01001213 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
1214 intel_lrc_irq_handler(&dev_priv->ring[VCS2]);
1215 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT))
1216 notify_ring(&dev_priv->ring[VCS2]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001217 } else
1218 DRM_ERROR("The master control interrupt lied (GT1)!\n");
1219 }
1220
Chris Wilson74cdb332015-04-07 16:21:05 +01001221 if (master_ctl & GEN8_GT_VECS_IRQ) {
1222 u32 tmp = I915_READ_FW(GEN8_GT_IIR(3));
1223 if (tmp) {
1224 I915_WRITE_FW(GEN8_GT_IIR(3), tmp);
1225 ret = IRQ_HANDLED;
1226
1227 if (tmp & (GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
1228 intel_lrc_irq_handler(&dev_priv->ring[VECS]);
1229 if (tmp & (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT))
1230 notify_ring(&dev_priv->ring[VECS]);
1231 } else
1232 DRM_ERROR("The master control interrupt lied (GT3)!\n");
1233 }
1234
Ben Widawsky09610212014-05-15 20:58:08 +03001235 if (master_ctl & GEN8_GT_PM_IRQ) {
Chris Wilson74cdb332015-04-07 16:21:05 +01001236 u32 tmp = I915_READ_FW(GEN8_GT_IIR(2));
Ben Widawsky09610212014-05-15 20:58:08 +03001237 if (tmp & dev_priv->pm_rps_events) {
Chris Wilsoncb0d2052015-04-07 16:21:04 +01001238 I915_WRITE_FW(GEN8_GT_IIR(2),
1239 tmp & dev_priv->pm_rps_events);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01001240 ret = IRQ_HANDLED;
Imre Deakc9a9a262014-11-05 20:48:37 +02001241 gen6_rps_irq_handler(dev_priv, tmp);
Ben Widawsky09610212014-05-15 20:58:08 +03001242 } else
1243 DRM_ERROR("The master control interrupt lied (PM)!\n");
1244 }
1245
Ben Widawskyabd58f02013-11-02 21:07:09 -07001246 return ret;
1247}
1248
Imre Deak63c88d22015-07-20 14:43:39 -07001249static bool bxt_port_hotplug_long_detect(enum port port, u32 val)
1250{
1251 switch (port) {
1252 case PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001253 return val & PORTA_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001254 case PORT_B:
1255 return val & PORTB_HOTPLUG_LONG_DETECT;
1256 case PORT_C:
1257 return val & PORTC_HOTPLUG_LONG_DETECT;
1258 case PORT_D:
1259 return val & PORTD_HOTPLUG_LONG_DETECT;
1260 default:
1261 return false;
1262 }
1263}
1264
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001265static bool spt_port_hotplug2_long_detect(enum port port, u32 val)
1266{
1267 switch (port) {
1268 case PORT_E:
1269 return val & PORTE_HOTPLUG_LONG_DETECT;
1270 default:
1271 return false;
1272 }
1273}
1274
Jani Nikula676574d2015-05-28 15:43:53 +03001275static bool pch_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001276{
1277 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001278 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001279 return val & PORTB_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001280 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001281 return val & PORTC_HOTPLUG_LONG_DETECT;
Dave Airlie13cf5502014-06-18 11:29:35 +10001282 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001283 return val & PORTD_HOTPLUG_LONG_DETECT;
1284 default:
1285 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001286 }
1287}
1288
Jani Nikula676574d2015-05-28 15:43:53 +03001289static bool i9xx_port_hotplug_long_detect(enum port port, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001290{
1291 switch (port) {
Dave Airlie13cf5502014-06-18 11:29:35 +10001292 case PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001293 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001294 case PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001295 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Dave Airlie13cf5502014-06-18 11:29:35 +10001296 case PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001297 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1298 default:
1299 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001300 }
1301}
1302
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001303/*
1304 * Get a bit mask of pins that have triggered, and which ones may be long.
1305 * This can be called multiple times with the same masks to accumulate
1306 * hotplug detection results from several registers.
1307 *
1308 * Note that the caller is expected to zero out the masks initially.
1309 */
Imre Deakfd63e2a2015-07-21 15:32:44 -07001310static void intel_get_hpd_pins(u32 *pin_mask, u32 *long_mask,
Jani Nikula8c841e52015-06-18 13:06:17 +03001311 u32 hotplug_trigger, u32 dig_hotplug_reg,
Imre Deakfd63e2a2015-07-21 15:32:44 -07001312 const u32 hpd[HPD_NUM_PINS],
1313 bool long_pulse_detect(enum port port, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001314{
Jani Nikula8c841e52015-06-18 13:06:17 +03001315 enum port port;
Jani Nikula676574d2015-05-28 15:43:53 +03001316 int i;
1317
Jani Nikula676574d2015-05-28 15:43:53 +03001318 for_each_hpd_pin(i) {
Jani Nikula8c841e52015-06-18 13:06:17 +03001319 if ((hpd[i] & hotplug_trigger) == 0)
1320 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001321
Jani Nikula8c841e52015-06-18 13:06:17 +03001322 *pin_mask |= BIT(i);
1323
Imre Deakcc24fcd2015-07-21 15:32:45 -07001324 if (!intel_hpd_pin_to_port(i, &port))
1325 continue;
1326
Imre Deakfd63e2a2015-07-21 15:32:44 -07001327 if (long_pulse_detect(port, dig_hotplug_reg))
Jani Nikula8c841e52015-06-18 13:06:17 +03001328 *long_mask |= BIT(i);
Jani Nikula676574d2015-05-28 15:43:53 +03001329 }
1330
1331 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x\n",
1332 hotplug_trigger, dig_hotplug_reg, *pin_mask);
1333
1334}
1335
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001336static void gmbus_irq_handler(struct drm_device *dev)
1337{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001338 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter28c70f12012-12-01 13:53:45 +01001339
Daniel Vetter28c70f12012-12-01 13:53:45 +01001340 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001341}
1342
Daniel Vetterce99c252012-12-01 13:53:47 +01001343static void dp_aux_irq_handler(struct drm_device *dev)
1344{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001345 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001346
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001347 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001348}
1349
Shuang He8bf1e9f2013-10-15 18:55:27 +01001350#if defined(CONFIG_DEBUG_FS)
Daniel Vetter277de952013-10-18 16:37:07 +02001351static void display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1352 uint32_t crc0, uint32_t crc1,
1353 uint32_t crc2, uint32_t crc3,
1354 uint32_t crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001355{
1356 struct drm_i915_private *dev_priv = dev->dev_private;
1357 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
1358 struct intel_pipe_crc_entry *entry;
Damien Lespiauac2300d2013-10-15 18:55:30 +01001359 int head, tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001360
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001361 spin_lock(&pipe_crc->lock);
1362
Damien Lespiau0c912c72013-10-15 18:55:37 +01001363 if (!pipe_crc->entries) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001364 spin_unlock(&pipe_crc->lock);
Daniel Vetter34273622014-11-26 16:29:04 +01001365 DRM_DEBUG_KMS("spurious interrupt\n");
Damien Lespiau0c912c72013-10-15 18:55:37 +01001366 return;
1367 }
1368
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001369 head = pipe_crc->head;
1370 tail = pipe_crc->tail;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001371
1372 if (CIRC_SPACE(head, tail, INTEL_PIPE_CRC_ENTRIES_NR) < 1) {
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001373 spin_unlock(&pipe_crc->lock);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001374 DRM_ERROR("CRC buffer overflowing\n");
1375 return;
1376 }
1377
1378 entry = &pipe_crc->entries[head];
Shuang He8bf1e9f2013-10-15 18:55:27 +01001379
Daniel Vetter8bc5e952013-10-16 22:55:49 +02001380 entry->frame = dev->driver->get_vblank_counter(dev, pipe);
Daniel Vettereba94eb2013-10-16 22:55:46 +02001381 entry->crc[0] = crc0;
1382 entry->crc[1] = crc1;
1383 entry->crc[2] = crc2;
1384 entry->crc[3] = crc3;
1385 entry->crc[4] = crc4;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001386
1387 head = (head + 1) & (INTEL_PIPE_CRC_ENTRIES_NR - 1);
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001388 pipe_crc->head = head;
1389
1390 spin_unlock(&pipe_crc->lock);
Damien Lespiau07144422013-10-15 18:55:40 +01001391
1392 wake_up_interruptible(&pipe_crc->wq);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001393}
Daniel Vetter277de952013-10-18 16:37:07 +02001394#else
1395static inline void
1396display_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe,
1397 uint32_t crc0, uint32_t crc1,
1398 uint32_t crc2, uint32_t crc3,
1399 uint32_t crc4) {}
1400#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001401
Daniel Vetter277de952013-10-18 16:37:07 +02001402
1403static void hsw_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001404{
1405 struct drm_i915_private *dev_priv = dev->dev_private;
1406
Daniel Vetter277de952013-10-18 16:37:07 +02001407 display_pipe_crc_irq_handler(dev, pipe,
1408 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1409 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001410}
1411
Daniel Vetter277de952013-10-18 16:37:07 +02001412static void ivb_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001413{
1414 struct drm_i915_private *dev_priv = dev->dev_private;
1415
Daniel Vetter277de952013-10-18 16:37:07 +02001416 display_pipe_crc_irq_handler(dev, pipe,
1417 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1418 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1419 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1420 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1421 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001422}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001423
Daniel Vetter277de952013-10-18 16:37:07 +02001424static void i9xx_pipe_crc_irq_handler(struct drm_device *dev, enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001425{
1426 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001427 uint32_t res1, res2;
1428
1429 if (INTEL_INFO(dev)->gen >= 3)
1430 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1431 else
1432 res1 = 0;
1433
1434 if (INTEL_INFO(dev)->gen >= 5 || IS_G4X(dev))
1435 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1436 else
1437 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001438
Daniel Vetter277de952013-10-18 16:37:07 +02001439 display_pipe_crc_irq_handler(dev, pipe,
1440 I915_READ(PIPE_CRC_RES_RED(pipe)),
1441 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1442 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1443 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001444}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001445
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001446/* The RPS events need forcewake, so we add them to a work queue and mask their
1447 * IMR bits until the work is done. Other interrupts can be processed without
1448 * the work queue. */
1449static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001450{
Deepak Sa6706b42014-03-15 20:23:22 +05301451 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001452 spin_lock(&dev_priv->irq_lock);
Daniel Vetter480c8032014-07-16 09:49:40 +02001453 gen6_disable_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001454 if (dev_priv->rps.interrupts_enabled) {
1455 dev_priv->rps.pm_iir |= pm_iir & dev_priv->pm_rps_events;
1456 queue_work(dev_priv->wq, &dev_priv->rps.work);
1457 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001458 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001459 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001460
Imre Deakc9a9a262014-11-05 20:48:37 +02001461 if (INTEL_INFO(dev_priv)->gen >= 8)
1462 return;
1463
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001464 if (HAS_VEBOX(dev_priv->dev)) {
1465 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01001466 notify_ring(&dev_priv->ring[VECS]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001467
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001468 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1469 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawsky12638c52013-05-28 19:22:31 -07001470 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001471}
1472
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001473static bool intel_pipe_handle_vblank(struct drm_device *dev, enum pipe pipe)
1474{
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001475 if (!drm_handle_vblank(dev, pipe))
1476 return false;
1477
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03001478 return true;
1479}
1480
Imre Deakc1874ed2014-02-04 21:35:46 +02001481static void valleyview_pipestat_irq_handler(struct drm_device *dev, u32 iir)
1482{
1483 struct drm_i915_private *dev_priv = dev->dev_private;
Imre Deak91d181d2014-02-10 18:42:49 +02001484 u32 pipe_stats[I915_MAX_PIPES] = { };
Imre Deakc1874ed2014-02-04 21:35:46 +02001485 int pipe;
1486
Imre Deak58ead0d2014-02-04 21:35:47 +02001487 spin_lock(&dev_priv->irq_lock);
Damien Lespiau055e3932014-08-18 13:49:10 +01001488 for_each_pipe(dev_priv, pipe) {
Imre Deak91d181d2014-02-10 18:42:49 +02001489 int reg;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001490 u32 mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001491
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001492 /*
1493 * PIPESTAT bits get signalled even when the interrupt is
1494 * disabled with the mask bits, and some of the status bits do
1495 * not generate interrupts at all (like the underrun bit). Hence
1496 * we need to be careful that we only handle what we want to
1497 * handle.
1498 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001499
1500 /* fifo underruns are filterered in the underrun handler. */
1501 mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001502
1503 switch (pipe) {
1504 case PIPE_A:
1505 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1506 break;
1507 case PIPE_B:
1508 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1509 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001510 case PIPE_C:
1511 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1512 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001513 }
1514 if (iir & iir_bit)
1515 mask |= dev_priv->pipestat_irq_mask[pipe];
1516
1517 if (!mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001518 continue;
1519
1520 reg = PIPESTAT(pipe);
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001521 mask |= PIPESTAT_INT_ENABLE_MASK;
1522 pipe_stats[pipe] = I915_READ(reg) & mask;
Imre Deakc1874ed2014-02-04 21:35:46 +02001523
1524 /*
1525 * Clear the PIPE*STAT regs before the IIR
1526 */
Imre Deak91d181d2014-02-10 18:42:49 +02001527 if (pipe_stats[pipe] & (PIPE_FIFO_UNDERRUN_STATUS |
1528 PIPESTAT_INT_STATUS_MASK))
Imre Deakc1874ed2014-02-04 21:35:46 +02001529 I915_WRITE(reg, pipe_stats[pipe]);
1530 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001531 spin_unlock(&dev_priv->irq_lock);
Imre Deakc1874ed2014-02-04 21:35:46 +02001532
Damien Lespiau055e3932014-08-18 13:49:10 +01001533 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001534 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
1535 intel_pipe_handle_vblank(dev, pipe))
1536 intel_check_page_flip(dev, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001537
Imre Deak579a9b02014-02-04 21:35:48 +02001538 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) {
Imre Deakc1874ed2014-02-04 21:35:46 +02001539 intel_prepare_page_flip(dev, pipe);
1540 intel_finish_page_flip(dev, pipe);
1541 }
1542
1543 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1544 i9xx_pipe_crc_irq_handler(dev, pipe);
1545
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001546 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1547 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001548 }
1549
1550 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
1551 gmbus_irq_handler(dev);
1552}
1553
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001554static void i9xx_hpd_irq_handler(struct drm_device *dev)
1555{
1556 struct drm_i915_private *dev_priv = dev->dev_private;
1557 u32 hotplug_status = I915_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001558 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001559
Jani Nikula0d2e4292015-05-27 15:03:39 +03001560 if (!hotplug_status)
1561 return;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001562
Jani Nikula0d2e4292015-05-27 15:03:39 +03001563 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
1564 /*
1565 * Make sure hotplug status is cleared before we clear IIR, or else we
1566 * may miss hotplug events.
1567 */
1568 POSTING_READ(PORT_HOTPLUG_STAT);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001569
Jani Nikula0d2e4292015-05-27 15:03:39 +03001570 if (IS_G4X(dev) || IS_VALLEYVIEW(dev)) {
1571 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001572
Imre Deakfd63e2a2015-07-21 15:32:44 -07001573 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1574 hotplug_trigger, hpd_status_g4x,
1575 i9xx_port_hotplug_long_detect);
Jani Nikula676574d2015-05-28 15:43:53 +03001576 intel_hpd_irq_handler(dev, pin_mask, long_mask);
Jani Nikula369712e2015-05-27 15:03:40 +03001577
1578 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
1579 dp_aux_irq_handler(dev);
Jani Nikula0d2e4292015-05-27 15:03:39 +03001580 } else {
1581 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001582
Imre Deakfd63e2a2015-07-21 15:32:44 -07001583 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1584 hotplug_trigger, hpd_status_g4x,
1585 i9xx_port_hotplug_long_detect);
Jani Nikula676574d2015-05-28 15:43:53 +03001586 intel_hpd_irq_handler(dev, pin_mask, long_mask);
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001587 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03001588}
1589
Daniel Vetterff1f5252012-10-02 15:10:55 +02001590static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001591{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001592 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001593 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001594 u32 iir, gt_iir, pm_iir;
1595 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001596
Imre Deak2dd2a882015-02-24 11:14:30 +02001597 if (!intel_irqs_enabled(dev_priv))
1598 return IRQ_NONE;
1599
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001600 while (true) {
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001601 /* Find, clear, then process each source of interrupt */
1602
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001603 gt_iir = I915_READ(GTIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001604 if (gt_iir)
1605 I915_WRITE(GTIIR, gt_iir);
1606
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001607 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001608 if (pm_iir)
1609 I915_WRITE(GEN6_PMIIR, pm_iir);
1610
1611 iir = I915_READ(VLV_IIR);
1612 if (iir) {
1613 /* Consume port before clearing IIR or we'll miss events */
1614 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1615 i9xx_hpd_irq_handler(dev);
1616 I915_WRITE(VLV_IIR, iir);
1617 }
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001618
1619 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
1620 goto out;
1621
1622 ret = IRQ_HANDLED;
1623
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001624 if (gt_iir)
1625 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanoni60611c12013-08-15 11:50:01 -03001626 if (pm_iir)
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001627 gen6_rps_irq_handler(dev_priv, pm_iir);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01001628 /* Call regardless, as some status bits might not be
1629 * signalled in iir */
1630 valleyview_pipestat_irq_handler(dev, iir);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07001631 }
1632
1633out:
1634 return ret;
1635}
1636
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001637static irqreturn_t cherryview_irq_handler(int irq, void *arg)
1638{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001639 struct drm_device *dev = arg;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001640 struct drm_i915_private *dev_priv = dev->dev_private;
1641 u32 master_ctl, iir;
1642 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001643
Imre Deak2dd2a882015-02-24 11:14:30 +02001644 if (!intel_irqs_enabled(dev_priv))
1645 return IRQ_NONE;
1646
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001647 for (;;) {
1648 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
1649 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03001650
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001651 if (master_ctl == 0 && iir == 0)
1652 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001653
Oscar Mateo27b6c122014-06-16 16:11:00 +01001654 ret = IRQ_HANDLED;
1655
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001656 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001657
Oscar Mateo27b6c122014-06-16 16:11:00 +01001658 /* Find, clear, then process each source of interrupt */
1659
1660 if (iir) {
1661 /* Consume port before clearing IIR or we'll miss events */
1662 if (iir & I915_DISPLAY_PORT_INTERRUPT)
1663 i9xx_hpd_irq_handler(dev);
1664 I915_WRITE(VLV_IIR, iir);
1665 }
1666
Chris Wilson74cdb332015-04-07 16:21:05 +01001667 gen8_gt_irq_handler(dev_priv, master_ctl);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001668
Oscar Mateo27b6c122014-06-16 16:11:00 +01001669 /* Call regardless, as some status bits might not be
1670 * signalled in iir */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001671 valleyview_pipestat_irq_handler(dev, iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001672
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03001673 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
1674 POSTING_READ(GEN8_MASTER_IRQ);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001675 }
1676
Ville Syrjälä43f328d2014-04-09 20:40:52 +03001677 return ret;
1678}
1679
Adam Jackson23e81d62012-06-06 15:45:44 -04001680static void ibx_irq_handler(struct drm_device *dev, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08001681{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001682 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001683 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02001684 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08001685
Sonika Jindalaaf5ec22015-07-08 17:07:47 +05301686 if (hotplug_trigger) {
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001687 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Dave Airlie13cf5502014-06-18 11:29:35 +10001688
Sonika Jindalaaf5ec22015-07-08 17:07:47 +05301689 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1690 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1691
Imre Deakfd63e2a2015-07-21 15:32:44 -07001692 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1693 dig_hotplug_reg, hpd_ibx,
1694 pch_port_hotplug_long_detect);
Sonika Jindalaaf5ec22015-07-08 17:07:47 +05301695 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1696 }
Daniel Vetter91d131d2013-06-27 17:52:14 +02001697
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001698 if (pch_iir & SDE_AUDIO_POWER_MASK) {
1699 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
1700 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08001701 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001702 port_name(port));
1703 }
Jesse Barnes776ad802011-01-04 15:09:39 -08001704
Daniel Vetterce99c252012-12-01 13:53:47 +01001705 if (pch_iir & SDE_AUX_MASK)
1706 dp_aux_irq_handler(dev);
1707
Jesse Barnes776ad802011-01-04 15:09:39 -08001708 if (pch_iir & SDE_GMBUS)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001709 gmbus_irq_handler(dev);
Jesse Barnes776ad802011-01-04 15:09:39 -08001710
1711 if (pch_iir & SDE_AUDIO_HDCP_MASK)
1712 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
1713
1714 if (pch_iir & SDE_AUDIO_TRANS_MASK)
1715 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
1716
1717 if (pch_iir & SDE_POISON)
1718 DRM_ERROR("PCH poison interrupt\n");
1719
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001720 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01001721 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001722 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1723 pipe_name(pipe),
1724 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08001725
1726 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
1727 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
1728
1729 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
1730 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
1731
Jesse Barnes776ad802011-01-04 15:09:39 -08001732 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001733 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001734
1735 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001736 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001737}
1738
1739static void ivb_err_int_handler(struct drm_device *dev)
1740{
1741 struct drm_i915_private *dev_priv = dev->dev_private;
1742 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001743 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03001744
Paulo Zanonide032bf2013-04-12 17:57:58 -03001745 if (err_int & ERR_INT_POISON)
1746 DRM_ERROR("Poison interrupt\n");
1747
Damien Lespiau055e3932014-08-18 13:49:10 +01001748 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001749 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
1750 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03001751
Daniel Vetter5a69b892013-10-16 22:55:52 +02001752 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
1753 if (IS_IVYBRIDGE(dev))
Daniel Vetter277de952013-10-18 16:37:07 +02001754 ivb_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001755 else
Daniel Vetter277de952013-10-18 16:37:07 +02001756 hsw_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001757 }
1758 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01001759
Paulo Zanoni86642812013-04-12 17:57:57 -03001760 I915_WRITE(GEN7_ERR_INT, err_int);
1761}
1762
1763static void cpt_serr_int_handler(struct drm_device *dev)
1764{
1765 struct drm_i915_private *dev_priv = dev->dev_private;
1766 u32 serr_int = I915_READ(SERR_INT);
1767
Paulo Zanonide032bf2013-04-12 17:57:58 -03001768 if (serr_int & SERR_INT_POISON)
1769 DRM_ERROR("PCH poison interrupt\n");
1770
Paulo Zanoni86642812013-04-12 17:57:57 -03001771 if (serr_int & SERR_INT_TRANS_A_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001772 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03001773
1774 if (serr_int & SERR_INT_TRANS_B_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001775 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03001776
1777 if (serr_int & SERR_INT_TRANS_C_FIFO_UNDERRUN)
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001778 intel_pch_fifo_underrun_irq_handler(dev_priv, TRANSCODER_C);
Paulo Zanoni86642812013-04-12 17:57:57 -03001779
1780 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08001781}
1782
Adam Jackson23e81d62012-06-06 15:45:44 -04001783static void cpt_irq_handler(struct drm_device *dev, u32 pch_iir)
1784{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001785 struct drm_i915_private *dev_priv = dev->dev_private;
Adam Jackson23e81d62012-06-06 15:45:44 -04001786 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001787 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04001788
Sonika Jindalaaf5ec22015-07-08 17:07:47 +05301789 if (hotplug_trigger) {
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001790 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Dave Airlie13cf5502014-06-18 11:29:35 +10001791
Sonika Jindalaaf5ec22015-07-08 17:07:47 +05301792 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1793 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Imre Deakfd63e2a2015-07-21 15:32:44 -07001794
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001795 intel_get_hpd_pins(&pin_mask, &long_mask,
1796 hotplug_trigger,
1797 dig_hotplug_reg, hpd_cpt,
1798 pch_port_hotplug_long_detect);
Xiong Zhang26951ca2015-08-17 15:55:50 +08001799
Sonika Jindalaaf5ec22015-07-08 17:07:47 +05301800 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1801 }
Daniel Vetter91d131d2013-06-27 17:52:14 +02001802
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03001803 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
1804 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
1805 SDE_AUDIO_POWER_SHIFT_CPT);
1806 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
1807 port_name(port));
1808 }
Adam Jackson23e81d62012-06-06 15:45:44 -04001809
1810 if (pch_iir & SDE_AUX_MASK_CPT)
Daniel Vetterce99c252012-12-01 13:53:47 +01001811 dp_aux_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001812
1813 if (pch_iir & SDE_GMBUS_CPT)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001814 gmbus_irq_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001815
1816 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
1817 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
1818
1819 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
1820 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
1821
1822 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01001823 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04001824 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
1825 pipe_name(pipe),
1826 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03001827
1828 if (pch_iir & SDE_ERROR_CPT)
1829 cpt_serr_int_handler(dev);
Adam Jackson23e81d62012-06-06 15:45:44 -04001830}
1831
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001832static void spt_irq_handler(struct drm_device *dev, u32 pch_iir)
1833{
1834 struct drm_i915_private *dev_priv = dev->dev_private;
1835 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
1836 ~SDE_PORTE_HOTPLUG_SPT;
1837 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
1838 u32 pin_mask = 0, long_mask = 0;
1839
1840 if (hotplug_trigger) {
1841 u32 dig_hotplug_reg;
1842
1843 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
1844 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
1845
1846 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug_trigger,
1847 dig_hotplug_reg, hpd_spt,
1848 pch_port_hotplug_long_detect);
1849 }
1850
1851 if (hotplug2_trigger) {
1852 u32 dig_hotplug_reg;
1853
1854 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
1855 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
1856
1857 intel_get_hpd_pins(&pin_mask, &long_mask, hotplug2_trigger,
1858 dig_hotplug_reg, hpd_spt,
1859 spt_port_hotplug2_long_detect);
1860 }
1861
1862 if (pin_mask)
1863 intel_hpd_irq_handler(dev, pin_mask, long_mask);
1864
1865 if (pch_iir & SDE_GMBUS_CPT)
1866 gmbus_irq_handler(dev);
1867}
1868
Paulo Zanonic008bc62013-07-12 16:35:10 -03001869static void ilk_display_irq_handler(struct drm_device *dev, u32 de_iir)
1870{
1871 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter40da17c2013-10-21 18:04:36 +02001872 enum pipe pipe;
Paulo Zanonic008bc62013-07-12 16:35:10 -03001873
1874 if (de_iir & DE_AUX_CHANNEL_A)
1875 dp_aux_irq_handler(dev);
1876
1877 if (de_iir & DE_GSE)
1878 intel_opregion_asle_intr(dev);
1879
Paulo Zanonic008bc62013-07-12 16:35:10 -03001880 if (de_iir & DE_POISON)
1881 DRM_ERROR("Poison interrupt\n");
1882
Damien Lespiau055e3932014-08-18 13:49:10 +01001883 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001884 if (de_iir & DE_PIPE_VBLANK(pipe) &&
1885 intel_pipe_handle_vblank(dev, pipe))
1886 intel_check_page_flip(dev, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001887
Daniel Vetter40da17c2013-10-21 18:04:36 +02001888 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02001889 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03001890
Daniel Vetter40da17c2013-10-21 18:04:36 +02001891 if (de_iir & DE_PIPE_CRC_DONE(pipe))
1892 i9xx_pipe_crc_irq_handler(dev, pipe);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001893
Daniel Vetter40da17c2013-10-21 18:04:36 +02001894 /* plane/pipes map 1:1 on ilk+ */
1895 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) {
1896 intel_prepare_page_flip(dev, pipe);
1897 intel_finish_page_flip_plane(dev, pipe);
1898 }
Paulo Zanonic008bc62013-07-12 16:35:10 -03001899 }
1900
1901 /* check event from PCH */
1902 if (de_iir & DE_PCH_EVENT) {
1903 u32 pch_iir = I915_READ(SDEIIR);
1904
1905 if (HAS_PCH_CPT(dev))
1906 cpt_irq_handler(dev, pch_iir);
1907 else
1908 ibx_irq_handler(dev, pch_iir);
1909
1910 /* should clear PCH hotplug event before clear CPU irq */
1911 I915_WRITE(SDEIIR, pch_iir);
1912 }
1913
1914 if (IS_GEN5(dev) && de_iir & DE_PCU_EVENT)
1915 ironlake_rps_change_irq_handler(dev);
1916}
1917
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001918static void ivb_display_irq_handler(struct drm_device *dev, u32 de_iir)
1919{
1920 struct drm_i915_private *dev_priv = dev->dev_private;
Damien Lespiau07d27e22014-03-03 17:31:46 +00001921 enum pipe pipe;
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001922
1923 if (de_iir & DE_ERR_INT_IVB)
1924 ivb_err_int_handler(dev);
1925
1926 if (de_iir & DE_AUX_CHANNEL_A_IVB)
1927 dp_aux_irq_handler(dev);
1928
1929 if (de_iir & DE_GSE_IVB)
1930 intel_opregion_asle_intr(dev);
1931
Damien Lespiau055e3932014-08-18 13:49:10 +01001932 for_each_pipe(dev_priv, pipe) {
Chris Wilsond6bbafa2014-09-05 07:13:24 +01001933 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)) &&
1934 intel_pipe_handle_vblank(dev, pipe))
1935 intel_check_page_flip(dev, pipe);
Daniel Vetter40da17c2013-10-21 18:04:36 +02001936
1937 /* plane/pipes map 1:1 on ilk+ */
Damien Lespiau07d27e22014-03-03 17:31:46 +00001938 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) {
1939 intel_prepare_page_flip(dev, pipe);
1940 intel_finish_page_flip_plane(dev, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03001941 }
1942 }
1943
1944 /* check event from PCH */
1945 if (!HAS_PCH_NOP(dev) && (de_iir & DE_PCH_EVENT_IVB)) {
1946 u32 pch_iir = I915_READ(SDEIIR);
1947
1948 cpt_irq_handler(dev, pch_iir);
1949
1950 /* clear PCH hotplug event before clear CPU irq */
1951 I915_WRITE(SDEIIR, pch_iir);
1952 }
1953}
1954
Oscar Mateo72c90f62014-06-16 16:10:57 +01001955/*
1956 * To handle irqs with the minimum potential races with fresh interrupts, we:
1957 * 1 - Disable Master Interrupt Control.
1958 * 2 - Find the source(s) of the interrupt.
1959 * 3 - Clear the Interrupt Identity bits (IIR).
1960 * 4 - Process the interrupt(s) that had bits set in the IIRs.
1961 * 5 - Re-enable Master Interrupt Control.
1962 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001963static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001964{
Daniel Vetter45a83f82014-05-12 19:17:55 +02001965 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03001966 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001967 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01001968 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001969
Imre Deak2dd2a882015-02-24 11:14:30 +02001970 if (!intel_irqs_enabled(dev_priv))
1971 return IRQ_NONE;
1972
Paulo Zanoni86642812013-04-12 17:57:57 -03001973 /* We get interrupts on unclaimed registers, so check for this before we
1974 * do any I915_{READ,WRITE}. */
Chris Wilson907b28c2013-07-19 20:36:52 +01001975 intel_uncore_check_errors(dev);
Paulo Zanoni86642812013-04-12 17:57:57 -03001976
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07001977 /* disable master interrupt before clearing iir */
1978 de_ier = I915_READ(DEIER);
1979 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Paulo Zanoni23a78512013-07-12 16:35:14 -03001980 POSTING_READ(DEIER);
Chris Wilson0e434062012-05-09 21:45:44 +01001981
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001982 /* Disable south interrupts. We'll only write to SDEIIR once, so further
1983 * interrupts will will be stored on its back queue, and then we'll be
1984 * able to process them after we restore SDEIER (as soon as we restore
1985 * it, we'll get an interrupt if SDEIIR still has something to process
1986 * due to its back queue). */
Ben Widawskyab5c6082013-04-05 13:12:41 -07001987 if (!HAS_PCH_NOP(dev)) {
1988 sde_ier = I915_READ(SDEIER);
1989 I915_WRITE(SDEIER, 0);
1990 POSTING_READ(SDEIER);
1991 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03001992
Oscar Mateo72c90f62014-06-16 16:10:57 +01001993 /* Find, clear, then process each source of interrupt */
1994
Chris Wilson0e434062012-05-09 21:45:44 +01001995 gt_iir = I915_READ(GTIIR);
1996 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01001997 I915_WRITE(GTIIR, gt_iir);
1998 ret = IRQ_HANDLED;
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03001999 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002000 snb_gt_irq_handler(dev, dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002001 else
2002 ilk_gt_irq_handler(dev, dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002003 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002004
2005 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002006 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002007 I915_WRITE(DEIIR, de_iir);
2008 ret = IRQ_HANDLED;
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002009 if (INTEL_INFO(dev)->gen >= 7)
2010 ivb_display_irq_handler(dev, de_iir);
2011 else
2012 ilk_display_irq_handler(dev, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002013 }
2014
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002015 if (INTEL_INFO(dev)->gen >= 6) {
2016 u32 pm_iir = I915_READ(GEN6_PMIIR);
2017 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002018 I915_WRITE(GEN6_PMIIR, pm_iir);
2019 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002020 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002021 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002022 }
2023
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002024 I915_WRITE(DEIER, de_ier);
2025 POSTING_READ(DEIER);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002026 if (!HAS_PCH_NOP(dev)) {
2027 I915_WRITE(SDEIER, sde_ier);
2028 POSTING_READ(SDEIER);
2029 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002030
2031 return ret;
2032}
2033
Shashank Sharmad04a4922014-08-22 17:40:41 +05302034static void bxt_hpd_handler(struct drm_device *dev, uint32_t iir_status)
2035{
2036 struct drm_i915_private *dev_priv = dev->dev_private;
Jani Nikula676574d2015-05-28 15:43:53 +03002037 u32 hp_control, hp_trigger;
Ville Syrjälä42db67d2015-08-28 21:26:27 +03002038 u32 pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302039
2040 /* Get the status */
2041 hp_trigger = iir_status & BXT_DE_PORT_HOTPLUG_MASK;
2042 hp_control = I915_READ(BXT_HOTPLUG_CTL);
2043
2044 /* Hotplug not enabled ? */
2045 if (!(hp_control & BXT_HOTPLUG_CTL_MASK)) {
2046 DRM_ERROR("Interrupt when HPD disabled\n");
2047 return;
2048 }
2049
Shashank Sharmad04a4922014-08-22 17:40:41 +05302050 /* Clear sticky bits in hpd status */
2051 I915_WRITE(BXT_HOTPLUG_CTL, hp_control);
Jani Nikula475c2e32015-05-28 15:43:54 +03002052
Imre Deakfd63e2a2015-07-21 15:32:44 -07002053 intel_get_hpd_pins(&pin_mask, &long_mask, hp_trigger, hp_control,
Imre Deak63c88d22015-07-20 14:43:39 -07002054 hpd_bxt, bxt_port_hotplug_long_detect);
Jani Nikula475c2e32015-05-28 15:43:54 +03002055 intel_hpd_irq_handler(dev, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302056}
2057
Ben Widawskyabd58f02013-11-02 21:07:09 -07002058static irqreturn_t gen8_irq_handler(int irq, void *arg)
2059{
2060 struct drm_device *dev = arg;
2061 struct drm_i915_private *dev_priv = dev->dev_private;
2062 u32 master_ctl;
2063 irqreturn_t ret = IRQ_NONE;
2064 uint32_t tmp = 0;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002065 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002066 u32 aux_mask = GEN8_AUX_CHANNEL_A;
2067
Imre Deak2dd2a882015-02-24 11:14:30 +02002068 if (!intel_irqs_enabled(dev_priv))
2069 return IRQ_NONE;
2070
Jesse Barnes88e04702014-11-13 17:51:48 +00002071 if (IS_GEN9(dev))
2072 aux_mask |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
2073 GEN9_AUX_CHANNEL_D;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002074
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002075 master_ctl = I915_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002076 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
2077 if (!master_ctl)
2078 return IRQ_NONE;
2079
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002080 I915_WRITE_FW(GEN8_MASTER_IRQ, 0);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002081
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002082 /* Find, clear, then process each source of interrupt */
2083
Chris Wilson74cdb332015-04-07 16:21:05 +01002084 ret = gen8_gt_irq_handler(dev_priv, master_ctl);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002085
2086 if (master_ctl & GEN8_DE_MISC_IRQ) {
2087 tmp = I915_READ(GEN8_DE_MISC_IIR);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002088 if (tmp) {
2089 I915_WRITE(GEN8_DE_MISC_IIR, tmp);
2090 ret = IRQ_HANDLED;
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002091 if (tmp & GEN8_DE_MISC_GSE)
2092 intel_opregion_asle_intr(dev);
2093 else
2094 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002095 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002096 else
2097 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002098 }
2099
Daniel Vetter6d766f02013-11-07 14:49:55 +01002100 if (master_ctl & GEN8_DE_PORT_IRQ) {
2101 tmp = I915_READ(GEN8_DE_PORT_IIR);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002102 if (tmp) {
Shashank Sharmad04a4922014-08-22 17:40:41 +05302103 bool found = false;
2104
Daniel Vetter6d766f02013-11-07 14:49:55 +01002105 I915_WRITE(GEN8_DE_PORT_IIR, tmp);
2106 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002107
Shashank Sharmad04a4922014-08-22 17:40:41 +05302108 if (tmp & aux_mask) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002109 dp_aux_irq_handler(dev);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302110 found = true;
2111 }
2112
2113 if (IS_BROXTON(dev) && tmp & BXT_DE_PORT_HOTPLUG_MASK) {
2114 bxt_hpd_handler(dev, tmp);
2115 found = true;
2116 }
2117
Shashank Sharma9e637432014-08-22 17:40:43 +05302118 if (IS_BROXTON(dev) && (tmp & BXT_DE_PORT_GMBUS)) {
2119 gmbus_irq_handler(dev);
2120 found = true;
2121 }
2122
Shashank Sharmad04a4922014-08-22 17:40:41 +05302123 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002124 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002125 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002126 else
2127 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002128 }
2129
Damien Lespiau055e3932014-08-18 13:49:10 +01002130 for_each_pipe(dev_priv, pipe) {
Damien Lespiau770de832014-03-20 20:45:01 +00002131 uint32_t pipe_iir, flip_done = 0, fault_errors = 0;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002132
Daniel Vetterc42664c2013-11-07 11:05:40 +01002133 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2134 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002135
Daniel Vetterc42664c2013-11-07 11:05:40 +01002136 pipe_iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
Daniel Vetterc42664c2013-11-07 11:05:40 +01002137 if (pipe_iir) {
2138 ret = IRQ_HANDLED;
2139 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), pipe_iir);
Damien Lespiau770de832014-03-20 20:45:01 +00002140
Chris Wilsond6bbafa2014-09-05 07:13:24 +01002141 if (pipe_iir & GEN8_PIPE_VBLANK &&
2142 intel_pipe_handle_vblank(dev, pipe))
2143 intel_check_page_flip(dev, pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002144
Damien Lespiau770de832014-03-20 20:45:01 +00002145 if (IS_GEN9(dev))
2146 flip_done = pipe_iir & GEN9_PIPE_PLANE1_FLIP_DONE;
2147 else
2148 flip_done = pipe_iir & GEN8_PIPE_PRIMARY_FLIP_DONE;
2149
2150 if (flip_done) {
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002151 intel_prepare_page_flip(dev, pipe);
2152 intel_finish_page_flip_plane(dev, pipe);
2153 }
2154
2155 if (pipe_iir & GEN8_PIPE_CDCLK_CRC_DONE)
2156 hsw_pipe_crc_irq_handler(dev, pipe);
2157
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002158 if (pipe_iir & GEN8_PIPE_FIFO_UNDERRUN)
2159 intel_cpu_fifo_underrun_irq_handler(dev_priv,
2160 pipe);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002161
Damien Lespiau770de832014-03-20 20:45:01 +00002162
2163 if (IS_GEN9(dev))
2164 fault_errors = pipe_iir & GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2165 else
2166 fault_errors = pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2167
2168 if (fault_errors)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002169 DRM_ERROR("Fault errors on pipe %c\n: 0x%08x",
2170 pipe_name(pipe),
2171 pipe_iir & GEN8_DE_PIPE_IRQ_FAULT_ERRORS);
Daniel Vetterc42664c2013-11-07 11:05:40 +01002172 } else
Ben Widawskyabd58f02013-11-02 21:07:09 -07002173 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
2174 }
2175
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302176 if (HAS_PCH_SPLIT(dev) && !HAS_PCH_NOP(dev) &&
2177 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002178 /*
2179 * FIXME(BDW): Assume for now that the new interrupt handling
2180 * scheme also closed the SDE interrupt handling race we've seen
2181 * on older pch-split platforms. But this needs testing.
2182 */
2183 u32 pch_iir = I915_READ(SDEIIR);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002184 if (pch_iir) {
2185 I915_WRITE(SDEIIR, pch_iir);
2186 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002187
2188 if (HAS_PCH_SPT(dev_priv))
2189 spt_irq_handler(dev, pch_iir);
2190 else
2191 cpt_irq_handler(dev, pch_iir);
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002192 } else
2193 DRM_ERROR("The master control interrupt lied (SDE)!\n");
2194
Daniel Vetter92d03a82013-11-07 11:05:43 +01002195 }
2196
Chris Wilsoncb0d2052015-04-07 16:21:04 +01002197 I915_WRITE_FW(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2198 POSTING_READ_FW(GEN8_MASTER_IRQ);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002199
2200 return ret;
2201}
2202
Daniel Vetter17e1df02013-09-08 21:57:13 +02002203static void i915_error_wake_up(struct drm_i915_private *dev_priv,
2204 bool reset_completed)
2205{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002206 struct intel_engine_cs *ring;
Daniel Vetter17e1df02013-09-08 21:57:13 +02002207 int i;
2208
2209 /*
2210 * Notify all waiters for GPU completion events that reset state has
2211 * been changed, and that they need to restart their wait after
2212 * checking for potential errors (and bail out to drop locks if there is
2213 * a gpu reset pending so that i915_error_work_func can acquire them).
2214 */
2215
2216 /* Wake up __wait_seqno, potentially holding dev->struct_mutex. */
2217 for_each_ring(ring, dev_priv, i)
2218 wake_up_all(&ring->irq_queue);
2219
2220 /* Wake up intel_crtc_wait_for_pending_flips, holding crtc->mutex. */
2221 wake_up_all(&dev_priv->pending_flip_queue);
2222
2223 /*
2224 * Signal tasks blocked in i915_gem_wait_for_error that the pending
2225 * reset state is cleared.
2226 */
2227 if (reset_completed)
2228 wake_up_all(&dev_priv->gpu_error.reset_queue);
2229}
2230
Jesse Barnes8a905232009-07-11 16:48:03 -04002231/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002232 * i915_reset_and_wakeup - do process context error handling work
Jesse Barnes8a905232009-07-11 16:48:03 -04002233 *
2234 * Fire an error uevent so userspace can see that a hang or error
2235 * was detected.
2236 */
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002237static void i915_reset_and_wakeup(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002238{
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002239 struct drm_i915_private *dev_priv = to_i915(dev);
2240 struct i915_gpu_error *error = &dev_priv->gpu_error;
Ben Widawskycce723e2013-07-19 09:16:42 -07002241 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL };
2242 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL };
2243 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL };
Daniel Vetter17e1df02013-09-08 21:57:13 +02002244 int ret;
Jesse Barnes8a905232009-07-11 16:48:03 -04002245
Dave Airlie5bdebb12013-10-11 14:07:25 +10002246 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE, error_event);
Jesse Barnes8a905232009-07-11 16:48:03 -04002247
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002248 /*
2249 * Note that there's only one work item which does gpu resets, so we
2250 * need not worry about concurrent gpu resets potentially incrementing
2251 * error->reset_counter twice. We only need to take care of another
2252 * racing irq/hangcheck declaring the gpu dead for a second time. A
2253 * quick check for that is good enough: schedule_work ensures the
2254 * correct ordering between hang detection and this work item, and since
2255 * the reset in-progress bit is only ever set by code outside of this
2256 * work we don't need to worry about any other races.
2257 */
2258 if (i915_reset_in_progress(error) && !i915_terminally_wedged(error)) {
Chris Wilsonf803aa52010-09-19 12:38:26 +01002259 DRM_DEBUG_DRIVER("resetting chip\n");
Dave Airlie5bdebb12013-10-11 14:07:25 +10002260 kobject_uevent_env(&dev->primary->kdev->kobj, KOBJ_CHANGE,
Daniel Vetter7db0ba22012-12-06 16:23:37 +01002261 reset_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002262
Daniel Vetter17e1df02013-09-08 21:57:13 +02002263 /*
Imre Deakf454c692014-04-23 01:09:04 +03002264 * In most cases it's guaranteed that we get here with an RPM
2265 * reference held, for example because there is a pending GPU
2266 * request that won't finish until the reset is done. This
2267 * isn't the case at least when we get here by doing a
2268 * simulated reset via debugs, so get an RPM reference.
2269 */
2270 intel_runtime_pm_get(dev_priv);
Ville Syrjälä75147472014-11-24 18:28:11 +02002271
2272 intel_prepare_reset(dev);
2273
Imre Deakf454c692014-04-23 01:09:04 +03002274 /*
Daniel Vetter17e1df02013-09-08 21:57:13 +02002275 * All state reset _must_ be completed before we update the
2276 * reset counter, for otherwise waiters might miss the reset
2277 * pending state and not properly drop locks, resulting in
2278 * deadlocks with the reset work.
2279 */
Daniel Vetterf69061b2012-12-06 09:01:42 +01002280 ret = i915_reset(dev);
2281
Ville Syrjälä75147472014-11-24 18:28:11 +02002282 intel_finish_reset(dev);
Daniel Vetter17e1df02013-09-08 21:57:13 +02002283
Imre Deakf454c692014-04-23 01:09:04 +03002284 intel_runtime_pm_put(dev_priv);
2285
Daniel Vetterf69061b2012-12-06 09:01:42 +01002286 if (ret == 0) {
2287 /*
2288 * After all the gem state is reset, increment the reset
2289 * counter and wake up everyone waiting for the reset to
2290 * complete.
2291 *
2292 * Since unlock operations are a one-sided barrier only,
2293 * we need to insert a barrier here to order any seqno
2294 * updates before
2295 * the counter increment.
2296 */
Peter Zijlstra4e857c52014-03-17 18:06:10 +01002297 smp_mb__before_atomic();
Daniel Vetterf69061b2012-12-06 09:01:42 +01002298 atomic_inc(&dev_priv->gpu_error.reset_counter);
2299
Dave Airlie5bdebb12013-10-11 14:07:25 +10002300 kobject_uevent_env(&dev->primary->kdev->kobj,
Daniel Vetterf69061b2012-12-06 09:01:42 +01002301 KOBJ_CHANGE, reset_done_event);
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002302 } else {
Mika Kuoppala2ac0f452013-11-12 14:44:19 +02002303 atomic_set_mask(I915_WEDGED, &error->reset_counter);
Ben Gamarif316a422009-09-14 17:48:46 -04002304 }
Daniel Vetter1f83fee2012-11-15 17:17:22 +01002305
Daniel Vetter17e1df02013-09-08 21:57:13 +02002306 /*
2307 * Note: The wake_up also serves as a memory barrier so that
2308 * waiters see the update value of the reset counter atomic_t.
2309 */
2310 i915_error_wake_up(dev_priv, true);
Ben Gamarif316a422009-09-14 17:48:46 -04002311 }
Jesse Barnes8a905232009-07-11 16:48:03 -04002312}
2313
Chris Wilson35aed2e2010-05-27 13:18:12 +01002314static void i915_report_and_clear_eir(struct drm_device *dev)
Jesse Barnes8a905232009-07-11 16:48:03 -04002315{
2316 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskybd9854f2012-08-23 15:18:09 -07002317 uint32_t instdone[I915_NUM_INSTDONE_REG];
Jesse Barnes8a905232009-07-11 16:48:03 -04002318 u32 eir = I915_READ(EIR);
Ben Widawsky050ee912012-08-22 11:32:15 -07002319 int pipe, i;
Jesse Barnes8a905232009-07-11 16:48:03 -04002320
Chris Wilson35aed2e2010-05-27 13:18:12 +01002321 if (!eir)
2322 return;
Jesse Barnes8a905232009-07-11 16:48:03 -04002323
Joe Perchesa70491c2012-03-18 13:00:11 -07002324 pr_err("render error detected, EIR: 0x%08x\n", eir);
Jesse Barnes8a905232009-07-11 16:48:03 -04002325
Ben Widawskybd9854f2012-08-23 15:18:09 -07002326 i915_get_extra_instdone(dev, instdone);
2327
Jesse Barnes8a905232009-07-11 16:48:03 -04002328 if (IS_G4X(dev)) {
2329 if (eir & (GM45_ERROR_MEM_PRIV | GM45_ERROR_CP_PRIV)) {
2330 u32 ipeir = I915_READ(IPEIR_I965);
2331
Joe Perchesa70491c2012-03-18 13:00:11 -07002332 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2333 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Ben Widawsky050ee912012-08-22 11:32:15 -07002334 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2335 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Joe Perchesa70491c2012-03-18 13:00:11 -07002336 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002337 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002338 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002339 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002340 }
2341 if (eir & GM45_ERROR_PAGE_TABLE) {
2342 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002343 pr_err("page table error\n");
2344 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002345 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002346 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002347 }
2348 }
2349
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002350 if (!IS_GEN2(dev)) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002351 if (eir & I915_ERROR_PAGE_TABLE) {
2352 u32 pgtbl_err = I915_READ(PGTBL_ER);
Joe Perchesa70491c2012-03-18 13:00:11 -07002353 pr_err("page table error\n");
2354 pr_err(" PGTBL_ER: 0x%08x\n", pgtbl_err);
Jesse Barnes8a905232009-07-11 16:48:03 -04002355 I915_WRITE(PGTBL_ER, pgtbl_err);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002356 POSTING_READ(PGTBL_ER);
Jesse Barnes8a905232009-07-11 16:48:03 -04002357 }
2358 }
2359
2360 if (eir & I915_ERROR_MEMORY_REFRESH) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002361 pr_err("memory refresh error:\n");
Damien Lespiau055e3932014-08-18 13:49:10 +01002362 for_each_pipe(dev_priv, pipe)
Joe Perchesa70491c2012-03-18 13:00:11 -07002363 pr_err("pipe %c stat: 0x%08x\n",
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002364 pipe_name(pipe), I915_READ(PIPESTAT(pipe)));
Jesse Barnes8a905232009-07-11 16:48:03 -04002365 /* pipestat has already been acked */
2366 }
2367 if (eir & I915_ERROR_INSTRUCTION) {
Joe Perchesa70491c2012-03-18 13:00:11 -07002368 pr_err("instruction error\n");
2369 pr_err(" INSTPM: 0x%08x\n", I915_READ(INSTPM));
Ben Widawsky050ee912012-08-22 11:32:15 -07002370 for (i = 0; i < ARRAY_SIZE(instdone); i++)
2371 pr_err(" INSTDONE_%d: 0x%08x\n", i, instdone[i]);
Chris Wilsona6c45cf2010-09-17 00:32:17 +01002372 if (INTEL_INFO(dev)->gen < 4) {
Jesse Barnes8a905232009-07-11 16:48:03 -04002373 u32 ipeir = I915_READ(IPEIR);
2374
Joe Perchesa70491c2012-03-18 13:00:11 -07002375 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR));
2376 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR));
Joe Perchesa70491c2012-03-18 13:00:11 -07002377 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD));
Jesse Barnes8a905232009-07-11 16:48:03 -04002378 I915_WRITE(IPEIR, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002379 POSTING_READ(IPEIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002380 } else {
2381 u32 ipeir = I915_READ(IPEIR_I965);
2382
Joe Perchesa70491c2012-03-18 13:00:11 -07002383 pr_err(" IPEIR: 0x%08x\n", I915_READ(IPEIR_I965));
2384 pr_err(" IPEHR: 0x%08x\n", I915_READ(IPEHR_I965));
Joe Perchesa70491c2012-03-18 13:00:11 -07002385 pr_err(" INSTPS: 0x%08x\n", I915_READ(INSTPS));
Joe Perchesa70491c2012-03-18 13:00:11 -07002386 pr_err(" ACTHD: 0x%08x\n", I915_READ(ACTHD_I965));
Jesse Barnes8a905232009-07-11 16:48:03 -04002387 I915_WRITE(IPEIR_I965, ipeir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002388 POSTING_READ(IPEIR_I965);
Jesse Barnes8a905232009-07-11 16:48:03 -04002389 }
2390 }
2391
2392 I915_WRITE(EIR, eir);
Chris Wilson3143a2b2010-11-16 15:55:10 +00002393 POSTING_READ(EIR);
Jesse Barnes8a905232009-07-11 16:48:03 -04002394 eir = I915_READ(EIR);
2395 if (eir) {
2396 /*
2397 * some errors might have become stuck,
2398 * mask them.
2399 */
2400 DRM_ERROR("EIR stuck: 0x%08x, masking\n", eir);
2401 I915_WRITE(EMR, I915_READ(EMR) | eir);
2402 I915_WRITE(IIR, I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
2403 }
Chris Wilson35aed2e2010-05-27 13:18:12 +01002404}
2405
2406/**
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002407 * i915_handle_error - handle a gpu error
Chris Wilson35aed2e2010-05-27 13:18:12 +01002408 * @dev: drm device
2409 *
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002410 * Do some basic checking of regsiter state at error time and
Chris Wilson35aed2e2010-05-27 13:18:12 +01002411 * dump it to the syslog. Also call i915_capture_error_state() to make
2412 * sure we get a record and make it available in debugfs. Fire a uevent
2413 * so userspace knows something bad happened (should trigger collection
2414 * of a ring dump etc.).
2415 */
Mika Kuoppala58174462014-02-25 17:11:26 +02002416void i915_handle_error(struct drm_device *dev, bool wedged,
2417 const char *fmt, ...)
Chris Wilson35aed2e2010-05-27 13:18:12 +01002418{
2419 struct drm_i915_private *dev_priv = dev->dev_private;
Mika Kuoppala58174462014-02-25 17:11:26 +02002420 va_list args;
2421 char error_msg[80];
Chris Wilson35aed2e2010-05-27 13:18:12 +01002422
Mika Kuoppala58174462014-02-25 17:11:26 +02002423 va_start(args, fmt);
2424 vscnprintf(error_msg, sizeof(error_msg), fmt, args);
2425 va_end(args);
2426
2427 i915_capture_error_state(dev, wedged, error_msg);
Chris Wilson35aed2e2010-05-27 13:18:12 +01002428 i915_report_and_clear_eir(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002429
Ben Gamariba1234d2009-09-14 17:48:47 -04002430 if (wedged) {
Daniel Vetterf69061b2012-12-06 09:01:42 +01002431 atomic_set_mask(I915_RESET_IN_PROGRESS_FLAG,
2432 &dev_priv->gpu_error.reset_counter);
Ben Gamariba1234d2009-09-14 17:48:47 -04002433
Ben Gamari11ed50e2009-09-14 17:48:45 -04002434 /*
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002435 * Wakeup waiting processes so that the reset function
2436 * i915_reset_and_wakeup doesn't deadlock trying to grab
2437 * various locks. By bumping the reset counter first, the woken
Daniel Vetter17e1df02013-09-08 21:57:13 +02002438 * processes will see a reset in progress and back off,
2439 * releasing their locks and then wait for the reset completion.
2440 * We must do this for _all_ gpu waiters that might hold locks
2441 * that the reset work needs to acquire.
2442 *
2443 * Note: The wake_up serves as the required memory barrier to
2444 * ensure that the waiters see the updated value of the reset
2445 * counter atomic_t.
Ben Gamari11ed50e2009-09-14 17:48:45 -04002446 */
Daniel Vetter17e1df02013-09-08 21:57:13 +02002447 i915_error_wake_up(dev_priv, false);
Ben Gamari11ed50e2009-09-14 17:48:45 -04002448 }
2449
Mika Kuoppalab8d24a02015-01-28 17:03:14 +02002450 i915_reset_and_wakeup(dev);
Jesse Barnes8a905232009-07-11 16:48:03 -04002451}
2452
Keith Packard42f52ef2008-10-18 19:39:29 -07002453/* Called from drm generic code, passed 'crtc' which
2454 * we use as a pipe index
2455 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002456static int i915_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002457{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002458 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002459 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08002460
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002461 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002462 if (INTEL_INFO(dev)->gen >= 4)
Keith Packard7c463582008-11-04 02:03:27 -08002463 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002464 PIPE_START_VBLANK_INTERRUPT_STATUS);
Keith Packarde9d21d72008-10-16 11:31:38 -07002465 else
Keith Packard7c463582008-11-04 02:03:27 -08002466 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002467 PIPE_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002468 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00002469
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002470 return 0;
2471}
2472
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002473static int ironlake_enable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002474{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002475 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002476 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002477 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002478 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002479
Jesse Barnesf796cf82011-04-07 13:58:17 -07002480 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002481 ironlake_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002482 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2483
2484 return 0;
2485}
2486
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002487static int valleyview_enable_vblank(struct drm_device *dev, int pipe)
2488{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002489 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002490 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002491
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002492 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002493 i915_enable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002494 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002495 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2496
2497 return 0;
2498}
2499
Ben Widawskyabd58f02013-11-02 21:07:09 -07002500static int gen8_enable_vblank(struct drm_device *dev, int pipe)
2501{
2502 struct drm_i915_private *dev_priv = dev->dev_private;
2503 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002504
Ben Widawskyabd58f02013-11-02 21:07:09 -07002505 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002506 dev_priv->de_irq_mask[pipe] &= ~GEN8_PIPE_VBLANK;
2507 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2508 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002509 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2510 return 0;
2511}
2512
Keith Packard42f52ef2008-10-18 19:39:29 -07002513/* Called from drm generic code, passed 'crtc' which
2514 * we use as a pipe index
2515 */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002516static void i915_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002517{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002518 struct drm_i915_private *dev_priv = dev->dev_private;
Keith Packarde9d21d72008-10-16 11:31:38 -07002519 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07002520
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002521 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002522 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002523 PIPE_VBLANK_INTERRUPT_STATUS |
2524 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002525 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2526}
2527
Jesse Barnesf71d4af2011-06-28 13:00:41 -07002528static void ironlake_disable_vblank(struct drm_device *dev, int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07002529{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002530 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnesf796cf82011-04-07 13:58:17 -07002531 unsigned long irqflags;
Paulo Zanonib5184212013-07-12 20:00:08 -03002532 uint32_t bit = (INTEL_INFO(dev)->gen >= 7) ? DE_PIPE_VBLANK_IVB(pipe) :
Daniel Vetter40da17c2013-10-21 18:04:36 +02002533 DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07002534
2535 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Paulo Zanonib5184212013-07-12 20:00:08 -03002536 ironlake_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002537 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2538}
2539
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002540static void valleyview_disable_vblank(struct drm_device *dev, int pipe)
2541{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002542 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002543 unsigned long irqflags;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002544
2545 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnes31acc7f2012-06-20 10:53:11 -07002546 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02002547 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002548 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2549}
2550
Ben Widawskyabd58f02013-11-02 21:07:09 -07002551static void gen8_disable_vblank(struct drm_device *dev, int pipe)
2552{
2553 struct drm_i915_private *dev_priv = dev->dev_private;
2554 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002555
Ben Widawskyabd58f02013-11-02 21:07:09 -07002556 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Daniel Vetter7167d7c2013-11-07 11:05:45 +01002557 dev_priv->de_irq_mask[pipe] |= GEN8_PIPE_VBLANK;
2558 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
2559 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
Ben Widawskyabd58f02013-11-02 21:07:09 -07002560 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
2561}
2562
Chris Wilson9107e9d2013-06-10 11:20:20 +01002563static bool
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002564ring_idle(struct intel_engine_cs *ring, u32 seqno)
Chris Wilson893eead2010-10-27 14:44:35 +01002565{
Chris Wilson9107e9d2013-06-10 11:20:20 +01002566 return (list_empty(&ring->request_list) ||
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002567 i915_seqno_passed(seqno, ring->last_submitted_seqno));
Ben Gamarif65d9422009-09-14 17:48:44 -04002568}
2569
Daniel Vettera028c4b2014-03-15 00:08:56 +01002570static bool
2571ipehr_is_semaphore_wait(struct drm_device *dev, u32 ipehr)
2572{
2573 if (INTEL_INFO(dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002574 return (ipehr >> 23) == 0x1c;
Daniel Vettera028c4b2014-03-15 00:08:56 +01002575 } else {
2576 ipehr &= ~MI_SEMAPHORE_SYNC_MASK;
2577 return ipehr == (MI_SEMAPHORE_MBOX | MI_SEMAPHORE_COMPARE |
2578 MI_SEMAPHORE_REGISTER);
2579 }
2580}
2581
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002582static struct intel_engine_cs *
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002583semaphore_wait_to_signaller_ring(struct intel_engine_cs *ring, u32 ipehr, u64 offset)
Daniel Vetter921d42e2014-03-18 10:26:04 +01002584{
2585 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002586 struct intel_engine_cs *signaller;
Daniel Vetter921d42e2014-03-18 10:26:04 +01002587 int i;
2588
2589 if (INTEL_INFO(dev_priv->dev)->gen >= 8) {
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002590 for_each_ring(signaller, dev_priv, i) {
2591 if (ring == signaller)
2592 continue;
2593
2594 if (offset == signaller->semaphore.signal_ggtt[ring->id])
2595 return signaller;
2596 }
Daniel Vetter921d42e2014-03-18 10:26:04 +01002597 } else {
2598 u32 sync_bits = ipehr & MI_SEMAPHORE_SYNC_MASK;
2599
2600 for_each_ring(signaller, dev_priv, i) {
2601 if(ring == signaller)
2602 continue;
2603
Ben Widawskyebc348b2014-04-29 14:52:28 -07002604 if (sync_bits == signaller->semaphore.mbox.wait[ring->id])
Daniel Vetter921d42e2014-03-18 10:26:04 +01002605 return signaller;
2606 }
2607 }
2608
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002609 DRM_ERROR("No signaller ring found for ring %i, ipehr 0x%08x, offset 0x%016llx\n",
2610 ring->id, ipehr, offset);
Daniel Vetter921d42e2014-03-18 10:26:04 +01002611
2612 return NULL;
2613}
2614
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002615static struct intel_engine_cs *
2616semaphore_waits_for(struct intel_engine_cs *ring, u32 *seqno)
Chris Wilsona24a11e2013-03-14 17:52:05 +02002617{
2618 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002619 u32 cmd, ipehr, head;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002620 u64 offset = 0;
2621 int i, backwards;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002622
2623 ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
Daniel Vettera028c4b2014-03-15 00:08:56 +01002624 if (!ipehr_is_semaphore_wait(ring->dev, ipehr))
Chris Wilson6274f212013-06-10 11:20:21 +01002625 return NULL;
Chris Wilsona24a11e2013-03-14 17:52:05 +02002626
Daniel Vetter88fe4292014-03-15 00:08:55 +01002627 /*
2628 * HEAD is likely pointing to the dword after the actual command,
2629 * so scan backwards until we find the MBOX. But limit it to just 3
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002630 * or 4 dwords depending on the semaphore wait command size.
2631 * Note that we don't care about ACTHD here since that might
Daniel Vetter88fe4292014-03-15 00:08:55 +01002632 * point at at batch, and semaphores are always emitted into the
2633 * ringbuffer itself.
Chris Wilsona24a11e2013-03-14 17:52:05 +02002634 */
Daniel Vetter88fe4292014-03-15 00:08:55 +01002635 head = I915_READ_HEAD(ring) & HEAD_ADDR;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002636 backwards = (INTEL_INFO(ring->dev)->gen >= 8) ? 5 : 4;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002637
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002638 for (i = backwards; i; --i) {
Daniel Vetter88fe4292014-03-15 00:08:55 +01002639 /*
2640 * Be paranoid and presume the hw has gone off into the wild -
2641 * our ring is smaller than what the hardware (and hence
2642 * HEAD_ADDR) allows. Also handles wrap-around.
2643 */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002644 head &= ring->buffer->size - 1;
Daniel Vetter88fe4292014-03-15 00:08:55 +01002645
2646 /* This here seems to blow up */
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002647 cmd = ioread32(ring->buffer->virtual_start + head);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002648 if (cmd == ipehr)
2649 break;
2650
Daniel Vetter88fe4292014-03-15 00:08:55 +01002651 head -= 4;
2652 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002653
Daniel Vetter88fe4292014-03-15 00:08:55 +01002654 if (!i)
2655 return NULL;
2656
Oscar Mateoee1b1e52014-05-22 14:13:35 +01002657 *seqno = ioread32(ring->buffer->virtual_start + head + 4) + 1;
Rodrigo Vivia6cdb932014-06-30 09:53:39 -07002658 if (INTEL_INFO(ring->dev)->gen >= 8) {
2659 offset = ioread32(ring->buffer->virtual_start + head + 12);
2660 offset <<= 32;
2661 offset = ioread32(ring->buffer->virtual_start + head + 8);
2662 }
2663 return semaphore_wait_to_signaller_ring(ring, ipehr, offset);
Chris Wilsona24a11e2013-03-14 17:52:05 +02002664}
2665
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002666static int semaphore_passed(struct intel_engine_cs *ring)
Chris Wilson6274f212013-06-10 11:20:21 +01002667{
2668 struct drm_i915_private *dev_priv = ring->dev->dev_private;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002669 struct intel_engine_cs *signaller;
Chris Wilsona0d036b2014-07-19 12:40:42 +01002670 u32 seqno;
Chris Wilson6274f212013-06-10 11:20:21 +01002671
Chris Wilson4be17382014-06-06 10:22:29 +01002672 ring->hangcheck.deadlock++;
Chris Wilson6274f212013-06-10 11:20:21 +01002673
2674 signaller = semaphore_waits_for(ring, &seqno);
Chris Wilson4be17382014-06-06 10:22:29 +01002675 if (signaller == NULL)
2676 return -1;
2677
2678 /* Prevent pathological recursion due to driver bugs */
2679 if (signaller->hangcheck.deadlock >= I915_NUM_RINGS)
Chris Wilson6274f212013-06-10 11:20:21 +01002680 return -1;
2681
Chris Wilson4be17382014-06-06 10:22:29 +01002682 if (i915_seqno_passed(signaller->get_seqno(signaller, false), seqno))
2683 return 1;
2684
Chris Wilsona0d036b2014-07-19 12:40:42 +01002685 /* cursory check for an unkickable deadlock */
2686 if (I915_READ_CTL(signaller) & RING_WAIT_SEMAPHORE &&
2687 semaphore_passed(signaller) < 0)
Chris Wilson4be17382014-06-06 10:22:29 +01002688 return -1;
2689
2690 return 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002691}
2692
2693static void semaphore_clear_deadlocks(struct drm_i915_private *dev_priv)
2694{
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002695 struct intel_engine_cs *ring;
Chris Wilson6274f212013-06-10 11:20:21 +01002696 int i;
2697
2698 for_each_ring(ring, dev_priv, i)
Chris Wilson4be17382014-06-06 10:22:29 +01002699 ring->hangcheck.deadlock = 0;
Chris Wilson6274f212013-06-10 11:20:21 +01002700}
2701
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002702static enum intel_ring_hangcheck_action
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002703ring_stuck(struct intel_engine_cs *ring, u64 acthd)
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002704{
2705 struct drm_device *dev = ring->dev;
2706 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002707 u32 tmp;
2708
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002709 if (acthd != ring->hangcheck.acthd) {
2710 if (acthd > ring->hangcheck.max_acthd) {
2711 ring->hangcheck.max_acthd = acthd;
2712 return HANGCHECK_ACTIVE;
2713 }
2714
2715 return HANGCHECK_ACTIVE_LOOP;
2716 }
Chris Wilson6274f212013-06-10 11:20:21 +01002717
Chris Wilson9107e9d2013-06-10 11:20:20 +01002718 if (IS_GEN2(dev))
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002719 return HANGCHECK_HUNG;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002720
2721 /* Is the chip hanging on a WAIT_FOR_EVENT?
2722 * If so we can simply poke the RB_WAIT bit
2723 * and break the hang. This should work on
2724 * all but the second generation chipsets.
2725 */
2726 tmp = I915_READ_CTL(ring);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002727 if (tmp & RING_WAIT) {
Mika Kuoppala58174462014-02-25 17:11:26 +02002728 i915_handle_error(dev, false,
2729 "Kicking stuck wait on %s",
2730 ring->name);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002731 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002732 return HANGCHECK_KICK;
Chris Wilson1ec14ad2010-12-04 11:30:53 +00002733 }
Chris Wilsona24a11e2013-03-14 17:52:05 +02002734
Chris Wilson6274f212013-06-10 11:20:21 +01002735 if (INTEL_INFO(dev)->gen >= 6 && tmp & RING_WAIT_SEMAPHORE) {
2736 switch (semaphore_passed(ring)) {
2737 default:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002738 return HANGCHECK_HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002739 case 1:
Mika Kuoppala58174462014-02-25 17:11:26 +02002740 i915_handle_error(dev, false,
2741 "Kicking stuck semaphore on %s",
2742 ring->name);
Chris Wilson6274f212013-06-10 11:20:21 +01002743 I915_WRITE_CTL(ring, tmp);
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002744 return HANGCHECK_KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002745 case 0:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002746 return HANGCHECK_WAIT;
Chris Wilson6274f212013-06-10 11:20:21 +01002747 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002748 }
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002749
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002750 return HANGCHECK_HUNG;
Mika Kuoppalaed5cbb02013-05-13 16:32:11 +03002751}
2752
Chris Wilson737b1502015-01-26 18:03:03 +02002753/*
Ben Gamarif65d9422009-09-14 17:48:44 -04002754 * This is called when the chip hasn't reported back with completed
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002755 * batchbuffers in a long time. We keep track per ring seqno progress and
2756 * if there are no progress, hangcheck score for that ring is increased.
2757 * Further, acthd is inspected to see if the ring is stuck. On stuck case
2758 * we kick the ring. If we see no progress on three subsequent calls
2759 * we assume chip is wedged and try to fix it by resetting the chip.
Ben Gamarif65d9422009-09-14 17:48:44 -04002760 */
Chris Wilson737b1502015-01-26 18:03:03 +02002761static void i915_hangcheck_elapsed(struct work_struct *work)
Ben Gamarif65d9422009-09-14 17:48:44 -04002762{
Chris Wilson737b1502015-01-26 18:03:03 +02002763 struct drm_i915_private *dev_priv =
2764 container_of(work, typeof(*dev_priv),
2765 gpu_error.hangcheck_work.work);
2766 struct drm_device *dev = dev_priv->dev;
Oscar Mateoa4872ba2014-05-22 14:13:33 +01002767 struct intel_engine_cs *ring;
Chris Wilsonb4519512012-05-11 14:29:30 +01002768 int i;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002769 int busy_count = 0, rings_hung = 0;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002770 bool stuck[I915_NUM_RINGS] = { 0 };
2771#define BUSY 1
2772#define KICK 5
2773#define HUNG 20
Chris Wilson893eead2010-10-27 14:44:35 +01002774
Jani Nikulad330a952014-01-21 11:24:25 +02002775 if (!i915.enable_hangcheck)
Ben Widawsky3e0dc6b2011-06-29 10:26:42 -07002776 return;
2777
Chris Wilsonb4519512012-05-11 14:29:30 +01002778 for_each_ring(ring, dev_priv, i) {
Chris Wilson50877442014-03-21 12:41:53 +00002779 u64 acthd;
2780 u32 seqno;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002781 bool busy = true;
Chris Wilsonb4519512012-05-11 14:29:30 +01002782
Chris Wilson6274f212013-06-10 11:20:21 +01002783 semaphore_clear_deadlocks(dev_priv);
2784
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002785 seqno = ring->get_seqno(ring, false);
2786 acthd = intel_ring_get_active_head(ring);
Chris Wilsond1e61e72012-04-10 17:00:41 +01002787
Chris Wilson9107e9d2013-06-10 11:20:20 +01002788 if (ring->hangcheck.seqno == seqno) {
Tomas Elf94f7bbe2015-07-09 15:30:57 +01002789 if (ring_idle(ring, seqno)) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002790 ring->hangcheck.action = HANGCHECK_IDLE;
2791
Chris Wilson9107e9d2013-06-10 11:20:20 +01002792 if (waitqueue_active(&ring->irq_queue)) {
2793 /* Issue a wake-up to catch stuck h/w. */
Chris Wilson094f9a52013-09-25 17:34:55 +01002794 if (!test_and_set_bit(ring->id, &dev_priv->gpu_error.missed_irq_rings)) {
Daniel Vetterf4adcd22013-10-28 09:24:13 +01002795 if (!(dev_priv->gpu_error.test_irq_rings & intel_ring_flag(ring)))
2796 DRM_ERROR("Hangcheck timer elapsed... %s idle\n",
2797 ring->name);
2798 else
2799 DRM_INFO("Fake missed irq on %s\n",
2800 ring->name);
Chris Wilson094f9a52013-09-25 17:34:55 +01002801 wake_up_all(&ring->irq_queue);
2802 }
2803 /* Safeguard against driver failure */
2804 ring->hangcheck.score += BUSY;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002805 } else
2806 busy = false;
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002807 } else {
Chris Wilson6274f212013-06-10 11:20:21 +01002808 /* We always increment the hangcheck score
2809 * if the ring is busy and still processing
2810 * the same request, so that no single request
2811 * can run indefinitely (such as a chain of
2812 * batches). The only time we do not increment
2813 * the hangcheck score on this ring, if this
2814 * ring is in a legitimate wait for another
2815 * ring. In that case the waiting ring is a
2816 * victim and we want to be sure we catch the
2817 * right culprit. Then every time we do kick
2818 * the ring, add a small increment to the
2819 * score so that we can catch a batch that is
2820 * being repeatedly kicked and so responsible
2821 * for stalling the machine.
2822 */
Mika Kuoppalaad8beae2013-06-12 12:35:32 +03002823 ring->hangcheck.action = ring_stuck(ring,
2824 acthd);
2825
2826 switch (ring->hangcheck.action) {
Mika Kuoppalada661462013-09-06 16:03:28 +03002827 case HANGCHECK_IDLE:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002828 case HANGCHECK_WAIT:
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002829 case HANGCHECK_ACTIVE:
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002830 break;
2831 case HANGCHECK_ACTIVE_LOOP:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002832 ring->hangcheck.score += BUSY;
Chris Wilson6274f212013-06-10 11:20:21 +01002833 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002834 case HANGCHECK_KICK:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002835 ring->hangcheck.score += KICK;
Chris Wilson6274f212013-06-10 11:20:21 +01002836 break;
Jani Nikulaf2f4d822013-08-11 12:44:01 +03002837 case HANGCHECK_HUNG:
Jani Nikulaea04cb32013-08-11 12:44:02 +03002838 ring->hangcheck.score += HUNG;
Chris Wilson6274f212013-06-10 11:20:21 +01002839 stuck[i] = true;
2840 break;
2841 }
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002842 }
Chris Wilson9107e9d2013-06-10 11:20:20 +01002843 } else {
Mika Kuoppalada661462013-09-06 16:03:28 +03002844 ring->hangcheck.action = HANGCHECK_ACTIVE;
2845
Chris Wilson9107e9d2013-06-10 11:20:20 +01002846 /* Gradually reduce the count so that we catch DoS
2847 * attempts across multiple batches.
2848 */
2849 if (ring->hangcheck.score > 0)
2850 ring->hangcheck.score--;
Mika Kuoppalaf260fe72014-08-05 17:16:26 +03002851
2852 ring->hangcheck.acthd = ring->hangcheck.max_acthd = 0;
Chris Wilsond1e61e72012-04-10 17:00:41 +01002853 }
2854
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002855 ring->hangcheck.seqno = seqno;
2856 ring->hangcheck.acthd = acthd;
Chris Wilson9107e9d2013-06-10 11:20:20 +01002857 busy_count += busy;
Chris Wilson893eead2010-10-27 14:44:35 +01002858 }
Eric Anholtb9201c12010-01-08 14:25:16 -08002859
Mika Kuoppala92cab732013-05-24 17:16:07 +03002860 for_each_ring(ring, dev_priv, i) {
Mika Kuoppalab6b0fac2014-01-30 19:04:43 +02002861 if (ring->hangcheck.score >= HANGCHECK_SCORE_RING_HUNG) {
Daniel Vetterb8d88d12013-08-28 10:57:59 +02002862 DRM_INFO("%s on %s\n",
2863 stuck[i] ? "stuck" : "no progress",
2864 ring->name);
Chris Wilsona43adf02013-06-10 11:20:22 +01002865 rings_hung++;
Mika Kuoppala92cab732013-05-24 17:16:07 +03002866 }
2867 }
2868
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002869 if (rings_hung)
Mika Kuoppala58174462014-02-25 17:11:26 +02002870 return i915_handle_error(dev, true, "Ring hung");
Ben Gamarif65d9422009-09-14 17:48:44 -04002871
Mika Kuoppala05407ff2013-05-30 09:04:29 +03002872 if (busy_count)
2873 /* Reset timer case chip hangs without another request
2874 * being added */
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002875 i915_queue_hangcheck(dev);
2876}
2877
2878void i915_queue_hangcheck(struct drm_device *dev)
2879{
Chris Wilson737b1502015-01-26 18:03:03 +02002880 struct i915_gpu_error *e = &to_i915(dev)->gpu_error;
Chris Wilson672e7b72014-11-19 09:47:19 +00002881
Jani Nikulad330a952014-01-21 11:24:25 +02002882 if (!i915.enable_hangcheck)
Mika Kuoppala10cd45b2013-07-03 17:22:08 +03002883 return;
2884
Chris Wilson737b1502015-01-26 18:03:03 +02002885 /* Don't continually defer the hangcheck so that it is always run at
2886 * least once after work has been scheduled on any ring. Otherwise,
2887 * we will ignore a hung ring if a second ring is kept busy.
2888 */
2889
2890 queue_delayed_work(e->hangcheck_wq, &e->hangcheck_work,
2891 round_jiffies_up_relative(DRM_I915_HANGCHECK_JIFFIES));
Ben Gamarif65d9422009-09-14 17:48:44 -04002892}
2893
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03002894static void ibx_irq_reset(struct drm_device *dev)
Paulo Zanoni91738a92013-06-05 14:21:51 -03002895{
2896 struct drm_i915_private *dev_priv = dev->dev_private;
2897
2898 if (HAS_PCH_NOP(dev))
2899 return;
2900
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03002901 GEN5_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03002902
2903 if (HAS_PCH_CPT(dev) || HAS_PCH_LPT(dev))
2904 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03002905}
Paulo Zanoni105b1222014-04-01 15:37:17 -03002906
Paulo Zanoni622364b2014-04-01 15:37:22 -03002907/*
2908 * SDEIER is also touched by the interrupt handler to work around missed PCH
2909 * interrupts. Hence we can't update it after the interrupt handler is enabled -
2910 * instead we unconditionally enable all PCH interrupt sources here, but then
2911 * only unmask them as needed with SDEIMR.
2912 *
2913 * This function needs to be called before interrupts are enabled.
2914 */
2915static void ibx_irq_pre_postinstall(struct drm_device *dev)
2916{
2917 struct drm_i915_private *dev_priv = dev->dev_private;
2918
2919 if (HAS_PCH_NOP(dev))
2920 return;
2921
2922 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03002923 I915_WRITE(SDEIER, 0xffffffff);
2924 POSTING_READ(SDEIER);
2925}
2926
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03002927static void gen5_gt_irq_reset(struct drm_device *dev)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002928{
2929 struct drm_i915_private *dev_priv = dev->dev_private;
2930
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03002931 GEN5_IRQ_RESET(GT);
Paulo Zanonia9d356a2014-04-01 15:37:09 -03002932 if (INTEL_INFO(dev)->gen >= 6)
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03002933 GEN5_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02002934}
2935
Linus Torvalds1da177e2005-04-16 15:20:36 -07002936/* drm_dma.h hooks
2937*/
Paulo Zanonibe30b292014-04-01 15:37:25 -03002938static void ironlake_irq_reset(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002939{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002940 struct drm_i915_private *dev_priv = dev->dev_private;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002941
Paulo Zanoni0c841212014-04-01 15:37:27 -03002942 I915_WRITE(HWSTAM, 0xffffffff);
Daniel Vetterbdfcdb62012-01-05 01:05:26 +01002943
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03002944 GEN5_IRQ_RESET(DE);
Paulo Zanonic6d954c2014-04-01 15:37:18 -03002945 if (IS_GEN7(dev))
2946 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08002947
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03002948 gen5_gt_irq_reset(dev);
Zhenyu Wangc6501562009-11-03 18:57:21 +00002949
Paulo Zanoni1c69eb42014-04-01 15:37:23 -03002950 ibx_irq_reset(dev);
Ben Widawsky7d991632013-05-28 19:22:25 -07002951}
2952
Ville Syrjälä70591a42014-10-30 19:42:58 +02002953static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
2954{
2955 enum pipe pipe;
2956
2957 I915_WRITE(PORT_HOTPLUG_EN, 0);
2958 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
2959
2960 for_each_pipe(dev_priv, pipe)
2961 I915_WRITE(PIPESTAT(pipe), 0xffff);
2962
2963 GEN5_IRQ_RESET(VLV_);
2964}
2965
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002966static void valleyview_irq_preinstall(struct drm_device *dev)
2967{
Jani Nikula2d1013d2014-03-31 14:27:17 +03002968 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002969
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002970 /* VLV magic */
2971 I915_WRITE(VLV_IMR, 0);
2972 I915_WRITE(RING_IMR(RENDER_RING_BASE), 0);
2973 I915_WRITE(RING_IMR(GEN6_BSD_RING_BASE), 0);
2974 I915_WRITE(RING_IMR(BLT_RING_BASE), 0);
2975
Paulo Zanoni7c4d6642014-04-01 15:37:19 -03002976 gen5_gt_irq_reset(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002977
Ville Syrjälä7c4cde32014-10-30 19:42:51 +02002978 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002979
Ville Syrjälä70591a42014-10-30 19:42:58 +02002980 vlv_display_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002981}
2982
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02002983static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
2984{
2985 GEN8_IRQ_RESET_NDX(GT, 0);
2986 GEN8_IRQ_RESET_NDX(GT, 1);
2987 GEN8_IRQ_RESET_NDX(GT, 2);
2988 GEN8_IRQ_RESET_NDX(GT, 3);
2989}
2990
Paulo Zanoni823f6b32014-04-01 15:37:26 -03002991static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002992{
2993 struct drm_i915_private *dev_priv = dev->dev_private;
2994 int pipe;
2995
Ben Widawskyabd58f02013-11-02 21:07:09 -07002996 I915_WRITE(GEN8_MASTER_IRQ, 0);
2997 POSTING_READ(GEN8_MASTER_IRQ);
2998
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02002999 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003000
Damien Lespiau055e3932014-08-18 13:49:10 +01003001 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003002 if (intel_display_power_is_enabled(dev_priv,
3003 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003004 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003005
Paulo Zanonif86f3fb2014-04-01 15:37:14 -03003006 GEN5_IRQ_RESET(GEN8_DE_PORT_);
3007 GEN5_IRQ_RESET(GEN8_DE_MISC_);
3008 GEN5_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003009
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303010 if (HAS_PCH_SPLIT(dev))
3011 ibx_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003012}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003013
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003014void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
3015 unsigned int pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003016{
Paulo Zanoni1180e202014-10-07 18:02:52 -03003017 uint32_t extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003018
Daniel Vetter13321782014-09-15 14:55:29 +02003019 spin_lock_irq(&dev_priv->irq_lock);
Damien Lespiaud14c0342015-03-06 18:50:51 +00003020 if (pipe_mask & 1 << PIPE_A)
3021 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_A,
3022 dev_priv->de_irq_mask[PIPE_A],
3023 ~dev_priv->de_irq_mask[PIPE_A] | extra_ier);
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003024 if (pipe_mask & 1 << PIPE_B)
3025 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_B,
3026 dev_priv->de_irq_mask[PIPE_B],
3027 ~dev_priv->de_irq_mask[PIPE_B] | extra_ier);
3028 if (pipe_mask & 1 << PIPE_C)
3029 GEN8_IRQ_INIT_NDX(DE_PIPE, PIPE_C,
3030 dev_priv->de_irq_mask[PIPE_C],
3031 ~dev_priv->de_irq_mask[PIPE_C] | extra_ier);
Daniel Vetter13321782014-09-15 14:55:29 +02003032 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003033}
3034
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003035static void cherryview_irq_preinstall(struct drm_device *dev)
3036{
3037 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003038
3039 I915_WRITE(GEN8_MASTER_IRQ, 0);
3040 POSTING_READ(GEN8_MASTER_IRQ);
3041
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003042 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003043
3044 GEN5_IRQ_RESET(GEN8_PCU_);
3045
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003046 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3047
Ville Syrjälä70591a42014-10-30 19:42:58 +02003048 vlv_display_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003049}
3050
Ville Syrjälä87a02102015-08-27 23:55:57 +03003051static u32 intel_hpd_enabled_irqs(struct drm_device *dev,
3052 const u32 hpd[HPD_NUM_PINS])
3053{
3054 struct drm_i915_private *dev_priv = to_i915(dev);
3055 struct intel_encoder *encoder;
3056 u32 enabled_irqs = 0;
3057
3058 for_each_intel_encoder(dev, encoder)
3059 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3060 enabled_irqs |= hpd[encoder->hpd_pin];
3061
3062 return enabled_irqs;
3063}
3064
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003065static void ibx_hpd_irq_setup(struct drm_device *dev)
Keith Packard7fe0b972011-09-19 13:31:02 -07003066{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003067 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003068 u32 hotplug_irqs, hotplug, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003069
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003070 if (HAS_PCH_IBX(dev)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003071 hotplug_irqs = SDE_HOTPLUG_MASK;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003072 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003073 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003074 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003075 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003076 }
3077
Daniel Vetterfee884e2013-07-04 23:35:21 +02003078 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003079
3080 /*
3081 * Enable digital hotplug on the PCH, and configure the DP short pulse
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003082 * duration to 2ms (which is the minimum in the Display Port spec).
3083 * The pulse duration bits are reserved on LPT+.
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003084 */
Keith Packard7fe0b972011-09-19 13:31:02 -07003085 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3086 hotplug &= ~(PORTD_PULSE_DURATION_MASK|PORTC_PULSE_DURATION_MASK|PORTB_PULSE_DURATION_MASK);
3087 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3088 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3089 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3090 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003091}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003092
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003093static void spt_hpd_irq_setup(struct drm_device *dev)
3094{
3095 struct drm_i915_private *dev_priv = dev->dev_private;
3096 u32 hotplug_irqs, hotplug, enabled_irqs;
3097
3098 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
3099 enabled_irqs = intel_hpd_enabled_irqs(dev, hpd_spt);
3100
3101 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3102
3103 /* Enable digital hotplug on the PCH */
3104 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3105 hotplug |= PORTD_HOTPLUG_ENABLE | PORTC_HOTPLUG_ENABLE |
3106 PORTB_HOTPLUG_ENABLE;
3107 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3108
3109 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3110 hotplug |= PORTE_HOTPLUG_ENABLE;
3111 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
Keith Packard7fe0b972011-09-19 13:31:02 -07003112}
3113
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003114static void bxt_hpd_irq_setup(struct drm_device *dev)
3115{
3116 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä87a02102015-08-27 23:55:57 +03003117 u32 hotplug_port;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003118 u32 hotplug_ctrl;
3119
Ville Syrjälä87a02102015-08-27 23:55:57 +03003120 hotplug_port = intel_hpd_enabled_irqs(dev, hpd_bxt);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003121
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003122 hotplug_ctrl = I915_READ(BXT_HOTPLUG_CTL) & ~BXT_HOTPLUG_CTL_MASK;
3123
Sonika Jindal7f3561b2015-08-10 10:35:35 +05303124 if (hotplug_port & BXT_DE_PORT_HP_DDIA)
3125 hotplug_ctrl |= BXT_DDIA_HPD_ENABLE;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003126 if (hotplug_port & BXT_DE_PORT_HP_DDIB)
3127 hotplug_ctrl |= BXT_DDIB_HPD_ENABLE;
3128 if (hotplug_port & BXT_DE_PORT_HP_DDIC)
3129 hotplug_ctrl |= BXT_DDIC_HPD_ENABLE;
3130 I915_WRITE(BXT_HOTPLUG_CTL, hotplug_ctrl);
3131
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003132 hotplug_ctrl = I915_READ(GEN8_DE_PORT_IMR) & ~hotplug_port;
3133 I915_WRITE(GEN8_DE_PORT_IMR, hotplug_ctrl);
3134
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003135 hotplug_ctrl = I915_READ(GEN8_DE_PORT_IER) | hotplug_port;
3136 I915_WRITE(GEN8_DE_PORT_IER, hotplug_ctrl);
3137 POSTING_READ(GEN8_DE_PORT_IER);
3138}
3139
Paulo Zanonid46da432013-02-08 17:35:15 -02003140static void ibx_irq_postinstall(struct drm_device *dev)
3141{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003142 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003143 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003144
Daniel Vetter692a04c2013-05-29 21:43:05 +02003145 if (HAS_PCH_NOP(dev))
3146 return;
3147
Paulo Zanoni105b1222014-04-01 15:37:17 -03003148 if (HAS_PCH_IBX(dev))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003149 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Paulo Zanoni105b1222014-04-01 15:37:17 -03003150 else
Daniel Vetter5c673b62014-03-07 20:34:46 +01003151 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003152
Paulo Zanoni337ba012014-04-01 15:37:16 -03003153 GEN5_ASSERT_IIR_IS_ZERO(SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003154 I915_WRITE(SDEIMR, ~mask);
Paulo Zanonid46da432013-02-08 17:35:15 -02003155}
3156
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003157static void gen5_gt_irq_postinstall(struct drm_device *dev)
3158{
3159 struct drm_i915_private *dev_priv = dev->dev_private;
3160 u32 pm_irqs, gt_irqs;
3161
3162 pm_irqs = gt_irqs = 0;
3163
3164 dev_priv->gt_irq_mask = ~0;
Ben Widawsky040d2ba2013-09-19 11:01:40 -07003165 if (HAS_L3_DPF(dev)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003166 /* L3 parity interrupt is always unmasked. */
Ben Widawsky35a85ac2013-09-19 11:13:41 -07003167 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev);
3168 gt_irqs |= GT_PARITY_ERROR(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003169 }
3170
3171 gt_irqs |= GT_RENDER_USER_INTERRUPT;
3172 if (IS_GEN5(dev)) {
3173 gt_irqs |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT |
3174 ILK_BSD_USER_INTERRUPT;
3175 } else {
3176 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3177 }
3178
Paulo Zanoni35079892014-04-01 15:37:15 -03003179 GEN5_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003180
3181 if (INTEL_INFO(dev)->gen >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003182 /*
3183 * RPS interrupts will get enabled/disabled on demand when RPS
3184 * itself is enabled/disabled.
3185 */
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003186 if (HAS_VEBOX(dev))
3187 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
3188
Paulo Zanoni605cd252013-08-06 18:57:15 -03003189 dev_priv->pm_irq_mask = 0xffffffff;
Paulo Zanoni35079892014-04-01 15:37:15 -03003190 GEN5_IRQ_INIT(GEN6_PM, dev_priv->pm_irq_mask, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003191 }
3192}
3193
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003194static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003195{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003196 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003197 u32 display_mask, extra_mask;
3198
3199 if (INTEL_INFO(dev)->gen >= 7) {
3200 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
3201 DE_PCH_EVENT_IVB | DE_PLANEC_FLIP_DONE_IVB |
3202 DE_PLANEB_FLIP_DONE_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003203 DE_PLANEA_FLIP_DONE_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003204 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Daniel Vetter5c673b62014-03-07 20:34:46 +01003205 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003206 } else {
3207 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
3208 DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003209 DE_AUX_CHANNEL_A |
Daniel Vetter5b3a8562013-10-16 22:55:48 +02003210 DE_PIPEB_CRC_DONE | DE_PIPEA_CRC_DONE |
3211 DE_POISON);
Daniel Vetter5c673b62014-03-07 20:34:46 +01003212 extra_mask = DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3213 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003214 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003215
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003216 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003217
Paulo Zanoni0c841212014-04-01 15:37:27 -03003218 I915_WRITE(HWSTAM, 0xeffe);
3219
Paulo Zanoni622364b2014-04-01 15:37:22 -03003220 ibx_irq_pre_postinstall(dev);
3221
Paulo Zanoni35079892014-04-01 15:37:15 -03003222 GEN5_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003223
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003224 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003225
Paulo Zanonid46da432013-02-08 17:35:15 -02003226 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003227
Jesse Barnesf97108d2010-01-29 11:27:07 -08003228 if (IS_IRONLAKE_M(dev)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003229 /* Enable PCU event interrupts
3230 *
3231 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003232 * setup is guaranteed to run in single-threaded context. But we
3233 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003234 spin_lock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003235 ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003236 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003237 }
3238
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003239 return 0;
3240}
3241
Imre Deakf8b79e52014-03-04 19:23:07 +02003242static void valleyview_display_irqs_install(struct drm_i915_private *dev_priv)
3243{
3244 u32 pipestat_mask;
3245 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003246 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003247
3248 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3249 PIPE_FIFO_UNDERRUN_STATUS;
3250
Ville Syrjälä120dda42014-10-30 19:42:57 +02003251 for_each_pipe(dev_priv, pipe)
3252 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003253 POSTING_READ(PIPESTAT(PIPE_A));
3254
3255 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3256 PIPE_CRC_DONE_INTERRUPT_STATUS;
3257
Ville Syrjälä120dda42014-10-30 19:42:57 +02003258 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3259 for_each_pipe(dev_priv, pipe)
3260 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003261
3262 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3263 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3264 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003265 if (IS_CHERRYVIEW(dev_priv))
3266 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003267 dev_priv->irq_mask &= ~iir_mask;
3268
3269 I915_WRITE(VLV_IIR, iir_mask);
3270 I915_WRITE(VLV_IIR, iir_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003271 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003272 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3273 POSTING_READ(VLV_IMR);
Imre Deakf8b79e52014-03-04 19:23:07 +02003274}
3275
3276static void valleyview_display_irqs_uninstall(struct drm_i915_private *dev_priv)
3277{
3278 u32 pipestat_mask;
3279 u32 iir_mask;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003280 enum pipe pipe;
Imre Deakf8b79e52014-03-04 19:23:07 +02003281
3282 iir_mask = I915_DISPLAY_PORT_INTERRUPT |
3283 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Imre Deak6c7fba02014-03-10 19:44:48 +02003284 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003285 if (IS_CHERRYVIEW(dev_priv))
3286 iir_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
Imre Deakf8b79e52014-03-04 19:23:07 +02003287
3288 dev_priv->irq_mask |= iir_mask;
Imre Deakf8b79e52014-03-04 19:23:07 +02003289 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003290 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003291 I915_WRITE(VLV_IIR, iir_mask);
3292 I915_WRITE(VLV_IIR, iir_mask);
3293 POSTING_READ(VLV_IIR);
3294
3295 pipestat_mask = PLANE_FLIP_DONE_INT_STATUS_VLV |
3296 PIPE_CRC_DONE_INTERRUPT_STATUS;
3297
Ville Syrjälä120dda42014-10-30 19:42:57 +02003298 i915_disable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3299 for_each_pipe(dev_priv, pipe)
3300 i915_disable_pipestat(dev_priv, pipe, pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003301
3302 pipestat_mask = PIPESTAT_INT_STATUS_MASK |
3303 PIPE_FIFO_UNDERRUN_STATUS;
Ville Syrjälä120dda42014-10-30 19:42:57 +02003304
3305 for_each_pipe(dev_priv, pipe)
3306 I915_WRITE(PIPESTAT(pipe), pipestat_mask);
Imre Deakf8b79e52014-03-04 19:23:07 +02003307 POSTING_READ(PIPESTAT(PIPE_A));
3308}
3309
3310void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3311{
3312 assert_spin_locked(&dev_priv->irq_lock);
3313
3314 if (dev_priv->display_irqs_enabled)
3315 return;
3316
3317 dev_priv->display_irqs_enabled = true;
3318
Imre Deak950eaba2014-09-08 15:21:09 +03003319 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003320 valleyview_display_irqs_install(dev_priv);
3321}
3322
3323void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
3324{
3325 assert_spin_locked(&dev_priv->irq_lock);
3326
3327 if (!dev_priv->display_irqs_enabled)
3328 return;
3329
3330 dev_priv->display_irqs_enabled = false;
3331
Imre Deak950eaba2014-09-08 15:21:09 +03003332 if (intel_irqs_enabled(dev_priv))
Imre Deakf8b79e52014-03-04 19:23:07 +02003333 valleyview_display_irqs_uninstall(dev_priv);
3334}
3335
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003336static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003337{
Imre Deakf8b79e52014-03-04 19:23:07 +02003338 dev_priv->irq_mask = ~0;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003339
Daniel Vetter20afbda2012-12-11 14:05:07 +01003340 I915_WRITE(PORT_HOTPLUG_EN, 0);
3341 POSTING_READ(PORT_HOTPLUG_EN);
3342
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003343 I915_WRITE(VLV_IIR, 0xffffffff);
Ville Syrjälä76e41862014-10-30 19:42:54 +02003344 I915_WRITE(VLV_IIR, 0xffffffff);
3345 I915_WRITE(VLV_IER, ~dev_priv->irq_mask);
3346 I915_WRITE(VLV_IMR, dev_priv->irq_mask);
3347 POSTING_READ(VLV_IMR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003348
Daniel Vetterb79480b2013-06-27 17:52:10 +02003349 /* Interrupt setup is already guaranteed to be single-threaded, this is
3350 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003351 spin_lock_irq(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003352 if (dev_priv->display_irqs_enabled)
3353 valleyview_display_irqs_install(dev_priv);
Daniel Vetterd6207432014-09-15 14:55:27 +02003354 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02003355}
3356
3357static int valleyview_irq_postinstall(struct drm_device *dev)
3358{
3359 struct drm_i915_private *dev_priv = dev->dev_private;
3360
3361 vlv_display_irq_postinstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003362
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003363 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003364
3365 /* ack & enable invalid PTE error interrupts */
3366#if 0 /* FIXME: add support to irq handler for checking these bits */
3367 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3368 I915_WRITE(DPINVGTT, DPINVGTT_EN_MASK);
3369#endif
3370
3371 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003372
3373 return 0;
3374}
3375
Ben Widawskyabd58f02013-11-02 21:07:09 -07003376static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
3377{
Ben Widawskyabd58f02013-11-02 21:07:09 -07003378 /* These are interrupts we'll toggle with the ring mask register */
3379 uint32_t gt_interrupts[] = {
3380 GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003381 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
Ben Widawskyabd58f02013-11-02 21:07:09 -07003382 GT_RENDER_L3_PARITY_ERROR_INTERRUPT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003383 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
3384 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003385 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
Oscar Mateo73d477f2014-07-24 17:04:31 +01003386 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
3387 GT_RENDER_USER_INTERRUPT << GEN8_VCS2_IRQ_SHIFT |
3388 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS2_IRQ_SHIFT,
Ben Widawskyabd58f02013-11-02 21:07:09 -07003389 0,
Oscar Mateo73d477f2014-07-24 17:04:31 +01003390 GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
3391 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT
Ben Widawskyabd58f02013-11-02 21:07:09 -07003392 };
3393
Ben Widawsky09610212014-05-15 20:58:08 +03003394 dev_priv->pm_irq_mask = 0xffffffff;
Deepak S9a2d2d82014-08-22 08:32:40 +05303395 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
3396 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02003397 /*
3398 * RPS interrupts will get enabled/disabled on demand when RPS itself
3399 * is enabled/disabled.
3400 */
3401 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_irq_mask, 0);
Deepak S9a2d2d82014-08-22 08:32:40 +05303402 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003403}
3404
3405static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
3406{
Damien Lespiau770de832014-03-20 20:45:01 +00003407 uint32_t de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
3408 uint32_t de_pipe_enables;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003409 int pipe;
Shashank Sharma9e637432014-08-22 17:40:43 +05303410 u32 de_port_en = GEN8_AUX_CHANNEL_A;
Damien Lespiau770de832014-03-20 20:45:01 +00003411
Jesse Barnes88e04702014-11-13 17:51:48 +00003412 if (IS_GEN9(dev_priv)) {
Damien Lespiau770de832014-03-20 20:45:01 +00003413 de_pipe_masked |= GEN9_PIPE_PLANE1_FLIP_DONE |
3414 GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Shashank Sharma9e637432014-08-22 17:40:43 +05303415 de_port_en |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
Jesse Barnes88e04702014-11-13 17:51:48 +00003416 GEN9_AUX_CHANNEL_D;
Shashank Sharma9e637432014-08-22 17:40:43 +05303417
3418 if (IS_BROXTON(dev_priv))
3419 de_port_en |= BXT_DE_PORT_GMBUS;
Jesse Barnes88e04702014-11-13 17:51:48 +00003420 } else
Damien Lespiau770de832014-03-20 20:45:01 +00003421 de_pipe_masked |= GEN8_PIPE_PRIMARY_FLIP_DONE |
3422 GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
3423
3424 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
3425 GEN8_PIPE_FIFO_UNDERRUN;
3426
Daniel Vetter13b3a0a2013-11-07 15:31:52 +01003427 dev_priv->de_irq_mask[PIPE_A] = ~de_pipe_masked;
3428 dev_priv->de_irq_mask[PIPE_B] = ~de_pipe_masked;
3429 dev_priv->de_irq_mask[PIPE_C] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003430
Damien Lespiau055e3932014-08-18 13:49:10 +01003431 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003432 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03003433 POWER_DOMAIN_PIPE(pipe)))
3434 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3435 dev_priv->de_irq_mask[pipe],
3436 de_pipe_enables);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003437
Shashank Sharma9e637432014-08-22 17:40:43 +05303438 GEN5_IRQ_INIT(GEN8_DE_PORT_, ~de_port_en, de_port_en);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003439}
3440
3441static int gen8_irq_postinstall(struct drm_device *dev)
3442{
3443 struct drm_i915_private *dev_priv = dev->dev_private;
3444
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303445 if (HAS_PCH_SPLIT(dev))
3446 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003447
Ben Widawskyabd58f02013-11-02 21:07:09 -07003448 gen8_gt_irq_postinstall(dev_priv);
3449 gen8_de_irq_postinstall(dev_priv);
3450
Shashank Sharma266ea3d2014-08-22 17:40:42 +05303451 if (HAS_PCH_SPLIT(dev))
3452 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003453
3454 I915_WRITE(GEN8_MASTER_IRQ, DE_MASTER_IRQ_CONTROL);
3455 POSTING_READ(GEN8_MASTER_IRQ);
3456
3457 return 0;
3458}
3459
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003460static int cherryview_irq_postinstall(struct drm_device *dev)
3461{
3462 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003463
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003464 vlv_display_irq_postinstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003465
3466 gen8_gt_irq_postinstall(dev_priv);
3467
3468 I915_WRITE(GEN8_MASTER_IRQ, MASTER_INTERRUPT_ENABLE);
3469 POSTING_READ(GEN8_MASTER_IRQ);
3470
3471 return 0;
3472}
3473
Ben Widawskyabd58f02013-11-02 21:07:09 -07003474static void gen8_irq_uninstall(struct drm_device *dev)
3475{
3476 struct drm_i915_private *dev_priv = dev->dev_private;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003477
3478 if (!dev_priv)
3479 return;
3480
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003481 gen8_irq_reset(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003482}
3483
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003484static void vlv_display_irq_uninstall(struct drm_i915_private *dev_priv)
3485{
3486 /* Interrupt setup is already guaranteed to be single-threaded, this is
3487 * just to make the assert_spin_locked check happy. */
3488 spin_lock_irq(&dev_priv->irq_lock);
3489 if (dev_priv->display_irqs_enabled)
3490 valleyview_display_irqs_uninstall(dev_priv);
3491 spin_unlock_irq(&dev_priv->irq_lock);
3492
3493 vlv_display_irq_reset(dev_priv);
3494
Imre Deakc352d1b2014-11-20 16:05:55 +02003495 dev_priv->irq_mask = ~0;
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003496}
3497
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003498static void valleyview_irq_uninstall(struct drm_device *dev)
3499{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003500 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003501
3502 if (!dev_priv)
3503 return;
3504
Imre Deak843d0e72014-04-14 20:24:23 +03003505 I915_WRITE(VLV_MASTER_IER, 0);
3506
Ville Syrjälä893fce82014-10-30 19:42:56 +02003507 gen5_gt_irq_reset(dev);
3508
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003509 I915_WRITE(HWSTAM, 0xffffffff);
Imre Deakf8b79e52014-03-04 19:23:07 +02003510
Ville Syrjälä8ea0be42014-10-30 19:42:59 +02003511 vlv_display_irq_uninstall(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003512}
3513
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003514static void cherryview_irq_uninstall(struct drm_device *dev)
3515{
3516 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003517
3518 if (!dev_priv)
3519 return;
3520
3521 I915_WRITE(GEN8_MASTER_IRQ, 0);
3522 POSTING_READ(GEN8_MASTER_IRQ);
3523
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003524 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003525
Ville Syrjäläa2c30fb2014-10-30 19:42:52 +02003526 GEN5_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003527
Ville Syrjäläc2b66792014-10-30 19:43:02 +02003528 vlv_display_irq_uninstall(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003529}
3530
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003531static void ironlake_irq_uninstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003532{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003533 struct drm_i915_private *dev_priv = dev->dev_private;
Jesse Barnes46979952011-04-07 13:53:55 -07003534
3535 if (!dev_priv)
3536 return;
3537
Paulo Zanonibe30b292014-04-01 15:37:25 -03003538 ironlake_irq_reset(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003539}
3540
Chris Wilsonc2798b12012-04-22 21:13:57 +01003541static void i8xx_irq_preinstall(struct drm_device * dev)
3542{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003543 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003544 int pipe;
3545
Damien Lespiau055e3932014-08-18 13:49:10 +01003546 for_each_pipe(dev_priv, pipe)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003547 I915_WRITE(PIPESTAT(pipe), 0);
3548 I915_WRITE16(IMR, 0xffff);
3549 I915_WRITE16(IER, 0x0);
3550 POSTING_READ16(IER);
3551}
3552
3553static int i8xx_irq_postinstall(struct drm_device *dev)
3554{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003555 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003556
Chris Wilsonc2798b12012-04-22 21:13:57 +01003557 I915_WRITE16(EMR,
3558 ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3559
3560 /* Unmask the interrupts that we always want on. */
3561 dev_priv->irq_mask =
3562 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3563 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3564 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003565 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003566 I915_WRITE16(IMR, dev_priv->irq_mask);
3567
3568 I915_WRITE16(IER,
3569 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3570 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilsonc2798b12012-04-22 21:13:57 +01003571 I915_USER_INTERRUPT);
3572 POSTING_READ16(IER);
3573
Daniel Vetter379ef822013-10-16 22:55:56 +02003574 /* Interrupt setup is already guaranteed to be single-threaded, this is
3575 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003576 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003577 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3578 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003579 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003580
Chris Wilsonc2798b12012-04-22 21:13:57 +01003581 return 0;
3582}
3583
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003584/*
3585 * Returns true when a page flip has completed.
3586 */
3587static bool i8xx_handle_vblank(struct drm_device *dev,
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003588 int plane, int pipe, u32 iir)
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003589{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003590 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003591 u16 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003592
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003593 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003594 return false;
3595
3596 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003597 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003598
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003599 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3600 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3601 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3602 * the flip is completed (no longer pending). Since this doesn't raise
3603 * an interrupt per se, we watch for the change at vblank.
3604 */
3605 if (I915_READ16(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003606 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003607
Ville Syrjälä7d475592014-12-17 23:08:03 +02003608 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003609 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003610 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003611
3612check_page_flip:
3613 intel_check_page_flip(dev, pipe);
3614 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003615}
3616
Daniel Vetterff1f5252012-10-02 15:10:55 +02003617static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003618{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003619 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003620 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003621 u16 iir, new_iir;
3622 u32 pipe_stats[2];
Chris Wilsonc2798b12012-04-22 21:13:57 +01003623 int pipe;
3624 u16 flip_mask =
3625 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3626 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
3627
Imre Deak2dd2a882015-02-24 11:14:30 +02003628 if (!intel_irqs_enabled(dev_priv))
3629 return IRQ_NONE;
3630
Chris Wilsonc2798b12012-04-22 21:13:57 +01003631 iir = I915_READ16(IIR);
3632 if (iir == 0)
3633 return IRQ_NONE;
3634
3635 while (iir & ~flip_mask) {
3636 /* Can't rely on pipestat interrupt bit in iir as it might
3637 * have been cleared after the pipestat interrupt was received.
3638 * It doesn't set the bit in iir again, but it still produces
3639 * interrupts (for non-MSI).
3640 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003641 spin_lock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003642 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003643 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003644
Damien Lespiau055e3932014-08-18 13:49:10 +01003645 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003646 int reg = PIPESTAT(pipe);
3647 pipe_stats[pipe] = I915_READ(reg);
3648
3649 /*
3650 * Clear the PIPE*STAT regs before the IIR
3651 */
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003652 if (pipe_stats[pipe] & 0x8000ffff)
Chris Wilsonc2798b12012-04-22 21:13:57 +01003653 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003654 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003655 spin_unlock(&dev_priv->irq_lock);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003656
3657 I915_WRITE16(IIR, iir & ~flip_mask);
3658 new_iir = I915_READ16(IIR); /* Flush posted writes */
3659
Chris Wilsonc2798b12012-04-22 21:13:57 +01003660 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01003661 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003662
Damien Lespiau055e3932014-08-18 13:49:10 +01003663 for_each_pipe(dev_priv, pipe) {
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003664 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003665 if (HAS_FBC(dev))
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003666 plane = !plane;
3667
Daniel Vetter4356d582013-10-16 22:55:55 +02003668 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä1f1c2e22013-11-28 17:30:01 +02003669 i8xx_handle_vblank(dev, plane, pipe, iir))
3670 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsonc2798b12012-04-22 21:13:57 +01003671
Daniel Vetter4356d582013-10-16 22:55:55 +02003672 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003673 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003674
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003675 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3676 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3677 pipe);
Daniel Vetter4356d582013-10-16 22:55:55 +02003678 }
Chris Wilsonc2798b12012-04-22 21:13:57 +01003679
3680 iir = new_iir;
3681 }
3682
3683 return IRQ_HANDLED;
3684}
3685
3686static void i8xx_irq_uninstall(struct drm_device * dev)
3687{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003688 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonc2798b12012-04-22 21:13:57 +01003689 int pipe;
3690
Damien Lespiau055e3932014-08-18 13:49:10 +01003691 for_each_pipe(dev_priv, pipe) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01003692 /* Clear enable bits; then clear status bits */
3693 I915_WRITE(PIPESTAT(pipe), 0);
3694 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3695 }
3696 I915_WRITE16(IMR, 0xffff);
3697 I915_WRITE16(IER, 0x0);
3698 I915_WRITE16(IIR, I915_READ16(IIR));
3699}
3700
Chris Wilsona266c7d2012-04-24 22:59:44 +01003701static void i915_irq_preinstall(struct drm_device * dev)
3702{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003703 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003704 int pipe;
3705
Chris Wilsona266c7d2012-04-24 22:59:44 +01003706 if (I915_HAS_HOTPLUG(dev)) {
3707 I915_WRITE(PORT_HOTPLUG_EN, 0);
3708 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3709 }
3710
Chris Wilson00d98eb2012-04-24 22:59:48 +01003711 I915_WRITE16(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01003712 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003713 I915_WRITE(PIPESTAT(pipe), 0);
3714 I915_WRITE(IMR, 0xffffffff);
3715 I915_WRITE(IER, 0x0);
3716 POSTING_READ(IER);
3717}
3718
3719static int i915_irq_postinstall(struct drm_device *dev)
3720{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003721 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson38bde182012-04-24 22:59:50 +01003722 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003723
Chris Wilson38bde182012-04-24 22:59:50 +01003724 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | I915_ERROR_MEMORY_REFRESH));
3725
3726 /* Unmask the interrupts that we always want on. */
3727 dev_priv->irq_mask =
3728 ~(I915_ASLE_INTERRUPT |
3729 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3730 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3731 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
Daniel Vetter37ef01a2015-04-01 13:43:46 +02003732 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01003733
3734 enable_mask =
3735 I915_ASLE_INTERRUPT |
3736 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3737 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01003738 I915_USER_INTERRUPT;
3739
Chris Wilsona266c7d2012-04-24 22:59:44 +01003740 if (I915_HAS_HOTPLUG(dev)) {
Daniel Vetter20afbda2012-12-11 14:05:07 +01003741 I915_WRITE(PORT_HOTPLUG_EN, 0);
3742 POSTING_READ(PORT_HOTPLUG_EN);
3743
Chris Wilsona266c7d2012-04-24 22:59:44 +01003744 /* Enable in IER... */
3745 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
3746 /* and unmask in IMR */
3747 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
3748 }
3749
Chris Wilsona266c7d2012-04-24 22:59:44 +01003750 I915_WRITE(IMR, dev_priv->irq_mask);
3751 I915_WRITE(IER, enable_mask);
3752 POSTING_READ(IER);
3753
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003754 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003755
Daniel Vetter379ef822013-10-16 22:55:56 +02003756 /* Interrupt setup is already guaranteed to be single-threaded, this is
3757 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003758 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003759 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3760 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003761 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02003762
Daniel Vetter20afbda2012-12-11 14:05:07 +01003763 return 0;
3764}
3765
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003766/*
3767 * Returns true when a page flip has completed.
3768 */
3769static bool i915_handle_vblank(struct drm_device *dev,
3770 int plane, int pipe, u32 iir)
3771{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003772 struct drm_i915_private *dev_priv = dev->dev_private;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003773 u32 flip_pending = DISPLAY_PLANE_FLIP_PENDING(plane);
3774
Ville Syrjälä8d7849d2014-04-29 13:35:46 +03003775 if (!intel_pipe_handle_vblank(dev, pipe))
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003776 return false;
3777
3778 if ((iir & flip_pending) == 0)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003779 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003780
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003781 /* We detect FlipDone by looking for the change in PendingFlip from '1'
3782 * to '0' on the following vblank, i.e. IIR has the Pendingflip
3783 * asserted following the MI_DISPLAY_FLIP, but ISR is deasserted, hence
3784 * the flip is completed (no longer pending). Since this doesn't raise
3785 * an interrupt per se, we watch for the change at vblank.
3786 */
3787 if (I915_READ(ISR) & flip_pending)
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003788 goto check_page_flip;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003789
Ville Syrjälä7d475592014-12-17 23:08:03 +02003790 intel_prepare_page_flip(dev, plane);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003791 intel_finish_page_flip(dev, pipe);
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003792 return true;
Chris Wilsond6bbafa2014-09-05 07:13:24 +01003793
3794check_page_flip:
3795 intel_check_page_flip(dev, pipe);
3796 return false;
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003797}
3798
Daniel Vetterff1f5252012-10-02 15:10:55 +02003799static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003800{
Daniel Vetter45a83f82014-05-12 19:17:55 +02003801 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03003802 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilson8291ee92012-04-24 22:59:47 +01003803 u32 iir, new_iir, pipe_stats[I915_MAX_PIPES];
Chris Wilson38bde182012-04-24 22:59:50 +01003804 u32 flip_mask =
3805 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3806 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilson38bde182012-04-24 22:59:50 +01003807 int pipe, ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003808
Imre Deak2dd2a882015-02-24 11:14:30 +02003809 if (!intel_irqs_enabled(dev_priv))
3810 return IRQ_NONE;
3811
Chris Wilsona266c7d2012-04-24 22:59:44 +01003812 iir = I915_READ(IIR);
Chris Wilson38bde182012-04-24 22:59:50 +01003813 do {
3814 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson8291ee92012-04-24 22:59:47 +01003815 bool blc_event = false;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003816
3817 /* Can't rely on pipestat interrupt bit in iir as it might
3818 * have been cleared after the pipestat interrupt was received.
3819 * It doesn't set the bit in iir again, but it still produces
3820 * interrupts (for non-MSI).
3821 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02003822 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003823 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01003824 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003825
Damien Lespiau055e3932014-08-18 13:49:10 +01003826 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003827 int reg = PIPESTAT(pipe);
3828 pipe_stats[pipe] = I915_READ(reg);
3829
Chris Wilson38bde182012-04-24 22:59:50 +01003830 /* Clear the PIPE*STAT regs before the IIR */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003831 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01003832 I915_WRITE(reg, pipe_stats[pipe]);
Chris Wilson38bde182012-04-24 22:59:50 +01003833 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003834 }
3835 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02003836 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003837
3838 if (!irq_received)
3839 break;
3840
Chris Wilsona266c7d2012-04-24 22:59:44 +01003841 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03003842 if (I915_HAS_HOTPLUG(dev) &&
3843 iir & I915_DISPLAY_PORT_INTERRUPT)
3844 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003845
Chris Wilson38bde182012-04-24 22:59:50 +01003846 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003847 new_iir = I915_READ(IIR); /* Flush posted writes */
3848
Chris Wilsona266c7d2012-04-24 22:59:44 +01003849 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01003850 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003851
Damien Lespiau055e3932014-08-18 13:49:10 +01003852 for_each_pipe(dev_priv, pipe) {
Chris Wilson38bde182012-04-24 22:59:50 +01003853 int plane = pipe;
Daniel Vetter3a77c4c2014-01-10 08:50:12 +01003854 if (HAS_FBC(dev))
Chris Wilson38bde182012-04-24 22:59:50 +01003855 plane = !plane;
Ville Syrjälä5e2032d2013-02-19 15:16:38 +02003856
Ville Syrjälä90a72f82013-02-19 23:16:44 +02003857 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS &&
3858 i915_handle_vblank(dev, plane, pipe, iir))
3859 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(plane);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003860
3861 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
3862 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02003863
3864 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02003865 i9xx_pipe_crc_irq_handler(dev, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02003866
Daniel Vetter1f7247c2014-09-30 10:56:48 +02003867 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
3868 intel_cpu_fifo_underrun_irq_handler(dev_priv,
3869 pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003870 }
3871
Chris Wilsona266c7d2012-04-24 22:59:44 +01003872 if (blc_event || (iir & I915_ASLE_INTERRUPT))
3873 intel_opregion_asle_intr(dev);
3874
3875 /* With MSI, interrupts are only generated when iir
3876 * transitions from zero to nonzero. If another bit got
3877 * set while we were handling the existing iir bits, then
3878 * we would never get another interrupt.
3879 *
3880 * This is fine on non-MSI as well, as if we hit this path
3881 * we avoid exiting the interrupt handler only to generate
3882 * another one.
3883 *
3884 * Note that for MSI this could cause a stray interrupt report
3885 * if an interrupt landed in the time between writing IIR and
3886 * the posting read. This should be rare enough to never
3887 * trigger the 99% of 100,000 interrupts test for disabling
3888 * stray interrupts.
3889 */
Chris Wilson38bde182012-04-24 22:59:50 +01003890 ret = IRQ_HANDLED;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003891 iir = new_iir;
Chris Wilson38bde182012-04-24 22:59:50 +01003892 } while (iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003893
3894 return ret;
3895}
3896
3897static void i915_irq_uninstall(struct drm_device * dev)
3898{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003899 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003900 int pipe;
3901
Chris Wilsona266c7d2012-04-24 22:59:44 +01003902 if (I915_HAS_HOTPLUG(dev)) {
3903 I915_WRITE(PORT_HOTPLUG_EN, 0);
3904 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3905 }
3906
Chris Wilson00d98eb2012-04-24 22:59:48 +01003907 I915_WRITE16(HWSTAM, 0xffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01003908 for_each_pipe(dev_priv, pipe) {
Chris Wilson55b39752012-04-24 22:59:49 +01003909 /* Clear enable bits; then clear status bits */
Chris Wilsona266c7d2012-04-24 22:59:44 +01003910 I915_WRITE(PIPESTAT(pipe), 0);
Chris Wilson55b39752012-04-24 22:59:49 +01003911 I915_WRITE(PIPESTAT(pipe), I915_READ(PIPESTAT(pipe)));
3912 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01003913 I915_WRITE(IMR, 0xffffffff);
3914 I915_WRITE(IER, 0x0);
3915
Chris Wilsona266c7d2012-04-24 22:59:44 +01003916 I915_WRITE(IIR, I915_READ(IIR));
3917}
3918
3919static void i965_irq_preinstall(struct drm_device * dev)
3920{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003921 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003922 int pipe;
3923
Chris Wilsonadca4732012-05-11 18:01:31 +01003924 I915_WRITE(PORT_HOTPLUG_EN, 0);
3925 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01003926
3927 I915_WRITE(HWSTAM, 0xeffe);
Damien Lespiau055e3932014-08-18 13:49:10 +01003928 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01003929 I915_WRITE(PIPESTAT(pipe), 0);
3930 I915_WRITE(IMR, 0xffffffff);
3931 I915_WRITE(IER, 0x0);
3932 POSTING_READ(IER);
3933}
3934
3935static int i965_irq_postinstall(struct drm_device *dev)
3936{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003937 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003938 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003939 u32 error_mask;
3940
Chris Wilsona266c7d2012-04-24 22:59:44 +01003941 /* Unmask the interrupts that we always want on. */
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003942 dev_priv->irq_mask = ~(I915_ASLE_INTERRUPT |
Chris Wilsonadca4732012-05-11 18:01:31 +01003943 I915_DISPLAY_PORT_INTERRUPT |
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003944 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
3945 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3946 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3947 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT |
3948 I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT);
3949
3950 enable_mask = ~dev_priv->irq_mask;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02003951 enable_mask &= ~(I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
3952 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01003953 enable_mask |= I915_USER_INTERRUPT;
3954
3955 if (IS_G4X(dev))
3956 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01003957
Daniel Vetterb79480b2013-06-27 17:52:10 +02003958 /* Interrupt setup is already guaranteed to be single-threaded, this is
3959 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003960 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02003961 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3962 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
3963 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02003964 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01003965
Chris Wilsona266c7d2012-04-24 22:59:44 +01003966 /*
3967 * Enable some error detection, note the instruction error mask
3968 * bit is reserved, so we leave it masked.
3969 */
3970 if (IS_G4X(dev)) {
3971 error_mask = ~(GM45_ERROR_PAGE_TABLE |
3972 GM45_ERROR_MEM_PRIV |
3973 GM45_ERROR_CP_PRIV |
3974 I915_ERROR_MEMORY_REFRESH);
3975 } else {
3976 error_mask = ~(I915_ERROR_PAGE_TABLE |
3977 I915_ERROR_MEMORY_REFRESH);
3978 }
3979 I915_WRITE(EMR, error_mask);
3980
3981 I915_WRITE(IMR, dev_priv->irq_mask);
3982 I915_WRITE(IER, enable_mask);
3983 POSTING_READ(IER);
3984
Daniel Vetter20afbda2012-12-11 14:05:07 +01003985 I915_WRITE(PORT_HOTPLUG_EN, 0);
3986 POSTING_READ(PORT_HOTPLUG_EN);
3987
Jani Nikulaf49e38d2013-04-29 13:02:54 +03003988 i915_enable_asle_pipestat(dev);
Daniel Vetter20afbda2012-12-11 14:05:07 +01003989
3990 return 0;
3991}
3992
Egbert Eichbac56d52013-02-25 12:06:51 -05003993static void i915_hpd_irq_setup(struct drm_device *dev)
Daniel Vetter20afbda2012-12-11 14:05:07 +01003994{
Jani Nikula2d1013d2014-03-31 14:27:17 +03003995 struct drm_i915_private *dev_priv = dev->dev_private;
Daniel Vetter20afbda2012-12-11 14:05:07 +01003996 u32 hotplug_en;
3997
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02003998 assert_spin_locked(&dev_priv->irq_lock);
3999
Ville Syrjälä778eb332015-01-09 14:21:13 +02004000 hotplug_en = I915_READ(PORT_HOTPLUG_EN);
4001 hotplug_en &= ~HOTPLUG_INT_EN_MASK;
4002 /* Note HDMI and DP share hotplug bits */
4003 /* enable bits are the same for all generations */
Ville Syrjälä87a02102015-08-27 23:55:57 +03004004 hotplug_en |= intel_hpd_enabled_irqs(dev, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004005 /* Programming the CRT detection parameters tends
4006 to generate a spurious hotplug event about three
4007 seconds later. So just do it once.
4008 */
4009 if (IS_G4X(dev))
4010 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
4011 hotplug_en &= ~CRT_HOTPLUG_VOLTAGE_COMPARE_MASK;
4012 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004013
Ville Syrjälä778eb332015-01-09 14:21:13 +02004014 /* Ignore TV since it's buggy */
4015 I915_WRITE(PORT_HOTPLUG_EN, hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004016}
4017
Daniel Vetterff1f5252012-10-02 15:10:55 +02004018static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004019{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004020 struct drm_device *dev = arg;
Jani Nikula2d1013d2014-03-31 14:27:17 +03004021 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004022 u32 iir, new_iir;
4023 u32 pipe_stats[I915_MAX_PIPES];
Chris Wilsona266c7d2012-04-24 22:59:44 +01004024 int ret = IRQ_NONE, pipe;
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004025 u32 flip_mask =
4026 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
4027 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004028
Imre Deak2dd2a882015-02-24 11:14:30 +02004029 if (!intel_irqs_enabled(dev_priv))
4030 return IRQ_NONE;
4031
Chris Wilsona266c7d2012-04-24 22:59:44 +01004032 iir = I915_READ(IIR);
4033
Chris Wilsona266c7d2012-04-24 22:59:44 +01004034 for (;;) {
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004035 bool irq_received = (iir & ~flip_mask) != 0;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004036 bool blc_event = false;
4037
Chris Wilsona266c7d2012-04-24 22:59:44 +01004038 /* Can't rely on pipestat interrupt bit in iir as it might
4039 * have been cleared after the pipestat interrupt was received.
4040 * It doesn't set the bit in iir again, but it still produces
4041 * interrupts (for non-MSI).
4042 */
Daniel Vetter222c7f52014-09-15 14:55:28 +02004043 spin_lock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004044 if (iir & I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT)
Daniel Vetteraaecdf62014-11-04 15:52:22 +01004045 DRM_DEBUG("Command parser error, iir 0x%08x\n", iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004046
Damien Lespiau055e3932014-08-18 13:49:10 +01004047 for_each_pipe(dev_priv, pipe) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004048 int reg = PIPESTAT(pipe);
4049 pipe_stats[pipe] = I915_READ(reg);
4050
4051 /*
4052 * Clear the PIPE*STAT regs before the IIR
4053 */
4054 if (pipe_stats[pipe] & 0x8000ffff) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004055 I915_WRITE(reg, pipe_stats[pipe]);
Ville Syrjälä501e01d2014-01-17 11:35:15 +02004056 irq_received = true;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004057 }
4058 }
Daniel Vetter222c7f52014-09-15 14:55:28 +02004059 spin_unlock(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004060
4061 if (!irq_received)
4062 break;
4063
4064 ret = IRQ_HANDLED;
4065
4066 /* Consume port. Then clear IIR or we'll miss events */
Ville Syrjälä16c6c562014-04-01 10:54:36 +03004067 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4068 i9xx_hpd_irq_handler(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004069
Ville Syrjälä21ad8332013-02-19 15:16:39 +02004070 I915_WRITE(IIR, iir & ~flip_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004071 new_iir = I915_READ(IIR); /* Flush posted writes */
4072
Chris Wilsona266c7d2012-04-24 22:59:44 +01004073 if (iir & I915_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004074 notify_ring(&dev_priv->ring[RCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004075 if (iir & I915_BSD_USER_INTERRUPT)
Chris Wilson74cdb332015-04-07 16:21:05 +01004076 notify_ring(&dev_priv->ring[VCS]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004077
Damien Lespiau055e3932014-08-18 13:49:10 +01004078 for_each_pipe(dev_priv, pipe) {
Chris Wilson2c8ba292012-04-24 22:59:46 +01004079 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS &&
Ville Syrjälä90a72f82013-02-19 23:16:44 +02004080 i915_handle_vblank(dev, pipe, pipe, iir))
4081 flip_mask &= ~DISPLAY_PLANE_FLIP_PENDING(pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004082
4083 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
4084 blc_event = true;
Daniel Vetter4356d582013-10-16 22:55:55 +02004085
4086 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Daniel Vetter277de952013-10-18 16:37:07 +02004087 i9xx_pipe_crc_irq_handler(dev, pipe);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004088
Daniel Vetter1f7247c2014-09-30 10:56:48 +02004089 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
4090 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Ville Syrjälä2d9d2b02014-01-17 11:44:31 +02004091 }
Chris Wilsona266c7d2012-04-24 22:59:44 +01004092
4093 if (blc_event || (iir & I915_ASLE_INTERRUPT))
4094 intel_opregion_asle_intr(dev);
4095
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004096 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
4097 gmbus_irq_handler(dev);
4098
Chris Wilsona266c7d2012-04-24 22:59:44 +01004099 /* With MSI, interrupts are only generated when iir
4100 * transitions from zero to nonzero. If another bit got
4101 * set while we were handling the existing iir bits, then
4102 * we would never get another interrupt.
4103 *
4104 * This is fine on non-MSI as well, as if we hit this path
4105 * we avoid exiting the interrupt handler only to generate
4106 * another one.
4107 *
4108 * Note that for MSI this could cause a stray interrupt report
4109 * if an interrupt landed in the time between writing IIR and
4110 * the posting read. This should be rare enough to never
4111 * trigger the 99% of 100,000 interrupts test for disabling
4112 * stray interrupts.
4113 */
4114 iir = new_iir;
4115 }
4116
4117 return ret;
4118}
4119
4120static void i965_irq_uninstall(struct drm_device * dev)
4121{
Jani Nikula2d1013d2014-03-31 14:27:17 +03004122 struct drm_i915_private *dev_priv = dev->dev_private;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004123 int pipe;
4124
4125 if (!dev_priv)
4126 return;
4127
Chris Wilsonadca4732012-05-11 18:01:31 +01004128 I915_WRITE(PORT_HOTPLUG_EN, 0);
4129 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004130
4131 I915_WRITE(HWSTAM, 0xffffffff);
Damien Lespiau055e3932014-08-18 13:49:10 +01004132 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004133 I915_WRITE(PIPESTAT(pipe), 0);
4134 I915_WRITE(IMR, 0xffffffff);
4135 I915_WRITE(IER, 0x0);
4136
Damien Lespiau055e3932014-08-18 13:49:10 +01004137 for_each_pipe(dev_priv, pipe)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004138 I915_WRITE(PIPESTAT(pipe),
4139 I915_READ(PIPESTAT(pipe)) & 0x8000ffff);
4140 I915_WRITE(IIR, I915_READ(IIR));
4141}
4142
Daniel Vetterfca52a52014-09-30 10:56:45 +02004143/**
4144 * intel_irq_init - initializes irq support
4145 * @dev_priv: i915 device instance
4146 *
4147 * This function initializes all the irq support including work items, timers
4148 * and all the vtables. It does not setup the interrupt itself though.
4149 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004150void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004151{
Daniel Vetterb9632912014-09-30 10:56:44 +02004152 struct drm_device *dev = dev_priv->dev;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004153
Jani Nikula77913b32015-06-18 13:06:16 +03004154 intel_hpd_init_work(dev_priv);
4155
Daniel Vetterc6a828d2012-08-08 23:35:35 +02004156 INIT_WORK(&dev_priv->rps.work, gen6_pm_rps_work);
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004157 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Chris Wilson8b2e3262012-04-24 22:59:41 +01004158
Deepak Sa6706b42014-03-15 20:23:22 +05304159 /* Let's track the enabled rps events */
Daniel Vetterb9632912014-09-30 10:56:44 +02004160 if (IS_VALLEYVIEW(dev_priv) && !IS_CHERRYVIEW(dev_priv))
Ville Syrjälä6c65a582014-08-29 14:14:07 +03004161 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilson6f4b12f82015-03-18 09:48:23 +00004162 dev_priv->pm_rps_events = GEN6_PM_RP_DOWN_EI_EXPIRED | GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004163 else
4164 dev_priv->pm_rps_events = GEN6_PM_RPS_EVENTS;
Deepak Sa6706b42014-03-15 20:23:22 +05304165
Chris Wilson737b1502015-01-26 18:03:03 +02004166 INIT_DELAYED_WORK(&dev_priv->gpu_error.hangcheck_work,
4167 i915_hangcheck_elapsed);
Daniel Vetter61bac782012-12-01 21:03:21 +01004168
Tomas Janousek97a19a22012-12-08 13:48:13 +01004169 pm_qos_add_request(&dev_priv->pm_qos, PM_QOS_CPU_DMA_LATENCY, PM_QOS_DEFAULT_VALUE);
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01004170
Daniel Vetterb9632912014-09-30 10:56:44 +02004171 if (IS_GEN2(dev_priv)) {
Ville Syrjälä4cdb83e2013-10-11 21:52:44 +03004172 dev->max_vblank_count = 0;
4173 dev->driver->get_vblank_counter = i8xx_get_vblank_counter;
Daniel Vetterb9632912014-09-30 10:56:44 +02004174 } else if (IS_G4X(dev_priv) || INTEL_INFO(dev_priv)->gen >= 5) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004175 dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */
4176 dev->driver->get_vblank_counter = gm45_get_vblank_counter;
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004177 } else {
4178 dev->driver->get_vblank_counter = i915_get_vblank_counter;
4179 dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004180 }
4181
Ville Syrjälä21da2702014-08-06 14:49:55 +03004182 /*
4183 * Opt out of the vblank disable timer on everything except gen2.
4184 * Gen2 doesn't have a hardware frame counter and so depends on
4185 * vblank interrupts to produce sane vblank seuquence numbers.
4186 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004187 if (!IS_GEN2(dev_priv))
Ville Syrjälä21da2702014-08-06 14:49:55 +03004188 dev->vblank_disable_immediate = true;
4189
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004190 dev->driver->get_vblank_timestamp = i915_get_vblank_timestamp;
4191 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004192
Daniel Vetterb9632912014-09-30 10:56:44 +02004193 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004194 dev->driver->irq_handler = cherryview_irq_handler;
4195 dev->driver->irq_preinstall = cherryview_irq_preinstall;
4196 dev->driver->irq_postinstall = cherryview_irq_postinstall;
4197 dev->driver->irq_uninstall = cherryview_irq_uninstall;
4198 dev->driver->enable_vblank = valleyview_enable_vblank;
4199 dev->driver->disable_vblank = valleyview_disable_vblank;
4200 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004201 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004202 dev->driver->irq_handler = valleyview_irq_handler;
4203 dev->driver->irq_preinstall = valleyview_irq_preinstall;
4204 dev->driver->irq_postinstall = valleyview_irq_postinstall;
4205 dev->driver->irq_uninstall = valleyview_irq_uninstall;
4206 dev->driver->enable_vblank = valleyview_enable_vblank;
4207 dev->driver->disable_vblank = valleyview_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004208 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004209 } else if (INTEL_INFO(dev_priv)->gen >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004210 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004211 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004212 dev->driver->irq_postinstall = gen8_irq_postinstall;
4213 dev->driver->irq_uninstall = gen8_irq_uninstall;
4214 dev->driver->enable_vblank = gen8_enable_vblank;
4215 dev->driver->disable_vblank = gen8_disable_vblank;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004216 if (IS_BROXTON(dev))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004217 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004218 else if (HAS_PCH_SPT(dev))
4219 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4220 else
4221 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004222 } else if (HAS_PCH_SPLIT(dev)) {
4223 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004224 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004225 dev->driver->irq_postinstall = ironlake_irq_postinstall;
4226 dev->driver->irq_uninstall = ironlake_irq_uninstall;
4227 dev->driver->enable_vblank = ironlake_enable_vblank;
4228 dev->driver->disable_vblank = ironlake_disable_vblank;
Daniel Vetter82a28bc2013-03-27 15:55:01 +01004229 dev_priv->display.hpd_irq_setup = ibx_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004230 } else {
Daniel Vetterb9632912014-09-30 10:56:44 +02004231 if (INTEL_INFO(dev_priv)->gen == 2) {
Chris Wilsonc2798b12012-04-22 21:13:57 +01004232 dev->driver->irq_preinstall = i8xx_irq_preinstall;
4233 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4234 dev->driver->irq_handler = i8xx_irq_handler;
4235 dev->driver->irq_uninstall = i8xx_irq_uninstall;
Daniel Vetterb9632912014-09-30 10:56:44 +02004236 } else if (INTEL_INFO(dev_priv)->gen == 3) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004237 dev->driver->irq_preinstall = i915_irq_preinstall;
4238 dev->driver->irq_postinstall = i915_irq_postinstall;
4239 dev->driver->irq_uninstall = i915_irq_uninstall;
4240 dev->driver->irq_handler = i915_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004241 } else {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004242 dev->driver->irq_preinstall = i965_irq_preinstall;
4243 dev->driver->irq_postinstall = i965_irq_postinstall;
4244 dev->driver->irq_uninstall = i965_irq_uninstall;
4245 dev->driver->irq_handler = i965_irq_handler;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004246 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004247 if (I915_HAS_HOTPLUG(dev_priv))
4248 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004249 dev->driver->enable_vblank = i915_enable_vblank;
4250 dev->driver->disable_vblank = i915_disable_vblank;
4251 }
4252}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004253
Daniel Vetterfca52a52014-09-30 10:56:45 +02004254/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004255 * intel_irq_install - enables the hardware interrupt
4256 * @dev_priv: i915 device instance
4257 *
4258 * This function enables the hardware interrupt handling, but leaves the hotplug
4259 * handling still disabled. It is called after intel_irq_init().
4260 *
4261 * In the driver load and resume code we need working interrupts in a few places
4262 * but don't want to deal with the hassle of concurrent probe and hotplug
4263 * workers. Hence the split into this two-stage approach.
4264 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004265int intel_irq_install(struct drm_i915_private *dev_priv)
4266{
4267 /*
4268 * We enable some interrupt sources in our postinstall hooks, so mark
4269 * interrupts as enabled _before_ actually enabling them to avoid
4270 * special cases in our ordering checks.
4271 */
4272 dev_priv->pm.irqs_enabled = true;
4273
4274 return drm_irq_install(dev_priv->dev, dev_priv->dev->pdev->irq);
4275}
4276
Daniel Vetterfca52a52014-09-30 10:56:45 +02004277/**
4278 * intel_irq_uninstall - finilizes all irq handling
4279 * @dev_priv: i915 device instance
4280 *
4281 * This stops interrupt and hotplug handling and unregisters and frees all
4282 * resources acquired in the init functions.
4283 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004284void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4285{
4286 drm_irq_uninstall(dev_priv->dev);
4287 intel_hpd_cancel_work(dev_priv);
4288 dev_priv->pm.irqs_enabled = false;
4289}
4290
Daniel Vetterfca52a52014-09-30 10:56:45 +02004291/**
4292 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4293 * @dev_priv: i915 device instance
4294 *
4295 * This function is used to disable interrupts at runtime, both in the runtime
4296 * pm and the system suspend/resume code.
4297 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004298void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004299{
Daniel Vetterb9632912014-09-30 10:56:44 +02004300 dev_priv->dev->driver->irq_uninstall(dev_priv->dev);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004301 dev_priv->pm.irqs_enabled = false;
Imre Deak2dd2a882015-02-24 11:14:30 +02004302 synchronize_irq(dev_priv->dev->irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004303}
4304
Daniel Vetterfca52a52014-09-30 10:56:45 +02004305/**
4306 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4307 * @dev_priv: i915 device instance
4308 *
4309 * This function is used to enable interrupts at runtime, both in the runtime
4310 * pm and the system suspend/resume code.
4311 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004312void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004313{
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004314 dev_priv->pm.irqs_enabled = true;
Daniel Vetterb9632912014-09-30 10:56:44 +02004315 dev_priv->dev->driver->irq_preinstall(dev_priv->dev);
4316 dev_priv->dev->driver->irq_postinstall(dev_priv->dev);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004317}