blob: 233211fde0eabb17e8c4e28d714f5b6c66ff38da [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
Damien Lespiaub2c88f52013-10-15 18:55:29 +010031#include <linux/circ_buf.h>
Jani Nikula55367a22019-04-05 14:00:09 +030032#include <linux/cpuidle.h>
33#include <linux/slab.h>
34#include <linux/sysrq.h>
35
Daniel Vetterfcd70cd2019-01-17 22:03:34 +010036#include <drm/drm_drv.h>
Jani Nikula55367a22019-04-05 14:00:09 +030037#include <drm/drm_irq.h>
David Howells760285e2012-10-02 18:01:07 +010038#include <drm/i915_drm.h>
Jani Nikula55367a22019-04-05 14:00:09 +030039
Linus Torvalds1da177e2005-04-16 15:20:36 -070040#include "i915_drv.h"
Jani Nikula440e2b32019-04-29 15:29:27 +030041#include "i915_irq.h"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010042#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080043#include "intel_drv.h"
Jani Nikula8834e362019-04-29 15:29:24 +030044#include "intel_fifo_underrun.h"
Jani Nikuladbeb38d2019-04-29 15:50:11 +030045#include "intel_hotplug.h"
Jani Nikulaa2649b32019-05-02 18:02:41 +030046#include "intel_lpe_audio.h"
Jani Nikula55367a22019-04-05 14:00:09 +030047#include "intel_psr.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070048
Daniel Vetterfca52a52014-09-30 10:56:45 +020049/**
50 * DOC: interrupt handling
51 *
52 * These functions provide the basic support for enabling and disabling the
53 * interrupt handling support. There's a lot more functionality in i915_irq.c
54 * and related files, but that will be described in separate chapters.
55 */
56
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +030057static const u32 hpd_ilk[HPD_NUM_PINS] = {
58 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
59};
60
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +030061static const u32 hpd_ivb[HPD_NUM_PINS] = {
62 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
63};
64
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +030065static const u32 hpd_bdw[HPD_NUM_PINS] = {
66 [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
67};
68
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020069static const u32 hpd_ibx[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050070 [HPD_CRT] = SDE_CRT_HOTPLUG,
71 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
72 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
73 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
74 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
75};
76
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020077static const u32 hpd_cpt[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050078 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010079 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050080 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
81 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
82 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
83};
84
Xiong Zhang26951ca2015-08-17 15:55:50 +080085static const u32 hpd_spt[HPD_NUM_PINS] = {
Ville Syrjälä74c0b392015-08-27 23:56:07 +030086 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
Xiong Zhang26951ca2015-08-17 15:55:50 +080087 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
88 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
89 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
90 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
91};
92
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020093static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050094 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
95 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
96 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
97 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
98 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
99 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
100};
101
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +0200102static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -0500103 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
104 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
105 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
106 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
107 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
108 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
109};
110
Ville Syrjälä4bca26d2015-05-11 20:49:10 +0300111static const u32 hpd_status_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -0500112 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
113 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
114 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
115 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
116 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
117 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
118};
119
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200120/* BXT hpd list */
121static const u32 hpd_bxt[HPD_NUM_PINS] = {
Sonika Jindal7f3561b2015-08-10 10:35:35 +0530122 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200123 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
124 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
125};
126
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -0700127static const u32 hpd_gen11[HPD_NUM_PINS] = {
128 [HPD_PORT_C] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG,
129 [HPD_PORT_D] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG,
130 [HPD_PORT_E] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG,
131 [HPD_PORT_F] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -0700132};
133
Anusha Srivatsa31604222018-06-26 13:52:23 -0700134static const u32 hpd_icp[HPD_NUM_PINS] = {
135 [HPD_PORT_A] = SDE_DDIA_HOTPLUG_ICP,
136 [HPD_PORT_B] = SDE_DDIB_HOTPLUG_ICP,
137 [HPD_PORT_C] = SDE_TC1_HOTPLUG_ICP,
138 [HPD_PORT_D] = SDE_TC2_HOTPLUG_ICP,
139 [HPD_PORT_E] = SDE_TC3_HOTPLUG_ICP,
140 [HPD_PORT_F] = SDE_TC4_HOTPLUG_ICP
141};
142
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700143static void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700144 i915_reg_t iir, i915_reg_t ier)
145{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700146 intel_uncore_write(uncore, imr, 0xffffffff);
147 intel_uncore_posting_read(uncore, imr);
Paulo Zanoni5c502442014-04-01 15:37:11 -0300148
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700149 intel_uncore_write(uncore, ier, 0);
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300150
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700151 /* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700152 intel_uncore_write(uncore, iir, 0xffffffff);
153 intel_uncore_posting_read(uncore, iir);
154 intel_uncore_write(uncore, iir, 0xffffffff);
155 intel_uncore_posting_read(uncore, iir);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700156}
157
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700158static void gen2_irq_reset(struct intel_uncore *uncore)
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700159{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700160 intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
161 intel_uncore_posting_read16(uncore, GEN2_IMR);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700162
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700163 intel_uncore_write16(uncore, GEN2_IER, 0);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700164
165 /* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700166 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
167 intel_uncore_posting_read16(uncore, GEN2_IIR);
168 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
169 intel_uncore_posting_read16(uncore, GEN2_IIR);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700170}
171
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700172#define GEN8_IRQ_RESET_NDX(uncore, type, which) \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700173({ \
174 unsigned int which_ = which; \
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700175 gen3_irq_reset((uncore), GEN8_##type##_IMR(which_), \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700176 GEN8_##type##_IIR(which_), GEN8_##type##_IER(which_)); \
177})
178
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700179#define GEN3_IRQ_RESET(uncore, type) \
180 gen3_irq_reset((uncore), type##IMR, type##IIR, type##IER)
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700181
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700182#define GEN2_IRQ_RESET(uncore) \
183 gen2_irq_reset(uncore)
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300184
Paulo Zanoni337ba012014-04-01 15:37:16 -0300185/*
186 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
187 */
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700188static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300189{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700190 u32 val = intel_uncore_read(uncore, reg);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300191
192 if (val == 0)
193 return;
194
195 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200196 i915_mmio_reg_offset(reg), val);
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700197 intel_uncore_write(uncore, reg, 0xffffffff);
198 intel_uncore_posting_read(uncore, reg);
199 intel_uncore_write(uncore, reg, 0xffffffff);
200 intel_uncore_posting_read(uncore, reg);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300201}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300202
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700203static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300204{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700205 u16 val = intel_uncore_read16(uncore, GEN2_IIR);
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300206
207 if (val == 0)
208 return;
209
210 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Paulo Zanoni9d9523d2019-04-10 16:53:42 -0700211 i915_mmio_reg_offset(GEN2_IIR), val);
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700212 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
213 intel_uncore_posting_read16(uncore, GEN2_IIR);
214 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
215 intel_uncore_posting_read16(uncore, GEN2_IIR);
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300216}
217
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700218static void gen3_irq_init(struct intel_uncore *uncore,
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700219 i915_reg_t imr, u32 imr_val,
220 i915_reg_t ier, u32 ier_val,
221 i915_reg_t iir)
222{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700223 gen3_assert_iir_is_zero(uncore, iir);
Paulo Zanoni35079892014-04-01 15:37:15 -0300224
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700225 intel_uncore_write(uncore, ier, ier_val);
226 intel_uncore_write(uncore, imr, imr_val);
227 intel_uncore_posting_read(uncore, imr);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700228}
Paulo Zanoni35079892014-04-01 15:37:15 -0300229
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700230static void gen2_irq_init(struct intel_uncore *uncore,
Paulo Zanoni2918c3c2019-04-10 16:53:41 -0700231 u32 imr_val, u32 ier_val)
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700232{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700233 gen2_assert_iir_is_zero(uncore);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700234
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700235 intel_uncore_write16(uncore, GEN2_IER, ier_val);
236 intel_uncore_write16(uncore, GEN2_IMR, imr_val);
237 intel_uncore_posting_read16(uncore, GEN2_IMR);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700238}
239
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700240#define GEN8_IRQ_INIT_NDX(uncore, type, which, imr_val, ier_val) \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700241({ \
242 unsigned int which_ = which; \
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700243 gen3_irq_init((uncore), \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700244 GEN8_##type##_IMR(which_), imr_val, \
245 GEN8_##type##_IER(which_), ier_val, \
246 GEN8_##type##_IIR(which_)); \
247})
248
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700249#define GEN3_IRQ_INIT(uncore, type, imr_val, ier_val) \
250 gen3_irq_init((uncore), \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700251 type##IMR, imr_val, \
252 type##IER, ier_val, \
253 type##IIR)
254
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -0700255#define GEN2_IRQ_INIT(uncore, imr_val, ier_val) \
256 gen2_irq_init((uncore), imr_val, ier_val)
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300257
Imre Deakc9a9a262014-11-05 20:48:37 +0200258static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530259static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Imre Deakc9a9a262014-11-05 20:48:37 +0200260
Egbert Eich0706f172015-09-23 16:15:27 +0200261/* For display hotplug interrupt */
262static inline void
263i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200264 u32 mask,
265 u32 bits)
Egbert Eich0706f172015-09-23 16:15:27 +0200266{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200267 u32 val;
Egbert Eich0706f172015-09-23 16:15:27 +0200268
Chris Wilson67520412017-03-02 13:28:01 +0000269 lockdep_assert_held(&dev_priv->irq_lock);
Egbert Eich0706f172015-09-23 16:15:27 +0200270 WARN_ON(bits & ~mask);
271
272 val = I915_READ(PORT_HOTPLUG_EN);
273 val &= ~mask;
274 val |= bits;
275 I915_WRITE(PORT_HOTPLUG_EN, val);
276}
277
278/**
279 * i915_hotplug_interrupt_update - update hotplug interrupt enable
280 * @dev_priv: driver private
281 * @mask: bits to update
282 * @bits: bits to enable
283 * NOTE: the HPD enable bits are modified both inside and outside
284 * of an interrupt context. To avoid that read-modify-write cycles
285 * interfer, these bits are protected by a spinlock. Since this
286 * function is usually not called from a context where the lock is
287 * held already, this function acquires the lock itself. A non-locking
288 * version is also available.
289 */
290void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200291 u32 mask,
292 u32 bits)
Egbert Eich0706f172015-09-23 16:15:27 +0200293{
294 spin_lock_irq(&dev_priv->irq_lock);
295 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
296 spin_unlock_irq(&dev_priv->irq_lock);
297}
298
Oscar Mateo96606f32018-04-06 12:32:37 +0300299static u32
300gen11_gt_engine_identity(struct drm_i915_private * const i915,
301 const unsigned int bank, const unsigned int bit);
302
Chris Wilson60a94322018-07-13 21:35:29 +0100303static bool gen11_reset_one_iir(struct drm_i915_private * const i915,
304 const unsigned int bank,
305 const unsigned int bit)
Oscar Mateo96606f32018-04-06 12:32:37 +0300306{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700307 void __iomem * const regs = i915->uncore.regs;
Oscar Mateo96606f32018-04-06 12:32:37 +0300308 u32 dw;
309
310 lockdep_assert_held(&i915->irq_lock);
311
312 dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
313 if (dw & BIT(bit)) {
314 /*
315 * According to the BSpec, DW_IIR bits cannot be cleared without
316 * first servicing the Selector & Shared IIR registers.
317 */
318 gen11_gt_engine_identity(i915, bank, bit);
319
320 /*
321 * We locked GT INT DW by reading it. If we want to (try
322 * to) recover from this succesfully, we need to clear
323 * our bit, otherwise we are locking the register for
324 * everybody.
325 */
326 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), BIT(bit));
327
328 return true;
329 }
330
331 return false;
332}
333
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300334/**
335 * ilk_update_display_irq - update DEIMR
336 * @dev_priv: driver private
337 * @interrupt_mask: mask of interrupt bits to update
338 * @enabled_irq_mask: mask of interrupt bits to enable
339 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200340void ilk_update_display_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200341 u32 interrupt_mask,
342 u32 enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800343{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200344 u32 new_val;
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300345
Chris Wilson67520412017-03-02 13:28:01 +0000346 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200347
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300348 WARN_ON(enabled_irq_mask & ~interrupt_mask);
349
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700350 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300351 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300352
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300353 new_val = dev_priv->irq_mask;
354 new_val &= ~interrupt_mask;
355 new_val |= (~enabled_irq_mask & interrupt_mask);
356
357 if (new_val != dev_priv->irq_mask) {
358 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000359 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000360 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800361 }
362}
363
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300364/**
365 * ilk_update_gt_irq - update GTIMR
366 * @dev_priv: driver private
367 * @interrupt_mask: mask of interrupt bits to update
368 * @enabled_irq_mask: mask of interrupt bits to enable
369 */
370static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200371 u32 interrupt_mask,
372 u32 enabled_irq_mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300373{
Chris Wilson67520412017-03-02 13:28:01 +0000374 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300375
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100376 WARN_ON(enabled_irq_mask & ~interrupt_mask);
377
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700378 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300379 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300380
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300381 dev_priv->gt_irq_mask &= ~interrupt_mask;
382 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
383 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300384}
385
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200386void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300387{
388 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100389 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300390}
391
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200392void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300393{
394 ilk_update_gt_irq(dev_priv, mask, 0);
395}
396
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200397static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200398{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300399 WARN_ON_ONCE(INTEL_GEN(dev_priv) >= 11);
400
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700401 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
Imre Deakb900b942014-11-05 20:48:48 +0200402}
403
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300404static void write_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200405{
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300406 i915_reg_t reg;
407 u32 mask = dev_priv->pm_imr;
408
409 if (INTEL_GEN(dev_priv) >= 11) {
410 reg = GEN11_GPM_WGBOXPERF_INTR_MASK;
411 /* pm is in upper half */
412 mask = mask << 16;
413 } else if (INTEL_GEN(dev_priv) >= 8) {
414 reg = GEN8_GT_IMR(2);
415 } else {
416 reg = GEN6_PMIMR;
417 }
418
419 I915_WRITE(reg, mask);
420 POSTING_READ(reg);
Imre Deaka72fbc32014-11-05 20:48:31 +0200421}
422
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300423static void write_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200424{
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300425 i915_reg_t reg;
426 u32 mask = dev_priv->pm_ier;
427
428 if (INTEL_GEN(dev_priv) >= 11) {
429 reg = GEN11_GPM_WGBOXPERF_INTR_ENABLE;
430 /* pm is in upper half */
431 mask = mask << 16;
432 } else if (INTEL_GEN(dev_priv) >= 8) {
433 reg = GEN8_GT_IER(2);
434 } else {
435 reg = GEN6_PMIER;
436 }
437
438 I915_WRITE(reg, mask);
Imre Deakb900b942014-11-05 20:48:48 +0200439}
440
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300441/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200442 * snb_update_pm_irq - update GEN6_PMIMR
443 * @dev_priv: driver private
444 * @interrupt_mask: mask of interrupt bits to update
445 * @enabled_irq_mask: mask of interrupt bits to enable
446 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300447static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200448 u32 interrupt_mask,
449 u32 enabled_irq_mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300450{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200451 u32 new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300452
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100453 WARN_ON(enabled_irq_mask & ~interrupt_mask);
454
Chris Wilson67520412017-03-02 13:28:01 +0000455 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300456
Akash Goelf4e9af42016-10-12 21:54:30 +0530457 new_val = dev_priv->pm_imr;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300458 new_val &= ~interrupt_mask;
459 new_val |= (~enabled_irq_mask & interrupt_mask);
460
Akash Goelf4e9af42016-10-12 21:54:30 +0530461 if (new_val != dev_priv->pm_imr) {
462 dev_priv->pm_imr = new_val;
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300463 write_pm_imr(dev_priv);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300464 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300465}
466
Akash Goelf4e9af42016-10-12 21:54:30 +0530467void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300468{
Imre Deak9939fba2014-11-20 23:01:47 +0200469 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
470 return;
471
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300472 snb_update_pm_irq(dev_priv, mask, mask);
473}
474
Akash Goelf4e9af42016-10-12 21:54:30 +0530475static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Imre Deak9939fba2014-11-20 23:01:47 +0200476{
477 snb_update_pm_irq(dev_priv, mask, 0);
478}
479
Akash Goelf4e9af42016-10-12 21:54:30 +0530480void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300481{
Imre Deak9939fba2014-11-20 23:01:47 +0200482 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
483 return;
484
Akash Goelf4e9af42016-10-12 21:54:30 +0530485 __gen6_mask_pm_irq(dev_priv, mask);
486}
487
Oscar Mateo3814fd72017-08-23 16:58:24 -0700488static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530489{
490 i915_reg_t reg = gen6_pm_iir(dev_priv);
491
Chris Wilson67520412017-03-02 13:28:01 +0000492 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530493
494 I915_WRITE(reg, reset_mask);
495 I915_WRITE(reg, reset_mask);
496 POSTING_READ(reg);
497}
498
Oscar Mateo3814fd72017-08-23 16:58:24 -0700499static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530500{
Chris Wilson67520412017-03-02 13:28:01 +0000501 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530502
503 dev_priv->pm_ier |= enable_mask;
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300504 write_pm_ier(dev_priv);
Akash Goelf4e9af42016-10-12 21:54:30 +0530505 gen6_unmask_pm_irq(dev_priv, enable_mask);
506 /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */
507}
508
Oscar Mateo3814fd72017-08-23 16:58:24 -0700509static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530510{
Chris Wilson67520412017-03-02 13:28:01 +0000511 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530512
513 dev_priv->pm_ier &= ~disable_mask;
514 __gen6_mask_pm_irq(dev_priv, disable_mask);
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300515 write_pm_ier(dev_priv);
Akash Goelf4e9af42016-10-12 21:54:30 +0530516 /* though a barrier is missing here, but don't really need a one */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300517}
518
Oscar Mateod02b98b2018-04-05 17:00:50 +0300519void gen11_reset_rps_interrupts(struct drm_i915_private *dev_priv)
520{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300521 spin_lock_irq(&dev_priv->irq_lock);
522
Oscar Mateo96606f32018-04-06 12:32:37 +0300523 while (gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM))
524 ;
Oscar Mateod02b98b2018-04-05 17:00:50 +0300525
526 dev_priv->gt_pm.rps.pm_iir = 0;
527
528 spin_unlock_irq(&dev_priv->irq_lock);
529}
530
Chris Wilsondc979972016-05-10 14:10:04 +0100531void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200532{
Imre Deak3cc134e2014-11-19 15:30:03 +0200533 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilson4668f692018-08-02 11:06:30 +0100534 gen6_reset_pm_iir(dev_priv, GEN6_PM_RPS_EVENTS);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100535 dev_priv->gt_pm.rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200536 spin_unlock_irq(&dev_priv->irq_lock);
537}
538
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100539void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200540{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100541 struct intel_rps *rps = &dev_priv->gt_pm.rps;
542
543 if (READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100544 return;
545
Imre Deakb900b942014-11-05 20:48:48 +0200546 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100547 WARN_ON_ONCE(rps->pm_iir);
Oscar Mateo96606f32018-04-06 12:32:37 +0300548
Oscar Mateod02b98b2018-04-05 17:00:50 +0300549 if (INTEL_GEN(dev_priv) >= 11)
Oscar Mateo96606f32018-04-06 12:32:37 +0300550 WARN_ON_ONCE(gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM));
Oscar Mateod02b98b2018-04-05 17:00:50 +0300551 else
552 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Oscar Mateo96606f32018-04-06 12:32:37 +0300553
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100554 rps->interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200555 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200556
Imre Deakb900b942014-11-05 20:48:48 +0200557 spin_unlock_irq(&dev_priv->irq_lock);
558}
559
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100560void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200561{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100562 struct intel_rps *rps = &dev_priv->gt_pm.rps;
563
564 if (!READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100565 return;
566
Imre Deakd4d70aa2014-11-19 15:30:04 +0200567 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100568 rps->interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200569
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100570 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200571
Chris Wilson4668f692018-08-02 11:06:30 +0100572 gen6_disable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Imre Deak58072cc2015-03-23 19:11:34 +0200573
574 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100575 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100576
577 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700578 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100579 * we will reset the GPU to minimum frequencies, so the current
580 * state of the worker can be discarded.
581 */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100582 cancel_work_sync(&rps->work);
Oscar Mateod02b98b2018-04-05 17:00:50 +0300583 if (INTEL_GEN(dev_priv) >= 11)
584 gen11_reset_rps_interrupts(dev_priv);
585 else
586 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200587}
588
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530589void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
590{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530591 assert_rpm_wakelock_held(dev_priv);
592
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530593 spin_lock_irq(&dev_priv->irq_lock);
594 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
595 spin_unlock_irq(&dev_priv->irq_lock);
596}
597
598void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
599{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530600 assert_rpm_wakelock_held(dev_priv);
601
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530602 spin_lock_irq(&dev_priv->irq_lock);
603 if (!dev_priv->guc.interrupts_enabled) {
604 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
605 dev_priv->pm_guc_events);
606 dev_priv->guc.interrupts_enabled = true;
607 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
608 }
609 spin_unlock_irq(&dev_priv->irq_lock);
610}
611
612void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
613{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530614 assert_rpm_wakelock_held(dev_priv);
615
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530616 spin_lock_irq(&dev_priv->irq_lock);
617 dev_priv->guc.interrupts_enabled = false;
618
619 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
620
621 spin_unlock_irq(&dev_priv->irq_lock);
622 synchronize_irq(dev_priv->drm.irq);
623
624 gen9_reset_guc_interrupts(dev_priv);
625}
626
Ben Widawsky09610212014-05-15 20:58:08 +0300627/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200628 * bdw_update_port_irq - update DE port interrupt
629 * @dev_priv: driver private
630 * @interrupt_mask: mask of interrupt bits to update
631 * @enabled_irq_mask: mask of interrupt bits to enable
632 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300633static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200634 u32 interrupt_mask,
635 u32 enabled_irq_mask)
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300636{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200637 u32 new_val;
638 u32 old_val;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300639
Chris Wilson67520412017-03-02 13:28:01 +0000640 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300641
642 WARN_ON(enabled_irq_mask & ~interrupt_mask);
643
644 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
645 return;
646
647 old_val = I915_READ(GEN8_DE_PORT_IMR);
648
649 new_val = old_val;
650 new_val &= ~interrupt_mask;
651 new_val |= (~enabled_irq_mask & interrupt_mask);
652
653 if (new_val != old_val) {
654 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
655 POSTING_READ(GEN8_DE_PORT_IMR);
656 }
657}
658
659/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200660 * bdw_update_pipe_irq - update DE pipe interrupt
661 * @dev_priv: driver private
662 * @pipe: pipe whose interrupt to update
663 * @interrupt_mask: mask of interrupt bits to update
664 * @enabled_irq_mask: mask of interrupt bits to enable
665 */
666void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
667 enum pipe pipe,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200668 u32 interrupt_mask,
669 u32 enabled_irq_mask)
Ville Syrjälä013d3752015-11-23 18:06:17 +0200670{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200671 u32 new_val;
Ville Syrjälä013d3752015-11-23 18:06:17 +0200672
Chris Wilson67520412017-03-02 13:28:01 +0000673 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200674
675 WARN_ON(enabled_irq_mask & ~interrupt_mask);
676
677 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
678 return;
679
680 new_val = dev_priv->de_irq_mask[pipe];
681 new_val &= ~interrupt_mask;
682 new_val |= (~enabled_irq_mask & interrupt_mask);
683
684 if (new_val != dev_priv->de_irq_mask[pipe]) {
685 dev_priv->de_irq_mask[pipe] = new_val;
686 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
687 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
688 }
689}
690
691/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200692 * ibx_display_interrupt_update - update SDEIMR
693 * @dev_priv: driver private
694 * @interrupt_mask: mask of interrupt bits to update
695 * @enabled_irq_mask: mask of interrupt bits to enable
696 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200697void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200698 u32 interrupt_mask,
699 u32 enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200700{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200701 u32 sdeimr = I915_READ(SDEIMR);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200702 sdeimr &= ~interrupt_mask;
703 sdeimr |= (~enabled_irq_mask & interrupt_mask);
704
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100705 WARN_ON(enabled_irq_mask & ~interrupt_mask);
706
Chris Wilson67520412017-03-02 13:28:01 +0000707 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200708
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700709 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300710 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300711
Daniel Vetterfee884e2013-07-04 23:35:21 +0200712 I915_WRITE(SDEIMR, sdeimr);
713 POSTING_READ(SDEIMR);
714}
Paulo Zanoni86642812013-04-12 17:57:57 -0300715
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300716u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
717 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800718{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300719 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200720 u32 enable_mask = status_mask << 16;
721
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300722 lockdep_assert_held(&dev_priv->irq_lock);
723
724 if (INTEL_GEN(dev_priv) < 5)
725 goto out;
726
Imre Deak10c59c52014-02-10 18:42:48 +0200727 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300728 * On pipe A we don't support the PSR interrupt yet,
729 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200730 */
731 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
732 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300733 /*
734 * On pipe B and C we don't support the PSR interrupt yet, on pipe
735 * A the same bit is for perf counters which we don't use either.
736 */
737 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
738 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200739
740 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
741 SPRITE0_FLIP_DONE_INT_EN_VLV |
742 SPRITE1_FLIP_DONE_INT_EN_VLV);
743 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
744 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
745 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
746 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
747
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300748out:
749 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
750 status_mask & ~PIPESTAT_INT_STATUS_MASK,
751 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
752 pipe_name(pipe), enable_mask, status_mask);
753
Imre Deak10c59c52014-02-10 18:42:48 +0200754 return enable_mask;
755}
756
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300757void i915_enable_pipestat(struct drm_i915_private *dev_priv,
758 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200759{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300760 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200761 u32 enable_mask;
762
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300763 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
764 "pipe %c: status_mask=0x%x\n",
765 pipe_name(pipe), status_mask);
766
767 lockdep_assert_held(&dev_priv->irq_lock);
768 WARN_ON(!intel_irqs_enabled(dev_priv));
769
770 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
771 return;
772
773 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
774 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
775
776 I915_WRITE(reg, enable_mask | status_mask);
777 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200778}
779
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300780void i915_disable_pipestat(struct drm_i915_private *dev_priv,
781 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200782{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300783 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200784 u32 enable_mask;
785
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300786 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
787 "pipe %c: status_mask=0x%x\n",
788 pipe_name(pipe), status_mask);
789
790 lockdep_assert_held(&dev_priv->irq_lock);
791 WARN_ON(!intel_irqs_enabled(dev_priv));
792
793 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
794 return;
795
796 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
797 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
798
799 I915_WRITE(reg, enable_mask | status_mask);
800 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200801}
802
Ville Syrjäläf3e30482019-03-18 18:56:31 +0200803static bool i915_has_asle(struct drm_i915_private *dev_priv)
804{
805 if (!dev_priv->opregion.asle)
806 return false;
807
808 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
809}
810
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000811/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300812 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100813 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000814 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100815static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000816{
Ville Syrjäläf3e30482019-03-18 18:56:31 +0200817 if (!i915_has_asle(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300818 return;
819
Daniel Vetter13321782014-09-15 14:55:29 +0200820 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000821
Imre Deak755e9012014-02-10 18:42:47 +0200822 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100823 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200824 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200825 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000826
Daniel Vetter13321782014-09-15 14:55:29 +0200827 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000828}
829
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300830/*
831 * This timing diagram depicts the video signal in and
832 * around the vertical blanking period.
833 *
834 * Assumptions about the fictitious mode used in this example:
835 * vblank_start >= 3
836 * vsync_start = vblank_start + 1
837 * vsync_end = vblank_start + 2
838 * vtotal = vblank_start + 3
839 *
840 * start of vblank:
841 * latch double buffered registers
842 * increment frame counter (ctg+)
843 * generate start of vblank interrupt (gen4+)
844 * |
845 * | frame start:
846 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
847 * | may be shifted forward 1-3 extra lines via PIPECONF
848 * | |
849 * | | start of vsync:
850 * | | generate vsync interrupt
851 * | | |
852 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
853 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
854 * ----va---> <-----------------vb--------------------> <--------va-------------
855 * | | <----vs-----> |
856 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
857 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
858 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
859 * | | |
860 * last visible pixel first visible pixel
861 * | increment frame counter (gen3/4)
862 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
863 *
864 * x = horizontal active
865 * _ = horizontal blanking
866 * hs = horizontal sync
867 * va = vertical active
868 * vb = vertical blanking
869 * vs = vertical sync
870 * vbs = vblank_start (number)
871 *
872 * Summary:
873 * - most events happen at the start of horizontal sync
874 * - frame start happens at the start of horizontal blank, 1-4 lines
875 * (depending on PIPECONF settings) after the start of vblank
876 * - gen3/4 pixel and frame counter are synchronized with the start
877 * of horizontal active on the first line of vertical active
878 */
879
Keith Packard42f52ef2008-10-18 19:39:29 -0700880/* Called from drm generic code, passed a 'crtc', which
881 * we use as a pipe index
882 */
Thierry Reding88e72712015-09-24 18:35:31 +0200883static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700884{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100885 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä32db0b62018-11-27 22:05:50 +0200886 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
887 const struct drm_display_mode *mode = &vblank->hwmode;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200888 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300889 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200890 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700891
Ville Syrjälä32db0b62018-11-27 22:05:50 +0200892 /*
893 * On i965gm TV output the frame counter only works up to
894 * the point when we enable the TV encoder. After that the
895 * frame counter ceases to work and reads zero. We need a
896 * vblank wait before enabling the TV encoder and so we
897 * have to enable vblank interrupts while the frame counter
898 * is still in a working state. However the core vblank code
899 * does not like us returning non-zero frame counter values
900 * when we've told it that we don't have a working frame
901 * counter. Thus we must stop non-zero values leaking out.
902 */
903 if (!vblank->max_vblank_count)
904 return 0;
905
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100906 htotal = mode->crtc_htotal;
907 hsync_start = mode->crtc_hsync_start;
908 vbl_start = mode->crtc_vblank_start;
909 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
910 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300911
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300912 /* Convert to pixel count */
913 vbl_start *= htotal;
914
915 /* Start of vblank event occurs at start of hsync */
916 vbl_start -= htotal - hsync_start;
917
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800918 high_frame = PIPEFRAME(pipe);
919 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100920
Ville Syrjälä694e4092017-03-09 17:44:30 +0200921 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
922
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700923 /*
924 * High & low register fields aren't synchronized, so make sure
925 * we get a low value that's stable across two reads of the high
926 * register.
927 */
928 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200929 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
930 low = I915_READ_FW(low_frame);
931 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700932 } while (high1 != high2);
933
Ville Syrjälä694e4092017-03-09 17:44:30 +0200934 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
935
Chris Wilson5eddb702010-09-11 13:48:45 +0100936 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300937 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100938 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300939
940 /*
941 * The frame counter increments at beginning of active.
942 * Cook up a vblank counter by also checking the pixel
943 * counter against vblank start.
944 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200945 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700946}
947
Dave Airlie974e59b2015-10-30 09:45:33 +1000948static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800949{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100950 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800951
Ville Syrjälä649636e2015-09-22 19:50:01 +0300952 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800953}
954
Uma Shankaraec02462017-09-25 19:26:01 +0530955/*
956 * On certain encoders on certain platforms, pipe
957 * scanline register will not work to get the scanline,
958 * since the timings are driven from the PORT or issues
959 * with scanline register updates.
960 * This function will use Framestamp and current
961 * timestamp registers to calculate the scanline.
962 */
963static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
964{
965 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
966 struct drm_vblank_crtc *vblank =
967 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
968 const struct drm_display_mode *mode = &vblank->hwmode;
969 u32 vblank_start = mode->crtc_vblank_start;
970 u32 vtotal = mode->crtc_vtotal;
971 u32 htotal = mode->crtc_htotal;
972 u32 clock = mode->crtc_clock;
973 u32 scanline, scan_prev_time, scan_curr_time, scan_post_time;
974
975 /*
976 * To avoid the race condition where we might cross into the
977 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
978 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
979 * during the same frame.
980 */
981 do {
982 /*
983 * This field provides read back of the display
984 * pipe frame time stamp. The time stamp value
985 * is sampled at every start of vertical blank.
986 */
987 scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
988
989 /*
990 * The TIMESTAMP_CTR register has the current
991 * time stamp value.
992 */
993 scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR);
994
995 scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
996 } while (scan_post_time != scan_prev_time);
997
998 scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
999 clock), 1000 * htotal);
1000 scanline = min(scanline, vtotal - 1);
1001 scanline = (scanline + vblank_start) % vtotal;
1002
1003 return scanline;
1004}
1005
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001006/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +03001007static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
1008{
1009 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001010 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +02001011 const struct drm_display_mode *mode;
1012 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001013 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +03001014 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001015
Ville Syrjälä72259532017-03-02 19:15:05 +02001016 if (!crtc->active)
1017 return -1;
1018
Daniel Vetter5caa0fe2017-05-09 16:03:29 +02001019 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
1020 mode = &vblank->hwmode;
1021
Uma Shankaraec02462017-09-25 19:26:01 +05301022 if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
1023 return __intel_get_crtc_scanline_from_timestamp(crtc);
1024
Ville Syrjälä80715b22014-05-15 20:23:23 +03001025 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001026 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1027 vtotal /= 2;
1028
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001029 if (IS_GEN(dev_priv, 2))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001030 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001031 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001032 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001033
1034 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -07001035 * On HSW, the DSL reg (0x70000) appears to return 0 if we
1036 * read it just before the start of vblank. So try it again
1037 * so we don't accidentally end up spanning a vblank frame
1038 * increment, causing the pipe_update_end() code to squak at us.
1039 *
1040 * The nature of this problem means we can't simply check the ISR
1041 * bit and return the vblank start value; nor can we use the scanline
1042 * debug register in the transcoder as it appears to have the same
1043 * problem. We may need to extend this to include other platforms,
1044 * but so far testing only shows the problem on HSW.
1045 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001046 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -07001047 int i, temp;
1048
1049 for (i = 0; i < 100; i++) {
1050 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +02001051 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -07001052 if (temp != position) {
1053 position = temp;
1054 break;
1055 }
1056 }
1057 }
1058
1059 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +03001060 * See update_scanline_offset() for the details on the
1061 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +03001062 */
Ville Syrjälä80715b22014-05-15 20:23:23 +03001063 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001064}
1065
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001066static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
1067 bool in_vblank_irq, int *vpos, int *hpos,
1068 ktime_t *stime, ktime_t *etime,
1069 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001070{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001071 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +02001072 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1073 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001074 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001075 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +01001076 unsigned long irqflags;
Ville Syrjälä8a920e22019-01-25 20:19:31 +02001077 bool use_scanline_counter = INTEL_GEN(dev_priv) >= 5 ||
1078 IS_G4X(dev_priv) || IS_GEN(dev_priv, 2) ||
1079 mode->private_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001080
Maarten Lankhorstfc467a222015-06-01 12:50:07 +02001081 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001082 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001083 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001084 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001085 }
1086
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03001087 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001088 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03001089 vtotal = mode->crtc_vtotal;
1090 vbl_start = mode->crtc_vblank_start;
1091 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001092
Ville Syrjäläd31faf62013-10-28 16:31:41 +02001093 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1094 vbl_start = DIV_ROUND_UP(vbl_start, 2);
1095 vbl_end /= 2;
1096 vtotal /= 2;
1097 }
1098
Mario Kleinerad3543e2013-10-30 05:13:08 +01001099 /*
1100 * Lock uncore.lock, as we will do multiple timing critical raw
1101 * register reads, potentially with preemption disabled, so the
1102 * following code must not block on uncore.lock.
1103 */
1104 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001105
Mario Kleinerad3543e2013-10-30 05:13:08 +01001106 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
1107
1108 /* Get optional system timestamp before query. */
1109 if (stime)
1110 *stime = ktime_get();
1111
Ville Syrjälä8a920e22019-01-25 20:19:31 +02001112 if (use_scanline_counter) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001113 /* No obvious pixelcount register. Only query vertical
1114 * scanout position from Display scan line register.
1115 */
Ville Syrjäläa225f072014-04-29 13:35:45 +03001116 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001117 } else {
1118 /* Have access to pixelcount since start of frame.
1119 * We can split this into vertical and horizontal
1120 * scanout position.
1121 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001122 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001123
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001124 /* convert to pixel counts */
1125 vbl_start *= htotal;
1126 vbl_end *= htotal;
1127 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001128
1129 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +03001130 * In interlaced modes, the pixel counter counts all pixels,
1131 * so one field will have htotal more pixels. In order to avoid
1132 * the reported position from jumping backwards when the pixel
1133 * counter is beyond the length of the shorter field, just
1134 * clamp the position the length of the shorter field. This
1135 * matches how the scanline counter based position works since
1136 * the scanline counter doesn't count the two half lines.
1137 */
1138 if (position >= vtotal)
1139 position = vtotal - 1;
1140
1141 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001142 * Start of vblank interrupt is triggered at start of hsync,
1143 * just prior to the first active line of vblank. However we
1144 * consider lines to start at the leading edge of horizontal
1145 * active. So, should we get here before we've crossed into
1146 * the horizontal active of the first line in vblank, we would
1147 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
1148 * always add htotal-hsync_start to the current pixel position.
1149 */
1150 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001151 }
1152
Mario Kleinerad3543e2013-10-30 05:13:08 +01001153 /* Get optional system timestamp after query. */
1154 if (etime)
1155 *etime = ktime_get();
1156
1157 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1158
1159 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1160
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001161 /*
1162 * While in vblank, position will be negative
1163 * counting up towards 0 at vbl_end. And outside
1164 * vblank, position will be positive counting
1165 * up since vbl_end.
1166 */
1167 if (position >= vbl_start)
1168 position -= vbl_end;
1169 else
1170 position += vtotal - vbl_end;
1171
Ville Syrjälä8a920e22019-01-25 20:19:31 +02001172 if (use_scanline_counter) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001173 *vpos = position;
1174 *hpos = 0;
1175 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001176 *vpos = position / htotal;
1177 *hpos = position - (*vpos * htotal);
1178 }
1179
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001180 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001181}
1182
Ville Syrjäläa225f072014-04-29 13:35:45 +03001183int intel_get_crtc_scanline(struct intel_crtc *crtc)
1184{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001185 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +03001186 unsigned long irqflags;
1187 int position;
1188
1189 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1190 position = __intel_get_crtc_scanline(crtc);
1191 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1192
1193 return position;
1194}
1195
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001196static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001197{
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001198 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001199 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001200
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001201 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001202
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001203 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1204
Daniel Vetter20e4d402012-08-08 23:35:39 +02001205 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001206
Jesse Barnes7648fa92010-05-20 14:28:11 -07001207 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001208 busy_up = I915_READ(RCPREVBSYTUPAVG);
1209 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001210 max_avg = I915_READ(RCBMAXAVG);
1211 min_avg = I915_READ(RCBMINAVG);
1212
1213 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001214 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001215 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1216 new_delay = dev_priv->ips.cur_delay - 1;
1217 if (new_delay < dev_priv->ips.max_delay)
1218 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001219 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001220 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1221 new_delay = dev_priv->ips.cur_delay + 1;
1222 if (new_delay > dev_priv->ips.min_delay)
1223 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001224 }
1225
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001226 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001227 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001228
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001229 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001230
Jesse Barnesf97108d2010-01-29 11:27:07 -08001231 return;
1232}
1233
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001234static void vlv_c0_read(struct drm_i915_private *dev_priv,
1235 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001236{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001237 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001238 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1239 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001240}
1241
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001242void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1243{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001244 memset(&dev_priv->gt_pm.rps.ei, 0, sizeof(dev_priv->gt_pm.rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001245}
1246
1247static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1248{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001249 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1250 const struct intel_rps_ei *prev = &rps->ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001251 struct intel_rps_ei now;
1252 u32 events = 0;
1253
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001254 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001255 return 0;
1256
1257 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001258
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001259 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001260 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001261 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001262
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001263 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001264
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001265 time *= dev_priv->czclk_freq;
1266
1267 /* Workload can be split between render + media,
1268 * e.g. SwapBuffers being blitted in X after being rendered in
1269 * mesa. To account for this we need to combine both engines
1270 * into our activity counter.
1271 */
Chris Wilson569884e2017-03-09 21:12:31 +00001272 render = now.render_c0 - prev->render_c0;
1273 media = now.media_c0 - prev->media_c0;
1274 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001275 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001276
Chris Wilson60548c52018-07-31 14:26:29 +01001277 if (c0 > time * rps->power.up_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001278 events = GEN6_PM_RP_UP_THRESHOLD;
Chris Wilson60548c52018-07-31 14:26:29 +01001279 else if (c0 < time * rps->power.down_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001280 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001281 }
1282
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001283 rps->ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001284 return events;
Deepak S31685c22014-07-03 17:33:01 -04001285}
1286
Ben Widawsky4912d042011-04-25 11:25:20 -07001287static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001288{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001289 struct drm_i915_private *dev_priv =
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001290 container_of(work, struct drm_i915_private, gt_pm.rps.work);
1291 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001292 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001293 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001294 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001295
Daniel Vetter59cdb632013-07-04 23:35:28 +02001296 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001297 if (rps->interrupts_enabled) {
1298 pm_iir = fetch_and_zero(&rps->pm_iir);
1299 client_boost = atomic_read(&rps->num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001300 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001301 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001302
Paulo Zanoni60611c12013-08-15 11:50:01 -03001303 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301304 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001305 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001306 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001307
Chris Wilsonebb5eb72019-04-26 09:17:21 +01001308 mutex_lock(&rps->lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001309
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001310 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1311
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001312 adj = rps->last_adj;
1313 new_delay = rps->cur_freq;
1314 min = rps->min_freq_softlimit;
1315 max = rps->max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001316 if (client_boost)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001317 max = rps->max_freq;
1318 if (client_boost && new_delay < rps->boost_freq) {
1319 new_delay = rps->boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001320 adj = 0;
1321 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001322 if (adj > 0)
1323 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001324 else /* CHV needs even encode values */
1325 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301326
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001327 if (new_delay >= rps->max_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301328 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001329 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001330 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001331 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001332 if (rps->cur_freq > rps->efficient_freq)
1333 new_delay = rps->efficient_freq;
1334 else if (rps->cur_freq > rps->min_freq_softlimit)
1335 new_delay = rps->min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001336 adj = 0;
1337 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1338 if (adj < 0)
1339 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001340 else /* CHV needs even encode values */
1341 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301342
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001343 if (new_delay <= rps->min_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301344 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001345 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001346 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001347 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001348
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001349 rps->last_adj = adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001350
Chris Wilson2a8862d2019-02-19 12:22:03 +00001351 /*
1352 * Limit deboosting and boosting to keep ourselves at the extremes
1353 * when in the respective power modes (i.e. slowly decrease frequencies
1354 * while in the HIGH_POWER zone and slowly increase frequencies while
1355 * in the LOW_POWER zone). On idle, we will hit the timeout and drop
1356 * to the next level quickly, and conversely if busy we expect to
1357 * hit a waitboost and rapidly switch into max power.
1358 */
1359 if ((adj < 0 && rps->power.mode == HIGH_POWER) ||
1360 (adj > 0 && rps->power.mode == LOW_POWER))
1361 rps->last_adj = 0;
1362
Ben Widawsky79249632012-09-07 19:43:42 -07001363 /* sysfs frequency interfaces may have snuck in while servicing the
1364 * interrupt
1365 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001366 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001367 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301368
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001369 if (intel_set_rps(dev_priv, new_delay)) {
1370 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001371 rps->last_adj = 0;
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001372 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001373
Chris Wilsonebb5eb72019-04-26 09:17:21 +01001374 mutex_unlock(&rps->lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001375
1376out:
1377 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1378 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001379 if (rps->interrupts_enabled)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001380 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1381 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001382}
1383
Ben Widawskye3689192012-05-25 16:56:22 -07001384
1385/**
1386 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1387 * occurred.
1388 * @work: workqueue struct
1389 *
1390 * Doesn't actually do anything except notify userspace. As a consequence of
1391 * this event, userspace should try to remap the bad rows since statistically
1392 * it is likely the same row is more likely to go bad again.
1393 */
1394static void ivybridge_parity_work(struct work_struct *work)
1395{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001396 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001397 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001398 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001399 char *parity_event[6];
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001400 u32 misccpctl;
1401 u8 slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001402
1403 /* We must turn off DOP level clock gating to access the L3 registers.
1404 * In order to prevent a get/put style interface, acquire struct mutex
1405 * any time we access those registers.
1406 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001407 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001408
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001409 /* If we've screwed up tracking, just let the interrupt fire again */
1410 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1411 goto out;
1412
Ben Widawskye3689192012-05-25 16:56:22 -07001413 misccpctl = I915_READ(GEN7_MISCCPCTL);
1414 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1415 POSTING_READ(GEN7_MISCCPCTL);
1416
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001417 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001418 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001419
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001420 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001421 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001422 break;
1423
1424 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1425
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001426 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001427
1428 error_status = I915_READ(reg);
1429 row = GEN7_PARITY_ERROR_ROW(error_status);
1430 bank = GEN7_PARITY_ERROR_BANK(error_status);
1431 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1432
1433 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1434 POSTING_READ(reg);
1435
1436 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1437 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1438 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1439 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1440 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1441 parity_event[5] = NULL;
1442
Chris Wilson91c8a322016-07-05 10:40:23 +01001443 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001444 KOBJ_CHANGE, parity_event);
1445
1446 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1447 slice, row, bank, subbank);
1448
1449 kfree(parity_event[4]);
1450 kfree(parity_event[3]);
1451 kfree(parity_event[2]);
1452 kfree(parity_event[1]);
1453 }
Ben Widawskye3689192012-05-25 16:56:22 -07001454
1455 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1456
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001457out:
1458 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001459 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001460 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001461 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001462
Chris Wilson91c8a322016-07-05 10:40:23 +01001463 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001464}
1465
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001466static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1467 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001468{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001469 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001470 return;
1471
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001472 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001473 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001474 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001475
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001476 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001477 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1478 dev_priv->l3_parity.which_slice |= 1 << 1;
1479
1480 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1481 dev_priv->l3_parity.which_slice |= 1 << 0;
1482
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001483 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001484}
1485
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001486static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001487 u32 gt_iir)
1488{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001489 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001490 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001491 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001492 intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001493}
1494
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001495static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001496 u32 gt_iir)
1497{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001498 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001499 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001500 if (gt_iir & GT_BSD_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001501 intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001502 if (gt_iir & GT_BLT_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001503 intel_engine_breadcrumbs_irq(dev_priv->engine[BCS0]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001504
Ben Widawskycc609d52013-05-28 19:22:29 -07001505 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1506 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001507 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1508 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001509
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001510 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1511 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001512}
1513
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001514static void
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001515gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001516{
Chris Wilson31de7352017-03-16 12:56:18 +00001517 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001518
Chris Wilsonfd8526e2018-06-28 21:12:10 +01001519 if (iir & GT_CONTEXT_SWITCH_INTERRUPT)
1520 tasklet = true;
Chris Wilson31de7352017-03-16 12:56:18 +00001521
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001522 if (iir & GT_RENDER_USER_INTERRUPT) {
Chris Wilson52c0fdb2019-01-29 20:52:29 +00001523 intel_engine_breadcrumbs_irq(engine);
Chris Wilson4c6ce5c2019-03-29 15:49:12 +00001524 tasklet |= intel_engine_needs_breadcrumb_tasklet(engine);
Chris Wilson31de7352017-03-16 12:56:18 +00001525 }
1526
1527 if (tasklet)
Chris Wilsonfd8526e2018-06-28 21:12:10 +01001528 tasklet_hi_schedule(&engine->execlists.tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001529}
1530
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001531static void gen8_gt_irq_ack(struct drm_i915_private *i915,
Chris Wilson55ef72f2018-02-02 15:34:48 +00001532 u32 master_ctl, u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001533{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07001534 void __iomem * const regs = i915->uncore.regs;
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001535
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001536#define GEN8_GT_IRQS (GEN8_GT_RCS_IRQ | \
1537 GEN8_GT_BCS_IRQ | \
Chris Wilson8a68d462019-03-05 18:03:30 +00001538 GEN8_GT_VCS0_IRQ | \
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001539 GEN8_GT_VCS1_IRQ | \
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001540 GEN8_GT_VECS_IRQ | \
1541 GEN8_GT_PM_IRQ | \
1542 GEN8_GT_GUC_IRQ)
1543
Ben Widawskyabd58f02013-11-02 21:07:09 -07001544 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001545 gt_iir[0] = raw_reg_read(regs, GEN8_GT_IIR(0));
1546 if (likely(gt_iir[0]))
1547 raw_reg_write(regs, GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001548 }
1549
Chris Wilson8a68d462019-03-05 18:03:30 +00001550 if (master_ctl & (GEN8_GT_VCS0_IRQ | GEN8_GT_VCS1_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001551 gt_iir[1] = raw_reg_read(regs, GEN8_GT_IIR(1));
1552 if (likely(gt_iir[1]))
1553 raw_reg_write(regs, GEN8_GT_IIR(1), gt_iir[1]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001554 }
1555
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301556 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001557 gt_iir[2] = raw_reg_read(regs, GEN8_GT_IIR(2));
Chris Wilsonf4de7792018-08-02 11:06:29 +01001558 if (likely(gt_iir[2]))
1559 raw_reg_write(regs, GEN8_GT_IIR(2), gt_iir[2]);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001560 }
1561
1562 if (master_ctl & GEN8_GT_VECS_IRQ) {
1563 gt_iir[3] = raw_reg_read(regs, GEN8_GT_IIR(3));
1564 if (likely(gt_iir[3]))
1565 raw_reg_write(regs, GEN8_GT_IIR(3), gt_iir[3]);
Ben Widawsky09610212014-05-15 20:58:08 +03001566 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07001567}
1568
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001569static void gen8_gt_irq_handler(struct drm_i915_private *i915,
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001570 u32 master_ctl, u32 gt_iir[4])
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001571{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001572 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson8a68d462019-03-05 18:03:30 +00001573 gen8_cs_irq_handler(i915->engine[RCS0],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001574 gt_iir[0] >> GEN8_RCS_IRQ_SHIFT);
Chris Wilson8a68d462019-03-05 18:03:30 +00001575 gen8_cs_irq_handler(i915->engine[BCS0],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001576 gt_iir[0] >> GEN8_BCS_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001577 }
1578
Chris Wilson8a68d462019-03-05 18:03:30 +00001579 if (master_ctl & (GEN8_GT_VCS0_IRQ | GEN8_GT_VCS1_IRQ)) {
1580 gen8_cs_irq_handler(i915->engine[VCS0],
1581 gt_iir[1] >> GEN8_VCS0_IRQ_SHIFT);
1582 gen8_cs_irq_handler(i915->engine[VCS1],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001583 gt_iir[1] >> GEN8_VCS1_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001584 }
1585
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001586 if (master_ctl & GEN8_GT_VECS_IRQ) {
Chris Wilson8a68d462019-03-05 18:03:30 +00001587 gen8_cs_irq_handler(i915->engine[VECS0],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001588 gt_iir[3] >> GEN8_VECS_IRQ_SHIFT);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001589 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001590
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001591 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001592 gen6_rps_irq_handler(i915, gt_iir[2]);
1593 gen9_guc_irq_handler(i915, gt_iir[2]);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001594 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001595}
1596
Ville Syrjäläaf920582018-07-05 19:43:55 +03001597static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001598{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001599 switch (pin) {
1600 case HPD_PORT_C:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001601 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001602 case HPD_PORT_D:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001603 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001604 case HPD_PORT_E:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001605 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001606 case HPD_PORT_F:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001607 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4);
1608 default:
1609 return false;
1610 }
1611}
1612
Ville Syrjäläaf920582018-07-05 19:43:55 +03001613static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Imre Deak63c88d22015-07-20 14:43:39 -07001614{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001615 switch (pin) {
1616 case HPD_PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001617 return val & PORTA_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001618 case HPD_PORT_B:
Imre Deak63c88d22015-07-20 14:43:39 -07001619 return val & PORTB_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001620 case HPD_PORT_C:
Imre Deak63c88d22015-07-20 14:43:39 -07001621 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001622 default:
1623 return false;
1624 }
1625}
1626
Ville Syrjäläaf920582018-07-05 19:43:55 +03001627static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Anusha Srivatsa31604222018-06-26 13:52:23 -07001628{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001629 switch (pin) {
1630 case HPD_PORT_A:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001631 return val & ICP_DDIA_HPD_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001632 case HPD_PORT_B:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001633 return val & ICP_DDIB_HPD_LONG_DETECT;
1634 default:
1635 return false;
1636 }
1637}
1638
Ville Syrjäläaf920582018-07-05 19:43:55 +03001639static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Anusha Srivatsa31604222018-06-26 13:52:23 -07001640{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001641 switch (pin) {
1642 case HPD_PORT_C:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001643 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001644 case HPD_PORT_D:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001645 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001646 case HPD_PORT_E:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001647 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001648 case HPD_PORT_F:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001649 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4);
1650 default:
1651 return false;
1652 }
1653}
1654
Ville Syrjäläaf920582018-07-05 19:43:55 +03001655static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001656{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001657 switch (pin) {
1658 case HPD_PORT_E:
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001659 return val & PORTE_HOTPLUG_LONG_DETECT;
1660 default:
1661 return false;
1662 }
1663}
1664
Ville Syrjäläaf920582018-07-05 19:43:55 +03001665static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001666{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001667 switch (pin) {
1668 case HPD_PORT_A:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001669 return val & PORTA_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001670 case HPD_PORT_B:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001671 return val & PORTB_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001672 case HPD_PORT_C:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001673 return val & PORTC_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001674 case HPD_PORT_D:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001675 return val & PORTD_HOTPLUG_LONG_DETECT;
1676 default:
1677 return false;
1678 }
1679}
1680
Ville Syrjäläaf920582018-07-05 19:43:55 +03001681static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001682{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001683 switch (pin) {
1684 case HPD_PORT_A:
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001685 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1686 default:
1687 return false;
1688 }
1689}
1690
Ville Syrjäläaf920582018-07-05 19:43:55 +03001691static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001692{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001693 switch (pin) {
1694 case HPD_PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001695 return val & PORTB_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001696 case HPD_PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001697 return val & PORTC_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001698 case HPD_PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001699 return val & PORTD_HOTPLUG_LONG_DETECT;
1700 default:
1701 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001702 }
1703}
1704
Ville Syrjäläaf920582018-07-05 19:43:55 +03001705static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001706{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001707 switch (pin) {
1708 case HPD_PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001709 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001710 case HPD_PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001711 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001712 case HPD_PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001713 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1714 default:
1715 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001716 }
1717}
1718
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001719/*
1720 * Get a bit mask of pins that have triggered, and which ones may be long.
1721 * This can be called multiple times with the same masks to accumulate
1722 * hotplug detection results from several registers.
1723 *
1724 * Note that the caller is expected to zero out the masks initially.
1725 */
Rodrigo Vivicf539022018-01-29 15:22:21 -08001726static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1727 u32 *pin_mask, u32 *long_mask,
1728 u32 hotplug_trigger, u32 dig_hotplug_reg,
1729 const u32 hpd[HPD_NUM_PINS],
Ville Syrjäläaf920582018-07-05 19:43:55 +03001730 bool long_pulse_detect(enum hpd_pin pin, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001731{
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001732 enum hpd_pin pin;
Jani Nikula676574d2015-05-28 15:43:53 +03001733
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001734 for_each_hpd_pin(pin) {
1735 if ((hpd[pin] & hotplug_trigger) == 0)
Jani Nikula8c841e52015-06-18 13:06:17 +03001736 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001737
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001738 *pin_mask |= BIT(pin);
Jani Nikula8c841e52015-06-18 13:06:17 +03001739
Ville Syrjäläaf920582018-07-05 19:43:55 +03001740 if (long_pulse_detect(pin, dig_hotplug_reg))
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001741 *long_mask |= BIT(pin);
Jani Nikula676574d2015-05-28 15:43:53 +03001742 }
1743
Ville Syrjäläf88f0472018-07-05 19:43:57 +03001744 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
1745 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
Jani Nikula676574d2015-05-28 15:43:53 +03001746
1747}
1748
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001749static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001750{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001751 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001752}
1753
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001754static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001755{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001756 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001757}
1758
Shuang He8bf1e9f2013-10-15 18:55:27 +01001759#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001760static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1761 enum pipe pipe,
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001762 u32 crc0, u32 crc1,
1763 u32 crc2, u32 crc3,
1764 u32 crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001765{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001766 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001767 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä5cee6c42019-02-06 22:49:07 +02001768 u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
1769
1770 trace_intel_pipe_crc(crtc, crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001771
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001772 spin_lock(&pipe_crc->lock);
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001773 /*
1774 * For some not yet identified reason, the first CRC is
1775 * bonkers. So let's just wait for the next vblank and read
1776 * out the buggy result.
1777 *
1778 * On GEN8+ sometimes the second CRC is bonkers as well, so
1779 * don't trust that one either.
1780 */
1781 if (pipe_crc->skipped <= 0 ||
1782 (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
1783 pipe_crc->skipped++;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001784 spin_unlock(&pipe_crc->lock);
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001785 return;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001786 }
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001787 spin_unlock(&pipe_crc->lock);
1788
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001789 drm_crtc_add_crc_entry(&crtc->base, true,
1790 drm_crtc_accurate_vblank_count(&crtc->base),
1791 crcs);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001792}
Daniel Vetter277de952013-10-18 16:37:07 +02001793#else
1794static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001795display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1796 enum pipe pipe,
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001797 u32 crc0, u32 crc1,
1798 u32 crc2, u32 crc3,
1799 u32 crc4) {}
Daniel Vetter277de952013-10-18 16:37:07 +02001800#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001801
Daniel Vetter277de952013-10-18 16:37:07 +02001802
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001803static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1804 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001805{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001806 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001807 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1808 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001809}
1810
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001811static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1812 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001813{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001814 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001815 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1816 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1817 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1818 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1819 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001820}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001821
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001822static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1823 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001824{
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001825 u32 res1, res2;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001826
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001827 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001828 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1829 else
1830 res1 = 0;
1831
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001832 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001833 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1834 else
1835 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001836
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001837 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001838 I915_READ(PIPE_CRC_RES_RED(pipe)),
1839 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1840 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1841 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001842}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001843
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001844/* The RPS events need forcewake, so we add them to a work queue and mask their
1845 * IMR bits until the work is done. Other interrupts can be processed without
1846 * the work queue. */
Mika Kuoppalaa087baf2019-04-10 16:21:23 +03001847static void gen11_rps_irq_handler(struct drm_i915_private *i915, u32 pm_iir)
1848{
1849 struct intel_rps *rps = &i915->gt_pm.rps;
1850 const u32 events = i915->pm_rps_events & pm_iir;
1851
1852 lockdep_assert_held(&i915->irq_lock);
1853
1854 if (unlikely(!events))
1855 return;
1856
1857 gen6_mask_pm_irq(i915, events);
1858
1859 if (!rps->interrupts_enabled)
1860 return;
1861
1862 rps->pm_iir |= events;
1863 schedule_work(&rps->work);
1864}
1865
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001866static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001867{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001868 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1869
Deepak Sa6706b42014-03-15 20:23:22 +05301870 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001871 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301872 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001873 if (rps->interrupts_enabled) {
1874 rps->pm_iir |= pm_iir & dev_priv->pm_rps_events;
1875 schedule_work(&rps->work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001876 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001877 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001878 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001879
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001880 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001881 return;
1882
Chris Wilsonf14c0d92019-03-05 15:09:13 +00001883 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001884 intel_engine_breadcrumbs_irq(dev_priv->engine[VECS0]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001885
Chris Wilsonf14c0d92019-03-05 15:09:13 +00001886 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1887 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001888}
1889
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301890static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1891{
Michal Wajdeczko93bf8092018-03-08 16:46:55 +01001892 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT)
1893 intel_guc_to_host_event_handler(&dev_priv->guc);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301894}
1895
Ville Syrjälä44d92412017-08-18 21:36:51 +03001896static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1897{
1898 enum pipe pipe;
1899
1900 for_each_pipe(dev_priv, pipe) {
1901 I915_WRITE(PIPESTAT(pipe),
1902 PIPESTAT_INT_STATUS_MASK |
1903 PIPE_FIFO_UNDERRUN_STATUS);
1904
1905 dev_priv->pipestat_irq_mask[pipe] = 0;
1906 }
1907}
1908
Ville Syrjäläeb643432017-08-18 21:36:59 +03001909static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1910 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001911{
Imre Deakc1874ed2014-02-04 21:35:46 +02001912 int pipe;
1913
Imre Deak58ead0d2014-02-04 21:35:47 +02001914 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001915
1916 if (!dev_priv->display_irqs_enabled) {
1917 spin_unlock(&dev_priv->irq_lock);
1918 return;
1919 }
1920
Damien Lespiau055e3932014-08-18 13:49:10 +01001921 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001922 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001923 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001924
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001925 /*
1926 * PIPESTAT bits get signalled even when the interrupt is
1927 * disabled with the mask bits, and some of the status bits do
1928 * not generate interrupts at all (like the underrun bit). Hence
1929 * we need to be careful that we only handle what we want to
1930 * handle.
1931 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001932
1933 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001934 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001935
1936 switch (pipe) {
1937 case PIPE_A:
1938 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1939 break;
1940 case PIPE_B:
1941 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1942 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001943 case PIPE_C:
1944 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1945 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001946 }
1947 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001948 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001949
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001950 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001951 continue;
1952
1953 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001954 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1955 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001956
1957 /*
1958 * Clear the PIPE*STAT regs before the IIR
Ville Syrjälä132c27c2018-06-11 23:02:55 +03001959 *
1960 * Toggle the enable bits to make sure we get an
1961 * edge in the ISR pipe event bit if we don't clear
1962 * all the enabled status bits. Otherwise the edge
1963 * triggered IIR on i965/g4x wouldn't notice that
1964 * an interrupt is still pending.
Imre Deakc1874ed2014-02-04 21:35:46 +02001965 */
Ville Syrjälä132c27c2018-06-11 23:02:55 +03001966 if (pipe_stats[pipe]) {
1967 I915_WRITE(reg, pipe_stats[pipe]);
1968 I915_WRITE(reg, enable_mask);
1969 }
Imre Deakc1874ed2014-02-04 21:35:46 +02001970 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001971 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001972}
1973
Ville Syrjäläeb643432017-08-18 21:36:59 +03001974static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1975 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1976{
1977 enum pipe pipe;
1978
1979 for_each_pipe(dev_priv, pipe) {
1980 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1981 drm_handle_vblank(&dev_priv->drm, pipe);
1982
1983 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1984 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1985
1986 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1987 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1988 }
1989}
1990
1991static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1992 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1993{
1994 bool blc_event = false;
1995 enum pipe pipe;
1996
1997 for_each_pipe(dev_priv, pipe) {
1998 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1999 drm_handle_vblank(&dev_priv->drm, pipe);
2000
2001 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2002 blc_event = true;
2003
2004 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2005 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2006
2007 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2008 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2009 }
2010
2011 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2012 intel_opregion_asle_intr(dev_priv);
2013}
2014
2015static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
2016 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
2017{
2018 bool blc_event = false;
2019 enum pipe pipe;
2020
2021 for_each_pipe(dev_priv, pipe) {
2022 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
2023 drm_handle_vblank(&dev_priv->drm, pipe);
2024
2025 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2026 blc_event = true;
2027
2028 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2029 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2030
2031 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2032 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2033 }
2034
2035 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2036 intel_opregion_asle_intr(dev_priv);
2037
2038 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2039 gmbus_irq_handler(dev_priv);
2040}
2041
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002042static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002043 u32 pipe_stats[I915_MAX_PIPES])
2044{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002045 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02002046
Damien Lespiau055e3932014-08-18 13:49:10 +01002047 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002048 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
2049 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002050
2051 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002052 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002053
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002054 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2055 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002056 }
2057
2058 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002059 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02002060}
2061
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002062static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002063{
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002064 u32 hotplug_status = 0, hotplug_status_mask;
2065 int i;
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002066
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002067 if (IS_G4X(dev_priv) ||
2068 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2069 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
2070 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
2071 else
2072 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
2073
2074 /*
2075 * We absolutely have to clear all the pending interrupt
2076 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
2077 * interrupt bit won't have an edge, and the i965/g4x
2078 * edge triggered IIR will not notice that an interrupt
2079 * is still pending. We can't use PORT_HOTPLUG_EN to
2080 * guarantee the edge as the act of toggling the enable
2081 * bits can itself generate a new hotplug interrupt :(
2082 */
2083 for (i = 0; i < 10; i++) {
2084 u32 tmp = I915_READ(PORT_HOTPLUG_STAT) & hotplug_status_mask;
2085
2086 if (tmp == 0)
2087 return hotplug_status;
2088
2089 hotplug_status |= tmp;
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002090 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002091 }
2092
2093 WARN_ONCE(1,
2094 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
2095 I915_READ(PORT_HOTPLUG_STAT));
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002096
2097 return hotplug_status;
2098}
2099
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002100static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002101 u32 hotplug_status)
2102{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03002103 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002104
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002105 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2106 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03002107 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002108
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002109 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002110 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2111 hotplug_trigger, hotplug_trigger,
2112 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002113 i9xx_port_hotplug_long_detect);
2114
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002115 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002116 }
Jani Nikula369712e2015-05-27 15:03:40 +03002117
2118 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002119 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03002120 } else {
2121 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002122
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002123 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002124 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2125 hotplug_trigger, hotplug_trigger,
2126 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002127 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002128 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002129 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002130 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002131}
2132
Daniel Vetterff1f5252012-10-02 15:10:55 +02002133static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002134{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002135 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002136 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002137 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002138
Imre Deak2dd2a882015-02-24 11:14:30 +02002139 if (!intel_irqs_enabled(dev_priv))
2140 return IRQ_NONE;
2141
Imre Deak1f814da2015-12-16 02:52:19 +02002142 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2143 disable_rpm_wakeref_asserts(dev_priv);
2144
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002145 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002146 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002147 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002148 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002149 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002150
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002151 gt_iir = I915_READ(GTIIR);
2152 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002153 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002154
2155 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002156 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002157
2158 ret = IRQ_HANDLED;
2159
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002160 /*
2161 * Theory on interrupt generation, based on empirical evidence:
2162 *
2163 * x = ((VLV_IIR & VLV_IER) ||
2164 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2165 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2166 *
2167 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2168 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2169 * guarantee the CPU interrupt will be raised again even if we
2170 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2171 * bits this time around.
2172 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002173 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002174 ier = I915_READ(VLV_IER);
2175 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002176
2177 if (gt_iir)
2178 I915_WRITE(GTIIR, gt_iir);
2179 if (pm_iir)
2180 I915_WRITE(GEN6_PMIIR, pm_iir);
2181
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002182 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002183 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002184
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002185 /* Call regardless, as some status bits might not be
2186 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002187 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002188
Jerome Anandeef57322017-01-25 04:27:49 +05302189 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2190 I915_LPE_PIPE_B_INTERRUPT))
2191 intel_lpe_audio_irq_handler(dev_priv);
2192
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002193 /*
2194 * VLV_IIR is single buffered, and reflects the level
2195 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2196 */
2197 if (iir)
2198 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002199
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002200 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002201 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002202
Ville Syrjälä52894872016-04-13 21:19:56 +03002203 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002204 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002205 if (pm_iir)
2206 gen6_rps_irq_handler(dev_priv, pm_iir);
2207
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002208 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002209 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002210
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002211 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002212 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002213
Imre Deak1f814da2015-12-16 02:52:19 +02002214 enable_rpm_wakeref_asserts(dev_priv);
2215
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002216 return ret;
2217}
2218
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002219static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2220{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002221 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002222 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002223 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002224
Imre Deak2dd2a882015-02-24 11:14:30 +02002225 if (!intel_irqs_enabled(dev_priv))
2226 return IRQ_NONE;
2227
Imre Deak1f814da2015-12-16 02:52:19 +02002228 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2229 disable_rpm_wakeref_asserts(dev_priv);
2230
Chris Wilson579de732016-03-14 09:01:57 +00002231 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002232 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002233 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002234 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002235 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002236 u32 ier = 0;
2237
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002238 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2239 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002240
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002241 if (master_ctl == 0 && iir == 0)
2242 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002243
Oscar Mateo27b6c122014-06-16 16:11:00 +01002244 ret = IRQ_HANDLED;
2245
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002246 /*
2247 * Theory on interrupt generation, based on empirical evidence:
2248 *
2249 * x = ((VLV_IIR & VLV_IER) ||
2250 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2251 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2252 *
2253 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2254 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2255 * guarantee the CPU interrupt will be raised again even if we
2256 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2257 * bits this time around.
2258 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002259 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002260 ier = I915_READ(VLV_IER);
2261 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002262
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002263 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002264
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002265 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002266 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002267
Oscar Mateo27b6c122014-06-16 16:11:00 +01002268 /* Call regardless, as some status bits might not be
2269 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002270 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002271
Jerome Anandeef57322017-01-25 04:27:49 +05302272 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2273 I915_LPE_PIPE_B_INTERRUPT |
2274 I915_LPE_PIPE_C_INTERRUPT))
2275 intel_lpe_audio_irq_handler(dev_priv);
2276
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002277 /*
2278 * VLV_IIR is single buffered, and reflects the level
2279 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2280 */
2281 if (iir)
2282 I915_WRITE(VLV_IIR, iir);
2283
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002284 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002285 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002286
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002287 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002288
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002289 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002290 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002291
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002292 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002293 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002294
Imre Deak1f814da2015-12-16 02:52:19 +02002295 enable_rpm_wakeref_asserts(dev_priv);
2296
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002297 return ret;
2298}
2299
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002300static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2301 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002302 const u32 hpd[HPD_NUM_PINS])
2303{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002304 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2305
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002306 /*
2307 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2308 * unless we touch the hotplug register, even if hotplug_trigger is
2309 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2310 * errors.
2311 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002312 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002313 if (!hotplug_trigger) {
2314 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2315 PORTD_HOTPLUG_STATUS_MASK |
2316 PORTC_HOTPLUG_STATUS_MASK |
2317 PORTB_HOTPLUG_STATUS_MASK;
2318 dig_hotplug_reg &= ~mask;
2319 }
2320
Ville Syrjälä40e56412015-08-27 23:56:10 +03002321 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002322 if (!hotplug_trigger)
2323 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002324
Rodrigo Vivicf539022018-01-29 15:22:21 -08002325 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002326 dig_hotplug_reg, hpd,
2327 pch_port_hotplug_long_detect);
2328
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002329 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002330}
2331
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002332static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002333{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002334 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002335 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002336
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002337 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002338
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002339 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2340 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2341 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002342 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002343 port_name(port));
2344 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002345
Daniel Vetterce99c252012-12-01 13:53:47 +01002346 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002347 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002348
Jesse Barnes776ad802011-01-04 15:09:39 -08002349 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002350 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002351
2352 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2353 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2354
2355 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2356 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2357
2358 if (pch_iir & SDE_POISON)
2359 DRM_ERROR("PCH poison interrupt\n");
2360
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002361 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002362 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002363 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2364 pipe_name(pipe),
2365 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002366
2367 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2368 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2369
2370 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2371 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2372
Jesse Barnes776ad802011-01-04 15:09:39 -08002373 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002374 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002375
2376 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002377 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002378}
2379
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002380static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002381{
Paulo Zanoni86642812013-04-12 17:57:57 -03002382 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002383 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002384
Paulo Zanonide032bf2013-04-12 17:57:58 -03002385 if (err_int & ERR_INT_POISON)
2386 DRM_ERROR("Poison interrupt\n");
2387
Damien Lespiau055e3932014-08-18 13:49:10 +01002388 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002389 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2390 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002391
Daniel Vetter5a69b892013-10-16 22:55:52 +02002392 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002393 if (IS_IVYBRIDGE(dev_priv))
2394 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002395 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002396 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002397 }
2398 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002399
Paulo Zanoni86642812013-04-12 17:57:57 -03002400 I915_WRITE(GEN7_ERR_INT, err_int);
2401}
2402
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002403static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002404{
Paulo Zanoni86642812013-04-12 17:57:57 -03002405 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002406 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002407
Paulo Zanonide032bf2013-04-12 17:57:58 -03002408 if (serr_int & SERR_INT_POISON)
2409 DRM_ERROR("PCH poison interrupt\n");
2410
Mika Kahola45c1cd82017-10-10 13:17:06 +03002411 for_each_pipe(dev_priv, pipe)
2412 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2413 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002414
2415 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002416}
2417
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002418static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002419{
Adam Jackson23e81d62012-06-06 15:45:44 -04002420 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002421 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002422
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002423 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002424
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002425 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2426 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2427 SDE_AUDIO_POWER_SHIFT_CPT);
2428 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2429 port_name(port));
2430 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002431
2432 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002433 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002434
2435 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002436 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002437
2438 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2439 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2440
2441 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2442 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2443
2444 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002445 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002446 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2447 pipe_name(pipe),
2448 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002449
2450 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002451 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002452}
2453
Anusha Srivatsa31604222018-06-26 13:52:23 -07002454static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
2455{
2456 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP;
2457 u32 tc_hotplug_trigger = pch_iir & SDE_TC_MASK_ICP;
2458 u32 pin_mask = 0, long_mask = 0;
2459
2460 if (ddi_hotplug_trigger) {
2461 u32 dig_hotplug_reg;
2462
2463 dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_DDI);
2464 I915_WRITE(SHOTPLUG_CTL_DDI, dig_hotplug_reg);
2465
2466 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2467 ddi_hotplug_trigger,
2468 dig_hotplug_reg, hpd_icp,
2469 icp_ddi_port_hotplug_long_detect);
2470 }
2471
2472 if (tc_hotplug_trigger) {
2473 u32 dig_hotplug_reg;
2474
2475 dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_TC);
2476 I915_WRITE(SHOTPLUG_CTL_TC, dig_hotplug_reg);
2477
2478 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2479 tc_hotplug_trigger,
2480 dig_hotplug_reg, hpd_icp,
2481 icp_tc_port_hotplug_long_detect);
2482 }
2483
2484 if (pin_mask)
2485 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2486
2487 if (pch_iir & SDE_GMBUS_ICP)
2488 gmbus_irq_handler(dev_priv);
2489}
2490
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002491static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002492{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002493 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2494 ~SDE_PORTE_HOTPLUG_SPT;
2495 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2496 u32 pin_mask = 0, long_mask = 0;
2497
2498 if (hotplug_trigger) {
2499 u32 dig_hotplug_reg;
2500
2501 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2502 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2503
Rodrigo Vivicf539022018-01-29 15:22:21 -08002504 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2505 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002506 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002507 }
2508
2509 if (hotplug2_trigger) {
2510 u32 dig_hotplug_reg;
2511
2512 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2513 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2514
Rodrigo Vivicf539022018-01-29 15:22:21 -08002515 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2516 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002517 spt_port_hotplug2_long_detect);
2518 }
2519
2520 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002521 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002522
2523 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002524 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002525}
2526
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002527static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2528 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002529 const u32 hpd[HPD_NUM_PINS])
2530{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002531 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2532
2533 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2534 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2535
Rodrigo Vivicf539022018-01-29 15:22:21 -08002536 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002537 dig_hotplug_reg, hpd,
2538 ilk_port_hotplug_long_detect);
2539
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002540 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002541}
2542
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002543static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2544 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002545{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002546 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002547 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2548
Ville Syrjälä40e56412015-08-27 23:56:10 +03002549 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002550 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002551
2552 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002553 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002554
2555 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002556 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002557
Paulo Zanonic008bc62013-07-12 16:35:10 -03002558 if (de_iir & DE_POISON)
2559 DRM_ERROR("Poison interrupt\n");
2560
Damien Lespiau055e3932014-08-18 13:49:10 +01002561 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002562 if (de_iir & DE_PIPE_VBLANK(pipe))
2563 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002564
Daniel Vetter40da17c22013-10-21 18:04:36 +02002565 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002566 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002567
Daniel Vetter40da17c22013-10-21 18:04:36 +02002568 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002569 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002570 }
2571
2572 /* check event from PCH */
2573 if (de_iir & DE_PCH_EVENT) {
2574 u32 pch_iir = I915_READ(SDEIIR);
2575
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002576 if (HAS_PCH_CPT(dev_priv))
2577 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002578 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002579 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002580
2581 /* should clear PCH hotplug event before clear CPU irq */
2582 I915_WRITE(SDEIIR, pch_iir);
2583 }
2584
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002585 if (IS_GEN(dev_priv, 5) && de_iir & DE_PCU_EVENT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002586 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002587}
2588
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002589static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2590 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002591{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002592 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002593 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2594
Ville Syrjälä40e56412015-08-27 23:56:10 +03002595 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002596 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002597
2598 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002599 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002600
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002601 if (de_iir & DE_EDP_PSR_INT_HSW) {
2602 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2603
2604 intel_psr_irq_handler(dev_priv, psr_iir);
2605 I915_WRITE(EDP_PSR_IIR, psr_iir);
2606 }
Daniel Vetterfc340442018-04-05 15:00:23 -07002607
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002608 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002609 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002610
2611 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002612 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002613
Damien Lespiau055e3932014-08-18 13:49:10 +01002614 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002615 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2616 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002617 }
2618
2619 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002620 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002621 u32 pch_iir = I915_READ(SDEIIR);
2622
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002623 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002624
2625 /* clear PCH hotplug event before clear CPU irq */
2626 I915_WRITE(SDEIIR, pch_iir);
2627 }
2628}
2629
Oscar Mateo72c90f62014-06-16 16:10:57 +01002630/*
2631 * To handle irqs with the minimum potential races with fresh interrupts, we:
2632 * 1 - Disable Master Interrupt Control.
2633 * 2 - Find the source(s) of the interrupt.
2634 * 3 - Clear the Interrupt Identity bits (IIR).
2635 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2636 * 5 - Re-enable Master Interrupt Control.
2637 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002638static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002639{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002640 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002641 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002642 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002643 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002644
Imre Deak2dd2a882015-02-24 11:14:30 +02002645 if (!intel_irqs_enabled(dev_priv))
2646 return IRQ_NONE;
2647
Imre Deak1f814da2015-12-16 02:52:19 +02002648 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2649 disable_rpm_wakeref_asserts(dev_priv);
2650
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002651 /* disable master interrupt before clearing iir */
2652 de_ier = I915_READ(DEIER);
2653 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson0e434062012-05-09 21:45:44 +01002654
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002655 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2656 * interrupts will will be stored on its back queue, and then we'll be
2657 * able to process them after we restore SDEIER (as soon as we restore
2658 * it, we'll get an interrupt if SDEIIR still has something to process
2659 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002660 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002661 sde_ier = I915_READ(SDEIER);
2662 I915_WRITE(SDEIER, 0);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002663 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002664
Oscar Mateo72c90f62014-06-16 16:10:57 +01002665 /* Find, clear, then process each source of interrupt */
2666
Chris Wilson0e434062012-05-09 21:45:44 +01002667 gt_iir = I915_READ(GTIIR);
2668 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002669 I915_WRITE(GTIIR, gt_iir);
2670 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002671 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002672 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002673 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002674 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002675 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002676
2677 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002678 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002679 I915_WRITE(DEIIR, de_iir);
2680 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002681 if (INTEL_GEN(dev_priv) >= 7)
2682 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002683 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002684 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002685 }
2686
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002687 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002688 u32 pm_iir = I915_READ(GEN6_PMIIR);
2689 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002690 I915_WRITE(GEN6_PMIIR, pm_iir);
2691 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002692 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002693 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002694 }
2695
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002696 I915_WRITE(DEIER, de_ier);
Chris Wilson74093f32018-06-28 21:12:03 +01002697 if (!HAS_PCH_NOP(dev_priv))
Ben Widawskyab5c6082013-04-05 13:12:41 -07002698 I915_WRITE(SDEIER, sde_ier);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002699
Imre Deak1f814da2015-12-16 02:52:19 +02002700 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2701 enable_rpm_wakeref_asserts(dev_priv);
2702
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002703 return ret;
2704}
2705
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002706static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2707 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002708 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302709{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002710 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302711
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002712 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2713 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302714
Rodrigo Vivicf539022018-01-29 15:22:21 -08002715 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002716 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002717 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002718
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002719 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302720}
2721
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002722static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2723{
2724 u32 pin_mask = 0, long_mask = 0;
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002725 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
2726 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002727
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002728 if (trigger_tc) {
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002729 u32 dig_hotplug_reg;
2730
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002731 dig_hotplug_reg = I915_READ(GEN11_TC_HOTPLUG_CTL);
2732 I915_WRITE(GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg);
2733
2734 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tc,
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002735 dig_hotplug_reg, hpd_gen11,
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002736 gen11_port_hotplug_long_detect);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002737 }
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002738
2739 if (trigger_tbt) {
2740 u32 dig_hotplug_reg;
2741
2742 dig_hotplug_reg = I915_READ(GEN11_TBT_HOTPLUG_CTL);
2743 I915_WRITE(GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg);
2744
2745 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tbt,
2746 dig_hotplug_reg, hpd_gen11,
2747 gen11_port_hotplug_long_detect);
2748 }
2749
2750 if (pin_mask)
2751 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2752 else
2753 DRM_ERROR("Unexpected DE HPD interrupt 0x%08x\n", iir);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002754}
2755
Lucas De Marchi9d172102019-02-25 16:49:00 -08002756static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
2757{
2758 u32 mask = GEN8_AUX_CHANNEL_A;
2759
2760 if (INTEL_GEN(dev_priv) >= 9)
2761 mask |= GEN9_AUX_CHANNEL_B |
2762 GEN9_AUX_CHANNEL_C |
2763 GEN9_AUX_CHANNEL_D;
2764
2765 if (IS_CNL_WITH_PORT_F(dev_priv))
2766 mask |= CNL_AUX_CHANNEL_F;
2767
2768 if (INTEL_GEN(dev_priv) >= 11)
2769 mask |= ICL_AUX_CHANNEL_E |
2770 CNL_AUX_CHANNEL_F;
2771
2772 return mask;
2773}
2774
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002775static irqreturn_t
2776gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002777{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002778 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002779 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002780 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002781
Ben Widawskyabd58f02013-11-02 21:07:09 -07002782 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002783 iir = I915_READ(GEN8_DE_MISC_IIR);
2784 if (iir) {
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002785 bool found = false;
2786
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002787 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002788 ret = IRQ_HANDLED;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002789
2790 if (iir & GEN8_DE_MISC_GSE) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002791 intel_opregion_asle_intr(dev_priv);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002792 found = true;
2793 }
2794
2795 if (iir & GEN8_DE_EDP_PSR) {
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002796 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2797
2798 intel_psr_irq_handler(dev_priv, psr_iir);
2799 I915_WRITE(EDP_PSR_IIR, psr_iir);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002800 found = true;
2801 }
2802
2803 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002804 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002805 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002806 else
2807 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002808 }
2809
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002810 if (INTEL_GEN(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
2811 iir = I915_READ(GEN11_DE_HPD_IIR);
2812 if (iir) {
2813 I915_WRITE(GEN11_DE_HPD_IIR, iir);
2814 ret = IRQ_HANDLED;
2815 gen11_hpd_irq_handler(dev_priv, iir);
2816 } else {
2817 DRM_ERROR("The master control interrupt lied, (DE HPD)!\n");
2818 }
2819 }
2820
Daniel Vetter6d766f02013-11-07 14:49:55 +01002821 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002822 iir = I915_READ(GEN8_DE_PORT_IIR);
2823 if (iir) {
2824 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302825 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002826
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002827 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002828 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002829
Lucas De Marchi9d172102019-02-25 16:49:00 -08002830 if (iir & gen8_de_port_aux_mask(dev_priv)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002831 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302832 found = true;
2833 }
2834
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002835 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002836 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2837 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002838 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2839 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002840 found = true;
2841 }
2842 } else if (IS_BROADWELL(dev_priv)) {
2843 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2844 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002845 ilk_hpd_irq_handler(dev_priv,
2846 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002847 found = true;
2848 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302849 }
2850
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002851 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002852 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302853 found = true;
2854 }
2855
Shashank Sharmad04a4922014-08-22 17:40:41 +05302856 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002857 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002858 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002859 else
2860 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002861 }
2862
Damien Lespiau055e3932014-08-18 13:49:10 +01002863 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002864 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002865
Daniel Vetterc42664c2013-11-07 11:05:40 +01002866 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2867 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002868
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002869 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2870 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002871 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002872 continue;
2873 }
2874
2875 ret = IRQ_HANDLED;
2876 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2877
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002878 if (iir & GEN8_PIPE_VBLANK)
2879 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002880
2881 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002882 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002883
2884 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2885 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2886
2887 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002888 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002889 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2890 else
2891 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2892
2893 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002894 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002895 pipe_name(pipe),
2896 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002897 }
2898
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002899 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302900 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002901 /*
2902 * FIXME(BDW): Assume for now that the new interrupt handling
2903 * scheme also closed the SDE interrupt handling race we've seen
2904 * on older pch-split platforms. But this needs testing.
2905 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002906 iir = I915_READ(SDEIIR);
2907 if (iir) {
2908 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002909 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002910
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07002911 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07002912 icp_irq_handler(dev_priv, iir);
Rodrigo Vivic6c30b92019-03-08 13:43:00 -08002913 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002914 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002915 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002916 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002917 } else {
2918 /*
2919 * Like on previous PCH there seems to be something
2920 * fishy going on with forwarding PCH interrupts.
2921 */
2922 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2923 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002924 }
2925
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002926 return ret;
2927}
2928
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002929static inline u32 gen8_master_intr_disable(void __iomem * const regs)
2930{
2931 raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
2932
2933 /*
2934 * Now with master disabled, get a sample of level indications
2935 * for this interrupt. Indications will be cleared on related acks.
2936 * New indications can and will light up during processing,
2937 * and will generate new interrupt after enabling master.
2938 */
2939 return raw_reg_read(regs, GEN8_MASTER_IRQ);
2940}
2941
2942static inline void gen8_master_intr_enable(void __iomem * const regs)
2943{
2944 raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2945}
2946
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002947static irqreturn_t gen8_irq_handler(int irq, void *arg)
2948{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002949 struct drm_i915_private *dev_priv = to_i915(arg);
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07002950 void __iomem * const regs = dev_priv->uncore.regs;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002951 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002952 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002953
2954 if (!intel_irqs_enabled(dev_priv))
2955 return IRQ_NONE;
2956
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002957 master_ctl = gen8_master_intr_disable(regs);
2958 if (!master_ctl) {
2959 gen8_master_intr_enable(regs);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002960 return IRQ_NONE;
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002961 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002962
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002963 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002964 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002965
2966 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2967 if (master_ctl & ~GEN8_GT_IRQS) {
2968 disable_rpm_wakeref_asserts(dev_priv);
2969 gen8_de_irq_handler(dev_priv, master_ctl);
2970 enable_rpm_wakeref_asserts(dev_priv);
2971 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002972
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002973 gen8_master_intr_enable(regs);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002974
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002975 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002976
Chris Wilson55ef72f2018-02-02 15:34:48 +00002977 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002978}
2979
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002980static u32
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002981gen11_gt_engine_identity(struct drm_i915_private * const i915,
2982 const unsigned int bank, const unsigned int bit)
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002983{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07002984 void __iomem * const regs = i915->uncore.regs;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002985 u32 timeout_ts;
2986 u32 ident;
2987
Oscar Mateo96606f32018-04-06 12:32:37 +03002988 lockdep_assert_held(&i915->irq_lock);
2989
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002990 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
2991
2992 /*
2993 * NB: Specs do not specify how long to spin wait,
2994 * so we do ~100us as an educated guess.
2995 */
2996 timeout_ts = (local_clock() >> 10) + 100;
2997 do {
2998 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
2999 } while (!(ident & GEN11_INTR_DATA_VALID) &&
3000 !time_after32(local_clock() >> 10, timeout_ts));
3001
3002 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
3003 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
3004 bank, bit, ident);
3005 return 0;
3006 }
3007
3008 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
3009 GEN11_INTR_DATA_VALID);
3010
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003011 return ident;
3012}
3013
3014static void
3015gen11_other_irq_handler(struct drm_i915_private * const i915,
3016 const u8 instance, const u16 iir)
3017{
Oscar Mateod02b98b2018-04-05 17:00:50 +03003018 if (instance == OTHER_GTPM_INSTANCE)
Mika Kuoppalaa087baf2019-04-10 16:21:23 +03003019 return gen11_rps_irq_handler(i915, iir);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003020
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003021 WARN_ONCE(1, "unhandled other interrupt instance=0x%x, iir=0x%x\n",
3022 instance, iir);
3023}
3024
3025static void
3026gen11_engine_irq_handler(struct drm_i915_private * const i915,
3027 const u8 class, const u8 instance, const u16 iir)
3028{
3029 struct intel_engine_cs *engine;
3030
3031 if (instance <= MAX_ENGINE_INSTANCE)
3032 engine = i915->engine_class[class][instance];
3033 else
3034 engine = NULL;
3035
3036 if (likely(engine))
3037 return gen8_cs_irq_handler(engine, iir);
3038
3039 WARN_ONCE(1, "unhandled engine interrupt class=0x%x, instance=0x%x\n",
3040 class, instance);
3041}
3042
3043static void
3044gen11_gt_identity_handler(struct drm_i915_private * const i915,
3045 const u32 identity)
3046{
3047 const u8 class = GEN11_INTR_ENGINE_CLASS(identity);
3048 const u8 instance = GEN11_INTR_ENGINE_INSTANCE(identity);
3049 const u16 intr = GEN11_INTR_ENGINE_INTR(identity);
3050
3051 if (unlikely(!intr))
3052 return;
3053
3054 if (class <= COPY_ENGINE_CLASS)
3055 return gen11_engine_irq_handler(i915, class, instance, intr);
3056
3057 if (class == OTHER_CLASS)
3058 return gen11_other_irq_handler(i915, instance, intr);
3059
3060 WARN_ONCE(1, "unknown interrupt class=0x%x, instance=0x%x, intr=0x%x\n",
3061 class, instance, intr);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003062}
3063
3064static void
Oscar Mateo96606f32018-04-06 12:32:37 +03003065gen11_gt_bank_handler(struct drm_i915_private * const i915,
3066 const unsigned int bank)
3067{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003068 void __iomem * const regs = i915->uncore.regs;
Oscar Mateo96606f32018-04-06 12:32:37 +03003069 unsigned long intr_dw;
3070 unsigned int bit;
3071
3072 lockdep_assert_held(&i915->irq_lock);
3073
3074 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
3075
Oscar Mateo96606f32018-04-06 12:32:37 +03003076 for_each_set_bit(bit, &intr_dw, 32) {
Mika Kuoppala8455dad2019-04-10 16:21:24 +03003077 const u32 ident = gen11_gt_engine_identity(i915, bank, bit);
Oscar Mateo96606f32018-04-06 12:32:37 +03003078
3079 gen11_gt_identity_handler(i915, ident);
3080 }
3081
3082 /* Clear must be after shared has been served for engine */
3083 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
3084}
3085
3086static void
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003087gen11_gt_irq_handler(struct drm_i915_private * const i915,
3088 const u32 master_ctl)
3089{
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003090 unsigned int bank;
3091
Oscar Mateo96606f32018-04-06 12:32:37 +03003092 spin_lock(&i915->irq_lock);
3093
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003094 for (bank = 0; bank < 2; bank++) {
Oscar Mateo96606f32018-04-06 12:32:37 +03003095 if (master_ctl & GEN11_GT_DW_IRQ(bank))
3096 gen11_gt_bank_handler(i915, bank);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003097 }
Oscar Mateo96606f32018-04-06 12:32:37 +03003098
3099 spin_unlock(&i915->irq_lock);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003100}
3101
Chris Wilson7a909382018-09-26 11:47:18 +01003102static u32
3103gen11_gu_misc_irq_ack(struct drm_i915_private *dev_priv, const u32 master_ctl)
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003104{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003105 void __iomem * const regs = dev_priv->uncore.regs;
Chris Wilson7a909382018-09-26 11:47:18 +01003106 u32 iir;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003107
3108 if (!(master_ctl & GEN11_GU_MISC_IRQ))
Chris Wilson7a909382018-09-26 11:47:18 +01003109 return 0;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003110
Chris Wilson7a909382018-09-26 11:47:18 +01003111 iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
3112 if (likely(iir))
3113 raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
3114
3115 return iir;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003116}
3117
3118static void
Chris Wilson7a909382018-09-26 11:47:18 +01003119gen11_gu_misc_irq_handler(struct drm_i915_private *dev_priv, const u32 iir)
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003120{
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003121 if (iir & GEN11_GU_MISC_GSE)
3122 intel_opregion_asle_intr(dev_priv);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003123}
3124
Mika Kuoppala81067b72018-10-15 17:14:40 +03003125static inline u32 gen11_master_intr_disable(void __iomem * const regs)
3126{
3127 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
3128
3129 /*
3130 * Now with master disabled, get a sample of level indications
3131 * for this interrupt. Indications will be cleared on related acks.
3132 * New indications can and will light up during processing,
3133 * and will generate new interrupt after enabling master.
3134 */
3135 return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
3136}
3137
3138static inline void gen11_master_intr_enable(void __iomem * const regs)
3139{
3140 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
3141}
3142
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003143static irqreturn_t gen11_irq_handler(int irq, void *arg)
3144{
3145 struct drm_i915_private * const i915 = to_i915(arg);
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003146 void __iomem * const regs = i915->uncore.regs;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003147 u32 master_ctl;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003148 u32 gu_misc_iir;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003149
3150 if (!intel_irqs_enabled(i915))
3151 return IRQ_NONE;
3152
Mika Kuoppala81067b72018-10-15 17:14:40 +03003153 master_ctl = gen11_master_intr_disable(regs);
3154 if (!master_ctl) {
3155 gen11_master_intr_enable(regs);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003156 return IRQ_NONE;
Mika Kuoppala81067b72018-10-15 17:14:40 +03003157 }
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003158
3159 /* Find, clear, then process each source of interrupt. */
3160 gen11_gt_irq_handler(i915, master_ctl);
3161
3162 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3163 if (master_ctl & GEN11_DISPLAY_IRQ) {
3164 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
3165
3166 disable_rpm_wakeref_asserts(i915);
3167 /*
3168 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
3169 * for the display related bits.
3170 */
3171 gen8_de_irq_handler(i915, disp_ctl);
3172 enable_rpm_wakeref_asserts(i915);
3173 }
3174
Chris Wilson7a909382018-09-26 11:47:18 +01003175 gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003176
Mika Kuoppala81067b72018-10-15 17:14:40 +03003177 gen11_master_intr_enable(regs);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003178
Chris Wilson7a909382018-09-26 11:47:18 +01003179 gen11_gu_misc_irq_handler(i915, gu_misc_iir);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003180
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003181 return IRQ_HANDLED;
3182}
3183
Keith Packard42f52ef2008-10-18 19:39:29 -07003184/* Called from drm generic code, passed 'crtc' which
3185 * we use as a pipe index
3186 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003187static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003188{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003189 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003190 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003191
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003192 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003193 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3194 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3195
3196 return 0;
3197}
3198
Ville Syrjäläd938da62019-03-22 20:08:03 +02003199static int i945gm_enable_vblank(struct drm_device *dev, unsigned int pipe)
3200{
3201 struct drm_i915_private *dev_priv = to_i915(dev);
3202
3203 if (dev_priv->i945gm_vblank.enabled++ == 0)
3204 schedule_work(&dev_priv->i945gm_vblank.work);
3205
3206 return i8xx_enable_vblank(dev, pipe);
3207}
3208
Chris Wilson86e83e32016-10-07 20:49:52 +01003209static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3210{
3211 struct drm_i915_private *dev_priv = to_i915(dev);
3212 unsigned long irqflags;
3213
3214 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3215 i915_enable_pipestat(dev_priv, pipe,
3216 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003217 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003218
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003219 return 0;
3220}
3221
Thierry Reding88e72712015-09-24 18:35:31 +02003222static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003223{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003224 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003225 unsigned long irqflags;
Jani Nikulaa9c287c2019-01-16 11:15:24 +02003226 u32 bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003227 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003228
Jesse Barnesf796cf82011-04-07 13:58:17 -07003229 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003230 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003231 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3232
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003233 /* Even though there is no DMC, frame counter can get stuck when
3234 * PSR is active as no frames are generated.
3235 */
3236 if (HAS_PSR(dev_priv))
3237 drm_vblank_restore(dev, pipe);
3238
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003239 return 0;
3240}
3241
Thierry Reding88e72712015-09-24 18:35:31 +02003242static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003243{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003244 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003245 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003246
Ben Widawskyabd58f02013-11-02 21:07:09 -07003247 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003248 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003249 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003250
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003251 /* Even if there is no DMC, frame counter can get stuck when
3252 * PSR is active as no frames are generated, so check only for PSR.
3253 */
3254 if (HAS_PSR(dev_priv))
3255 drm_vblank_restore(dev, pipe);
3256
Ben Widawskyabd58f02013-11-02 21:07:09 -07003257 return 0;
3258}
3259
Keith Packard42f52ef2008-10-18 19:39:29 -07003260/* Called from drm generic code, passed 'crtc' which
3261 * we use as a pipe index
3262 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003263static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3264{
3265 struct drm_i915_private *dev_priv = to_i915(dev);
3266 unsigned long irqflags;
3267
3268 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3269 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3270 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3271}
3272
Ville Syrjäläd938da62019-03-22 20:08:03 +02003273static void i945gm_disable_vblank(struct drm_device *dev, unsigned int pipe)
3274{
3275 struct drm_i915_private *dev_priv = to_i915(dev);
3276
3277 i8xx_disable_vblank(dev, pipe);
3278
3279 if (--dev_priv->i945gm_vblank.enabled == 0)
3280 schedule_work(&dev_priv->i945gm_vblank.work);
3281}
3282
Chris Wilson86e83e32016-10-07 20:49:52 +01003283static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003284{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003285 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003286 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003287
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003288 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003289 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003290 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003291 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3292}
3293
Thierry Reding88e72712015-09-24 18:35:31 +02003294static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003295{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003296 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003297 unsigned long irqflags;
Jani Nikulaa9c287c2019-01-16 11:15:24 +02003298 u32 bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003299 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003300
3301 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003302 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003303 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3304}
3305
Thierry Reding88e72712015-09-24 18:35:31 +02003306static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003307{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003308 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003309 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003310
Ben Widawskyabd58f02013-11-02 21:07:09 -07003311 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003312 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003313 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3314}
3315
Ville Syrjäläd938da62019-03-22 20:08:03 +02003316static void i945gm_vblank_work_func(struct work_struct *work)
3317{
3318 struct drm_i915_private *dev_priv =
3319 container_of(work, struct drm_i915_private, i945gm_vblank.work);
3320
3321 /*
3322 * Vblank interrupts fail to wake up the device from C3,
3323 * hence we want to prevent C3 usage while vblank interrupts
3324 * are enabled.
3325 */
3326 pm_qos_update_request(&dev_priv->i945gm_vblank.pm_qos,
3327 READ_ONCE(dev_priv->i945gm_vblank.enabled) ?
3328 dev_priv->i945gm_vblank.c3_disable_latency :
3329 PM_QOS_DEFAULT_VALUE);
3330}
3331
3332static int cstate_disable_latency(const char *name)
3333{
3334 const struct cpuidle_driver *drv;
3335 int i;
3336
3337 drv = cpuidle_get_driver();
3338 if (!drv)
3339 return 0;
3340
3341 for (i = 0; i < drv->state_count; i++) {
3342 const struct cpuidle_state *state = &drv->states[i];
3343
3344 if (!strcmp(state->name, name))
3345 return state->exit_latency ?
3346 state->exit_latency - 1 : 0;
3347 }
3348
3349 return 0;
3350}
3351
3352static void i945gm_vblank_work_init(struct drm_i915_private *dev_priv)
3353{
3354 INIT_WORK(&dev_priv->i945gm_vblank.work,
3355 i945gm_vblank_work_func);
3356
3357 dev_priv->i945gm_vblank.c3_disable_latency =
3358 cstate_disable_latency("C3");
3359 pm_qos_add_request(&dev_priv->i945gm_vblank.pm_qos,
3360 PM_QOS_CPU_DMA_LATENCY,
3361 PM_QOS_DEFAULT_VALUE);
3362}
3363
3364static void i945gm_vblank_work_fini(struct drm_i915_private *dev_priv)
3365{
3366 cancel_work_sync(&dev_priv->i945gm_vblank.work);
3367 pm_qos_remove_request(&dev_priv->i945gm_vblank.pm_qos);
3368}
3369
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003370static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003371{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003372 struct intel_uncore *uncore = &dev_priv->uncore;
3373
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003374 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003375 return;
3376
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003377 GEN3_IRQ_RESET(uncore, SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003378
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003379 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003380 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003381}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003382
Paulo Zanoni622364b2014-04-01 15:37:22 -03003383/*
3384 * SDEIER is also touched by the interrupt handler to work around missed PCH
3385 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3386 * instead we unconditionally enable all PCH interrupt sources here, but then
3387 * only unmask them as needed with SDEIMR.
3388 *
3389 * This function needs to be called before interrupts are enabled.
3390 */
3391static void ibx_irq_pre_postinstall(struct drm_device *dev)
3392{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003393 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003394
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003395 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003396 return;
3397
3398 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003399 I915_WRITE(SDEIER, 0xffffffff);
3400 POSTING_READ(SDEIER);
3401}
3402
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003403static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003404{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003405 struct intel_uncore *uncore = &dev_priv->uncore;
3406
3407 GEN3_IRQ_RESET(uncore, GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003408 if (INTEL_GEN(dev_priv) >= 6)
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003409 GEN3_IRQ_RESET(uncore, GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003410}
3411
Ville Syrjälä70591a42014-10-30 19:42:58 +02003412static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3413{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003414 struct intel_uncore *uncore = &dev_priv->uncore;
3415
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003416 if (IS_CHERRYVIEW(dev_priv))
3417 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3418 else
3419 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3420
Ville Syrjäläad22d102016-04-12 18:56:14 +03003421 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003422 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3423
Ville Syrjälä44d92412017-08-18 21:36:51 +03003424 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003425
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003426 GEN3_IRQ_RESET(uncore, VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003427 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003428}
3429
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003430static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3431{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003432 struct intel_uncore *uncore = &dev_priv->uncore;
3433
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003434 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003435 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003436 enum pipe pipe;
3437
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003438 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003439
3440 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3441 for_each_pipe(dev_priv, pipe)
3442 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3443
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003444 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3445 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003446 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3447 I915_LPE_PIPE_A_INTERRUPT |
3448 I915_LPE_PIPE_B_INTERRUPT;
3449
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003450 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003451 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3452 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003453
Chris Wilson8bd099a2017-11-30 12:52:53 +00003454 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003455
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003456 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003457
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003458 GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003459}
3460
3461/* drm_dma.h hooks
3462*/
3463static void ironlake_irq_reset(struct drm_device *dev)
3464{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003465 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003466 struct intel_uncore *uncore = &dev_priv->uncore;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003467
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003468 GEN3_IRQ_RESET(uncore, DE);
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003469 if (IS_GEN(dev_priv, 7))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003470 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3471
Daniel Vetterfc340442018-04-05 15:00:23 -07003472 if (IS_HASWELL(dev_priv)) {
3473 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3474 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3475 }
3476
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003477 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003478
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003479 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003480}
3481
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003482static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003483{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003484 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003485
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003486 I915_WRITE(VLV_MASTER_IER, 0);
3487 POSTING_READ(VLV_MASTER_IER);
3488
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003489 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003490
Ville Syrjäläad22d102016-04-12 18:56:14 +03003491 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003492 if (dev_priv->display_irqs_enabled)
3493 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003494 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003495}
3496
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003497static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3498{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003499 struct intel_uncore *uncore = &dev_priv->uncore;
3500
3501 GEN8_IRQ_RESET_NDX(uncore, GT, 0);
3502 GEN8_IRQ_RESET_NDX(uncore, GT, 1);
3503 GEN8_IRQ_RESET_NDX(uncore, GT, 2);
3504 GEN8_IRQ_RESET_NDX(uncore, GT, 3);
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003505}
3506
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003507static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003508{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003509 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003510 struct intel_uncore *uncore = &dev_priv->uncore;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003511 int pipe;
3512
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003513 gen8_master_intr_disable(dev_priv->uncore.regs);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003514
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003515 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003516
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003517 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3518 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3519
Damien Lespiau055e3932014-08-18 13:49:10 +01003520 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003521 if (intel_display_power_is_enabled(dev_priv,
3522 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003523 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003524
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003525 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
3526 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
3527 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003528
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003529 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003530 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003531}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003532
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003533static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3534{
3535 /* Disable RCS, BCS, VCS and VECS class engines. */
3536 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3537 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3538
3539 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3540 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3541 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3542 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3543 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3544 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003545
3546 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
3547 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003548}
3549
3550static void gen11_irq_reset(struct drm_device *dev)
3551{
3552 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003553 struct intel_uncore *uncore = &dev_priv->uncore;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003554 int pipe;
3555
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003556 gen11_master_intr_disable(dev_priv->uncore.regs);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003557
3558 gen11_gt_irq_reset(dev_priv);
3559
3560 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3561
José Roberto de Souza62819df2018-11-06 11:08:42 -08003562 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3563 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3564
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003565 for_each_pipe(dev_priv, pipe)
3566 if (intel_display_power_is_enabled(dev_priv,
3567 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003568 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003569
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003570 GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_);
3571 GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_);
3572 GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_);
3573 GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_);
3574 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
Anusha Srivatsa31604222018-06-26 13:52:23 -07003575
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07003576 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003577 GEN3_IRQ_RESET(uncore, SDE);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003578}
3579
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003580void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003581 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003582{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003583 struct intel_uncore *uncore = &dev_priv->uncore;
3584
Jani Nikulaa9c287c2019-01-16 11:15:24 +02003585 u32 extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003586 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003587
Daniel Vetter13321782014-09-15 14:55:29 +02003588 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003589
3590 if (!intel_irqs_enabled(dev_priv)) {
3591 spin_unlock_irq(&dev_priv->irq_lock);
3592 return;
3593 }
3594
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003595 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003596 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003597 dev_priv->de_irq_mask[pipe],
3598 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003599
Daniel Vetter13321782014-09-15 14:55:29 +02003600 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003601}
3602
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003603void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003604 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003605{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003606 struct intel_uncore *uncore = &dev_priv->uncore;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003607 enum pipe pipe;
3608
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003609 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003610
3611 if (!intel_irqs_enabled(dev_priv)) {
3612 spin_unlock_irq(&dev_priv->irq_lock);
3613 return;
3614 }
3615
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003616 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003617 GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003618
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003619 spin_unlock_irq(&dev_priv->irq_lock);
3620
3621 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003622 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003623}
3624
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003625static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003626{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003627 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003628 struct intel_uncore *uncore = &dev_priv->uncore;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003629
3630 I915_WRITE(GEN8_MASTER_IRQ, 0);
3631 POSTING_READ(GEN8_MASTER_IRQ);
3632
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003633 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003634
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003635 GEN3_IRQ_RESET(uncore, GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003636
Ville Syrjäläad22d102016-04-12 18:56:14 +03003637 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003638 if (dev_priv->display_irqs_enabled)
3639 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003640 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003641}
3642
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003643static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003644 const u32 hpd[HPD_NUM_PINS])
3645{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003646 struct intel_encoder *encoder;
3647 u32 enabled_irqs = 0;
3648
Chris Wilson91c8a322016-07-05 10:40:23 +01003649 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003650 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3651 enabled_irqs |= hpd[encoder->hpd_pin];
3652
3653 return enabled_irqs;
3654}
3655
Imre Deak1a56b1a2017-01-27 11:39:21 +02003656static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3657{
3658 u32 hotplug;
3659
3660 /*
3661 * Enable digital hotplug on the PCH, and configure the DP short pulse
3662 * duration to 2ms (which is the minimum in the Display Port spec).
3663 * The pulse duration bits are reserved on LPT+.
3664 */
3665 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3666 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3667 PORTC_PULSE_DURATION_MASK |
3668 PORTD_PULSE_DURATION_MASK);
3669 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3670 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3671 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3672 /*
3673 * When CPU and PCH are on the same package, port A
3674 * HPD must be enabled in both north and south.
3675 */
3676 if (HAS_PCH_LPT_LP(dev_priv))
3677 hotplug |= PORTA_HOTPLUG_ENABLE;
3678 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3679}
3680
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003681static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003682{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003683 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003684
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003685 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003686 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003687 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003688 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003689 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003690 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003691 }
3692
Daniel Vetterfee884e2013-07-04 23:35:21 +02003693 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003694
Imre Deak1a56b1a2017-01-27 11:39:21 +02003695 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003696}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003697
Anusha Srivatsa31604222018-06-26 13:52:23 -07003698static void icp_hpd_detection_setup(struct drm_i915_private *dev_priv)
3699{
3700 u32 hotplug;
3701
3702 hotplug = I915_READ(SHOTPLUG_CTL_DDI);
3703 hotplug |= ICP_DDIA_HPD_ENABLE |
3704 ICP_DDIB_HPD_ENABLE;
3705 I915_WRITE(SHOTPLUG_CTL_DDI, hotplug);
3706
3707 hotplug = I915_READ(SHOTPLUG_CTL_TC);
3708 hotplug |= ICP_TC_HPD_ENABLE(PORT_TC1) |
3709 ICP_TC_HPD_ENABLE(PORT_TC2) |
3710 ICP_TC_HPD_ENABLE(PORT_TC3) |
3711 ICP_TC_HPD_ENABLE(PORT_TC4);
3712 I915_WRITE(SHOTPLUG_CTL_TC, hotplug);
3713}
3714
3715static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
3716{
3717 u32 hotplug_irqs, enabled_irqs;
3718
3719 hotplug_irqs = SDE_DDI_MASK_ICP | SDE_TC_MASK_ICP;
3720 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_icp);
3721
3722 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3723
3724 icp_hpd_detection_setup(dev_priv);
3725}
3726
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003727static void gen11_hpd_detection_setup(struct drm_i915_private *dev_priv)
3728{
3729 u32 hotplug;
3730
3731 hotplug = I915_READ(GEN11_TC_HOTPLUG_CTL);
3732 hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) |
3733 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) |
3734 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) |
3735 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4);
3736 I915_WRITE(GEN11_TC_HOTPLUG_CTL, hotplug);
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07003737
3738 hotplug = I915_READ(GEN11_TBT_HOTPLUG_CTL);
3739 hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) |
3740 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) |
3741 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) |
3742 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4);
3743 I915_WRITE(GEN11_TBT_HOTPLUG_CTL, hotplug);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003744}
3745
3746static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3747{
3748 u32 hotplug_irqs, enabled_irqs;
3749 u32 val;
3750
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07003751 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_gen11);
3752 hotplug_irqs = GEN11_DE_TC_HOTPLUG_MASK | GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003753
3754 val = I915_READ(GEN11_DE_HPD_IMR);
3755 val &= ~hotplug_irqs;
3756 I915_WRITE(GEN11_DE_HPD_IMR, val);
3757 POSTING_READ(GEN11_DE_HPD_IMR);
3758
3759 gen11_hpd_detection_setup(dev_priv);
Anusha Srivatsa31604222018-06-26 13:52:23 -07003760
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07003761 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07003762 icp_hpd_irq_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003763}
3764
Imre Deak2a57d9c2017-01-27 11:39:18 +02003765static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3766{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003767 u32 val, hotplug;
3768
3769 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3770 if (HAS_PCH_CNP(dev_priv)) {
3771 val = I915_READ(SOUTH_CHICKEN1);
3772 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3773 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3774 I915_WRITE(SOUTH_CHICKEN1, val);
3775 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003776
3777 /* Enable digital hotplug on the PCH */
3778 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3779 hotplug |= PORTA_HOTPLUG_ENABLE |
3780 PORTB_HOTPLUG_ENABLE |
3781 PORTC_HOTPLUG_ENABLE |
3782 PORTD_HOTPLUG_ENABLE;
3783 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3784
3785 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3786 hotplug |= PORTE_HOTPLUG_ENABLE;
3787 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3788}
3789
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003790static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003791{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003792 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003793
3794 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003795 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003796
3797 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3798
Imre Deak2a57d9c2017-01-27 11:39:18 +02003799 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003800}
3801
Imre Deak1a56b1a2017-01-27 11:39:21 +02003802static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3803{
3804 u32 hotplug;
3805
3806 /*
3807 * Enable digital hotplug on the CPU, and configure the DP short pulse
3808 * duration to 2ms (which is the minimum in the Display Port spec)
3809 * The pulse duration bits are reserved on HSW+.
3810 */
3811 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3812 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3813 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3814 DIGITAL_PORTA_PULSE_DURATION_2ms;
3815 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3816}
3817
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003818static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003819{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003820 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003821
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003822 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003823 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003824 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003825
3826 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003827 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003828 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003829 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003830
3831 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003832 } else {
3833 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003834 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003835
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003836 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3837 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003838
Imre Deak1a56b1a2017-01-27 11:39:21 +02003839 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003840
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003841 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003842}
3843
Imre Deak2a57d9c2017-01-27 11:39:18 +02003844static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3845 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003846{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003847 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003848
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003849 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003850 hotplug |= PORTA_HOTPLUG_ENABLE |
3851 PORTB_HOTPLUG_ENABLE |
3852 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303853
3854 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3855 hotplug, enabled_irqs);
3856 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3857
3858 /*
3859 * For BXT invert bit has to be set based on AOB design
3860 * for HPD detection logic, update it based on VBT fields.
3861 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303862 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3863 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3864 hotplug |= BXT_DDIA_HPD_INVERT;
3865 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3866 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3867 hotplug |= BXT_DDIB_HPD_INVERT;
3868 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3869 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3870 hotplug |= BXT_DDIC_HPD_INVERT;
3871
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003872 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003873}
3874
Imre Deak2a57d9c2017-01-27 11:39:18 +02003875static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3876{
3877 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3878}
3879
3880static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3881{
3882 u32 hotplug_irqs, enabled_irqs;
3883
3884 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3885 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3886
3887 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3888
3889 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3890}
3891
Paulo Zanonid46da432013-02-08 17:35:15 -02003892static void ibx_irq_postinstall(struct drm_device *dev)
3893{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003894 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003895 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003896
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003897 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003898 return;
3899
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003900 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003901 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003902 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003903 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003904 else
3905 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003906
Paulo Zanoni65f42cd2019-04-10 16:53:43 -07003907 gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003908 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003909
3910 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3911 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003912 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003913 else
3914 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003915}
3916
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003917static void gen5_gt_irq_postinstall(struct drm_device *dev)
3918{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003919 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003920 struct intel_uncore *uncore = &dev_priv->uncore;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003921 u32 pm_irqs, gt_irqs;
3922
3923 pm_irqs = gt_irqs = 0;
3924
3925 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003926 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003927 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003928 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3929 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003930 }
3931
3932 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003933 if (IS_GEN(dev_priv, 5)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003934 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003935 } else {
3936 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3937 }
3938
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003939 GEN3_IRQ_INIT(uncore, GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003940
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003941 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003942 /*
3943 * RPS interrupts will get enabled/disabled on demand when RPS
3944 * itself is enabled/disabled.
3945 */
Chris Wilson8a68d462019-03-05 18:03:30 +00003946 if (HAS_ENGINE(dev_priv, VECS0)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003947 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303948 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3949 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003950
Akash Goelf4e9af42016-10-12 21:54:30 +05303951 dev_priv->pm_imr = 0xffffffff;
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003952 GEN3_IRQ_INIT(uncore, GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003953 }
3954}
3955
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003956static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003957{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003958 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003959 struct intel_uncore *uncore = &dev_priv->uncore;
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003960 u32 display_mask, extra_mask;
3961
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003962 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003963 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003964 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003965 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003966 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3967 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003968 } else {
3969 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003970 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3971 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003972 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3973 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3974 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003975 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003976
Daniel Vetterfc340442018-04-05 15:00:23 -07003977 if (IS_HASWELL(dev_priv)) {
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003978 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
Dhinakaran Pandiyan1aeb1b52018-08-21 15:11:56 -07003979 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Daniel Vetterfc340442018-04-05 15:00:23 -07003980 display_mask |= DE_EDP_PSR_INT_HSW;
3981 }
3982
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003983 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003984
Paulo Zanoni622364b2014-04-01 15:37:22 -03003985 ibx_irq_pre_postinstall(dev);
3986
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07003987 GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask,
3988 display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003989
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003990 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003991
Imre Deak1a56b1a2017-01-27 11:39:21 +02003992 ilk_hpd_detection_setup(dev_priv);
3993
Paulo Zanonid46da432013-02-08 17:35:15 -02003994 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003995
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003996 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003997 /* Enable PCU event interrupts
3998 *
3999 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02004000 * setup is guaranteed to run in single-threaded context. But we
4001 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004002 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02004003 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02004004 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08004005 }
4006
Zhenyu Wang036a4a72009-06-08 14:40:19 +08004007 return 0;
4008}
4009
Imre Deakf8b79e52014-03-04 19:23:07 +02004010void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
4011{
Chris Wilson67520412017-03-02 13:28:01 +00004012 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02004013
4014 if (dev_priv->display_irqs_enabled)
4015 return;
4016
4017 dev_priv->display_irqs_enabled = true;
4018
Ville Syrjäläd6c69802016-04-11 16:56:27 +03004019 if (intel_irqs_enabled(dev_priv)) {
4020 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004021 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03004022 }
Imre Deakf8b79e52014-03-04 19:23:07 +02004023}
4024
4025void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
4026{
Chris Wilson67520412017-03-02 13:28:01 +00004027 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02004028
4029 if (!dev_priv->display_irqs_enabled)
4030 return;
4031
4032 dev_priv->display_irqs_enabled = false;
4033
Imre Deak950eaba2014-09-08 15:21:09 +03004034 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03004035 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02004036}
4037
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02004038
4039static int valleyview_irq_postinstall(struct drm_device *dev)
4040{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004041 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02004042
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004043 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004044
Ville Syrjäläad22d102016-04-12 18:56:14 +03004045 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004046 if (dev_priv->display_irqs_enabled)
4047 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004048 spin_unlock_irq(&dev_priv->irq_lock);
4049
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004050 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03004051 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004052
4053 return 0;
4054}
4055
Ben Widawskyabd58f02013-11-02 21:07:09 -07004056static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
4057{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004058 struct intel_uncore *uncore = &dev_priv->uncore;
4059
Ben Widawskyabd58f02013-11-02 21:07:09 -07004060 /* These are interrupts we'll toggle with the ring mask register */
Jani Nikulaa9c287c2019-01-16 11:15:24 +02004061 u32 gt_interrupts[] = {
Chris Wilson8a68d462019-03-05 18:03:30 +00004062 (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
4063 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
4064 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
4065 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT),
4066
4067 (GT_RENDER_USER_INTERRUPT << GEN8_VCS0_IRQ_SHIFT |
4068 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS0_IRQ_SHIFT |
4069 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
4070 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT),
4071
Ben Widawskyabd58f02013-11-02 21:07:09 -07004072 0,
Chris Wilson8a68d462019-03-05 18:03:30 +00004073
4074 (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
4075 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT)
4076 };
Ben Widawskyabd58f02013-11-02 21:07:09 -07004077
Akash Goelf4e9af42016-10-12 21:54:30 +05304078 dev_priv->pm_ier = 0x0;
4079 dev_priv->pm_imr = ~dev_priv->pm_ier;
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004080 GEN8_IRQ_INIT_NDX(uncore, GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
4081 GEN8_IRQ_INIT_NDX(uncore, GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02004082 /*
4083 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304084 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02004085 */
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004086 GEN8_IRQ_INIT_NDX(uncore, GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
4087 GEN8_IRQ_INIT_NDX(uncore, GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004088}
4089
4090static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
4091{
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004092 struct intel_uncore *uncore = &dev_priv->uncore;
4093
Jani Nikulaa9c287c2019-01-16 11:15:24 +02004094 u32 de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
4095 u32 de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004096 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
4097 u32 de_port_enables;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004098 u32 de_misc_masked = GEN8_DE_EDP_PSR;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004099 enum pipe pipe;
Damien Lespiau770de83d2014-03-20 20:45:01 +00004100
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004101 if (INTEL_GEN(dev_priv) <= 10)
4102 de_misc_masked |= GEN8_DE_MISC_GSE;
4103
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004104 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004105 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004106 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
4107 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004108 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004109 de_port_masked |= BXT_DE_PORT_GMBUS;
4110 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004111 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004112 }
Damien Lespiau770de83d2014-03-20 20:45:01 +00004113
James Ausmusbb187e92018-06-11 17:25:12 -07004114 if (INTEL_GEN(dev_priv) >= 11)
4115 de_port_masked |= ICL_AUX_CHANNEL_E;
4116
Dhinakaran Pandiyan9bb635d2018-05-21 17:25:35 -07004117 if (IS_CNL_WITH_PORT_F(dev_priv) || INTEL_GEN(dev_priv) >= 11)
Rodrigo Vivia324fca2018-01-29 15:22:15 -08004118 de_port_masked |= CNL_AUX_CHANNEL_F;
4119
Damien Lespiau770de83d2014-03-20 20:45:01 +00004120 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
4121 GEN8_PIPE_FIFO_UNDERRUN;
4122
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004123 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004124 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03004125 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
4126 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004127 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
4128
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004129 gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07004130 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07004131
Mika Kahola0a195c02017-10-10 13:17:04 +03004132 for_each_pipe(dev_priv, pipe) {
4133 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004134
Daniel Vetterf458ebb2014-09-30 10:56:39 +02004135 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03004136 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004137 GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe,
Paulo Zanoni813bde42014-07-04 11:50:29 -03004138 dev_priv->de_irq_mask[pipe],
4139 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03004140 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07004141
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004142 GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
4143 GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02004144
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004145 if (INTEL_GEN(dev_priv) >= 11) {
4146 u32 de_hpd_masked = 0;
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07004147 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
4148 GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004149
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004150 GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked,
4151 de_hpd_enables);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004152 gen11_hpd_detection_setup(dev_priv);
4153 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deak2a57d9c2017-01-27 11:39:18 +02004154 bxt_hpd_detection_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004155 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak1a56b1a2017-01-27 11:39:21 +02004156 ilk_hpd_detection_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004157 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07004158}
4159
4160static int gen8_irq_postinstall(struct drm_device *dev)
4161{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004162 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004163
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004164 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05304165 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03004166
Ben Widawskyabd58f02013-11-02 21:07:09 -07004167 gen8_gt_irq_postinstall(dev_priv);
4168 gen8_de_irq_postinstall(dev_priv);
4169
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004170 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05304171 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004172
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07004173 gen8_master_intr_enable(dev_priv->uncore.regs);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004174
4175 return 0;
4176}
4177
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004178static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
4179{
4180 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
4181
4182 BUILD_BUG_ON(irqs & 0xffff0000);
4183
4184 /* Enable RCS, BCS, VCS and VECS class interrupts. */
4185 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
4186 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
4187
4188 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
4189 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
4190 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
4191 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
4192 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
4193 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
4194
Oscar Mateod02b98b2018-04-05 17:00:50 +03004195 /*
4196 * RPS interrupts will get enabled/disabled on demand when RPS itself
4197 * is enabled/disabled.
4198 */
4199 dev_priv->pm_ier = 0x0;
4200 dev_priv->pm_imr = ~dev_priv->pm_ier;
4201 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
4202 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004203}
4204
Anusha Srivatsa31604222018-06-26 13:52:23 -07004205static void icp_irq_postinstall(struct drm_device *dev)
4206{
4207 struct drm_i915_private *dev_priv = to_i915(dev);
4208 u32 mask = SDE_GMBUS_ICP;
4209
4210 WARN_ON(I915_READ(SDEIER) != 0);
4211 I915_WRITE(SDEIER, 0xffffffff);
4212 POSTING_READ(SDEIER);
4213
Paulo Zanoni65f42cd2019-04-10 16:53:43 -07004214 gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR);
Anusha Srivatsa31604222018-06-26 13:52:23 -07004215 I915_WRITE(SDEIMR, ~mask);
4216
4217 icp_hpd_detection_setup(dev_priv);
4218}
4219
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004220static int gen11_irq_postinstall(struct drm_device *dev)
4221{
4222 struct drm_i915_private *dev_priv = dev->dev_private;
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004223 struct intel_uncore *uncore = &dev_priv->uncore;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004224 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004225
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07004226 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07004227 icp_irq_postinstall(dev);
4228
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004229 gen11_gt_irq_postinstall(dev_priv);
4230 gen8_de_irq_postinstall(dev_priv);
4231
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004232 GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004233
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004234 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
4235
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07004236 gen11_master_intr_enable(dev_priv->uncore.regs);
Daniele Ceraolo Spurioc25f0c62019-01-22 18:32:27 -08004237 POSTING_READ(GEN11_GFX_MSTR_IRQ);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004238
4239 return 0;
4240}
4241
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004242static int cherryview_irq_postinstall(struct drm_device *dev)
4243{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004244 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004245
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004246 gen8_gt_irq_postinstall(dev_priv);
4247
Ville Syrjäläad22d102016-04-12 18:56:14 +03004248 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004249 if (dev_priv->display_irqs_enabled)
4250 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004251 spin_unlock_irq(&dev_priv->irq_lock);
4252
Ville Syrjäläe5328c42016-04-13 21:19:47 +03004253 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004254 POSTING_READ(GEN8_MASTER_IRQ);
4255
4256 return 0;
4257}
4258
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004259static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004260{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004261 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004262 struct intel_uncore *uncore = &dev_priv->uncore;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004263
Ville Syrjälä44d92412017-08-18 21:36:51 +03004264 i9xx_pipestat_irq_reset(dev_priv);
4265
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004266 GEN2_IRQ_RESET(uncore);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004267}
4268
4269static int i8xx_irq_postinstall(struct drm_device *dev)
4270{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004271 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004272 struct intel_uncore *uncore = &dev_priv->uncore;
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004273 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004274
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004275 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
4276 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01004277
4278 /* Unmask the interrupts that we always want on. */
4279 dev_priv->irq_mask =
4280 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004281 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4282 I915_MASTER_ERROR_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004283
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004284 enable_mask =
4285 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4286 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004287 I915_MASTER_ERROR_INTERRUPT |
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004288 I915_USER_INTERRUPT;
4289
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004290 GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004291
Daniel Vetter379ef822013-10-16 22:55:56 +02004292 /* Interrupt setup is already guaranteed to be single-threaded, this is
4293 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004294 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004295 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4296 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004297 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004298
Chris Wilsonc2798b12012-04-22 21:13:57 +01004299 return 0;
4300}
4301
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004302static void i8xx_error_irq_ack(struct drm_i915_private *dev_priv,
4303 u16 *eir, u16 *eir_stuck)
4304{
4305 u16 emr;
4306
4307 *eir = I915_READ16(EIR);
4308
4309 if (*eir)
4310 I915_WRITE16(EIR, *eir);
4311
4312 *eir_stuck = I915_READ16(EIR);
4313 if (*eir_stuck == 0)
4314 return;
4315
4316 /*
4317 * Toggle all EMR bits to make sure we get an edge
4318 * in the ISR master error bit if we don't clear
4319 * all the EIR bits. Otherwise the edge triggered
4320 * IIR on i965/g4x wouldn't notice that an interrupt
4321 * is still pending. Also some EIR bits can't be
4322 * cleared except by handling the underlying error
4323 * (or by a GPU reset) so we mask any bit that
4324 * remains set.
4325 */
4326 emr = I915_READ16(EMR);
4327 I915_WRITE16(EMR, 0xffff);
4328 I915_WRITE16(EMR, emr | *eir_stuck);
4329}
4330
4331static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
4332 u16 eir, u16 eir_stuck)
4333{
4334 DRM_DEBUG("Master Error: EIR 0x%04x\n", eir);
4335
4336 if (eir_stuck)
4337 DRM_DEBUG_DRIVER("EIR stuck: 0x%04x, masked\n", eir_stuck);
4338}
4339
4340static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
4341 u32 *eir, u32 *eir_stuck)
4342{
4343 u32 emr;
4344
4345 *eir = I915_READ(EIR);
4346
4347 I915_WRITE(EIR, *eir);
4348
4349 *eir_stuck = I915_READ(EIR);
4350 if (*eir_stuck == 0)
4351 return;
4352
4353 /*
4354 * Toggle all EMR bits to make sure we get an edge
4355 * in the ISR master error bit if we don't clear
4356 * all the EIR bits. Otherwise the edge triggered
4357 * IIR on i965/g4x wouldn't notice that an interrupt
4358 * is still pending. Also some EIR bits can't be
4359 * cleared except by handling the underlying error
4360 * (or by a GPU reset) so we mask any bit that
4361 * remains set.
4362 */
4363 emr = I915_READ(EMR);
4364 I915_WRITE(EMR, 0xffffffff);
4365 I915_WRITE(EMR, emr | *eir_stuck);
4366}
4367
4368static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
4369 u32 eir, u32 eir_stuck)
4370{
4371 DRM_DEBUG("Master Error, EIR 0x%08x\n", eir);
4372
4373 if (eir_stuck)
4374 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masked\n", eir_stuck);
4375}
4376
Daniel Vetterff1f5252012-10-02 15:10:55 +02004377static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004378{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004379 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004380 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004381 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004382
Imre Deak2dd2a882015-02-24 11:14:30 +02004383 if (!intel_irqs_enabled(dev_priv))
4384 return IRQ_NONE;
4385
Imre Deak1f814da2015-12-16 02:52:19 +02004386 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4387 disable_rpm_wakeref_asserts(dev_priv);
4388
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004389 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004390 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004391 u16 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004392 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03004393
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004394 iir = I915_READ16(GEN2_IIR);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004395 if (iir == 0)
4396 break;
4397
4398 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004399
Ville Syrjäläeb643432017-08-18 21:36:59 +03004400 /* Call regardless, as some status bits might not be
4401 * signalled in iir */
4402 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004403
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004404 if (iir & I915_MASTER_ERROR_INTERRUPT)
4405 i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4406
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004407 I915_WRITE16(GEN2_IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004408
Chris Wilsonc2798b12012-04-22 21:13:57 +01004409 if (iir & I915_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004410 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004411
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004412 if (iir & I915_MASTER_ERROR_INTERRUPT)
4413 i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004414
Ville Syrjäläeb643432017-08-18 21:36:59 +03004415 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004416 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004417
Imre Deak1f814da2015-12-16 02:52:19 +02004418 enable_rpm_wakeref_asserts(dev_priv);
4419
4420 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004421}
4422
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004423static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004424{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004425 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004426 struct intel_uncore *uncore = &dev_priv->uncore;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004427
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004428 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004429 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004430 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4431 }
4432
Ville Syrjälä44d92412017-08-18 21:36:51 +03004433 i9xx_pipestat_irq_reset(dev_priv);
4434
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004435 GEN3_IRQ_RESET(uncore, GEN2_);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004436}
4437
4438static int i915_irq_postinstall(struct drm_device *dev)
4439{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004440 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004441 struct intel_uncore *uncore = &dev_priv->uncore;
Chris Wilson38bde182012-04-24 22:59:50 +01004442 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004443
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004444 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
4445 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01004446
4447 /* Unmask the interrupts that we always want on. */
4448 dev_priv->irq_mask =
4449 ~(I915_ASLE_INTERRUPT |
4450 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004451 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4452 I915_MASTER_ERROR_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004453
4454 enable_mask =
4455 I915_ASLE_INTERRUPT |
4456 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4457 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004458 I915_MASTER_ERROR_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004459 I915_USER_INTERRUPT;
4460
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004461 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004462 /* Enable in IER... */
4463 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4464 /* and unmask in IMR */
4465 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4466 }
4467
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004468 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004469
Daniel Vetter379ef822013-10-16 22:55:56 +02004470 /* Interrupt setup is already guaranteed to be single-threaded, this is
4471 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004472 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004473 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4474 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004475 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004476
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004477 i915_enable_asle_pipestat(dev_priv);
4478
Daniel Vetter20afbda2012-12-11 14:05:07 +01004479 return 0;
4480}
4481
Daniel Vetterff1f5252012-10-02 15:10:55 +02004482static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004483{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004484 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004485 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004486 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004487
Imre Deak2dd2a882015-02-24 11:14:30 +02004488 if (!intel_irqs_enabled(dev_priv))
4489 return IRQ_NONE;
4490
Imre Deak1f814da2015-12-16 02:52:19 +02004491 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4492 disable_rpm_wakeref_asserts(dev_priv);
4493
Chris Wilson38bde182012-04-24 22:59:50 +01004494 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004495 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004496 u32 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004497 u32 hotplug_status = 0;
4498 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004499
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004500 iir = I915_READ(GEN2_IIR);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004501 if (iir == 0)
4502 break;
4503
4504 ret = IRQ_HANDLED;
4505
4506 if (I915_HAS_HOTPLUG(dev_priv) &&
4507 iir & I915_DISPLAY_PORT_INTERRUPT)
4508 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004509
Ville Syrjäläeb643432017-08-18 21:36:59 +03004510 /* Call regardless, as some status bits might not be
4511 * signalled in iir */
4512 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004513
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004514 if (iir & I915_MASTER_ERROR_INTERRUPT)
4515 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4516
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004517 I915_WRITE(GEN2_IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004518
Chris Wilsona266c7d2012-04-24 22:59:44 +01004519 if (iir & I915_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004520 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004521
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004522 if (iir & I915_MASTER_ERROR_INTERRUPT)
4523 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004524
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004525 if (hotplug_status)
4526 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4527
4528 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4529 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004530
Imre Deak1f814da2015-12-16 02:52:19 +02004531 enable_rpm_wakeref_asserts(dev_priv);
4532
Chris Wilsona266c7d2012-04-24 22:59:44 +01004533 return ret;
4534}
4535
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004536static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004537{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004538 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004539 struct intel_uncore *uncore = &dev_priv->uncore;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004540
Egbert Eich0706f172015-09-23 16:15:27 +02004541 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004542 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004543
Ville Syrjälä44d92412017-08-18 21:36:51 +03004544 i9xx_pipestat_irq_reset(dev_priv);
4545
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004546 GEN3_IRQ_RESET(uncore, GEN2_);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004547}
4548
4549static int i965_irq_postinstall(struct drm_device *dev)
4550{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004551 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004552 struct intel_uncore *uncore = &dev_priv->uncore;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004553 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004554 u32 error_mask;
4555
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004556 /*
4557 * Enable some error detection, note the instruction error mask
4558 * bit is reserved, so we leave it masked.
4559 */
4560 if (IS_G4X(dev_priv)) {
4561 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4562 GM45_ERROR_MEM_PRIV |
4563 GM45_ERROR_CP_PRIV |
4564 I915_ERROR_MEMORY_REFRESH);
4565 } else {
4566 error_mask = ~(I915_ERROR_PAGE_TABLE |
4567 I915_ERROR_MEMORY_REFRESH);
4568 }
4569 I915_WRITE(EMR, error_mask);
4570
Chris Wilsona266c7d2012-04-24 22:59:44 +01004571 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004572 dev_priv->irq_mask =
4573 ~(I915_ASLE_INTERRUPT |
4574 I915_DISPLAY_PORT_INTERRUPT |
4575 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4576 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004577 I915_MASTER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004578
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004579 enable_mask =
4580 I915_ASLE_INTERRUPT |
4581 I915_DISPLAY_PORT_INTERRUPT |
4582 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4583 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004584 I915_MASTER_ERROR_INTERRUPT |
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004585 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004586
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004587 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004588 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004589
Paulo Zanonib16b2a2f2019-04-10 16:53:44 -07004590 GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask);
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004591
Daniel Vetterb79480b2013-06-27 17:52:10 +02004592 /* Interrupt setup is already guaranteed to be single-threaded, this is
4593 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004594 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004595 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4596 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4597 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004598 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004599
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004600 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004601
4602 return 0;
4603}
4604
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004605static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004606{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004607 u32 hotplug_en;
4608
Chris Wilson67520412017-03-02 13:28:01 +00004609 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004610
Ville Syrjälä778eb332015-01-09 14:21:13 +02004611 /* Note HDMI and DP share hotplug bits */
4612 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004613 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004614 /* Programming the CRT detection parameters tends
4615 to generate a spurious hotplug event about three
4616 seconds later. So just do it once.
4617 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004618 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004619 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004620 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004621
Ville Syrjälä778eb332015-01-09 14:21:13 +02004622 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004623 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004624 HOTPLUG_INT_EN_MASK |
4625 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4626 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4627 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004628}
4629
Daniel Vetterff1f5252012-10-02 15:10:55 +02004630static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004631{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004632 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004633 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004634 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004635
Imre Deak2dd2a882015-02-24 11:14:30 +02004636 if (!intel_irqs_enabled(dev_priv))
4637 return IRQ_NONE;
4638
Imre Deak1f814da2015-12-16 02:52:19 +02004639 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4640 disable_rpm_wakeref_asserts(dev_priv);
4641
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004642 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004643 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004644 u32 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004645 u32 hotplug_status = 0;
4646 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004647
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004648 iir = I915_READ(GEN2_IIR);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004649 if (iir == 0)
4650 break;
4651
4652 ret = IRQ_HANDLED;
4653
4654 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4655 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004656
Ville Syrjäläeb643432017-08-18 21:36:59 +03004657 /* Call regardless, as some status bits might not be
4658 * signalled in iir */
4659 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004660
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004661 if (iir & I915_MASTER_ERROR_INTERRUPT)
4662 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4663
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004664 I915_WRITE(GEN2_IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004665
Chris Wilsona266c7d2012-04-24 22:59:44 +01004666 if (iir & I915_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004667 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004668
Chris Wilsona266c7d2012-04-24 22:59:44 +01004669 if (iir & I915_BSD_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004670 intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004671
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004672 if (iir & I915_MASTER_ERROR_INTERRUPT)
4673 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004674
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004675 if (hotplug_status)
4676 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4677
4678 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4679 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004680
Imre Deak1f814da2015-12-16 02:52:19 +02004681 enable_rpm_wakeref_asserts(dev_priv);
4682
Chris Wilsona266c7d2012-04-24 22:59:44 +01004683 return ret;
4684}
4685
Daniel Vetterfca52a52014-09-30 10:56:45 +02004686/**
4687 * intel_irq_init - initializes irq support
4688 * @dev_priv: i915 device instance
4689 *
4690 * This function initializes all the irq support including work items, timers
4691 * and all the vtables. It does not setup the interrupt itself though.
4692 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004693void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004694{
Chris Wilson91c8a322016-07-05 10:40:23 +01004695 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004696 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004697 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004698
Ville Syrjäläd938da62019-03-22 20:08:03 +02004699 if (IS_I945GM(dev_priv))
4700 i945gm_vblank_work_init(dev_priv);
4701
Jani Nikula77913b32015-06-18 13:06:16 +03004702 intel_hpd_init_work(dev_priv);
4703
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004704 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004705
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004706 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004707 for (i = 0; i < MAX_L3_SLICES; ++i)
4708 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004709
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004710 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304711 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4712
Deepak Sa6706b42014-03-15 20:23:22 +05304713 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004714 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a5872014-08-29 14:14:07 +03004715 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004716 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004717 else
Chris Wilson4668f692018-08-02 11:06:30 +01004718 dev_priv->pm_rps_events = (GEN6_PM_RP_UP_THRESHOLD |
4719 GEN6_PM_RP_DOWN_THRESHOLD |
4720 GEN6_PM_RP_DOWN_TIMEOUT);
Deepak Sa6706b42014-03-15 20:23:22 +05304721
Mika Kuoppala917dc6b2019-04-10 13:59:22 +03004722 /* We share the register with other engine */
4723 if (INTEL_GEN(dev_priv) > 9)
4724 GEM_WARN_ON(dev_priv->pm_rps_events & 0xffff0000);
4725
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004726 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304727
4728 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004729 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304730 * if GEN6_PM_UP_EI_EXPIRED is masked.
4731 *
4732 * TODO: verify if this can be reproduced on VLV,CHV.
4733 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004734 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004735 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304736
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004737 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004738 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304739
Ville Syrjälä32db0b62018-11-27 22:05:50 +02004740 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjäläfd8f507c2015-09-18 20:03:42 +03004741 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä32db0b62018-11-27 22:05:50 +02004742 else if (INTEL_GEN(dev_priv) >= 3)
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004743 dev->driver->get_vblank_counter = i915_get_vblank_counter;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004744
Ville Syrjälä0df3f092019-03-22 20:08:04 +02004745 dev->vblank_disable_immediate = true;
Ville Syrjälä21da2702014-08-06 14:49:55 +03004746
Chris Wilson262fd482017-02-15 13:15:47 +00004747 /* Most platforms treat the display irq block as an always-on
4748 * power domain. vlv/chv can disable it at runtime and need
4749 * special care to avoid writing any of the display block registers
4750 * outside of the power domain. We defer setting up the display irqs
4751 * in this case to the runtime pm.
4752 */
4753 dev_priv->display_irqs_enabled = true;
4754 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4755 dev_priv->display_irqs_enabled = false;
4756
Lyude317eaa92017-02-03 21:18:25 -05004757 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
Lyude Paul9a64c652018-11-06 16:30:16 -05004758 /* If we have MST support, we want to avoid doing short HPD IRQ storm
4759 * detection, as short HPD storms will occur as a natural part of
4760 * sideband messaging with MST.
4761 * On older platforms however, IRQ storms can occur with both long and
4762 * short pulses, as seen on some G4x systems.
4763 */
4764 dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv);
Lyude317eaa92017-02-03 21:18:25 -05004765
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004766 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004767 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004768
Daniel Vetterb9632912014-09-30 10:56:44 +02004769 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004770 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004771 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004772 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004773 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004774 dev->driver->enable_vblank = i965_enable_vblank;
4775 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004776 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004777 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004778 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004779 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004780 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004781 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004782 dev->driver->enable_vblank = i965_enable_vblank;
4783 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004784 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004785 } else if (INTEL_GEN(dev_priv) >= 11) {
4786 dev->driver->irq_handler = gen11_irq_handler;
4787 dev->driver->irq_preinstall = gen11_irq_reset;
4788 dev->driver->irq_postinstall = gen11_irq_postinstall;
4789 dev->driver->irq_uninstall = gen11_irq_reset;
4790 dev->driver->enable_vblank = gen8_enable_vblank;
4791 dev->driver->disable_vblank = gen8_disable_vblank;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004792 dev_priv->display.hpd_irq_setup = gen11_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004793 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004794 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004795 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004796 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004797 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004798 dev->driver->enable_vblank = gen8_enable_vblank;
4799 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004800 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004801 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivic6c30b92019-03-08 13:43:00 -08004802 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004803 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4804 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004805 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004806 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004807 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004808 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004809 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004810 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004811 dev->driver->enable_vblank = ironlake_enable_vblank;
4812 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004813 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004814 } else {
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004815 if (IS_GEN(dev_priv, 2)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004816 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004817 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4818 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004819 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004820 dev->driver->enable_vblank = i8xx_enable_vblank;
4821 dev->driver->disable_vblank = i8xx_disable_vblank;
Ville Syrjäläd938da62019-03-22 20:08:03 +02004822 } else if (IS_I945GM(dev_priv)) {
4823 dev->driver->irq_preinstall = i915_irq_reset;
4824 dev->driver->irq_postinstall = i915_irq_postinstall;
4825 dev->driver->irq_uninstall = i915_irq_reset;
4826 dev->driver->irq_handler = i915_irq_handler;
4827 dev->driver->enable_vblank = i945gm_enable_vblank;
4828 dev->driver->disable_vblank = i945gm_disable_vblank;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004829 } else if (IS_GEN(dev_priv, 3)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004830 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004831 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004832 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004833 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004834 dev->driver->enable_vblank = i8xx_enable_vblank;
4835 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004836 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004837 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004838 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004839 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004840 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004841 dev->driver->enable_vblank = i965_enable_vblank;
4842 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004843 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004844 if (I915_HAS_HOTPLUG(dev_priv))
4845 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004846 }
4847}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004848
Daniel Vetterfca52a52014-09-30 10:56:45 +02004849/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004850 * intel_irq_fini - deinitializes IRQ support
4851 * @i915: i915 device instance
4852 *
4853 * This function deinitializes all the IRQ support.
4854 */
4855void intel_irq_fini(struct drm_i915_private *i915)
4856{
4857 int i;
4858
Ville Syrjäläd938da62019-03-22 20:08:03 +02004859 if (IS_I945GM(i915))
4860 i945gm_vblank_work_fini(i915);
4861
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004862 for (i = 0; i < MAX_L3_SLICES; ++i)
4863 kfree(i915->l3_parity.remap_info[i]);
4864}
4865
4866/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004867 * intel_irq_install - enables the hardware interrupt
4868 * @dev_priv: i915 device instance
4869 *
4870 * This function enables the hardware interrupt handling, but leaves the hotplug
4871 * handling still disabled. It is called after intel_irq_init().
4872 *
4873 * In the driver load and resume code we need working interrupts in a few places
4874 * but don't want to deal with the hassle of concurrent probe and hotplug
4875 * workers. Hence the split into this two-stage approach.
4876 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004877int intel_irq_install(struct drm_i915_private *dev_priv)
4878{
4879 /*
4880 * We enable some interrupt sources in our postinstall hooks, so mark
4881 * interrupts as enabled _before_ actually enabling them to avoid
4882 * special cases in our ordering checks.
4883 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004884 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004885
Chris Wilson91c8a322016-07-05 10:40:23 +01004886 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004887}
4888
Daniel Vetterfca52a52014-09-30 10:56:45 +02004889/**
4890 * intel_irq_uninstall - finilizes all irq handling
4891 * @dev_priv: i915 device instance
4892 *
4893 * This stops interrupt and hotplug handling and unregisters and frees all
4894 * resources acquired in the init functions.
4895 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004896void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4897{
Chris Wilson91c8a322016-07-05 10:40:23 +01004898 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004899 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004900 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004901}
4902
Daniel Vetterfca52a52014-09-30 10:56:45 +02004903/**
4904 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4905 * @dev_priv: i915 device instance
4906 *
4907 * This function is used to disable interrupts at runtime, both in the runtime
4908 * pm and the system suspend/resume code.
4909 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004910void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004911{
Chris Wilson91c8a322016-07-05 10:40:23 +01004912 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004913 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004914 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004915}
4916
Daniel Vetterfca52a52014-09-30 10:56:45 +02004917/**
4918 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4919 * @dev_priv: i915 device instance
4920 *
4921 * This function is used to enable interrupts at runtime, both in the runtime
4922 * pm and the system suspend/resume code.
4923 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004924void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004925{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004926 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004927 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4928 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004929}