blob: 2f34304ee63708a583a6249f63b4fdbf0bc63eaf [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"
Chris Wilson1c5d22f2009-08-25 11:15:50 +010041#include "i915_trace.h"
Jesse Barnes79e53942008-11-07 14:24:08 -080042#include "intel_drv.h"
Jani Nikula55367a22019-04-05 14:00:09 +030043#include "intel_psr.h"
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Daniel Vetterfca52a52014-09-30 10:56:45 +020045/**
46 * DOC: interrupt handling
47 *
48 * These functions provide the basic support for enabling and disabling the
49 * interrupt handling support. There's a lot more functionality in i915_irq.c
50 * and related files, but that will be described in separate chapters.
51 */
52
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +030053static const u32 hpd_ilk[HPD_NUM_PINS] = {
54 [HPD_PORT_A] = DE_DP_A_HOTPLUG,
55};
56
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +030057static const u32 hpd_ivb[HPD_NUM_PINS] = {
58 [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB,
59};
60
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +030061static const u32 hpd_bdw[HPD_NUM_PINS] = {
62 [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG,
63};
64
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020065static const u32 hpd_ibx[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050066 [HPD_CRT] = SDE_CRT_HOTPLUG,
67 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG,
68 [HPD_PORT_B] = SDE_PORTB_HOTPLUG,
69 [HPD_PORT_C] = SDE_PORTC_HOTPLUG,
70 [HPD_PORT_D] = SDE_PORTD_HOTPLUG
71};
72
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020073static const u32 hpd_cpt[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050074 [HPD_CRT] = SDE_CRT_HOTPLUG_CPT,
Daniel Vetter73c352a2013-03-26 22:38:43 +010075 [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT,
Egbert Eiche5868a32013-02-28 04:17:12 -050076 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
77 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
78 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT
79};
80
Xiong Zhang26951ca2015-08-17 15:55:50 +080081static const u32 hpd_spt[HPD_NUM_PINS] = {
Ville Syrjälä74c0b392015-08-27 23:56:07 +030082 [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT,
Xiong Zhang26951ca2015-08-17 15:55:50 +080083 [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT,
84 [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT,
85 [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT,
86 [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT
87};
88
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020089static const u32 hpd_mask_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050090 [HPD_CRT] = CRT_HOTPLUG_INT_EN,
91 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN,
92 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN,
93 [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN,
94 [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN,
95 [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN
96};
97
Ville Syrjälä7c7e10d2015-01-09 14:21:12 +020098static const u32 hpd_status_g4x[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -050099 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
100 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X,
101 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X,
102 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
103 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
104 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
105};
106
Ville Syrjälä4bca26d2015-05-11 20:49:10 +0300107static const u32 hpd_status_i915[HPD_NUM_PINS] = {
Egbert Eiche5868a32013-02-28 04:17:12 -0500108 [HPD_CRT] = CRT_HOTPLUG_INT_STATUS,
109 [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915,
110 [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915,
111 [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS,
112 [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS,
113 [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS
114};
115
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200116/* BXT hpd list */
117static const u32 hpd_bxt[HPD_NUM_PINS] = {
Sonika Jindal7f3561b2015-08-10 10:35:35 +0530118 [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA,
Shashank Sharmae0a20ad2015-03-27 14:54:14 +0200119 [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB,
120 [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC
121};
122
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -0700123static const u32 hpd_gen11[HPD_NUM_PINS] = {
124 [HPD_PORT_C] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG,
125 [HPD_PORT_D] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG,
126 [HPD_PORT_E] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG,
127 [HPD_PORT_F] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -0700128};
129
Anusha Srivatsa31604222018-06-26 13:52:23 -0700130static const u32 hpd_icp[HPD_NUM_PINS] = {
131 [HPD_PORT_A] = SDE_DDIA_HOTPLUG_ICP,
132 [HPD_PORT_B] = SDE_DDIB_HOTPLUG_ICP,
133 [HPD_PORT_C] = SDE_TC1_HOTPLUG_ICP,
134 [HPD_PORT_D] = SDE_TC2_HOTPLUG_ICP,
135 [HPD_PORT_E] = SDE_TC3_HOTPLUG_ICP,
136 [HPD_PORT_F] = SDE_TC4_HOTPLUG_ICP
137};
138
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700139static void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr,
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700140 i915_reg_t iir, i915_reg_t ier)
141{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700142 intel_uncore_write(uncore, imr, 0xffffffff);
143 intel_uncore_posting_read(uncore, imr);
Paulo Zanoni5c502442014-04-01 15:37:11 -0300144
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700145 intel_uncore_write(uncore, ier, 0);
Paulo Zanonia9d356a2014-04-01 15:37:09 -0300146
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700147 /* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700148 intel_uncore_write(uncore, iir, 0xffffffff);
149 intel_uncore_posting_read(uncore, iir);
150 intel_uncore_write(uncore, iir, 0xffffffff);
151 intel_uncore_posting_read(uncore, iir);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700152}
153
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700154static void gen2_irq_reset(struct intel_uncore *uncore)
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700155{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700156 intel_uncore_write16(uncore, GEN2_IMR, 0xffff);
157 intel_uncore_posting_read16(uncore, GEN2_IMR);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700158
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700159 intel_uncore_write16(uncore, GEN2_IER, 0);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700160
161 /* IIR can theoretically queue up two events. Be paranoid. */
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700162 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
163 intel_uncore_posting_read16(uncore, GEN2_IIR);
164 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
165 intel_uncore_posting_read16(uncore, GEN2_IIR);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700166}
167
168#define GEN8_IRQ_RESET_NDX(type, which) \
169({ \
170 unsigned int which_ = which; \
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700171 gen3_irq_reset(&dev_priv->uncore, GEN8_##type##_IMR(which_), \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700172 GEN8_##type##_IIR(which_), GEN8_##type##_IER(which_)); \
173})
174
175#define GEN3_IRQ_RESET(type) \
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700176 gen3_irq_reset(&dev_priv->uncore, type##IMR, type##IIR, type##IER)
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700177
Paulo Zanoni2918c3c2019-04-10 16:53:41 -0700178#define GEN2_IRQ_RESET() \
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700179 gen2_irq_reset(&dev_priv->uncore)
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300180
Paulo Zanoni337ba012014-04-01 15:37:16 -0300181/*
182 * We should clear IMR at preinstall/uninstall, and just check at postinstall.
183 */
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700184static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg)
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300185{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700186 u32 val = intel_uncore_read(uncore, reg);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300187
188 if (val == 0)
189 return;
190
191 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200192 i915_mmio_reg_offset(reg), val);
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700193 intel_uncore_write(uncore, reg, 0xffffffff);
194 intel_uncore_posting_read(uncore, reg);
195 intel_uncore_write(uncore, reg, 0xffffffff);
196 intel_uncore_posting_read(uncore, reg);
Ville Syrjäläb51a2842015-09-18 20:03:41 +0300197}
Paulo Zanoni337ba012014-04-01 15:37:16 -0300198
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700199static void gen2_assert_iir_is_zero(struct intel_uncore *uncore)
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300200{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700201 u16 val = intel_uncore_read16(uncore, GEN2_IIR);
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300202
203 if (val == 0)
204 return;
205
206 WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n",
Paulo Zanoni9d9523d2019-04-10 16:53:42 -0700207 i915_mmio_reg_offset(GEN2_IIR), val);
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700208 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
209 intel_uncore_posting_read16(uncore, GEN2_IIR);
210 intel_uncore_write16(uncore, GEN2_IIR, 0xffff);
211 intel_uncore_posting_read16(uncore, GEN2_IIR);
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300212}
213
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700214static void gen3_irq_init(struct intel_uncore *uncore,
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700215 i915_reg_t imr, u32 imr_val,
216 i915_reg_t ier, u32 ier_val,
217 i915_reg_t iir)
218{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700219 gen3_assert_iir_is_zero(uncore, iir);
Paulo Zanoni35079892014-04-01 15:37:15 -0300220
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700221 intel_uncore_write(uncore, ier, ier_val);
222 intel_uncore_write(uncore, imr, imr_val);
223 intel_uncore_posting_read(uncore, imr);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700224}
Paulo Zanoni35079892014-04-01 15:37:15 -0300225
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700226static void gen2_irq_init(struct intel_uncore *uncore,
Paulo Zanoni2918c3c2019-04-10 16:53:41 -0700227 u32 imr_val, u32 ier_val)
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700228{
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700229 gen2_assert_iir_is_zero(uncore);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700230
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700231 intel_uncore_write16(uncore, GEN2_IER, ier_val);
232 intel_uncore_write16(uncore, GEN2_IMR, imr_val);
233 intel_uncore_posting_read16(uncore, GEN2_IMR);
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700234}
235
236#define GEN8_IRQ_INIT_NDX(type, which, imr_val, ier_val) \
237({ \
238 unsigned int which_ = which; \
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700239 gen3_irq_init(&dev_priv->uncore, \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700240 GEN8_##type##_IMR(which_), imr_val, \
241 GEN8_##type##_IER(which_), ier_val, \
242 GEN8_##type##_IIR(which_)); \
243})
244
245#define GEN3_IRQ_INIT(type, imr_val, ier_val) \
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700246 gen3_irq_init(&dev_priv->uncore, \
Paulo Zanoni68eb49b2019-04-10 16:53:40 -0700247 type##IMR, imr_val, \
248 type##IER, ier_val, \
249 type##IIR)
250
Paulo Zanoni2918c3c2019-04-10 16:53:41 -0700251#define GEN2_IRQ_INIT(imr_val, ier_val) \
Paulo Zanoni65f42cd2019-04-10 16:53:43 -0700252 gen2_irq_init(&dev_priv->uncore, imr_val, ier_val)
Ville Syrjäläe9e98482017-08-18 21:36:54 +0300253
Imre Deakc9a9a262014-11-05 20:48:37 +0200254static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530255static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir);
Imre Deakc9a9a262014-11-05 20:48:37 +0200256
Egbert Eich0706f172015-09-23 16:15:27 +0200257/* For display hotplug interrupt */
258static inline void
259i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200260 u32 mask,
261 u32 bits)
Egbert Eich0706f172015-09-23 16:15:27 +0200262{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200263 u32 val;
Egbert Eich0706f172015-09-23 16:15:27 +0200264
Chris Wilson67520412017-03-02 13:28:01 +0000265 lockdep_assert_held(&dev_priv->irq_lock);
Egbert Eich0706f172015-09-23 16:15:27 +0200266 WARN_ON(bits & ~mask);
267
268 val = I915_READ(PORT_HOTPLUG_EN);
269 val &= ~mask;
270 val |= bits;
271 I915_WRITE(PORT_HOTPLUG_EN, val);
272}
273
274/**
275 * i915_hotplug_interrupt_update - update hotplug interrupt enable
276 * @dev_priv: driver private
277 * @mask: bits to update
278 * @bits: bits to enable
279 * NOTE: the HPD enable bits are modified both inside and outside
280 * of an interrupt context. To avoid that read-modify-write cycles
281 * interfer, these bits are protected by a spinlock. Since this
282 * function is usually not called from a context where the lock is
283 * held already, this function acquires the lock itself. A non-locking
284 * version is also available.
285 */
286void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200287 u32 mask,
288 u32 bits)
Egbert Eich0706f172015-09-23 16:15:27 +0200289{
290 spin_lock_irq(&dev_priv->irq_lock);
291 i915_hotplug_interrupt_update_locked(dev_priv, mask, bits);
292 spin_unlock_irq(&dev_priv->irq_lock);
293}
294
Oscar Mateo96606f32018-04-06 12:32:37 +0300295static u32
296gen11_gt_engine_identity(struct drm_i915_private * const i915,
297 const unsigned int bank, const unsigned int bit);
298
Chris Wilson60a94322018-07-13 21:35:29 +0100299static bool gen11_reset_one_iir(struct drm_i915_private * const i915,
300 const unsigned int bank,
301 const unsigned int bit)
Oscar Mateo96606f32018-04-06 12:32:37 +0300302{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -0700303 void __iomem * const regs = i915->uncore.regs;
Oscar Mateo96606f32018-04-06 12:32:37 +0300304 u32 dw;
305
306 lockdep_assert_held(&i915->irq_lock);
307
308 dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
309 if (dw & BIT(bit)) {
310 /*
311 * According to the BSpec, DW_IIR bits cannot be cleared without
312 * first servicing the Selector & Shared IIR registers.
313 */
314 gen11_gt_engine_identity(i915, bank, bit);
315
316 /*
317 * We locked GT INT DW by reading it. If we want to (try
318 * to) recover from this succesfully, we need to clear
319 * our bit, otherwise we are locking the register for
320 * everybody.
321 */
322 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), BIT(bit));
323
324 return true;
325 }
326
327 return false;
328}
329
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300330/**
331 * ilk_update_display_irq - update DEIMR
332 * @dev_priv: driver private
333 * @interrupt_mask: mask of interrupt bits to update
334 * @enabled_irq_mask: mask of interrupt bits to enable
335 */
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +0200336void ilk_update_display_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200337 u32 interrupt_mask,
338 u32 enabled_irq_mask)
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800339{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200340 u32 new_val;
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300341
Chris Wilson67520412017-03-02 13:28:01 +0000342 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetter4bc9d432013-06-27 13:44:58 +0200343
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300344 WARN_ON(enabled_irq_mask & ~interrupt_mask);
345
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700346 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300347 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300348
Ville Syrjäläd9dc34f12015-08-27 23:55:58 +0300349 new_val = dev_priv->irq_mask;
350 new_val &= ~interrupt_mask;
351 new_val |= (~enabled_irq_mask & interrupt_mask);
352
353 if (new_val != dev_priv->irq_mask) {
354 dev_priv->irq_mask = new_val;
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000355 I915_WRITE(DEIMR, dev_priv->irq_mask);
Chris Wilson3143a2b2010-11-16 15:55:10 +0000356 POSTING_READ(DEIMR);
Zhenyu Wang036a4a72009-06-08 14:40:19 +0800357 }
358}
359
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300360/**
361 * ilk_update_gt_irq - update GTIMR
362 * @dev_priv: driver private
363 * @interrupt_mask: mask of interrupt bits to update
364 * @enabled_irq_mask: mask of interrupt bits to enable
365 */
366static void ilk_update_gt_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200367 u32 interrupt_mask,
368 u32 enabled_irq_mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300369{
Chris Wilson67520412017-03-02 13:28:01 +0000370 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300371
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100372 WARN_ON(enabled_irq_mask & ~interrupt_mask);
373
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700374 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300375 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300376
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300377 dev_priv->gt_irq_mask &= ~interrupt_mask;
378 dev_priv->gt_irq_mask |= (~enabled_irq_mask & interrupt_mask);
379 I915_WRITE(GTIMR, dev_priv->gt_irq_mask);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300380}
381
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200382void gen5_enable_gt_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300383{
384 ilk_update_gt_irq(dev_priv, mask, mask);
Chris Wilson31bb59c2016-07-01 17:23:27 +0100385 POSTING_READ_FW(GTIMR);
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300386}
387
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200388void gen5_disable_gt_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoni43eaea12013-08-06 18:57:12 -0300389{
390 ilk_update_gt_irq(dev_priv, mask, 0);
391}
392
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200393static i915_reg_t gen6_pm_iir(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200394{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300395 WARN_ON_ONCE(INTEL_GEN(dev_priv) >= 11);
396
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -0700397 return INTEL_GEN(dev_priv) >= 8 ? GEN8_GT_IIR(2) : GEN6_PMIIR;
Imre Deakb900b942014-11-05 20:48:48 +0200398}
399
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300400static void write_pm_imr(struct drm_i915_private *dev_priv)
Imre Deaka72fbc32014-11-05 20:48:31 +0200401{
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300402 i915_reg_t reg;
403 u32 mask = dev_priv->pm_imr;
404
405 if (INTEL_GEN(dev_priv) >= 11) {
406 reg = GEN11_GPM_WGBOXPERF_INTR_MASK;
407 /* pm is in upper half */
408 mask = mask << 16;
409 } else if (INTEL_GEN(dev_priv) >= 8) {
410 reg = GEN8_GT_IMR(2);
411 } else {
412 reg = GEN6_PMIMR;
413 }
414
415 I915_WRITE(reg, mask);
416 POSTING_READ(reg);
Imre Deaka72fbc32014-11-05 20:48:31 +0200417}
418
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300419static void write_pm_ier(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200420{
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300421 i915_reg_t reg;
422 u32 mask = dev_priv->pm_ier;
423
424 if (INTEL_GEN(dev_priv) >= 11) {
425 reg = GEN11_GPM_WGBOXPERF_INTR_ENABLE;
426 /* pm is in upper half */
427 mask = mask << 16;
428 } else if (INTEL_GEN(dev_priv) >= 8) {
429 reg = GEN8_GT_IER(2);
430 } else {
431 reg = GEN6_PMIER;
432 }
433
434 I915_WRITE(reg, mask);
Imre Deakb900b942014-11-05 20:48:48 +0200435}
436
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300437/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200438 * snb_update_pm_irq - update GEN6_PMIMR
439 * @dev_priv: driver private
440 * @interrupt_mask: mask of interrupt bits to update
441 * @enabled_irq_mask: mask of interrupt bits to enable
442 */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300443static void snb_update_pm_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200444 u32 interrupt_mask,
445 u32 enabled_irq_mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300446{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200447 u32 new_val;
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300448
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100449 WARN_ON(enabled_irq_mask & ~interrupt_mask);
450
Chris Wilson67520412017-03-02 13:28:01 +0000451 lockdep_assert_held(&dev_priv->irq_lock);
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300452
Akash Goelf4e9af42016-10-12 21:54:30 +0530453 new_val = dev_priv->pm_imr;
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300454 new_val &= ~interrupt_mask;
455 new_val |= (~enabled_irq_mask & interrupt_mask);
456
Akash Goelf4e9af42016-10-12 21:54:30 +0530457 if (new_val != dev_priv->pm_imr) {
458 dev_priv->pm_imr = new_val;
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300459 write_pm_imr(dev_priv);
Paulo Zanonif52ecbc2013-08-06 18:57:14 -0300460 }
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300461}
462
Akash Goelf4e9af42016-10-12 21:54:30 +0530463void gen6_unmask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300464{
Imre Deak9939fba2014-11-20 23:01:47 +0200465 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
466 return;
467
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300468 snb_update_pm_irq(dev_priv, mask, mask);
469}
470
Akash Goelf4e9af42016-10-12 21:54:30 +0530471static void __gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Imre Deak9939fba2014-11-20 23:01:47 +0200472{
473 snb_update_pm_irq(dev_priv, mask, 0);
474}
475
Akash Goelf4e9af42016-10-12 21:54:30 +0530476void gen6_mask_pm_irq(struct drm_i915_private *dev_priv, u32 mask)
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300477{
Imre Deak9939fba2014-11-20 23:01:47 +0200478 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
479 return;
480
Akash Goelf4e9af42016-10-12 21:54:30 +0530481 __gen6_mask_pm_irq(dev_priv, mask);
482}
483
Oscar Mateo3814fd72017-08-23 16:58:24 -0700484static void gen6_reset_pm_iir(struct drm_i915_private *dev_priv, u32 reset_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530485{
486 i915_reg_t reg = gen6_pm_iir(dev_priv);
487
Chris Wilson67520412017-03-02 13:28:01 +0000488 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530489
490 I915_WRITE(reg, reset_mask);
491 I915_WRITE(reg, reset_mask);
492 POSTING_READ(reg);
493}
494
Oscar Mateo3814fd72017-08-23 16:58:24 -0700495static void gen6_enable_pm_irq(struct drm_i915_private *dev_priv, u32 enable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530496{
Chris Wilson67520412017-03-02 13:28:01 +0000497 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530498
499 dev_priv->pm_ier |= enable_mask;
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300500 write_pm_ier(dev_priv);
Akash Goelf4e9af42016-10-12 21:54:30 +0530501 gen6_unmask_pm_irq(dev_priv, enable_mask);
502 /* unmask_pm_irq provides an implicit barrier (POSTING_READ) */
503}
504
Oscar Mateo3814fd72017-08-23 16:58:24 -0700505static void gen6_disable_pm_irq(struct drm_i915_private *dev_priv, u32 disable_mask)
Akash Goelf4e9af42016-10-12 21:54:30 +0530506{
Chris Wilson67520412017-03-02 13:28:01 +0000507 lockdep_assert_held(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +0530508
509 dev_priv->pm_ier &= ~disable_mask;
510 __gen6_mask_pm_irq(dev_priv, disable_mask);
Mika Kuoppala917dc6b2019-04-10 13:59:22 +0300511 write_pm_ier(dev_priv);
Akash Goelf4e9af42016-10-12 21:54:30 +0530512 /* though a barrier is missing here, but don't really need a one */
Paulo Zanoniedbfdb42013-08-06 18:57:13 -0300513}
514
Oscar Mateod02b98b2018-04-05 17:00:50 +0300515void gen11_reset_rps_interrupts(struct drm_i915_private *dev_priv)
516{
Oscar Mateod02b98b2018-04-05 17:00:50 +0300517 spin_lock_irq(&dev_priv->irq_lock);
518
Oscar Mateo96606f32018-04-06 12:32:37 +0300519 while (gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM))
520 ;
Oscar Mateod02b98b2018-04-05 17:00:50 +0300521
522 dev_priv->gt_pm.rps.pm_iir = 0;
523
524 spin_unlock_irq(&dev_priv->irq_lock);
525}
526
Chris Wilsondc979972016-05-10 14:10:04 +0100527void gen6_reset_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deak3cc134e2014-11-19 15:30:03 +0200528{
Imre Deak3cc134e2014-11-19 15:30:03 +0200529 spin_lock_irq(&dev_priv->irq_lock);
Chris Wilson4668f692018-08-02 11:06:30 +0100530 gen6_reset_pm_iir(dev_priv, GEN6_PM_RPS_EVENTS);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100531 dev_priv->gt_pm.rps.pm_iir = 0;
Imre Deak3cc134e2014-11-19 15:30:03 +0200532 spin_unlock_irq(&dev_priv->irq_lock);
533}
534
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100535void gen6_enable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200536{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100537 struct intel_rps *rps = &dev_priv->gt_pm.rps;
538
539 if (READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100540 return;
541
Imre Deakb900b942014-11-05 20:48:48 +0200542 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100543 WARN_ON_ONCE(rps->pm_iir);
Oscar Mateo96606f32018-04-06 12:32:37 +0300544
Oscar Mateod02b98b2018-04-05 17:00:50 +0300545 if (INTEL_GEN(dev_priv) >= 11)
Oscar Mateo96606f32018-04-06 12:32:37 +0300546 WARN_ON_ONCE(gen11_reset_one_iir(dev_priv, 0, GEN11_GTPM));
Oscar Mateod02b98b2018-04-05 17:00:50 +0300547 else
548 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) & dev_priv->pm_rps_events);
Oscar Mateo96606f32018-04-06 12:32:37 +0300549
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100550 rps->interrupts_enabled = true;
Imre Deakb900b942014-11-05 20:48:48 +0200551 gen6_enable_pm_irq(dev_priv, dev_priv->pm_rps_events);
Imre Deak78e68d32014-12-15 18:59:27 +0200552
Imre Deakb900b942014-11-05 20:48:48 +0200553 spin_unlock_irq(&dev_priv->irq_lock);
554}
555
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100556void gen6_disable_rps_interrupts(struct drm_i915_private *dev_priv)
Imre Deakb900b942014-11-05 20:48:48 +0200557{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100558 struct intel_rps *rps = &dev_priv->gt_pm.rps;
559
560 if (!READ_ONCE(rps->interrupts_enabled))
Chris Wilsonf2a91d12016-09-21 14:51:06 +0100561 return;
562
Imre Deakd4d70aa2014-11-19 15:30:04 +0200563 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100564 rps->interrupts_enabled = false;
Imre Deak9939fba2014-11-20 23:01:47 +0200565
Dave Gordonb20e3cf2016-09-12 21:19:35 +0100566 I915_WRITE(GEN6_PMINTRMSK, gen6_sanitize_rps_pm_mask(dev_priv, ~0u));
Imre Deak9939fba2014-11-20 23:01:47 +0200567
Chris Wilson4668f692018-08-02 11:06:30 +0100568 gen6_disable_pm_irq(dev_priv, GEN6_PM_RPS_EVENTS);
Imre Deak58072cc2015-03-23 19:11:34 +0200569
570 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilson91c8a322016-07-05 10:40:23 +0100571 synchronize_irq(dev_priv->drm.irq);
Chris Wilsonc33d2472016-07-04 08:08:36 +0100572
573 /* Now that we will not be generating any more work, flush any
Oscar Mateo3814fd72017-08-23 16:58:24 -0700574 * outstanding tasks. As we are called on the RPS idle path,
Chris Wilsonc33d2472016-07-04 08:08:36 +0100575 * we will reset the GPU to minimum frequencies, so the current
576 * state of the worker can be discarded.
577 */
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +0100578 cancel_work_sync(&rps->work);
Oscar Mateod02b98b2018-04-05 17:00:50 +0300579 if (INTEL_GEN(dev_priv) >= 11)
580 gen11_reset_rps_interrupts(dev_priv);
581 else
582 gen6_reset_rps_interrupts(dev_priv);
Imre Deakb900b942014-11-05 20:48:48 +0200583}
584
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530585void gen9_reset_guc_interrupts(struct drm_i915_private *dev_priv)
586{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530587 assert_rpm_wakelock_held(dev_priv);
588
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530589 spin_lock_irq(&dev_priv->irq_lock);
590 gen6_reset_pm_iir(dev_priv, dev_priv->pm_guc_events);
591 spin_unlock_irq(&dev_priv->irq_lock);
592}
593
594void gen9_enable_guc_interrupts(struct drm_i915_private *dev_priv)
595{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530596 assert_rpm_wakelock_held(dev_priv);
597
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530598 spin_lock_irq(&dev_priv->irq_lock);
599 if (!dev_priv->guc.interrupts_enabled) {
600 WARN_ON_ONCE(I915_READ(gen6_pm_iir(dev_priv)) &
601 dev_priv->pm_guc_events);
602 dev_priv->guc.interrupts_enabled = true;
603 gen6_enable_pm_irq(dev_priv, dev_priv->pm_guc_events);
604 }
605 spin_unlock_irq(&dev_priv->irq_lock);
606}
607
608void gen9_disable_guc_interrupts(struct drm_i915_private *dev_priv)
609{
Sagar Arun Kamble1be333d2018-01-24 21:16:56 +0530610 assert_rpm_wakelock_held(dev_priv);
611
Sagar Arun Kamble26705e22016-10-12 21:54:31 +0530612 spin_lock_irq(&dev_priv->irq_lock);
613 dev_priv->guc.interrupts_enabled = false;
614
615 gen6_disable_pm_irq(dev_priv, dev_priv->pm_guc_events);
616
617 spin_unlock_irq(&dev_priv->irq_lock);
618 synchronize_irq(dev_priv->drm.irq);
619
620 gen9_reset_guc_interrupts(dev_priv);
621}
622
Ben Widawsky09610212014-05-15 20:58:08 +0300623/**
Ville Syrjälä81fd8742015-11-25 16:21:30 +0200624 * bdw_update_port_irq - update DE port interrupt
625 * @dev_priv: driver private
626 * @interrupt_mask: mask of interrupt bits to update
627 * @enabled_irq_mask: mask of interrupt bits to enable
628 */
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300629static void bdw_update_port_irq(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200630 u32 interrupt_mask,
631 u32 enabled_irq_mask)
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300632{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200633 u32 new_val;
634 u32 old_val;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300635
Chris Wilson67520412017-03-02 13:28:01 +0000636 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +0300637
638 WARN_ON(enabled_irq_mask & ~interrupt_mask);
639
640 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
641 return;
642
643 old_val = I915_READ(GEN8_DE_PORT_IMR);
644
645 new_val = old_val;
646 new_val &= ~interrupt_mask;
647 new_val |= (~enabled_irq_mask & interrupt_mask);
648
649 if (new_val != old_val) {
650 I915_WRITE(GEN8_DE_PORT_IMR, new_val);
651 POSTING_READ(GEN8_DE_PORT_IMR);
652 }
653}
654
655/**
Ville Syrjälä013d3752015-11-23 18:06:17 +0200656 * bdw_update_pipe_irq - update DE pipe interrupt
657 * @dev_priv: driver private
658 * @pipe: pipe whose interrupt to update
659 * @interrupt_mask: mask of interrupt bits to update
660 * @enabled_irq_mask: mask of interrupt bits to enable
661 */
662void bdw_update_pipe_irq(struct drm_i915_private *dev_priv,
663 enum pipe pipe,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200664 u32 interrupt_mask,
665 u32 enabled_irq_mask)
Ville Syrjälä013d3752015-11-23 18:06:17 +0200666{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200667 u32 new_val;
Ville Syrjälä013d3752015-11-23 18:06:17 +0200668
Chris Wilson67520412017-03-02 13:28:01 +0000669 lockdep_assert_held(&dev_priv->irq_lock);
Ville Syrjälä013d3752015-11-23 18:06:17 +0200670
671 WARN_ON(enabled_irq_mask & ~interrupt_mask);
672
673 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
674 return;
675
676 new_val = dev_priv->de_irq_mask[pipe];
677 new_val &= ~interrupt_mask;
678 new_val |= (~enabled_irq_mask & interrupt_mask);
679
680 if (new_val != dev_priv->de_irq_mask[pipe]) {
681 dev_priv->de_irq_mask[pipe] = new_val;
682 I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]);
683 POSTING_READ(GEN8_DE_PIPE_IMR(pipe));
684 }
685}
686
687/**
Daniel Vetterfee884e2013-07-04 23:35:21 +0200688 * ibx_display_interrupt_update - update SDEIMR
689 * @dev_priv: driver private
690 * @interrupt_mask: mask of interrupt bits to update
691 * @enabled_irq_mask: mask of interrupt bits to enable
692 */
Daniel Vetter47339cd2014-09-30 10:56:46 +0200693void ibx_display_interrupt_update(struct drm_i915_private *dev_priv,
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200694 u32 interrupt_mask,
695 u32 enabled_irq_mask)
Daniel Vetterfee884e2013-07-04 23:35:21 +0200696{
Jani Nikulaa9c287c2019-01-16 11:15:24 +0200697 u32 sdeimr = I915_READ(SDEIMR);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200698 sdeimr &= ~interrupt_mask;
699 sdeimr |= (~enabled_irq_mask & interrupt_mask);
700
Daniel Vetter15a17aa2014-12-08 16:30:00 +0100701 WARN_ON(enabled_irq_mask & ~interrupt_mask);
702
Chris Wilson67520412017-03-02 13:28:01 +0000703 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterfee884e2013-07-04 23:35:21 +0200704
Jesse Barnes9df7575f2014-06-20 09:29:20 -0700705 if (WARN_ON(!intel_irqs_enabled(dev_priv)))
Paulo Zanonic67a4702013-08-19 13:18:09 -0300706 return;
Paulo Zanonic67a4702013-08-19 13:18:09 -0300707
Daniel Vetterfee884e2013-07-04 23:35:21 +0200708 I915_WRITE(SDEIMR, sdeimr);
709 POSTING_READ(SDEIMR);
710}
Paulo Zanoni86642812013-04-12 17:57:57 -0300711
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300712u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv,
713 enum pipe pipe)
Keith Packard7c463582008-11-04 02:03:27 -0800714{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300715 u32 status_mask = dev_priv->pipestat_irq_mask[pipe];
Imre Deak10c59c52014-02-10 18:42:48 +0200716 u32 enable_mask = status_mask << 16;
717
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300718 lockdep_assert_held(&dev_priv->irq_lock);
719
720 if (INTEL_GEN(dev_priv) < 5)
721 goto out;
722
Imre Deak10c59c52014-02-10 18:42:48 +0200723 /*
Ville Syrjälä724a6902014-04-09 13:28:48 +0300724 * On pipe A we don't support the PSR interrupt yet,
725 * on pipe B and C the same bit MBZ.
Imre Deak10c59c52014-02-10 18:42:48 +0200726 */
727 if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV))
728 return 0;
Ville Syrjälä724a6902014-04-09 13:28:48 +0300729 /*
730 * On pipe B and C we don't support the PSR interrupt yet, on pipe
731 * A the same bit is for perf counters which we don't use either.
732 */
733 if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV))
734 return 0;
Imre Deak10c59c52014-02-10 18:42:48 +0200735
736 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS |
737 SPRITE0_FLIP_DONE_INT_EN_VLV |
738 SPRITE1_FLIP_DONE_INT_EN_VLV);
739 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV)
740 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV;
741 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV)
742 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV;
743
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300744out:
745 WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK ||
746 status_mask & ~PIPESTAT_INT_STATUS_MASK,
747 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n",
748 pipe_name(pipe), enable_mask, status_mask);
749
Imre Deak10c59c52014-02-10 18:42:48 +0200750 return enable_mask;
751}
752
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300753void i915_enable_pipestat(struct drm_i915_private *dev_priv,
754 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200755{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300756 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200757 u32 enable_mask;
758
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300759 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
760 "pipe %c: status_mask=0x%x\n",
761 pipe_name(pipe), status_mask);
762
763 lockdep_assert_held(&dev_priv->irq_lock);
764 WARN_ON(!intel_irqs_enabled(dev_priv));
765
766 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask)
767 return;
768
769 dev_priv->pipestat_irq_mask[pipe] |= status_mask;
770 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
771
772 I915_WRITE(reg, enable_mask | status_mask);
773 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200774}
775
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300776void i915_disable_pipestat(struct drm_i915_private *dev_priv,
777 enum pipe pipe, u32 status_mask)
Imre Deak755e9012014-02-10 18:42:47 +0200778{
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300779 i915_reg_t reg = PIPESTAT(pipe);
Imre Deak755e9012014-02-10 18:42:47 +0200780 u32 enable_mask;
781
Ville Syrjälä6b12ca52017-09-14 18:17:31 +0300782 WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK,
783 "pipe %c: status_mask=0x%x\n",
784 pipe_name(pipe), status_mask);
785
786 lockdep_assert_held(&dev_priv->irq_lock);
787 WARN_ON(!intel_irqs_enabled(dev_priv));
788
789 if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0)
790 return;
791
792 dev_priv->pipestat_irq_mask[pipe] &= ~status_mask;
793 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
794
795 I915_WRITE(reg, enable_mask | status_mask);
796 POSTING_READ(reg);
Imre Deak755e9012014-02-10 18:42:47 +0200797}
798
Ville Syrjäläf3e30482019-03-18 18:56:31 +0200799static bool i915_has_asle(struct drm_i915_private *dev_priv)
800{
801 if (!dev_priv->opregion.asle)
802 return false;
803
804 return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv);
805}
806
=?utf-8?q?Michel_D=C3=A4nzer?=a6b54f32006-10-24 23:37:43 +1000807/**
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300808 * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion
Tvrtko Ursulin14bb2c12016-06-03 14:02:17 +0100809 * @dev_priv: i915 device private
Zhao Yakui01c66882009-10-28 05:10:00 +0000810 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100811static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv)
Zhao Yakui01c66882009-10-28 05:10:00 +0000812{
Ville Syrjäläf3e30482019-03-18 18:56:31 +0200813 if (!i915_has_asle(dev_priv))
Jani Nikulaf49e38d2013-04-29 13:02:54 +0300814 return;
815
Daniel Vetter13321782014-09-15 14:55:29 +0200816 spin_lock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000817
Imre Deak755e9012014-02-10 18:42:47 +0200818 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +0100819 if (INTEL_GEN(dev_priv) >= 4)
Daniel Vetter3b6c42e2013-10-21 18:04:35 +0200820 i915_enable_pipestat(dev_priv, PIPE_A,
Imre Deak755e9012014-02-10 18:42:47 +0200821 PIPE_LEGACY_BLC_EVENT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +0000822
Daniel Vetter13321782014-09-15 14:55:29 +0200823 spin_unlock_irq(&dev_priv->irq_lock);
Zhao Yakui01c66882009-10-28 05:10:00 +0000824}
825
Ville Syrjäläf75f3742014-05-15 20:20:36 +0300826/*
827 * This timing diagram depicts the video signal in and
828 * around the vertical blanking period.
829 *
830 * Assumptions about the fictitious mode used in this example:
831 * vblank_start >= 3
832 * vsync_start = vblank_start + 1
833 * vsync_end = vblank_start + 2
834 * vtotal = vblank_start + 3
835 *
836 * start of vblank:
837 * latch double buffered registers
838 * increment frame counter (ctg+)
839 * generate start of vblank interrupt (gen4+)
840 * |
841 * | frame start:
842 * | generate frame start interrupt (aka. vblank interrupt) (gmch)
843 * | may be shifted forward 1-3 extra lines via PIPECONF
844 * | |
845 * | | start of vsync:
846 * | | generate vsync interrupt
847 * | | |
848 * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx
849 * . \hs/ . \hs/ \hs/ \hs/ . \hs/
850 * ----va---> <-----------------vb--------------------> <--------va-------------
851 * | | <----vs-----> |
852 * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2)
853 * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+)
854 * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi)
855 * | | |
856 * last visible pixel first visible pixel
857 * | increment frame counter (gen3/4)
858 * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4)
859 *
860 * x = horizontal active
861 * _ = horizontal blanking
862 * hs = horizontal sync
863 * va = vertical active
864 * vb = vertical blanking
865 * vs = vertical sync
866 * vbs = vblank_start (number)
867 *
868 * Summary:
869 * - most events happen at the start of horizontal sync
870 * - frame start happens at the start of horizontal blank, 1-4 lines
871 * (depending on PIPECONF settings) after the start of vblank
872 * - gen3/4 pixel and frame counter are synchronized with the start
873 * of horizontal active on the first line of vertical active
874 */
875
Keith Packard42f52ef2008-10-18 19:39:29 -0700876/* Called from drm generic code, passed a 'crtc', which
877 * we use as a pipe index
878 */
Thierry Reding88e72712015-09-24 18:35:31 +0200879static u32 i915_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700880{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100881 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä32db0b62018-11-27 22:05:50 +0200882 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
883 const struct drm_display_mode *mode = &vblank->hwmode;
Ville Syrjäläf0f59a02015-11-18 15:33:26 +0200884 i915_reg_t high_frame, low_frame;
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300885 u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal;
Ville Syrjälä694e4092017-03-09 17:44:30 +0200886 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700887
Ville Syrjälä32db0b62018-11-27 22:05:50 +0200888 /*
889 * On i965gm TV output the frame counter only works up to
890 * the point when we enable the TV encoder. After that the
891 * frame counter ceases to work and reads zero. We need a
892 * vblank wait before enabling the TV encoder and so we
893 * have to enable vblank interrupts while the frame counter
894 * is still in a working state. However the core vblank code
895 * does not like us returning non-zero frame counter values
896 * when we've told it that we don't have a working frame
897 * counter. Thus we must stop non-zero values leaking out.
898 */
899 if (!vblank->max_vblank_count)
900 return 0;
901
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +0100902 htotal = mode->crtc_htotal;
903 hsync_start = mode->crtc_hsync_start;
904 vbl_start = mode->crtc_vblank_start;
905 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
906 vbl_start = DIV_ROUND_UP(vbl_start, 2);
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300907
Ville Syrjälä0b2a8e02014-04-29 13:35:50 +0300908 /* Convert to pixel count */
909 vbl_start *= htotal;
910
911 /* Start of vblank event occurs at start of hsync */
912 vbl_start -= htotal - hsync_start;
913
Jesse Barnes9db4a9c2011-02-07 12:26:52 -0800914 high_frame = PIPEFRAME(pipe);
915 low_frame = PIPEFRAMEPIXEL(pipe);
Chris Wilson5eddb702010-09-11 13:48:45 +0100916
Ville Syrjälä694e4092017-03-09 17:44:30 +0200917 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
918
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700919 /*
920 * High & low register fields aren't synchronized, so make sure
921 * we get a low value that's stable across two reads of the high
922 * register.
923 */
924 do {
Ville Syrjälä694e4092017-03-09 17:44:30 +0200925 high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
926 low = I915_READ_FW(low_frame);
927 high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700928 } while (high1 != high2);
929
Ville Syrjälä694e4092017-03-09 17:44:30 +0200930 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
931
Chris Wilson5eddb702010-09-11 13:48:45 +0100932 high1 >>= PIPE_FRAME_HIGH_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300933 pixel = low & PIPE_PIXEL_MASK;
Chris Wilson5eddb702010-09-11 13:48:45 +0100934 low >>= PIPE_FRAME_LOW_SHIFT;
Ville Syrjälä391f75e2013-09-25 19:55:26 +0300935
936 /*
937 * The frame counter increments at beginning of active.
938 * Cook up a vblank counter by also checking the pixel
939 * counter against vblank start.
940 */
Ville Syrjäläedc08d02013-11-06 13:56:27 -0200941 return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -0700942}
943
Dave Airlie974e59b2015-10-30 09:45:33 +1000944static u32 g4x_get_vblank_counter(struct drm_device *dev, unsigned int pipe)
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800945{
Chris Wilsonfac5e232016-07-04 11:34:36 +0100946 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800947
Ville Syrjälä649636e2015-09-22 19:50:01 +0300948 return I915_READ(PIPE_FRMCOUNT_G4X(pipe));
Jesse Barnes9880b7a2009-02-06 10:22:41 -0800949}
950
Uma Shankaraec02462017-09-25 19:26:01 +0530951/*
952 * On certain encoders on certain platforms, pipe
953 * scanline register will not work to get the scanline,
954 * since the timings are driven from the PORT or issues
955 * with scanline register updates.
956 * This function will use Framestamp and current
957 * timestamp registers to calculate the scanline.
958 */
959static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc)
960{
961 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
962 struct drm_vblank_crtc *vblank =
963 &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
964 const struct drm_display_mode *mode = &vblank->hwmode;
965 u32 vblank_start = mode->crtc_vblank_start;
966 u32 vtotal = mode->crtc_vtotal;
967 u32 htotal = mode->crtc_htotal;
968 u32 clock = mode->crtc_clock;
969 u32 scanline, scan_prev_time, scan_curr_time, scan_post_time;
970
971 /*
972 * To avoid the race condition where we might cross into the
973 * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR
974 * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR
975 * during the same frame.
976 */
977 do {
978 /*
979 * This field provides read back of the display
980 * pipe frame time stamp. The time stamp value
981 * is sampled at every start of vertical blank.
982 */
983 scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
984
985 /*
986 * The TIMESTAMP_CTR register has the current
987 * time stamp value.
988 */
989 scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR);
990
991 scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe));
992 } while (scan_post_time != scan_prev_time);
993
994 scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time,
995 clock), 1000 * htotal);
996 scanline = min(scanline, vtotal - 1);
997 scanline = (scanline + vblank_start) % vtotal;
998
999 return scanline;
1000}
1001
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001002/* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */
Ville Syrjäläa225f072014-04-29 13:35:45 +03001003static int __intel_get_crtc_scanline(struct intel_crtc *crtc)
1004{
1005 struct drm_device *dev = crtc->base.dev;
Chris Wilsonfac5e232016-07-04 11:34:36 +01001006 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter5caa0fe2017-05-09 16:03:29 +02001007 const struct drm_display_mode *mode;
1008 struct drm_vblank_crtc *vblank;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001009 enum pipe pipe = crtc->pipe;
Ville Syrjälä80715b22014-05-15 20:23:23 +03001010 int position, vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001011
Ville Syrjälä72259532017-03-02 19:15:05 +02001012 if (!crtc->active)
1013 return -1;
1014
Daniel Vetter5caa0fe2017-05-09 16:03:29 +02001015 vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)];
1016 mode = &vblank->hwmode;
1017
Uma Shankaraec02462017-09-25 19:26:01 +05301018 if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP)
1019 return __intel_get_crtc_scanline_from_timestamp(crtc);
1020
Ville Syrjälä80715b22014-05-15 20:23:23 +03001021 vtotal = mode->crtc_vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001022 if (mode->flags & DRM_MODE_FLAG_INTERLACE)
1023 vtotal /= 2;
1024
Lucas De Marchicf819ef2018-12-12 10:10:43 -08001025 if (IS_GEN(dev_priv, 2))
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001026 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001027 else
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001028 position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001029
1030 /*
Jesse Barnes41b578f2015-09-22 12:15:54 -07001031 * On HSW, the DSL reg (0x70000) appears to return 0 if we
1032 * read it just before the start of vblank. So try it again
1033 * so we don't accidentally end up spanning a vblank frame
1034 * increment, causing the pipe_update_end() code to squak at us.
1035 *
1036 * The nature of this problem means we can't simply check the ISR
1037 * bit and return the vblank start value; nor can we use the scanline
1038 * debug register in the transcoder as it appears to have the same
1039 * problem. We may need to extend this to include other platforms,
1040 * but so far testing only shows the problem on HSW.
1041 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001042 if (HAS_DDI(dev_priv) && !position) {
Jesse Barnes41b578f2015-09-22 12:15:54 -07001043 int i, temp;
1044
1045 for (i = 0; i < 100; i++) {
1046 udelay(1);
Ville Syrjälä707bdd32017-03-09 17:44:31 +02001047 temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3;
Jesse Barnes41b578f2015-09-22 12:15:54 -07001048 if (temp != position) {
1049 position = temp;
1050 break;
1051 }
1052 }
1053 }
1054
1055 /*
Ville Syrjälä80715b22014-05-15 20:23:23 +03001056 * See update_scanline_offset() for the details on the
1057 * scanline_offset adjustment.
Ville Syrjäläa225f072014-04-29 13:35:45 +03001058 */
Ville Syrjälä80715b22014-05-15 20:23:23 +03001059 return (position + crtc->scanline_offset) % vtotal;
Ville Syrjäläa225f072014-04-29 13:35:45 +03001060}
1061
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001062static bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int pipe,
1063 bool in_vblank_irq, int *vpos, int *hpos,
1064 ktime_t *stime, ktime_t *etime,
1065 const struct drm_display_mode *mode)
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001066{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001067 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä98187832016-10-31 22:37:10 +02001068 struct intel_crtc *intel_crtc = intel_get_crtc_for_pipe(dev_priv,
1069 pipe);
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001070 int position;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001071 int vbl_start, vbl_end, hsync_start, htotal, vtotal;
Mario Kleinerad3543e2013-10-30 05:13:08 +01001072 unsigned long irqflags;
Ville Syrjälä8a920e22019-01-25 20:19:31 +02001073 bool use_scanline_counter = INTEL_GEN(dev_priv) >= 5 ||
1074 IS_G4X(dev_priv) || IS_GEN(dev_priv, 2) ||
1075 mode->private_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001076
Maarten Lankhorstfc467a222015-06-01 12:50:07 +02001077 if (WARN_ON(!mode->crtc_clock)) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001078 DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled "
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08001079 "pipe %c\n", pipe_name(pipe));
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001080 return false;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001081 }
1082
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03001083 htotal = mode->crtc_htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001084 hsync_start = mode->crtc_hsync_start;
Ville Syrjäläc2baf4b2013-09-23 14:48:50 +03001085 vtotal = mode->crtc_vtotal;
1086 vbl_start = mode->crtc_vblank_start;
1087 vbl_end = mode->crtc_vblank_end;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001088
Ville Syrjäläd31faf62013-10-28 16:31:41 +02001089 if (mode->flags & DRM_MODE_FLAG_INTERLACE) {
1090 vbl_start = DIV_ROUND_UP(vbl_start, 2);
1091 vbl_end /= 2;
1092 vtotal /= 2;
1093 }
1094
Mario Kleinerad3543e2013-10-30 05:13:08 +01001095 /*
1096 * Lock uncore.lock, as we will do multiple timing critical raw
1097 * register reads, potentially with preemption disabled, so the
1098 * following code must not block on uncore.lock.
1099 */
1100 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001101
Mario Kleinerad3543e2013-10-30 05:13:08 +01001102 /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */
1103
1104 /* Get optional system timestamp before query. */
1105 if (stime)
1106 *stime = ktime_get();
1107
Ville Syrjälä8a920e22019-01-25 20:19:31 +02001108 if (use_scanline_counter) {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001109 /* No obvious pixelcount register. Only query vertical
1110 * scanout position from Display scan line register.
1111 */
Ville Syrjäläa225f072014-04-29 13:35:45 +03001112 position = __intel_get_crtc_scanline(intel_crtc);
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001113 } else {
1114 /* Have access to pixelcount since start of frame.
1115 * We can split this into vertical and horizontal
1116 * scanout position.
1117 */
Ville Syrjälä75aa3f62015-10-22 15:34:56 +03001118 position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001119
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001120 /* convert to pixel counts */
1121 vbl_start *= htotal;
1122 vbl_end *= htotal;
1123 vtotal *= htotal;
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001124
1125 /*
Ville Syrjälä7e78f1cb2014-04-29 13:35:49 +03001126 * In interlaced modes, the pixel counter counts all pixels,
1127 * so one field will have htotal more pixels. In order to avoid
1128 * the reported position from jumping backwards when the pixel
1129 * counter is beyond the length of the shorter field, just
1130 * clamp the position the length of the shorter field. This
1131 * matches how the scanline counter based position works since
1132 * the scanline counter doesn't count the two half lines.
1133 */
1134 if (position >= vtotal)
1135 position = vtotal - 1;
1136
1137 /*
Ville Syrjälä78e8fc62014-04-29 13:35:44 +03001138 * Start of vblank interrupt is triggered at start of hsync,
1139 * just prior to the first active line of vblank. However we
1140 * consider lines to start at the leading edge of horizontal
1141 * active. So, should we get here before we've crossed into
1142 * the horizontal active of the first line in vblank, we would
1143 * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that,
1144 * always add htotal-hsync_start to the current pixel position.
1145 */
1146 position = (position + htotal - hsync_start) % vtotal;
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001147 }
1148
Mario Kleinerad3543e2013-10-30 05:13:08 +01001149 /* Get optional system timestamp after query. */
1150 if (etime)
1151 *etime = ktime_get();
1152
1153 /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */
1154
1155 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1156
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001157 /*
1158 * While in vblank, position will be negative
1159 * counting up towards 0 at vbl_end. And outside
1160 * vblank, position will be positive counting
1161 * up since vbl_end.
1162 */
1163 if (position >= vbl_start)
1164 position -= vbl_end;
1165 else
1166 position += vtotal - vbl_end;
1167
Ville Syrjälä8a920e22019-01-25 20:19:31 +02001168 if (use_scanline_counter) {
Ville Syrjälä3aa18df2013-10-11 19:10:32 +03001169 *vpos = position;
1170 *hpos = 0;
1171 } else {
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001172 *vpos = position / htotal;
1173 *hpos = position - (*vpos * htotal);
1174 }
1175
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02001176 return true;
Mario Kleiner0af7e4d2010-12-08 04:07:19 +01001177}
1178
Ville Syrjäläa225f072014-04-29 13:35:45 +03001179int intel_get_crtc_scanline(struct intel_crtc *crtc)
1180{
Chris Wilsonfac5e232016-07-04 11:34:36 +01001181 struct drm_i915_private *dev_priv = to_i915(crtc->base.dev);
Ville Syrjäläa225f072014-04-29 13:35:45 +03001182 unsigned long irqflags;
1183 int position;
1184
1185 spin_lock_irqsave(&dev_priv->uncore.lock, irqflags);
1186 position = __intel_get_crtc_scanline(crtc);
1187 spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags);
1188
1189 return position;
1190}
1191
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001192static void ironlake_rps_change_irq_handler(struct drm_i915_private *dev_priv)
Jesse Barnesf97108d2010-01-29 11:27:07 -08001193{
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001194 u32 busy_up, busy_down, max_avg, min_avg;
Daniel Vetter92703882012-08-09 16:46:01 +02001195 u8 new_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001196
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001197 spin_lock(&mchdev_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001198
Daniel Vetter73edd18f2012-08-08 23:35:37 +02001199 I915_WRITE16(MEMINTRSTS, I915_READ(MEMINTRSTS));
1200
Daniel Vetter20e4d402012-08-08 23:35:39 +02001201 new_delay = dev_priv->ips.cur_delay;
Daniel Vetter92703882012-08-09 16:46:01 +02001202
Jesse Barnes7648fa92010-05-20 14:28:11 -07001203 I915_WRITE16(MEMINTRSTS, MEMINT_EVAL_CHG);
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001204 busy_up = I915_READ(RCPREVBSYTUPAVG);
1205 busy_down = I915_READ(RCPREVBSYTDNAVG);
Jesse Barnesf97108d2010-01-29 11:27:07 -08001206 max_avg = I915_READ(RCBMAXAVG);
1207 min_avg = I915_READ(RCBMINAVG);
1208
1209 /* Handle RCS change request from hw */
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001210 if (busy_up > max_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001211 if (dev_priv->ips.cur_delay != dev_priv->ips.max_delay)
1212 new_delay = dev_priv->ips.cur_delay - 1;
1213 if (new_delay < dev_priv->ips.max_delay)
1214 new_delay = dev_priv->ips.max_delay;
Matthew Garrettb5b72e82010-02-02 18:30:47 +00001215 } else if (busy_down < min_avg) {
Daniel Vetter20e4d402012-08-08 23:35:39 +02001216 if (dev_priv->ips.cur_delay != dev_priv->ips.min_delay)
1217 new_delay = dev_priv->ips.cur_delay + 1;
1218 if (new_delay > dev_priv->ips.min_delay)
1219 new_delay = dev_priv->ips.min_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001220 }
1221
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001222 if (ironlake_set_drps(dev_priv, new_delay))
Daniel Vetter20e4d402012-08-08 23:35:39 +02001223 dev_priv->ips.cur_delay = new_delay;
Jesse Barnesf97108d2010-01-29 11:27:07 -08001224
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001225 spin_unlock(&mchdev_lock);
Daniel Vetter92703882012-08-09 16:46:01 +02001226
Jesse Barnesf97108d2010-01-29 11:27:07 -08001227 return;
1228}
1229
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001230static void vlv_c0_read(struct drm_i915_private *dev_priv,
1231 struct intel_rps_ei *ei)
Deepak S31685c22014-07-03 17:33:01 -04001232{
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001233 ei->ktime = ktime_get_raw();
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001234 ei->render_c0 = I915_READ(VLV_RENDER_C0_COUNT);
1235 ei->media_c0 = I915_READ(VLV_MEDIA_C0_COUNT);
Deepak S31685c22014-07-03 17:33:01 -04001236}
1237
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001238void gen6_rps_reset_ei(struct drm_i915_private *dev_priv)
1239{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001240 memset(&dev_priv->gt_pm.rps.ei, 0, sizeof(dev_priv->gt_pm.rps.ei));
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001241}
1242
1243static u32 vlv_wa_c0_ei(struct drm_i915_private *dev_priv, u32 pm_iir)
1244{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001245 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1246 const struct intel_rps_ei *prev = &rps->ei;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001247 struct intel_rps_ei now;
1248 u32 events = 0;
1249
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001250 if ((pm_iir & GEN6_PM_RP_UP_EI_EXPIRED) == 0)
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001251 return 0;
1252
1253 vlv_c0_read(dev_priv, &now);
Deepak S31685c22014-07-03 17:33:01 -04001254
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001255 if (prev->ktime) {
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001256 u64 time, c0;
Chris Wilson569884e2017-03-09 21:12:31 +00001257 u32 render, media;
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001258
Mika Kuoppala679cb6c2017-03-15 17:43:03 +02001259 time = ktime_us_delta(now.ktime, prev->ktime);
Chris Wilson8f68d592017-03-13 17:06:17 +00001260
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001261 time *= dev_priv->czclk_freq;
1262
1263 /* Workload can be split between render + media,
1264 * e.g. SwapBuffers being blitted in X after being rendered in
1265 * mesa. To account for this we need to combine both engines
1266 * into our activity counter.
1267 */
Chris Wilson569884e2017-03-09 21:12:31 +00001268 render = now.render_c0 - prev->render_c0;
1269 media = now.media_c0 - prev->media_c0;
1270 c0 = max(render, media);
Mika Kuoppala6b7f6aa2017-03-15 18:12:59 +02001271 c0 *= 1000 * 100 << 8; /* to usecs and scale to threshold% */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001272
Chris Wilson60548c52018-07-31 14:26:29 +01001273 if (c0 > time * rps->power.up_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001274 events = GEN6_PM_RP_UP_THRESHOLD;
Chris Wilson60548c52018-07-31 14:26:29 +01001275 else if (c0 < time * rps->power.down_threshold)
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00001276 events = GEN6_PM_RP_DOWN_THRESHOLD;
Deepak S31685c22014-07-03 17:33:01 -04001277 }
1278
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001279 rps->ei = now;
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001280 return events;
Deepak S31685c22014-07-03 17:33:01 -04001281}
1282
Ben Widawsky4912d042011-04-25 11:25:20 -07001283static void gen6_pm_rps_work(struct work_struct *work)
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001284{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001285 struct drm_i915_private *dev_priv =
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001286 container_of(work, struct drm_i915_private, gt_pm.rps.work);
1287 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001288 bool client_boost = false;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001289 int new_delay, adj, min, max;
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001290 u32 pm_iir = 0;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001291
Daniel Vetter59cdb632013-07-04 23:35:28 +02001292 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001293 if (rps->interrupts_enabled) {
1294 pm_iir = fetch_and_zero(&rps->pm_iir);
1295 client_boost = atomic_read(&rps->num_waiters);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001296 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001297 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawsky4912d042011-04-25 11:25:20 -07001298
Paulo Zanoni60611c12013-08-15 11:50:01 -03001299 /* Make sure we didn't queue anything we're not going to process. */
Deepak Sa6706b42014-03-15 20:23:22 +05301300 WARN_ON(pm_iir & ~dev_priv->pm_rps_events);
Chris Wilson8d3afd72015-05-21 21:01:47 +01001301 if ((pm_iir & dev_priv->pm_rps_events) == 0 && !client_boost)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001302 goto out;
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001303
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001304 mutex_lock(&dev_priv->pcu_lock);
Chris Wilson7b9e0ae2012-04-28 08:56:39 +01001305
Chris Wilson43cf3bf2015-03-18 09:48:22 +00001306 pm_iir |= vlv_wa_c0_ei(dev_priv, pm_iir);
1307
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001308 adj = rps->last_adj;
1309 new_delay = rps->cur_freq;
1310 min = rps->min_freq_softlimit;
1311 max = rps->max_freq_softlimit;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001312 if (client_boost)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001313 max = rps->max_freq;
1314 if (client_boost && new_delay < rps->boost_freq) {
1315 new_delay = rps->boost_freq;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001316 adj = 0;
1317 } else if (pm_iir & GEN6_PM_RP_UP_THRESHOLD) {
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001318 if (adj > 0)
1319 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001320 else /* CHV needs even encode values */
1321 adj = IS_CHERRYVIEW(dev_priv) ? 2 : 1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301322
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001323 if (new_delay >= rps->max_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301324 adj = 0;
Chris Wilson7b92c1b2017-06-28 13:35:48 +01001325 } else if (client_boost) {
Chris Wilsonf5a4c672015-04-27 13:41:23 +01001326 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001327 } else if (pm_iir & GEN6_PM_RP_DOWN_TIMEOUT) {
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001328 if (rps->cur_freq > rps->efficient_freq)
1329 new_delay = rps->efficient_freq;
1330 else if (rps->cur_freq > rps->min_freq_softlimit)
1331 new_delay = rps->min_freq_softlimit;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001332 adj = 0;
1333 } else if (pm_iir & GEN6_PM_RP_DOWN_THRESHOLD) {
1334 if (adj < 0)
1335 adj *= 2;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001336 else /* CHV needs even encode values */
1337 adj = IS_CHERRYVIEW(dev_priv) ? -2 : -1;
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301338
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001339 if (new_delay <= rps->min_freq_softlimit)
Sagar Arun Kamble7e79a682017-01-20 09:18:24 +05301340 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001341 } else { /* unknown event */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001342 adj = 0;
Chris Wilsondd75fdc2013-09-25 17:34:57 +01001343 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001344
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001345 rps->last_adj = adj;
Chris Wilsonedcf2842015-04-07 16:20:29 +01001346
Chris Wilson2a8862d2019-02-19 12:22:03 +00001347 /*
1348 * Limit deboosting and boosting to keep ourselves at the extremes
1349 * when in the respective power modes (i.e. slowly decrease frequencies
1350 * while in the HIGH_POWER zone and slowly increase frequencies while
1351 * in the LOW_POWER zone). On idle, we will hit the timeout and drop
1352 * to the next level quickly, and conversely if busy we expect to
1353 * hit a waitboost and rapidly switch into max power.
1354 */
1355 if ((adj < 0 && rps->power.mode == HIGH_POWER) ||
1356 (adj > 0 && rps->power.mode == LOW_POWER))
1357 rps->last_adj = 0;
1358
Ben Widawsky79249632012-09-07 19:43:42 -07001359 /* sysfs frequency interfaces may have snuck in while servicing the
1360 * interrupt
1361 */
Chris Wilsonedcf2842015-04-07 16:20:29 +01001362 new_delay += adj;
Chris Wilson8d3afd72015-05-21 21:01:47 +01001363 new_delay = clamp_t(int, new_delay, min, max);
Deepak S27544362014-01-27 21:35:05 +05301364
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001365 if (intel_set_rps(dev_priv, new_delay)) {
1366 DRM_DEBUG_DRIVER("Failed to set new GPU frequency\n");
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001367 rps->last_adj = 0;
Chris Wilson9fcee2f2017-01-26 10:19:19 +00001368 }
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001369
Sagar Arun Kamble9f817502017-10-10 22:30:05 +01001370 mutex_unlock(&dev_priv->pcu_lock);
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001371
1372out:
1373 /* Make sure not to corrupt PMIMR state used by ringbuffer on GEN6 */
1374 spin_lock_irq(&dev_priv->irq_lock);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001375 if (rps->interrupts_enabled)
Chris Wilson7c0a16a2017-03-09 21:12:32 +00001376 gen6_unmask_pm_irq(dev_priv, dev_priv->pm_rps_events);
1377 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes3b8d8d92010-12-17 14:19:02 -08001378}
1379
Ben Widawskye3689192012-05-25 16:56:22 -07001380
1381/**
1382 * ivybridge_parity_work - Workqueue called when a parity error interrupt
1383 * occurred.
1384 * @work: workqueue struct
1385 *
1386 * Doesn't actually do anything except notify userspace. As a consequence of
1387 * this event, userspace should try to remap the bad rows since statistically
1388 * it is likely the same row is more likely to go bad again.
1389 */
1390static void ivybridge_parity_work(struct work_struct *work)
1391{
Jani Nikula2d1013d2014-03-31 14:27:17 +03001392 struct drm_i915_private *dev_priv =
Joonas Lahtinencefcff82017-04-28 10:58:39 +03001393 container_of(work, typeof(*dev_priv), l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001394 u32 error_status, row, bank, subbank;
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001395 char *parity_event[6];
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001396 u32 misccpctl;
1397 u8 slice = 0;
Ben Widawskye3689192012-05-25 16:56:22 -07001398
1399 /* We must turn off DOP level clock gating to access the L3 registers.
1400 * In order to prevent a get/put style interface, acquire struct mutex
1401 * any time we access those registers.
1402 */
Chris Wilson91c8a322016-07-05 10:40:23 +01001403 mutex_lock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001404
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001405 /* If we've screwed up tracking, just let the interrupt fire again */
1406 if (WARN_ON(!dev_priv->l3_parity.which_slice))
1407 goto out;
1408
Ben Widawskye3689192012-05-25 16:56:22 -07001409 misccpctl = I915_READ(GEN7_MISCCPCTL);
1410 I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE);
1411 POSTING_READ(GEN7_MISCCPCTL);
1412
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001413 while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001414 i915_reg_t reg;
Ben Widawskye3689192012-05-25 16:56:22 -07001415
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001416 slice--;
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001417 if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv)))
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001418 break;
1419
1420 dev_priv->l3_parity.which_slice &= ~(1<<slice);
1421
Ville Syrjälä6fa1c5f2015-11-04 23:20:02 +02001422 reg = GEN7_L3CDERRST1(slice);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001423
1424 error_status = I915_READ(reg);
1425 row = GEN7_PARITY_ERROR_ROW(error_status);
1426 bank = GEN7_PARITY_ERROR_BANK(error_status);
1427 subbank = GEN7_PARITY_ERROR_SUBBANK(error_status);
1428
1429 I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE);
1430 POSTING_READ(reg);
1431
1432 parity_event[0] = I915_L3_PARITY_UEVENT "=1";
1433 parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row);
1434 parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank);
1435 parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank);
1436 parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice);
1437 parity_event[5] = NULL;
1438
Chris Wilson91c8a322016-07-05 10:40:23 +01001439 kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj,
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001440 KOBJ_CHANGE, parity_event);
1441
1442 DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n",
1443 slice, row, bank, subbank);
1444
1445 kfree(parity_event[4]);
1446 kfree(parity_event[3]);
1447 kfree(parity_event[2]);
1448 kfree(parity_event[1]);
1449 }
Ben Widawskye3689192012-05-25 16:56:22 -07001450
1451 I915_WRITE(GEN7_MISCCPCTL, misccpctl);
1452
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001453out:
1454 WARN_ON(dev_priv->l3_parity.which_slice);
Daniel Vetter4cb21832014-09-15 14:55:26 +02001455 spin_lock_irq(&dev_priv->irq_lock);
Joonas Lahtinen2d1fe072016-04-07 11:08:05 +03001456 gen5_enable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetter4cb21832014-09-15 14:55:26 +02001457 spin_unlock_irq(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001458
Chris Wilson91c8a322016-07-05 10:40:23 +01001459 mutex_unlock(&dev_priv->drm.struct_mutex);
Ben Widawskye3689192012-05-25 16:56:22 -07001460}
1461
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001462static void ivybridge_parity_error_irq_handler(struct drm_i915_private *dev_priv,
1463 u32 iir)
Ben Widawskye3689192012-05-25 16:56:22 -07001464{
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001465 if (!HAS_L3_DPF(dev_priv))
Ben Widawskye3689192012-05-25 16:56:22 -07001466 return;
1467
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001468 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001469 gen5_disable_gt_irq(dev_priv, GT_PARITY_ERROR(dev_priv));
Daniel Vetterd0ecd7e2013-07-04 23:35:25 +02001470 spin_unlock(&dev_priv->irq_lock);
Ben Widawskye3689192012-05-25 16:56:22 -07001471
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001472 iir &= GT_PARITY_ERROR(dev_priv);
Ben Widawsky35a85ac2013-09-19 11:13:41 -07001473 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT_S1)
1474 dev_priv->l3_parity.which_slice |= 1 << 1;
1475
1476 if (iir & GT_RENDER_L3_PARITY_ERROR_INTERRUPT)
1477 dev_priv->l3_parity.which_slice |= 1 << 0;
1478
Daniel Vettera4da4fa2012-11-02 19:55:07 +01001479 queue_work(dev_priv->wq, &dev_priv->l3_parity.error_work);
Ben Widawskye3689192012-05-25 16:56:22 -07001480}
1481
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001482static void ilk_gt_irq_handler(struct drm_i915_private *dev_priv,
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001483 u32 gt_iir)
1484{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001485 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001486 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001487 if (gt_iir & ILK_BSD_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001488 intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03001489}
1490
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001491static void snb_gt_irq_handler(struct drm_i915_private *dev_priv,
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001492 u32 gt_iir)
1493{
Chris Wilsonf8973c22016-07-01 17:23:21 +01001494 if (gt_iir & GT_RENDER_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001495 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001496 if (gt_iir & GT_BSD_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001497 intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]);
Ben Widawskycc609d52013-05-28 19:22:29 -07001498 if (gt_iir & GT_BLT_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001499 intel_engine_breadcrumbs_irq(dev_priv->engine[BCS0]);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001500
Ben Widawskycc609d52013-05-28 19:22:29 -07001501 if (gt_iir & (GT_BLT_CS_ERROR_INTERRUPT |
1502 GT_BSD_CS_ERROR_INTERRUPT |
Daniel Vetteraaecdf62014-11-04 15:52:22 +01001503 GT_RENDER_CS_MASTER_ERROR_INTERRUPT))
1504 DRM_DEBUG("Command parser error, gt_iir 0x%08x\n", gt_iir);
Ben Widawskye3689192012-05-25 16:56:22 -07001505
Ville Syrjälä261e40b2016-04-13 21:19:57 +03001506 if (gt_iir & GT_PARITY_ERROR(dev_priv))
1507 ivybridge_parity_error_irq_handler(dev_priv, gt_iir);
Daniel Vettere7b4c6b2012-03-30 20:24:35 +02001508}
1509
Chris Wilson5d3d69d2017-05-17 13:10:06 +01001510static void
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001511gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001512{
Chris Wilson31de7352017-03-16 12:56:18 +00001513 bool tasklet = false;
Chris Wilsonf7470262017-01-24 15:20:21 +00001514
Chris Wilsonfd8526e2018-06-28 21:12:10 +01001515 if (iir & GT_CONTEXT_SWITCH_INTERRUPT)
1516 tasklet = true;
Chris Wilson31de7352017-03-16 12:56:18 +00001517
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001518 if (iir & GT_RENDER_USER_INTERRUPT) {
Chris Wilson52c0fdb2019-01-29 20:52:29 +00001519 intel_engine_breadcrumbs_irq(engine);
Chris Wilson4c6ce5c2019-03-29 15:49:12 +00001520 tasklet |= intel_engine_needs_breadcrumb_tasklet(engine);
Chris Wilson31de7352017-03-16 12:56:18 +00001521 }
1522
1523 if (tasklet)
Chris Wilsonfd8526e2018-06-28 21:12:10 +01001524 tasklet_hi_schedule(&engine->execlists.tasklet);
Nick Hoathfbcc1a02015-10-20 10:23:52 +01001525}
1526
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001527static void gen8_gt_irq_ack(struct drm_i915_private *i915,
Chris Wilson55ef72f2018-02-02 15:34:48 +00001528 u32 master_ctl, u32 gt_iir[4])
Ben Widawskyabd58f02013-11-02 21:07:09 -07001529{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07001530 void __iomem * const regs = i915->uncore.regs;
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001531
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001532#define GEN8_GT_IRQS (GEN8_GT_RCS_IRQ | \
1533 GEN8_GT_BCS_IRQ | \
Chris Wilson8a68d462019-03-05 18:03:30 +00001534 GEN8_GT_VCS0_IRQ | \
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001535 GEN8_GT_VCS1_IRQ | \
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001536 GEN8_GT_VECS_IRQ | \
1537 GEN8_GT_PM_IRQ | \
1538 GEN8_GT_GUC_IRQ)
1539
Ben Widawskyabd58f02013-11-02 21:07:09 -07001540 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001541 gt_iir[0] = raw_reg_read(regs, GEN8_GT_IIR(0));
1542 if (likely(gt_iir[0]))
1543 raw_reg_write(regs, GEN8_GT_IIR(0), gt_iir[0]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07001544 }
1545
Chris Wilson8a68d462019-03-05 18:03:30 +00001546 if (master_ctl & (GEN8_GT_VCS0_IRQ | GEN8_GT_VCS1_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001547 gt_iir[1] = raw_reg_read(regs, GEN8_GT_IIR(1));
1548 if (likely(gt_iir[1]))
1549 raw_reg_write(regs, GEN8_GT_IIR(1), gt_iir[1]);
Chris Wilson74cdb332015-04-07 16:21:05 +01001550 }
1551
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301552 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001553 gt_iir[2] = raw_reg_read(regs, GEN8_GT_IIR(2));
Chris Wilsonf4de7792018-08-02 11:06:29 +01001554 if (likely(gt_iir[2]))
1555 raw_reg_write(regs, GEN8_GT_IIR(2), gt_iir[2]);
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001556 }
1557
1558 if (master_ctl & GEN8_GT_VECS_IRQ) {
1559 gt_iir[3] = raw_reg_read(regs, GEN8_GT_IIR(3));
1560 if (likely(gt_iir[3]))
1561 raw_reg_write(regs, GEN8_GT_IIR(3), gt_iir[3]);
Ben Widawsky09610212014-05-15 20:58:08 +03001562 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07001563}
1564
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001565static void gen8_gt_irq_handler(struct drm_i915_private *i915,
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001566 u32 master_ctl, u32 gt_iir[4])
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001567{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001568 if (master_ctl & (GEN8_GT_RCS_IRQ | GEN8_GT_BCS_IRQ)) {
Chris Wilson8a68d462019-03-05 18:03:30 +00001569 gen8_cs_irq_handler(i915->engine[RCS0],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001570 gt_iir[0] >> GEN8_RCS_IRQ_SHIFT);
Chris Wilson8a68d462019-03-05 18:03:30 +00001571 gen8_cs_irq_handler(i915->engine[BCS0],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001572 gt_iir[0] >> GEN8_BCS_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001573 }
1574
Chris Wilson8a68d462019-03-05 18:03:30 +00001575 if (master_ctl & (GEN8_GT_VCS0_IRQ | GEN8_GT_VCS1_IRQ)) {
1576 gen8_cs_irq_handler(i915->engine[VCS0],
1577 gt_iir[1] >> GEN8_VCS0_IRQ_SHIFT);
1578 gen8_cs_irq_handler(i915->engine[VCS1],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001579 gt_iir[1] >> GEN8_VCS1_IRQ_SHIFT);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001580 }
1581
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001582 if (master_ctl & GEN8_GT_VECS_IRQ) {
Chris Wilson8a68d462019-03-05 18:03:30 +00001583 gen8_cs_irq_handler(i915->engine[VECS0],
Chris Wilson51f6b0f2018-03-09 01:08:08 +00001584 gt_iir[3] >> GEN8_VECS_IRQ_SHIFT);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001585 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001586
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001587 if (master_ctl & (GEN8_GT_PM_IRQ | GEN8_GT_GUC_IRQ)) {
Chris Wilson2e4a5b22018-02-19 10:09:26 +00001588 gen6_rps_irq_handler(i915, gt_iir[2]);
1589 gen9_guc_irq_handler(i915, gt_iir[2]);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00001590 }
Ville Syrjäläe30e2512016-04-13 21:19:58 +03001591}
1592
Ville Syrjäläaf920582018-07-05 19:43:55 +03001593static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001594{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001595 switch (pin) {
1596 case HPD_PORT_C:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001597 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001598 case HPD_PORT_D:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001599 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001600 case HPD_PORT_E:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001601 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001602 case HPD_PORT_F:
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07001603 return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4);
1604 default:
1605 return false;
1606 }
1607}
1608
Ville Syrjäläaf920582018-07-05 19:43:55 +03001609static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Imre Deak63c88d22015-07-20 14:43:39 -07001610{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001611 switch (pin) {
1612 case HPD_PORT_A:
Ville Syrjälä195baa02015-08-27 23:56:00 +03001613 return val & PORTA_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001614 case HPD_PORT_B:
Imre Deak63c88d22015-07-20 14:43:39 -07001615 return val & PORTB_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001616 case HPD_PORT_C:
Imre Deak63c88d22015-07-20 14:43:39 -07001617 return val & PORTC_HOTPLUG_LONG_DETECT;
Imre Deak63c88d22015-07-20 14:43:39 -07001618 default:
1619 return false;
1620 }
1621}
1622
Ville Syrjäläaf920582018-07-05 19:43:55 +03001623static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Anusha Srivatsa31604222018-06-26 13:52:23 -07001624{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001625 switch (pin) {
1626 case HPD_PORT_A:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001627 return val & ICP_DDIA_HPD_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001628 case HPD_PORT_B:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001629 return val & ICP_DDIB_HPD_LONG_DETECT;
1630 default:
1631 return false;
1632 }
1633}
1634
Ville Syrjäläaf920582018-07-05 19:43:55 +03001635static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Anusha Srivatsa31604222018-06-26 13:52:23 -07001636{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001637 switch (pin) {
1638 case HPD_PORT_C:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001639 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001640 case HPD_PORT_D:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001641 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001642 case HPD_PORT_E:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001643 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3);
Ville Syrjäläaf920582018-07-05 19:43:55 +03001644 case HPD_PORT_F:
Anusha Srivatsa31604222018-06-26 13:52:23 -07001645 return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4);
1646 default:
1647 return false;
1648 }
1649}
1650
Ville Syrjäläaf920582018-07-05 19:43:55 +03001651static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001652{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001653 switch (pin) {
1654 case HPD_PORT_E:
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03001655 return val & PORTE_HOTPLUG_LONG_DETECT;
1656 default:
1657 return false;
1658 }
1659}
1660
Ville Syrjäläaf920582018-07-05 19:43:55 +03001661static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001662{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001663 switch (pin) {
1664 case HPD_PORT_A:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001665 return val & PORTA_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001666 case HPD_PORT_B:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001667 return val & PORTB_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001668 case HPD_PORT_C:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001669 return val & PORTC_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001670 case HPD_PORT_D:
Ville Syrjälä74c0b392015-08-27 23:56:07 +03001671 return val & PORTD_HOTPLUG_LONG_DETECT;
1672 default:
1673 return false;
1674 }
1675}
1676
Ville Syrjäläaf920582018-07-05 19:43:55 +03001677static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001678{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001679 switch (pin) {
1680 case HPD_PORT_A:
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03001681 return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT;
1682 default:
1683 return false;
1684 }
1685}
1686
Ville Syrjäläaf920582018-07-05 19:43:55 +03001687static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001688{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001689 switch (pin) {
1690 case HPD_PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001691 return val & PORTB_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001692 case HPD_PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001693 return val & PORTC_HOTPLUG_LONG_DETECT;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001694 case HPD_PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001695 return val & PORTD_HOTPLUG_LONG_DETECT;
1696 default:
1697 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001698 }
1699}
1700
Ville Syrjäläaf920582018-07-05 19:43:55 +03001701static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val)
Dave Airlie13cf5502014-06-18 11:29:35 +10001702{
Ville Syrjäläaf920582018-07-05 19:43:55 +03001703 switch (pin) {
1704 case HPD_PORT_B:
Jani Nikula676574d2015-05-28 15:43:53 +03001705 return val & PORTB_HOTPLUG_INT_LONG_PULSE;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001706 case HPD_PORT_C:
Jani Nikula676574d2015-05-28 15:43:53 +03001707 return val & PORTC_HOTPLUG_INT_LONG_PULSE;
Ville Syrjäläaf920582018-07-05 19:43:55 +03001708 case HPD_PORT_D:
Jani Nikula676574d2015-05-28 15:43:53 +03001709 return val & PORTD_HOTPLUG_INT_LONG_PULSE;
1710 default:
1711 return false;
Dave Airlie13cf5502014-06-18 11:29:35 +10001712 }
1713}
1714
Ville Syrjälä42db67d2015-08-28 21:26:27 +03001715/*
1716 * Get a bit mask of pins that have triggered, and which ones may be long.
1717 * This can be called multiple times with the same masks to accumulate
1718 * hotplug detection results from several registers.
1719 *
1720 * Note that the caller is expected to zero out the masks initially.
1721 */
Rodrigo Vivicf539022018-01-29 15:22:21 -08001722static void intel_get_hpd_pins(struct drm_i915_private *dev_priv,
1723 u32 *pin_mask, u32 *long_mask,
1724 u32 hotplug_trigger, u32 dig_hotplug_reg,
1725 const u32 hpd[HPD_NUM_PINS],
Ville Syrjäläaf920582018-07-05 19:43:55 +03001726 bool long_pulse_detect(enum hpd_pin pin, u32 val))
Jani Nikula676574d2015-05-28 15:43:53 +03001727{
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001728 enum hpd_pin pin;
Jani Nikula676574d2015-05-28 15:43:53 +03001729
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001730 for_each_hpd_pin(pin) {
1731 if ((hpd[pin] & hotplug_trigger) == 0)
Jani Nikula8c841e52015-06-18 13:06:17 +03001732 continue;
Jani Nikula676574d2015-05-28 15:43:53 +03001733
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001734 *pin_mask |= BIT(pin);
Jani Nikula8c841e52015-06-18 13:06:17 +03001735
Ville Syrjäläaf920582018-07-05 19:43:55 +03001736 if (long_pulse_detect(pin, dig_hotplug_reg))
Ville Syrjäläe9be2852018-07-05 19:43:54 +03001737 *long_mask |= BIT(pin);
Jani Nikula676574d2015-05-28 15:43:53 +03001738 }
1739
Ville Syrjäläf88f0472018-07-05 19:43:57 +03001740 DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n",
1741 hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask);
Jani Nikula676574d2015-05-28 15:43:53 +03001742
1743}
1744
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001745static void gmbus_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001746{
Daniel Vetter28c70f12012-12-01 13:53:45 +01001747 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01001748}
1749
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001750static void dp_aux_irq_handler(struct drm_i915_private *dev_priv)
Daniel Vetterce99c252012-12-01 13:53:47 +01001751{
Daniel Vetter9ee32fea2012-12-01 13:53:48 +01001752 wake_up_all(&dev_priv->gmbus_wait_queue);
Daniel Vetterce99c252012-12-01 13:53:47 +01001753}
1754
Shuang He8bf1e9f2013-10-15 18:55:27 +01001755#if defined(CONFIG_DEBUG_FS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001756static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1757 enum pipe pipe,
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001758 u32 crc0, u32 crc1,
1759 u32 crc2, u32 crc3,
1760 u32 crc4)
Shuang He8bf1e9f2013-10-15 18:55:27 +01001761{
Shuang He8bf1e9f2013-10-15 18:55:27 +01001762 struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe];
Tomeu Vizoso8c6b7092017-01-10 14:43:04 +01001763 struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe);
Ville Syrjälä5cee6c42019-02-06 22:49:07 +02001764 u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 };
1765
1766 trace_intel_pipe_crc(crtc, crcs);
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001767
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001768 spin_lock(&pipe_crc->lock);
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001769 /*
1770 * For some not yet identified reason, the first CRC is
1771 * bonkers. So let's just wait for the next vblank and read
1772 * out the buggy result.
1773 *
1774 * On GEN8+ sometimes the second CRC is bonkers as well, so
1775 * don't trust that one either.
1776 */
1777 if (pipe_crc->skipped <= 0 ||
1778 (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) {
1779 pipe_crc->skipped++;
Damien Lespiaud538bbd2013-10-21 14:29:30 +01001780 spin_unlock(&pipe_crc->lock);
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001781 return;
Damien Lespiaub2c88f52013-10-15 18:55:29 +01001782 }
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001783 spin_unlock(&pipe_crc->lock);
1784
Maarten Lankhorst6cc42152018-06-28 09:23:02 +02001785 drm_crtc_add_crc_entry(&crtc->base, true,
1786 drm_crtc_accurate_vblank_count(&crtc->base),
1787 crcs);
Shuang He8bf1e9f2013-10-15 18:55:27 +01001788}
Daniel Vetter277de952013-10-18 16:37:07 +02001789#else
1790static inline void
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001791display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1792 enum pipe pipe,
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001793 u32 crc0, u32 crc1,
1794 u32 crc2, u32 crc3,
1795 u32 crc4) {}
Daniel Vetter277de952013-10-18 16:37:07 +02001796#endif
Daniel Vettereba94eb2013-10-16 22:55:46 +02001797
Daniel Vetter277de952013-10-18 16:37:07 +02001798
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001799static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1800 enum pipe pipe)
Daniel Vetter5a69b892013-10-16 22:55:52 +02001801{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001802 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001803 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1804 0, 0, 0, 0);
Daniel Vetter5a69b892013-10-16 22:55:52 +02001805}
1806
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001807static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1808 enum pipe pipe)
Daniel Vettereba94eb2013-10-16 22:55:46 +02001809{
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001810 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001811 I915_READ(PIPE_CRC_RES_1_IVB(pipe)),
1812 I915_READ(PIPE_CRC_RES_2_IVB(pipe)),
1813 I915_READ(PIPE_CRC_RES_3_IVB(pipe)),
1814 I915_READ(PIPE_CRC_RES_4_IVB(pipe)),
1815 I915_READ(PIPE_CRC_RES_5_IVB(pipe)));
Daniel Vettereba94eb2013-10-16 22:55:46 +02001816}
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001817
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001818static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv,
1819 enum pipe pipe)
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001820{
Jani Nikulaa9c287c2019-01-16 11:15:24 +02001821 u32 res1, res2;
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001822
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001823 if (INTEL_GEN(dev_priv) >= 3)
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001824 res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe));
1825 else
1826 res1 = 0;
1827
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001828 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Daniel Vetter0b5c5ed2013-10-16 22:55:53 +02001829 res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe));
1830 else
1831 res2 = 0;
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001832
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01001833 display_pipe_crc_irq_handler(dev_priv, pipe,
Daniel Vetter277de952013-10-18 16:37:07 +02001834 I915_READ(PIPE_CRC_RES_RED(pipe)),
1835 I915_READ(PIPE_CRC_RES_GREEN(pipe)),
1836 I915_READ(PIPE_CRC_RES_BLUE(pipe)),
1837 res1, res2);
Daniel Vetter5b3a8562013-10-16 22:55:48 +02001838}
Shuang He8bf1e9f2013-10-15 18:55:27 +01001839
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001840/* The RPS events need forcewake, so we add them to a work queue and mask their
1841 * IMR bits until the work is done. Other interrupts can be processed without
1842 * the work queue. */
Mika Kuoppalaa087baf2019-04-10 16:21:23 +03001843static void gen11_rps_irq_handler(struct drm_i915_private *i915, u32 pm_iir)
1844{
1845 struct intel_rps *rps = &i915->gt_pm.rps;
1846 const u32 events = i915->pm_rps_events & pm_iir;
1847
1848 lockdep_assert_held(&i915->irq_lock);
1849
1850 if (unlikely(!events))
1851 return;
1852
1853 gen6_mask_pm_irq(i915, events);
1854
1855 if (!rps->interrupts_enabled)
1856 return;
1857
1858 rps->pm_iir |= events;
1859 schedule_work(&rps->work);
1860}
1861
Paulo Zanoni1403c0d2013-08-15 11:51:32 -03001862static void gen6_rps_irq_handler(struct drm_i915_private *dev_priv, u32 pm_iir)
Ben Widawskybaf02a12013-05-28 19:22:24 -07001863{
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001864 struct intel_rps *rps = &dev_priv->gt_pm.rps;
1865
Deepak Sa6706b42014-03-15 20:23:22 +05301866 if (pm_iir & dev_priv->pm_rps_events) {
Daniel Vetter59cdb632013-07-04 23:35:28 +02001867 spin_lock(&dev_priv->irq_lock);
Akash Goelf4e9af42016-10-12 21:54:30 +05301868 gen6_mask_pm_irq(dev_priv, pm_iir & dev_priv->pm_rps_events);
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01001869 if (rps->interrupts_enabled) {
1870 rps->pm_iir |= pm_iir & dev_priv->pm_rps_events;
1871 schedule_work(&rps->work);
Imre Deakd4d70aa2014-11-19 15:30:04 +02001872 }
Daniel Vetter59cdb632013-07-04 23:35:28 +02001873 spin_unlock(&dev_priv->irq_lock);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001874 }
Ben Widawskybaf02a12013-05-28 19:22:24 -07001875
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07001876 if (INTEL_GEN(dev_priv) >= 8)
Imre Deakc9a9a262014-11-05 20:48:37 +02001877 return;
1878
Chris Wilsonf14c0d92019-03-05 15:09:13 +00001879 if (pm_iir & PM_VEBOX_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00001880 intel_engine_breadcrumbs_irq(dev_priv->engine[VECS0]);
Ben Widawsky12638c52013-05-28 19:22:31 -07001881
Chris Wilsonf14c0d92019-03-05 15:09:13 +00001882 if (pm_iir & PM_VEBOX_CS_ERROR_INTERRUPT)
1883 DRM_DEBUG("Command parser error, pm_iir 0x%08x\n", pm_iir);
Ben Widawskybaf02a12013-05-28 19:22:24 -07001884}
1885
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301886static void gen9_guc_irq_handler(struct drm_i915_private *dev_priv, u32 gt_iir)
1887{
Michal Wajdeczko93bf8092018-03-08 16:46:55 +01001888 if (gt_iir & GEN9_GUC_TO_HOST_INT_EVENT)
1889 intel_guc_to_host_event_handler(&dev_priv->guc);
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05301890}
1891
Ville Syrjälä44d92412017-08-18 21:36:51 +03001892static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv)
1893{
1894 enum pipe pipe;
1895
1896 for_each_pipe(dev_priv, pipe) {
1897 I915_WRITE(PIPESTAT(pipe),
1898 PIPESTAT_INT_STATUS_MASK |
1899 PIPE_FIFO_UNDERRUN_STATUS);
1900
1901 dev_priv->pipestat_irq_mask[pipe] = 0;
1902 }
1903}
1904
Ville Syrjäläeb643432017-08-18 21:36:59 +03001905static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv,
1906 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
Imre Deakc1874ed2014-02-04 21:35:46 +02001907{
Imre Deakc1874ed2014-02-04 21:35:46 +02001908 int pipe;
1909
Imre Deak58ead0d2014-02-04 21:35:47 +02001910 spin_lock(&dev_priv->irq_lock);
Ville Syrjälä1ca993d2016-02-18 21:54:26 +02001911
1912 if (!dev_priv->display_irqs_enabled) {
1913 spin_unlock(&dev_priv->irq_lock);
1914 return;
1915 }
1916
Damien Lespiau055e3932014-08-18 13:49:10 +01001917 for_each_pipe(dev_priv, pipe) {
Ville Syrjäläf0f59a02015-11-18 15:33:26 +02001918 i915_reg_t reg;
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001919 u32 status_mask, enable_mask, iir_bit = 0;
Imre Deak91d181d2014-02-10 18:42:49 +02001920
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001921 /*
1922 * PIPESTAT bits get signalled even when the interrupt is
1923 * disabled with the mask bits, and some of the status bits do
1924 * not generate interrupts at all (like the underrun bit). Hence
1925 * we need to be careful that we only handle what we want to
1926 * handle.
1927 */
Daniel Vetter0f239f42014-09-30 10:56:49 +02001928
1929 /* fifo underruns are filterered in the underrun handler. */
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001930 status_mask = PIPE_FIFO_UNDERRUN_STATUS;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001931
1932 switch (pipe) {
1933 case PIPE_A:
1934 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT;
1935 break;
1936 case PIPE_B:
1937 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT;
1938 break;
Ville Syrjälä3278f672014-04-09 13:28:49 +03001939 case PIPE_C:
1940 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT;
1941 break;
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001942 }
1943 if (iir & iir_bit)
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001944 status_mask |= dev_priv->pipestat_irq_mask[pipe];
Daniel Vetterbbb5eeb2014-02-12 17:55:36 +01001945
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001946 if (!status_mask)
Imre Deak91d181d2014-02-10 18:42:49 +02001947 continue;
1948
1949 reg = PIPESTAT(pipe);
Ville Syrjälä6b12ca52017-09-14 18:17:31 +03001950 pipe_stats[pipe] = I915_READ(reg) & status_mask;
1951 enable_mask = i915_pipestat_enable_mask(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02001952
1953 /*
1954 * Clear the PIPE*STAT regs before the IIR
Ville Syrjälä132c27c2018-06-11 23:02:55 +03001955 *
1956 * Toggle the enable bits to make sure we get an
1957 * edge in the ISR pipe event bit if we don't clear
1958 * all the enabled status bits. Otherwise the edge
1959 * triggered IIR on i965/g4x wouldn't notice that
1960 * an interrupt is still pending.
Imre Deakc1874ed2014-02-04 21:35:46 +02001961 */
Ville Syrjälä132c27c2018-06-11 23:02:55 +03001962 if (pipe_stats[pipe]) {
1963 I915_WRITE(reg, pipe_stats[pipe]);
1964 I915_WRITE(reg, enable_mask);
1965 }
Imre Deakc1874ed2014-02-04 21:35:46 +02001966 }
Imre Deak58ead0d2014-02-04 21:35:47 +02001967 spin_unlock(&dev_priv->irq_lock);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03001968}
1969
Ville Syrjäläeb643432017-08-18 21:36:59 +03001970static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1971 u16 iir, u32 pipe_stats[I915_MAX_PIPES])
1972{
1973 enum pipe pipe;
1974
1975 for_each_pipe(dev_priv, pipe) {
1976 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1977 drm_handle_vblank(&dev_priv->drm, pipe);
1978
1979 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
1980 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
1981
1982 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
1983 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
1984 }
1985}
1986
1987static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv,
1988 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
1989{
1990 bool blc_event = false;
1991 enum pipe pipe;
1992
1993 for_each_pipe(dev_priv, pipe) {
1994 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS)
1995 drm_handle_vblank(&dev_priv->drm, pipe);
1996
1997 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
1998 blc_event = true;
1999
2000 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2001 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2002
2003 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2004 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2005 }
2006
2007 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2008 intel_opregion_asle_intr(dev_priv);
2009}
2010
2011static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv,
2012 u32 iir, u32 pipe_stats[I915_MAX_PIPES])
2013{
2014 bool blc_event = false;
2015 enum pipe pipe;
2016
2017 for_each_pipe(dev_priv, pipe) {
2018 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
2019 drm_handle_vblank(&dev_priv->drm, pipe);
2020
2021 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS)
2022 blc_event = true;
2023
2024 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
2025 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
2026
2027 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2028 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2029 }
2030
2031 if (blc_event || (iir & I915_ASLE_INTERRUPT))
2032 intel_opregion_asle_intr(dev_priv);
2033
2034 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
2035 gmbus_irq_handler(dev_priv);
2036}
2037
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002038static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002039 u32 pipe_stats[I915_MAX_PIPES])
2040{
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002041 enum pipe pipe;
Imre Deakc1874ed2014-02-04 21:35:46 +02002042
Damien Lespiau055e3932014-08-18 13:49:10 +01002043 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002044 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS)
2045 drm_handle_vblank(&dev_priv->drm, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002046
2047 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002048 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002049
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002050 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS)
2051 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Imre Deakc1874ed2014-02-04 21:35:46 +02002052 }
2053
2054 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002055 gmbus_irq_handler(dev_priv);
Imre Deakc1874ed2014-02-04 21:35:46 +02002056}
2057
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002058static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv)
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002059{
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002060 u32 hotplug_status = 0, hotplug_status_mask;
2061 int i;
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002062
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002063 if (IS_G4X(dev_priv) ||
2064 IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
2065 hotplug_status_mask = HOTPLUG_INT_STATUS_G4X |
2066 DP_AUX_CHANNEL_MASK_INT_STATUS_G4X;
2067 else
2068 hotplug_status_mask = HOTPLUG_INT_STATUS_I915;
2069
2070 /*
2071 * We absolutely have to clear all the pending interrupt
2072 * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port
2073 * interrupt bit won't have an edge, and the i965/g4x
2074 * edge triggered IIR will not notice that an interrupt
2075 * is still pending. We can't use PORT_HOTPLUG_EN to
2076 * guarantee the edge as the act of toggling the enable
2077 * bits can itself generate a new hotplug interrupt :(
2078 */
2079 for (i = 0; i < 10; i++) {
2080 u32 tmp = I915_READ(PORT_HOTPLUG_STAT) & hotplug_status_mask;
2081
2082 if (tmp == 0)
2083 return hotplug_status;
2084
2085 hotplug_status |= tmp;
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002086 I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status);
Ville Syrjälä0ba7c512018-06-14 20:56:25 +03002087 }
2088
2089 WARN_ONCE(1,
2090 "PORT_HOTPLUG_STAT did not clear (0x%08x)\n",
2091 I915_READ(PORT_HOTPLUG_STAT));
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002092
2093 return hotplug_status;
2094}
2095
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002096static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv,
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002097 u32 hotplug_status)
2098{
Ville Syrjälä42db67d2015-08-28 21:26:27 +03002099 u32 pin_mask = 0, long_mask = 0;
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002100
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002101 if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) ||
2102 IS_CHERRYVIEW(dev_priv)) {
Jani Nikula0d2e4292015-05-27 15:03:39 +03002103 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002104
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002105 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002106 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2107 hotplug_trigger, hotplug_trigger,
2108 hpd_status_g4x,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002109 i9xx_port_hotplug_long_detect);
2110
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002111 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002112 }
Jani Nikula369712e2015-05-27 15:03:40 +03002113
2114 if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002115 dp_aux_irq_handler(dev_priv);
Jani Nikula0d2e4292015-05-27 15:03:39 +03002116 } else {
2117 u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002118
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002119 if (hotplug_trigger) {
Rodrigo Vivicf539022018-01-29 15:22:21 -08002120 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2121 hotplug_trigger, hotplug_trigger,
2122 hpd_status_i915,
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002123 i9xx_port_hotplug_long_detect);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002124 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä58f2cf22015-08-28 22:59:08 +03002125 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002126 }
Ville Syrjälä16c6c562014-04-01 10:54:36 +03002127}
2128
Daniel Vetterff1f5252012-10-02 15:10:55 +02002129static irqreturn_t valleyview_irq_handler(int irq, void *arg)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002130{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002131 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002132 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002133 irqreturn_t ret = IRQ_NONE;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002134
Imre Deak2dd2a882015-02-24 11:14:30 +02002135 if (!intel_irqs_enabled(dev_priv))
2136 return IRQ_NONE;
2137
Imre Deak1f814da2015-12-16 02:52:19 +02002138 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2139 disable_rpm_wakeref_asserts(dev_priv);
2140
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002141 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002142 u32 iir, gt_iir, pm_iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002143 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002144 u32 hotplug_status = 0;
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002145 u32 ier = 0;
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002146
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002147 gt_iir = I915_READ(GTIIR);
2148 pm_iir = I915_READ(GEN6_PMIIR);
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002149 iir = I915_READ(VLV_IIR);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002150
2151 if (gt_iir == 0 && pm_iir == 0 && iir == 0)
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002152 break;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002153
2154 ret = IRQ_HANDLED;
2155
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002156 /*
2157 * Theory on interrupt generation, based on empirical evidence:
2158 *
2159 * x = ((VLV_IIR & VLV_IER) ||
2160 * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) &&
2161 * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE)));
2162 *
2163 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2164 * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to
2165 * guarantee the CPU interrupt will be raised again even if we
2166 * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR
2167 * bits this time around.
2168 */
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002169 I915_WRITE(VLV_MASTER_IER, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002170 ier = I915_READ(VLV_IER);
2171 I915_WRITE(VLV_IER, 0);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002172
2173 if (gt_iir)
2174 I915_WRITE(GTIIR, gt_iir);
2175 if (pm_iir)
2176 I915_WRITE(GEN6_PMIIR, pm_iir);
2177
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002178 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002179 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002180
Oscar Mateo3ff60f82014-06-16 16:10:58 +01002181 /* Call regardless, as some status bits might not be
2182 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002183 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002184
Jerome Anandeef57322017-01-25 04:27:49 +05302185 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2186 I915_LPE_PIPE_B_INTERRUPT))
2187 intel_lpe_audio_irq_handler(dev_priv);
2188
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002189 /*
2190 * VLV_IIR is single buffered, and reflects the level
2191 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2192 */
2193 if (iir)
2194 I915_WRITE(VLV_IIR, iir);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002195
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002196 I915_WRITE(VLV_IER, ier);
Ville Syrjälä4a0a0202016-04-13 21:19:50 +03002197 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002198
Ville Syrjälä52894872016-04-13 21:19:56 +03002199 if (gt_iir)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002200 snb_gt_irq_handler(dev_priv, gt_iir);
Ville Syrjälä52894872016-04-13 21:19:56 +03002201 if (pm_iir)
2202 gen6_rps_irq_handler(dev_priv, pm_iir);
2203
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002204 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002205 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002206
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002207 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Ville Syrjälä1e1cace2016-04-13 21:19:52 +03002208 } while (0);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002209
Imre Deak1f814da2015-12-16 02:52:19 +02002210 enable_rpm_wakeref_asserts(dev_priv);
2211
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07002212 return ret;
2213}
2214
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002215static irqreturn_t cherryview_irq_handler(int irq, void *arg)
2216{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002217 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002218 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002219 irqreturn_t ret = IRQ_NONE;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002220
Imre Deak2dd2a882015-02-24 11:14:30 +02002221 if (!intel_irqs_enabled(dev_priv))
2222 return IRQ_NONE;
2223
Imre Deak1f814da2015-12-16 02:52:19 +02002224 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2225 disable_rpm_wakeref_asserts(dev_priv);
2226
Chris Wilson579de732016-03-14 09:01:57 +00002227 do {
Ville Syrjälä6e814802016-04-13 21:19:53 +03002228 u32 master_ctl, iir;
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002229 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002230 u32 hotplug_status = 0;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002231 u32 gt_iir[4];
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002232 u32 ier = 0;
2233
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002234 master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL;
2235 iir = I915_READ(VLV_IIR);
Ville Syrjälä3278f672014-04-09 13:28:49 +03002236
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002237 if (master_ctl == 0 && iir == 0)
2238 break;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002239
Oscar Mateo27b6c122014-06-16 16:11:00 +01002240 ret = IRQ_HANDLED;
2241
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002242 /*
2243 * Theory on interrupt generation, based on empirical evidence:
2244 *
2245 * x = ((VLV_IIR & VLV_IER) ||
2246 * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) &&
2247 * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL)));
2248 *
2249 * A CPU interrupt will only be raised when 'x' has a 0->1 edge.
2250 * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to
2251 * guarantee the CPU interrupt will be raised again even if we
2252 * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL
2253 * bits this time around.
2254 */
Ville Syrjälä8e5fd592014-04-09 13:28:50 +03002255 I915_WRITE(GEN8_MASTER_IRQ, 0);
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002256 ier = I915_READ(VLV_IER);
2257 I915_WRITE(VLV_IER, 0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002258
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002259 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002260
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002261 if (iir & I915_DISPLAY_PORT_INTERRUPT)
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002262 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002263
Oscar Mateo27b6c122014-06-16 16:11:00 +01002264 /* Call regardless, as some status bits might not be
2265 * signalled in iir */
Ville Syrjäläeb643432017-08-18 21:36:59 +03002266 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002267
Jerome Anandeef57322017-01-25 04:27:49 +05302268 if (iir & (I915_LPE_PIPE_A_INTERRUPT |
2269 I915_LPE_PIPE_B_INTERRUPT |
2270 I915_LPE_PIPE_C_INTERRUPT))
2271 intel_lpe_audio_irq_handler(dev_priv);
2272
Ville Syrjälä7ce4d1f2016-04-13 21:19:49 +03002273 /*
2274 * VLV_IIR is single buffered, and reflects the level
2275 * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last.
2276 */
2277 if (iir)
2278 I915_WRITE(VLV_IIR, iir);
2279
Ville Syrjäläa5e485a2016-04-13 21:19:51 +03002280 I915_WRITE(VLV_IER, ier);
Ville Syrjäläe5328c42016-04-13 21:19:47 +03002281 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002282
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002283 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Ville Syrjäläe30e2512016-04-13 21:19:58 +03002284
Ville Syrjälä1ae3c342016-04-13 21:19:54 +03002285 if (hotplug_status)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002286 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
Ville Syrjälä2ecb8ca2016-04-13 21:19:55 +03002287
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002288 valleyview_pipestat_irq_handler(dev_priv, pipe_stats);
Chris Wilson579de732016-03-14 09:01:57 +00002289 } while (0);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002290
Imre Deak1f814da2015-12-16 02:52:19 +02002291 enable_rpm_wakeref_asserts(dev_priv);
2292
Ville Syrjälä43f328d2014-04-09 20:40:52 +03002293 return ret;
2294}
2295
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002296static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv,
2297 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002298 const u32 hpd[HPD_NUM_PINS])
2299{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002300 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2301
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002302 /*
2303 * Somehow the PCH doesn't seem to really ack the interrupt to the CPU
2304 * unless we touch the hotplug register, even if hotplug_trigger is
2305 * zero. Not acking leads to "The master control interrupt lied (SDE)!"
2306 * errors.
2307 */
Ville Syrjälä40e56412015-08-27 23:56:10 +03002308 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002309 if (!hotplug_trigger) {
2310 u32 mask = PORTA_HOTPLUG_STATUS_MASK |
2311 PORTD_HOTPLUG_STATUS_MASK |
2312 PORTC_HOTPLUG_STATUS_MASK |
2313 PORTB_HOTPLUG_STATUS_MASK;
2314 dig_hotplug_reg &= ~mask;
2315 }
2316
Ville Syrjälä40e56412015-08-27 23:56:10 +03002317 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Jani Nikula6a39d7c2015-11-25 16:47:22 +02002318 if (!hotplug_trigger)
2319 return;
Ville Syrjälä40e56412015-08-27 23:56:10 +03002320
Rodrigo Vivicf539022018-01-29 15:22:21 -08002321 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002322 dig_hotplug_reg, hpd,
2323 pch_port_hotplug_long_detect);
2324
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002325 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002326}
2327
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002328static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Jesse Barnes776ad802011-01-04 15:09:39 -08002329{
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002330 int pipe;
Egbert Eichb543fb02013-04-16 13:36:54 +02002331 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK;
Jesse Barnes776ad802011-01-04 15:09:39 -08002332
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002333 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002334
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002335 if (pch_iir & SDE_AUDIO_POWER_MASK) {
2336 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >>
2337 SDE_AUDIO_POWER_SHIFT);
Jesse Barnes776ad802011-01-04 15:09:39 -08002338 DRM_DEBUG_DRIVER("PCH audio power change on port %d\n",
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002339 port_name(port));
2340 }
Jesse Barnes776ad802011-01-04 15:09:39 -08002341
Daniel Vetterce99c252012-12-01 13:53:47 +01002342 if (pch_iir & SDE_AUX_MASK)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002343 dp_aux_irq_handler(dev_priv);
Daniel Vetterce99c252012-12-01 13:53:47 +01002344
Jesse Barnes776ad802011-01-04 15:09:39 -08002345 if (pch_iir & SDE_GMBUS)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002346 gmbus_irq_handler(dev_priv);
Jesse Barnes776ad802011-01-04 15:09:39 -08002347
2348 if (pch_iir & SDE_AUDIO_HDCP_MASK)
2349 DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n");
2350
2351 if (pch_iir & SDE_AUDIO_TRANS_MASK)
2352 DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n");
2353
2354 if (pch_iir & SDE_POISON)
2355 DRM_ERROR("PCH poison interrupt\n");
2356
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002357 if (pch_iir & SDE_FDI_MASK)
Damien Lespiau055e3932014-08-18 13:49:10 +01002358 for_each_pipe(dev_priv, pipe)
Jesse Barnes9db4a9c2011-02-07 12:26:52 -08002359 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2360 pipe_name(pipe),
2361 I915_READ(FDI_RX_IIR(pipe)));
Jesse Barnes776ad802011-01-04 15:09:39 -08002362
2363 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE))
2364 DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n");
2365
2366 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR))
2367 DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n");
2368
Jesse Barnes776ad802011-01-04 15:09:39 -08002369 if (pch_iir & SDE_TRANSA_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002370 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A);
Paulo Zanoni86642812013-04-12 17:57:57 -03002371
2372 if (pch_iir & SDE_TRANSB_FIFO_UNDER)
Matthias Kaehlckea2196032017-07-17 11:14:03 -07002373 intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B);
Paulo Zanoni86642812013-04-12 17:57:57 -03002374}
2375
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002376static void ivb_err_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002377{
Paulo Zanoni86642812013-04-12 17:57:57 -03002378 u32 err_int = I915_READ(GEN7_ERR_INT);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002379 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002380
Paulo Zanonide032bf2013-04-12 17:57:58 -03002381 if (err_int & ERR_INT_POISON)
2382 DRM_ERROR("Poison interrupt\n");
2383
Damien Lespiau055e3932014-08-18 13:49:10 +01002384 for_each_pipe(dev_priv, pipe) {
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002385 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe))
2386 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002387
Daniel Vetter5a69b892013-10-16 22:55:52 +02002388 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002389 if (IS_IVYBRIDGE(dev_priv))
2390 ivb_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002391 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002392 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Daniel Vetter5a69b892013-10-16 22:55:52 +02002393 }
2394 }
Shuang He8bf1e9f2013-10-15 18:55:27 +01002395
Paulo Zanoni86642812013-04-12 17:57:57 -03002396 I915_WRITE(GEN7_ERR_INT, err_int);
2397}
2398
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002399static void cpt_serr_int_handler(struct drm_i915_private *dev_priv)
Paulo Zanoni86642812013-04-12 17:57:57 -03002400{
Paulo Zanoni86642812013-04-12 17:57:57 -03002401 u32 serr_int = I915_READ(SERR_INT);
Mika Kahola45c1cd82017-10-10 13:17:06 +03002402 enum pipe pipe;
Paulo Zanoni86642812013-04-12 17:57:57 -03002403
Paulo Zanonide032bf2013-04-12 17:57:58 -03002404 if (serr_int & SERR_INT_POISON)
2405 DRM_ERROR("PCH poison interrupt\n");
2406
Mika Kahola45c1cd82017-10-10 13:17:06 +03002407 for_each_pipe(dev_priv, pipe)
2408 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe))
2409 intel_pch_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanoni86642812013-04-12 17:57:57 -03002410
2411 I915_WRITE(SERR_INT, serr_int);
Jesse Barnes776ad802011-01-04 15:09:39 -08002412}
2413
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002414static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Adam Jackson23e81d62012-06-06 15:45:44 -04002415{
Adam Jackson23e81d62012-06-06 15:45:44 -04002416 int pipe;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002417 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT;
Adam Jackson23e81d62012-06-06 15:45:44 -04002418
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002419 ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt);
Daniel Vetter91d131d2013-06-27 17:52:14 +02002420
Ville Syrjäläcfc33bf2013-04-17 17:48:48 +03002421 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) {
2422 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >>
2423 SDE_AUDIO_POWER_SHIFT_CPT);
2424 DRM_DEBUG_DRIVER("PCH audio power change on port %c\n",
2425 port_name(port));
2426 }
Adam Jackson23e81d62012-06-06 15:45:44 -04002427
2428 if (pch_iir & SDE_AUX_MASK_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002429 dp_aux_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002430
2431 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002432 gmbus_irq_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002433
2434 if (pch_iir & SDE_AUDIO_CP_REQ_CPT)
2435 DRM_DEBUG_DRIVER("Audio CP request interrupt\n");
2436
2437 if (pch_iir & SDE_AUDIO_CP_CHG_CPT)
2438 DRM_DEBUG_DRIVER("Audio CP change interrupt\n");
2439
2440 if (pch_iir & SDE_FDI_MASK_CPT)
Damien Lespiau055e3932014-08-18 13:49:10 +01002441 for_each_pipe(dev_priv, pipe)
Adam Jackson23e81d62012-06-06 15:45:44 -04002442 DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n",
2443 pipe_name(pipe),
2444 I915_READ(FDI_RX_IIR(pipe)));
Paulo Zanoni86642812013-04-12 17:57:57 -03002445
2446 if (pch_iir & SDE_ERROR_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002447 cpt_serr_int_handler(dev_priv);
Adam Jackson23e81d62012-06-06 15:45:44 -04002448}
2449
Anusha Srivatsa31604222018-06-26 13:52:23 -07002450static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
2451{
2452 u32 ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP;
2453 u32 tc_hotplug_trigger = pch_iir & SDE_TC_MASK_ICP;
2454 u32 pin_mask = 0, long_mask = 0;
2455
2456 if (ddi_hotplug_trigger) {
2457 u32 dig_hotplug_reg;
2458
2459 dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_DDI);
2460 I915_WRITE(SHOTPLUG_CTL_DDI, dig_hotplug_reg);
2461
2462 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2463 ddi_hotplug_trigger,
2464 dig_hotplug_reg, hpd_icp,
2465 icp_ddi_port_hotplug_long_detect);
2466 }
2467
2468 if (tc_hotplug_trigger) {
2469 u32 dig_hotplug_reg;
2470
2471 dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_TC);
2472 I915_WRITE(SHOTPLUG_CTL_TC, dig_hotplug_reg);
2473
2474 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2475 tc_hotplug_trigger,
2476 dig_hotplug_reg, hpd_icp,
2477 icp_tc_port_hotplug_long_detect);
2478 }
2479
2480 if (pin_mask)
2481 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2482
2483 if (pch_iir & SDE_GMBUS_ICP)
2484 gmbus_irq_handler(dev_priv);
2485}
2486
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002487static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002488{
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002489 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT &
2490 ~SDE_PORTE_HOTPLUG_SPT;
2491 u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT;
2492 u32 pin_mask = 0, long_mask = 0;
2493
2494 if (hotplug_trigger) {
2495 u32 dig_hotplug_reg;
2496
2497 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2498 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
2499
Rodrigo Vivicf539022018-01-29 15:22:21 -08002500 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2501 hotplug_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä74c0b392015-08-27 23:56:07 +03002502 spt_port_hotplug_long_detect);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002503 }
2504
2505 if (hotplug2_trigger) {
2506 u32 dig_hotplug_reg;
2507
2508 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2);
2509 I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg);
2510
Rodrigo Vivicf539022018-01-29 15:22:21 -08002511 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask,
2512 hotplug2_trigger, dig_hotplug_reg, hpd_spt,
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002513 spt_port_hotplug2_long_detect);
2514 }
2515
2516 if (pin_mask)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002517 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002518
2519 if (pch_iir & SDE_GMBUS_CPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002520 gmbus_irq_handler(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002521}
2522
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002523static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv,
2524 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002525 const u32 hpd[HPD_NUM_PINS])
2526{
Ville Syrjälä40e56412015-08-27 23:56:10 +03002527 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
2528
2529 dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
2530 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg);
2531
Rodrigo Vivicf539022018-01-29 15:22:21 -08002532 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002533 dig_hotplug_reg, hpd,
2534 ilk_port_hotplug_long_detect);
2535
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002536 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002537}
2538
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002539static void ilk_display_irq_handler(struct drm_i915_private *dev_priv,
2540 u32 de_iir)
Paulo Zanonic008bc62013-07-12 16:35:10 -03002541{
Daniel Vetter40da17c22013-10-21 18:04:36 +02002542 enum pipe pipe;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03002543 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG;
2544
Ville Syrjälä40e56412015-08-27 23:56:10 +03002545 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002546 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002547
2548 if (de_iir & DE_AUX_CHANNEL_A)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002549 dp_aux_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002550
2551 if (de_iir & DE_GSE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002552 intel_opregion_asle_intr(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002553
Paulo Zanonic008bc62013-07-12 16:35:10 -03002554 if (de_iir & DE_POISON)
2555 DRM_ERROR("Poison interrupt\n");
2556
Damien Lespiau055e3932014-08-18 13:49:10 +01002557 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002558 if (de_iir & DE_PIPE_VBLANK(pipe))
2559 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002560
Daniel Vetter40da17c22013-10-21 18:04:36 +02002561 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe))
Daniel Vetter1f7247c2014-09-30 10:56:48 +02002562 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002563
Daniel Vetter40da17c22013-10-21 18:04:36 +02002564 if (de_iir & DE_PIPE_CRC_DONE(pipe))
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002565 i9xx_pipe_crc_irq_handler(dev_priv, pipe);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002566 }
2567
2568 /* check event from PCH */
2569 if (de_iir & DE_PCH_EVENT) {
2570 u32 pch_iir = I915_READ(SDEIIR);
2571
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002572 if (HAS_PCH_CPT(dev_priv))
2573 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002574 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002575 ibx_irq_handler(dev_priv, pch_iir);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002576
2577 /* should clear PCH hotplug event before clear CPU irq */
2578 I915_WRITE(SDEIIR, pch_iir);
2579 }
2580
Lucas De Marchicf819ef2018-12-12 10:10:43 -08002581 if (IS_GEN(dev_priv, 5) && de_iir & DE_PCU_EVENT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002582 ironlake_rps_change_irq_handler(dev_priv);
Paulo Zanonic008bc62013-07-12 16:35:10 -03002583}
2584
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002585static void ivb_display_irq_handler(struct drm_i915_private *dev_priv,
2586 u32 de_iir)
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002587{
Damien Lespiau07d27e22014-03-03 17:31:46 +00002588 enum pipe pipe;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03002589 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB;
2590
Ville Syrjälä40e56412015-08-27 23:56:10 +03002591 if (hotplug_trigger)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002592 ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002593
2594 if (de_iir & DE_ERR_INT_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002595 ivb_err_int_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002596
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002597 if (de_iir & DE_EDP_PSR_INT_HSW) {
2598 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2599
2600 intel_psr_irq_handler(dev_priv, psr_iir);
2601 I915_WRITE(EDP_PSR_IIR, psr_iir);
2602 }
Daniel Vetterfc340442018-04-05 15:00:23 -07002603
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002604 if (de_iir & DE_AUX_CHANNEL_A_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002605 dp_aux_irq_handler(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002606
2607 if (de_iir & DE_GSE_IVB)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002608 intel_opregion_asle_intr(dev_priv);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002609
Damien Lespiau055e3932014-08-18 13:49:10 +01002610 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002611 if (de_iir & (DE_PIPE_VBLANK_IVB(pipe)))
2612 drm_handle_vblank(&dev_priv->drm, pipe);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002613 }
2614
2615 /* check event from PCH */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002616 if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) {
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002617 u32 pch_iir = I915_READ(SDEIIR);
2618
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002619 cpt_irq_handler(dev_priv, pch_iir);
Paulo Zanoni9719fb92013-07-12 16:35:11 -03002620
2621 /* clear PCH hotplug event before clear CPU irq */
2622 I915_WRITE(SDEIIR, pch_iir);
2623 }
2624}
2625
Oscar Mateo72c90f62014-06-16 16:10:57 +01002626/*
2627 * To handle irqs with the minimum potential races with fresh interrupts, we:
2628 * 1 - Disable Master Interrupt Control.
2629 * 2 - Find the source(s) of the interrupt.
2630 * 3 - Clear the Interrupt Identity bits (IIR).
2631 * 4 - Process the interrupt(s) that had bits set in the IIRs.
2632 * 5 - Re-enable Master Interrupt Control.
2633 */
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002634static irqreturn_t ironlake_irq_handler(int irq, void *arg)
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002635{
Daniel Vetter45a83f82014-05-12 19:17:55 +02002636 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01002637 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002638 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
Chris Wilson0e434062012-05-09 21:45:44 +01002639 irqreturn_t ret = IRQ_NONE;
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002640
Imre Deak2dd2a882015-02-24 11:14:30 +02002641 if (!intel_irqs_enabled(dev_priv))
2642 return IRQ_NONE;
2643
Imre Deak1f814da2015-12-16 02:52:19 +02002644 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2645 disable_rpm_wakeref_asserts(dev_priv);
2646
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002647 /* disable master interrupt before clearing iir */
2648 de_ier = I915_READ(DEIER);
2649 I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL);
Chris Wilson0e434062012-05-09 21:45:44 +01002650
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002651 /* Disable south interrupts. We'll only write to SDEIIR once, so further
2652 * interrupts will will be stored on its back queue, and then we'll be
2653 * able to process them after we restore SDEIER (as soon as we restore
2654 * it, we'll get an interrupt if SDEIIR still has something to process
2655 * due to its back queue). */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002656 if (!HAS_PCH_NOP(dev_priv)) {
Ben Widawskyab5c6082013-04-05 13:12:41 -07002657 sde_ier = I915_READ(SDEIER);
2658 I915_WRITE(SDEIER, 0);
Ben Widawskyab5c6082013-04-05 13:12:41 -07002659 }
Paulo Zanoni44498ae2013-02-22 17:05:28 -03002660
Oscar Mateo72c90f62014-06-16 16:10:57 +01002661 /* Find, clear, then process each source of interrupt */
2662
Chris Wilson0e434062012-05-09 21:45:44 +01002663 gt_iir = I915_READ(GTIIR);
2664 if (gt_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002665 I915_WRITE(GTIIR, gt_iir);
2666 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002667 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002668 snb_gt_irq_handler(dev_priv, gt_iir);
Paulo Zanonid8fc8a42013-07-19 18:57:55 -03002669 else
Ville Syrjälä261e40b2016-04-13 21:19:57 +03002670 ilk_gt_irq_handler(dev_priv, gt_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002671 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002672
2673 de_iir = I915_READ(DEIIR);
Chris Wilson0e434062012-05-09 21:45:44 +01002674 if (de_iir) {
Oscar Mateo72c90f62014-06-16 16:10:57 +01002675 I915_WRITE(DEIIR, de_iir);
2676 ret = IRQ_HANDLED;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002677 if (INTEL_GEN(dev_priv) >= 7)
2678 ivb_display_irq_handler(dev_priv, de_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002679 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002680 ilk_display_irq_handler(dev_priv, de_iir);
Chris Wilson0e434062012-05-09 21:45:44 +01002681 }
2682
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002683 if (INTEL_GEN(dev_priv) >= 6) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002684 u32 pm_iir = I915_READ(GEN6_PMIIR);
2685 if (pm_iir) {
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002686 I915_WRITE(GEN6_PMIIR, pm_iir);
2687 ret = IRQ_HANDLED;
Oscar Mateo72c90f62014-06-16 16:10:57 +01002688 gen6_rps_irq_handler(dev_priv, pm_iir);
Paulo Zanonif1af8fc2013-07-12 19:56:30 -03002689 }
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002690 }
2691
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002692 I915_WRITE(DEIER, de_ier);
Chris Wilson74093f32018-06-28 21:12:03 +01002693 if (!HAS_PCH_NOP(dev_priv))
Ben Widawskyab5c6082013-04-05 13:12:41 -07002694 I915_WRITE(SDEIER, sde_ier);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002695
Imre Deak1f814da2015-12-16 02:52:19 +02002696 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2697 enable_rpm_wakeref_asserts(dev_priv);
2698
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07002699 return ret;
2700}
2701
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002702static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv,
2703 u32 hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002704 const u32 hpd[HPD_NUM_PINS])
Shashank Sharmad04a4922014-08-22 17:40:41 +05302705{
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002706 u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302707
Ville Syrjäläa52bb152015-08-27 23:56:11 +03002708 dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG);
2709 I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302710
Rodrigo Vivicf539022018-01-29 15:22:21 -08002711 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger,
Ville Syrjälä40e56412015-08-27 23:56:10 +03002712 dig_hotplug_reg, hpd,
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002713 bxt_port_hotplug_long_detect);
Ville Syrjälä40e56412015-08-27 23:56:10 +03002714
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002715 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302716}
2717
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002718static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir)
2719{
2720 u32 pin_mask = 0, long_mask = 0;
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002721 u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK;
2722 u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002723
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002724 if (trigger_tc) {
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002725 u32 dig_hotplug_reg;
2726
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002727 dig_hotplug_reg = I915_READ(GEN11_TC_HOTPLUG_CTL);
2728 I915_WRITE(GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg);
2729
2730 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tc,
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002731 dig_hotplug_reg, hpd_gen11,
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002732 gen11_port_hotplug_long_detect);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002733 }
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07002734
2735 if (trigger_tbt) {
2736 u32 dig_hotplug_reg;
2737
2738 dig_hotplug_reg = I915_READ(GEN11_TBT_HOTPLUG_CTL);
2739 I915_WRITE(GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg);
2740
2741 intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tbt,
2742 dig_hotplug_reg, hpd_gen11,
2743 gen11_port_hotplug_long_detect);
2744 }
2745
2746 if (pin_mask)
2747 intel_hpd_irq_handler(dev_priv, pin_mask, long_mask);
2748 else
2749 DRM_ERROR("Unexpected DE HPD interrupt 0x%08x\n", iir);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002750}
2751
Lucas De Marchi9d172102019-02-25 16:49:00 -08002752static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv)
2753{
2754 u32 mask = GEN8_AUX_CHANNEL_A;
2755
2756 if (INTEL_GEN(dev_priv) >= 9)
2757 mask |= GEN9_AUX_CHANNEL_B |
2758 GEN9_AUX_CHANNEL_C |
2759 GEN9_AUX_CHANNEL_D;
2760
2761 if (IS_CNL_WITH_PORT_F(dev_priv))
2762 mask |= CNL_AUX_CHANNEL_F;
2763
2764 if (INTEL_GEN(dev_priv) >= 11)
2765 mask |= ICL_AUX_CHANNEL_E |
2766 CNL_AUX_CHANNEL_F;
2767
2768 return mask;
2769}
2770
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002771static irqreturn_t
2772gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl)
Ben Widawskyabd58f02013-11-02 21:07:09 -07002773{
Ben Widawskyabd58f02013-11-02 21:07:09 -07002774 irqreturn_t ret = IRQ_NONE;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002775 u32 iir;
Daniel Vetterc42664c2013-11-07 11:05:40 +01002776 enum pipe pipe;
Jesse Barnes88e04702014-11-13 17:51:48 +00002777
Ben Widawskyabd58f02013-11-02 21:07:09 -07002778 if (master_ctl & GEN8_DE_MISC_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002779 iir = I915_READ(GEN8_DE_MISC_IIR);
2780 if (iir) {
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002781 bool found = false;
2782
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002783 I915_WRITE(GEN8_DE_MISC_IIR, iir);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002784 ret = IRQ_HANDLED;
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002785
2786 if (iir & GEN8_DE_MISC_GSE) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002787 intel_opregion_asle_intr(dev_priv);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002788 found = true;
2789 }
2790
2791 if (iir & GEN8_DE_EDP_PSR) {
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07002792 u32 psr_iir = I915_READ(EDP_PSR_IIR);
2793
2794 intel_psr_irq_handler(dev_priv, psr_iir);
2795 I915_WRITE(EDP_PSR_IIR, psr_iir);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07002796 found = true;
2797 }
2798
2799 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002800 DRM_ERROR("Unexpected DE Misc interrupt\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002801 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002802 else
2803 DRM_ERROR("The master control interrupt lied (DE MISC)!\n");
Ben Widawskyabd58f02013-11-02 21:07:09 -07002804 }
2805
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07002806 if (INTEL_GEN(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) {
2807 iir = I915_READ(GEN11_DE_HPD_IIR);
2808 if (iir) {
2809 I915_WRITE(GEN11_DE_HPD_IIR, iir);
2810 ret = IRQ_HANDLED;
2811 gen11_hpd_irq_handler(dev_priv, iir);
2812 } else {
2813 DRM_ERROR("The master control interrupt lied, (DE HPD)!\n");
2814 }
2815 }
2816
Daniel Vetter6d766f02013-11-07 14:49:55 +01002817 if (master_ctl & GEN8_DE_PORT_IRQ) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002818 iir = I915_READ(GEN8_DE_PORT_IIR);
2819 if (iir) {
2820 u32 tmp_mask;
Shashank Sharmad04a4922014-08-22 17:40:41 +05302821 bool found = false;
Ville Syrjäläcebd87a2015-08-27 23:56:09 +03002822
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002823 I915_WRITE(GEN8_DE_PORT_IIR, iir);
Daniel Vetter6d766f02013-11-07 14:49:55 +01002824 ret = IRQ_HANDLED;
Jesse Barnes88e04702014-11-13 17:51:48 +00002825
Lucas De Marchi9d172102019-02-25 16:49:00 -08002826 if (iir & gen8_de_port_aux_mask(dev_priv)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002827 dp_aux_irq_handler(dev_priv);
Shashank Sharmad04a4922014-08-22 17:40:41 +05302828 found = true;
2829 }
2830
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002831 if (IS_GEN9_LP(dev_priv)) {
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002832 tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK;
2833 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002834 bxt_hpd_irq_handler(dev_priv, tmp_mask,
2835 hpd_bxt);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002836 found = true;
2837 }
2838 } else if (IS_BROADWELL(dev_priv)) {
2839 tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG;
2840 if (tmp_mask) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002841 ilk_hpd_irq_handler(dev_priv,
2842 tmp_mask, hpd_bdw);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002843 found = true;
2844 }
Shashank Sharmad04a4922014-08-22 17:40:41 +05302845 }
2846
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02002847 if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) {
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002848 gmbus_irq_handler(dev_priv);
Shashank Sharma9e637432014-08-22 17:40:43 +05302849 found = true;
2850 }
2851
Shashank Sharmad04a4922014-08-22 17:40:41 +05302852 if (!found)
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002853 DRM_ERROR("Unexpected DE Port interrupt\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002854 }
Oscar Mateo38cc46d2014-06-16 16:10:59 +01002855 else
2856 DRM_ERROR("The master control interrupt lied (DE PORT)!\n");
Daniel Vetter6d766f02013-11-07 14:49:55 +01002857 }
2858
Damien Lespiau055e3932014-08-18 13:49:10 +01002859 for_each_pipe(dev_priv, pipe) {
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002860 u32 fault_errors;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002861
Daniel Vetterc42664c2013-11-07 11:05:40 +01002862 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe)))
2863 continue;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002864
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002865 iir = I915_READ(GEN8_DE_PIPE_IIR(pipe));
2866 if (!iir) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07002867 DRM_ERROR("The master control interrupt lied (DE PIPE)!\n");
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002868 continue;
2869 }
2870
2871 ret = IRQ_HANDLED;
2872 I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir);
2873
Daniel Vetterfd3a4022017-07-20 19:57:51 +02002874 if (iir & GEN8_PIPE_VBLANK)
2875 drm_handle_vblank(&dev_priv->drm, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002876
2877 if (iir & GEN8_PIPE_CDCLK_CRC_DONE)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002878 hsw_pipe_crc_irq_handler(dev_priv, pipe);
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002879
2880 if (iir & GEN8_PIPE_FIFO_UNDERRUN)
2881 intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe);
2882
2883 fault_errors = iir;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07002884 if (INTEL_GEN(dev_priv) >= 9)
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002885 fault_errors &= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
2886 else
2887 fault_errors &= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
2888
2889 if (fault_errors)
Tvrtko Ursulin1353ec32016-10-27 13:48:32 +01002890 DRM_ERROR("Fault errors on pipe %c: 0x%08x\n",
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002891 pipe_name(pipe),
2892 fault_errors);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002893 }
2894
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002895 if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) &&
Shashank Sharma266ea3d2014-08-22 17:40:42 +05302896 master_ctl & GEN8_DE_PCH_IRQ) {
Daniel Vetter92d03a82013-11-07 11:05:43 +01002897 /*
2898 * FIXME(BDW): Assume for now that the new interrupt handling
2899 * scheme also closed the SDE interrupt handling race we've seen
2900 * on older pch-split platforms. But this needs testing.
2901 */
Tvrtko Ursuline32192e2016-01-12 16:04:06 +00002902 iir = I915_READ(SDEIIR);
2903 if (iir) {
2904 I915_WRITE(SDEIIR, iir);
Daniel Vetter92d03a82013-11-07 11:05:43 +01002905 ret = IRQ_HANDLED;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002906
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07002907 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07002908 icp_irq_handler(dev_priv, iir);
Rodrigo Vivic6c30b92019-03-08 13:43:00 -08002909 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002910 spt_irq_handler(dev_priv, iir);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03002911 else
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01002912 cpt_irq_handler(dev_priv, iir);
Jani Nikula2dfb0b82016-01-07 10:29:10 +02002913 } else {
2914 /*
2915 * Like on previous PCH there seems to be something
2916 * fishy going on with forwarding PCH interrupts.
2917 */
2918 DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n");
2919 }
Daniel Vetter92d03a82013-11-07 11:05:43 +01002920 }
2921
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002922 return ret;
2923}
2924
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002925static inline u32 gen8_master_intr_disable(void __iomem * const regs)
2926{
2927 raw_reg_write(regs, GEN8_MASTER_IRQ, 0);
2928
2929 /*
2930 * Now with master disabled, get a sample of level indications
2931 * for this interrupt. Indications will be cleared on related acks.
2932 * New indications can and will light up during processing,
2933 * and will generate new interrupt after enabling master.
2934 */
2935 return raw_reg_read(regs, GEN8_MASTER_IRQ);
2936}
2937
2938static inline void gen8_master_intr_enable(void __iomem * const regs)
2939{
2940 raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
2941}
2942
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002943static irqreturn_t gen8_irq_handler(int irq, void *arg)
2944{
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002945 struct drm_i915_private *dev_priv = to_i915(arg);
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07002946 void __iomem * const regs = dev_priv->uncore.regs;
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002947 u32 master_ctl;
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002948 u32 gt_iir[4];
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002949
2950 if (!intel_irqs_enabled(dev_priv))
2951 return IRQ_NONE;
2952
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002953 master_ctl = gen8_master_intr_disable(regs);
2954 if (!master_ctl) {
2955 gen8_master_intr_enable(regs);
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002956 return IRQ_NONE;
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002957 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002958
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002959 /* Find, clear, then process each source of interrupt */
Chris Wilson55ef72f2018-02-02 15:34:48 +00002960 gen8_gt_irq_ack(dev_priv, master_ctl, gt_iir);
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002961
2962 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
2963 if (master_ctl & ~GEN8_GT_IRQS) {
2964 disable_rpm_wakeref_asserts(dev_priv);
2965 gen8_de_irq_handler(dev_priv, master_ctl);
2966 enable_rpm_wakeref_asserts(dev_priv);
2967 }
Tvrtko Ursulinf11a0f42016-01-12 16:04:07 +00002968
Mika Kuoppala4376b9c2018-10-15 17:14:38 +03002969 gen8_master_intr_enable(regs);
Ben Widawskyabd58f02013-11-02 21:07:09 -07002970
Chris Wilsonf0fd96f2018-02-15 07:37:12 +00002971 gen8_gt_irq_handler(dev_priv, master_ctl, gt_iir);
Imre Deak1f814da2015-12-16 02:52:19 +02002972
Chris Wilson55ef72f2018-02-02 15:34:48 +00002973 return IRQ_HANDLED;
Ben Widawskyabd58f02013-11-02 21:07:09 -07002974}
2975
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002976static u32
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03002977gen11_gt_engine_identity(struct drm_i915_private * const i915,
2978 const unsigned int bank, const unsigned int bit)
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002979{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07002980 void __iomem * const regs = i915->uncore.regs;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002981 u32 timeout_ts;
2982 u32 ident;
2983
Oscar Mateo96606f32018-04-06 12:32:37 +03002984 lockdep_assert_held(&i915->irq_lock);
2985
Mika Kuoppala51951ae2018-02-28 12:11:53 +02002986 raw_reg_write(regs, GEN11_IIR_REG_SELECTOR(bank), BIT(bit));
2987
2988 /*
2989 * NB: Specs do not specify how long to spin wait,
2990 * so we do ~100us as an educated guess.
2991 */
2992 timeout_ts = (local_clock() >> 10) + 100;
2993 do {
2994 ident = raw_reg_read(regs, GEN11_INTR_IDENTITY_REG(bank));
2995 } while (!(ident & GEN11_INTR_DATA_VALID) &&
2996 !time_after32(local_clock() >> 10, timeout_ts));
2997
2998 if (unlikely(!(ident & GEN11_INTR_DATA_VALID))) {
2999 DRM_ERROR("INTR_IDENTITY_REG%u:%u 0x%08x not valid!\n",
3000 bank, bit, ident);
3001 return 0;
3002 }
3003
3004 raw_reg_write(regs, GEN11_INTR_IDENTITY_REG(bank),
3005 GEN11_INTR_DATA_VALID);
3006
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003007 return ident;
3008}
3009
3010static void
3011gen11_other_irq_handler(struct drm_i915_private * const i915,
3012 const u8 instance, const u16 iir)
3013{
Oscar Mateod02b98b2018-04-05 17:00:50 +03003014 if (instance == OTHER_GTPM_INSTANCE)
Mika Kuoppalaa087baf2019-04-10 16:21:23 +03003015 return gen11_rps_irq_handler(i915, iir);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003016
Mika Kuoppalaf744dbc2018-04-06 12:31:45 +03003017 WARN_ONCE(1, "unhandled other interrupt instance=0x%x, iir=0x%x\n",
3018 instance, iir);
3019}
3020
3021static void
3022gen11_engine_irq_handler(struct drm_i915_private * const i915,
3023 const u8 class, const u8 instance, const u16 iir)
3024{
3025 struct intel_engine_cs *engine;
3026
3027 if (instance <= MAX_ENGINE_INSTANCE)
3028 engine = i915->engine_class[class][instance];
3029 else
3030 engine = NULL;
3031
3032 if (likely(engine))
3033 return gen8_cs_irq_handler(engine, iir);
3034
3035 WARN_ONCE(1, "unhandled engine interrupt class=0x%x, instance=0x%x\n",
3036 class, instance);
3037}
3038
3039static void
3040gen11_gt_identity_handler(struct drm_i915_private * const i915,
3041 const u32 identity)
3042{
3043 const u8 class = GEN11_INTR_ENGINE_CLASS(identity);
3044 const u8 instance = GEN11_INTR_ENGINE_INSTANCE(identity);
3045 const u16 intr = GEN11_INTR_ENGINE_INTR(identity);
3046
3047 if (unlikely(!intr))
3048 return;
3049
3050 if (class <= COPY_ENGINE_CLASS)
3051 return gen11_engine_irq_handler(i915, class, instance, intr);
3052
3053 if (class == OTHER_CLASS)
3054 return gen11_other_irq_handler(i915, instance, intr);
3055
3056 WARN_ONCE(1, "unknown interrupt class=0x%x, instance=0x%x, intr=0x%x\n",
3057 class, instance, intr);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003058}
3059
3060static void
Oscar Mateo96606f32018-04-06 12:32:37 +03003061gen11_gt_bank_handler(struct drm_i915_private * const i915,
3062 const unsigned int bank)
3063{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003064 void __iomem * const regs = i915->uncore.regs;
Oscar Mateo96606f32018-04-06 12:32:37 +03003065 unsigned long intr_dw;
3066 unsigned int bit;
3067
3068 lockdep_assert_held(&i915->irq_lock);
3069
3070 intr_dw = raw_reg_read(regs, GEN11_GT_INTR_DW(bank));
3071
Oscar Mateo96606f32018-04-06 12:32:37 +03003072 for_each_set_bit(bit, &intr_dw, 32) {
Mika Kuoppala8455dad2019-04-10 16:21:24 +03003073 const u32 ident = gen11_gt_engine_identity(i915, bank, bit);
Oscar Mateo96606f32018-04-06 12:32:37 +03003074
3075 gen11_gt_identity_handler(i915, ident);
3076 }
3077
3078 /* Clear must be after shared has been served for engine */
3079 raw_reg_write(regs, GEN11_GT_INTR_DW(bank), intr_dw);
3080}
3081
3082static void
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003083gen11_gt_irq_handler(struct drm_i915_private * const i915,
3084 const u32 master_ctl)
3085{
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003086 unsigned int bank;
3087
Oscar Mateo96606f32018-04-06 12:32:37 +03003088 spin_lock(&i915->irq_lock);
3089
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003090 for (bank = 0; bank < 2; bank++) {
Oscar Mateo96606f32018-04-06 12:32:37 +03003091 if (master_ctl & GEN11_GT_DW_IRQ(bank))
3092 gen11_gt_bank_handler(i915, bank);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003093 }
Oscar Mateo96606f32018-04-06 12:32:37 +03003094
3095 spin_unlock(&i915->irq_lock);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003096}
3097
Chris Wilson7a909382018-09-26 11:47:18 +01003098static u32
3099gen11_gu_misc_irq_ack(struct drm_i915_private *dev_priv, const u32 master_ctl)
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003100{
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003101 void __iomem * const regs = dev_priv->uncore.regs;
Chris Wilson7a909382018-09-26 11:47:18 +01003102 u32 iir;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003103
3104 if (!(master_ctl & GEN11_GU_MISC_IRQ))
Chris Wilson7a909382018-09-26 11:47:18 +01003105 return 0;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003106
Chris Wilson7a909382018-09-26 11:47:18 +01003107 iir = raw_reg_read(regs, GEN11_GU_MISC_IIR);
3108 if (likely(iir))
3109 raw_reg_write(regs, GEN11_GU_MISC_IIR, iir);
3110
3111 return iir;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003112}
3113
3114static void
Chris Wilson7a909382018-09-26 11:47:18 +01003115gen11_gu_misc_irq_handler(struct drm_i915_private *dev_priv, const u32 iir)
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003116{
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003117 if (iir & GEN11_GU_MISC_GSE)
3118 intel_opregion_asle_intr(dev_priv);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003119}
3120
Mika Kuoppala81067b72018-10-15 17:14:40 +03003121static inline u32 gen11_master_intr_disable(void __iomem * const regs)
3122{
3123 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0);
3124
3125 /*
3126 * Now with master disabled, get a sample of level indications
3127 * for this interrupt. Indications will be cleared on related acks.
3128 * New indications can and will light up during processing,
3129 * and will generate new interrupt after enabling master.
3130 */
3131 return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ);
3132}
3133
3134static inline void gen11_master_intr_enable(void __iomem * const regs)
3135{
3136 raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ);
3137}
3138
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003139static irqreturn_t gen11_irq_handler(int irq, void *arg)
3140{
3141 struct drm_i915_private * const i915 = to_i915(arg);
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003142 void __iomem * const regs = i915->uncore.regs;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003143 u32 master_ctl;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003144 u32 gu_misc_iir;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003145
3146 if (!intel_irqs_enabled(i915))
3147 return IRQ_NONE;
3148
Mika Kuoppala81067b72018-10-15 17:14:40 +03003149 master_ctl = gen11_master_intr_disable(regs);
3150 if (!master_ctl) {
3151 gen11_master_intr_enable(regs);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003152 return IRQ_NONE;
Mika Kuoppala81067b72018-10-15 17:14:40 +03003153 }
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003154
3155 /* Find, clear, then process each source of interrupt. */
3156 gen11_gt_irq_handler(i915, master_ctl);
3157
3158 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
3159 if (master_ctl & GEN11_DISPLAY_IRQ) {
3160 const u32 disp_ctl = raw_reg_read(regs, GEN11_DISPLAY_INT_CTL);
3161
3162 disable_rpm_wakeref_asserts(i915);
3163 /*
3164 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ
3165 * for the display related bits.
3166 */
3167 gen8_de_irq_handler(i915, disp_ctl);
3168 enable_rpm_wakeref_asserts(i915);
3169 }
3170
Chris Wilson7a909382018-09-26 11:47:18 +01003171 gu_misc_iir = gen11_gu_misc_irq_ack(i915, master_ctl);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003172
Mika Kuoppala81067b72018-10-15 17:14:40 +03003173 gen11_master_intr_enable(regs);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003174
Chris Wilson7a909382018-09-26 11:47:18 +01003175 gen11_gu_misc_irq_handler(i915, gu_misc_iir);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003176
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003177 return IRQ_HANDLED;
3178}
3179
Keith Packard42f52ef2008-10-18 19:39:29 -07003180/* Called from drm generic code, passed 'crtc' which
3181 * we use as a pipe index
3182 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003183static int i8xx_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003184{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003185 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003186 unsigned long irqflags;
Jesse Barnes71e0ffa2009-01-08 10:42:15 -08003187
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003188 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Chris Wilson86e83e32016-10-07 20:49:52 +01003189 i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3190 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3191
3192 return 0;
3193}
3194
Ville Syrjäläd938da62019-03-22 20:08:03 +02003195static int i945gm_enable_vblank(struct drm_device *dev, unsigned int pipe)
3196{
3197 struct drm_i915_private *dev_priv = to_i915(dev);
3198
3199 if (dev_priv->i945gm_vblank.enabled++ == 0)
3200 schedule_work(&dev_priv->i945gm_vblank.work);
3201
3202 return i8xx_enable_vblank(dev, pipe);
3203}
3204
Chris Wilson86e83e32016-10-07 20:49:52 +01003205static int i965_enable_vblank(struct drm_device *dev, unsigned int pipe)
3206{
3207 struct drm_i915_private *dev_priv = to_i915(dev);
3208 unsigned long irqflags;
3209
3210 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3211 i915_enable_pipestat(dev_priv, pipe,
3212 PIPE_START_VBLANK_INTERRUPT_STATUS);
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003213 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Chris Wilson8692d00e2011-02-05 10:08:21 +00003214
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003215 return 0;
3216}
3217
Thierry Reding88e72712015-09-24 18:35:31 +02003218static int ironlake_enable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003219{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003220 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003221 unsigned long irqflags;
Jani Nikulaa9c287c2019-01-16 11:15:24 +02003222 u32 bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003223 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003224
Jesse Barnesf796cf82011-04-07 13:58:17 -07003225 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003226 ilk_enable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003227 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3228
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003229 /* Even though there is no DMC, frame counter can get stuck when
3230 * PSR is active as no frames are generated.
3231 */
3232 if (HAS_PSR(dev_priv))
3233 drm_vblank_restore(dev, pipe);
3234
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003235 return 0;
3236}
3237
Thierry Reding88e72712015-09-24 18:35:31 +02003238static int gen8_enable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003239{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003240 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003241 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003242
Ben Widawskyabd58f02013-11-02 21:07:09 -07003243 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003244 bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003245 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003246
Dhinakaran Pandiyan2e8bf222018-02-02 21:13:02 -08003247 /* Even if there is no DMC, frame counter can get stuck when
3248 * PSR is active as no frames are generated, so check only for PSR.
3249 */
3250 if (HAS_PSR(dev_priv))
3251 drm_vblank_restore(dev, pipe);
3252
Ben Widawskyabd58f02013-11-02 21:07:09 -07003253 return 0;
3254}
3255
Keith Packard42f52ef2008-10-18 19:39:29 -07003256/* Called from drm generic code, passed 'crtc' which
3257 * we use as a pipe index
3258 */
Chris Wilson86e83e32016-10-07 20:49:52 +01003259static void i8xx_disable_vblank(struct drm_device *dev, unsigned int pipe)
3260{
3261 struct drm_i915_private *dev_priv = to_i915(dev);
3262 unsigned long irqflags;
3263
3264 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
3265 i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS);
3266 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3267}
3268
Ville Syrjäläd938da62019-03-22 20:08:03 +02003269static void i945gm_disable_vblank(struct drm_device *dev, unsigned int pipe)
3270{
3271 struct drm_i915_private *dev_priv = to_i915(dev);
3272
3273 i8xx_disable_vblank(dev, pipe);
3274
3275 if (--dev_priv->i945gm_vblank.enabled == 0)
3276 schedule_work(&dev_priv->i945gm_vblank.work);
3277}
3278
Chris Wilson86e83e32016-10-07 20:49:52 +01003279static void i965_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003280{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003281 struct drm_i915_private *dev_priv = to_i915(dev);
Keith Packarde9d21d72008-10-16 11:31:38 -07003282 unsigned long irqflags;
Jesse Barnes0a3e67a2008-09-30 12:14:26 -07003283
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003284 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003285 i915_disable_pipestat(dev_priv, pipe,
Imre Deak755e9012014-02-10 18:42:47 +02003286 PIPE_START_VBLANK_INTERRUPT_STATUS);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003287 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3288}
3289
Thierry Reding88e72712015-09-24 18:35:31 +02003290static void ironlake_disable_vblank(struct drm_device *dev, unsigned int pipe)
Jesse Barnesf796cf82011-04-07 13:58:17 -07003291{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003292 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003293 unsigned long irqflags;
Jani Nikulaa9c287c2019-01-16 11:15:24 +02003294 u32 bit = INTEL_GEN(dev_priv) >= 7 ?
Chris Wilson86e83e32016-10-07 20:49:52 +01003295 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe);
Jesse Barnesf796cf82011-04-07 13:58:17 -07003296
3297 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003298 ilk_disable_display_irq(dev_priv, bit);
Jesse Barnesb1f14ad2011-04-06 12:13:38 -07003299 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3300}
3301
Thierry Reding88e72712015-09-24 18:35:31 +02003302static void gen8_disable_vblank(struct drm_device *dev, unsigned int pipe)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003303{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003304 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003305 unsigned long irqflags;
Ben Widawskyabd58f02013-11-02 21:07:09 -07003306
Ben Widawskyabd58f02013-11-02 21:07:09 -07003307 spin_lock_irqsave(&dev_priv->irq_lock, irqflags);
Ville Syrjälä013d3752015-11-23 18:06:17 +02003308 bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003309 spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags);
3310}
3311
Ville Syrjäläd938da62019-03-22 20:08:03 +02003312static void i945gm_vblank_work_func(struct work_struct *work)
3313{
3314 struct drm_i915_private *dev_priv =
3315 container_of(work, struct drm_i915_private, i945gm_vblank.work);
3316
3317 /*
3318 * Vblank interrupts fail to wake up the device from C3,
3319 * hence we want to prevent C3 usage while vblank interrupts
3320 * are enabled.
3321 */
3322 pm_qos_update_request(&dev_priv->i945gm_vblank.pm_qos,
3323 READ_ONCE(dev_priv->i945gm_vblank.enabled) ?
3324 dev_priv->i945gm_vblank.c3_disable_latency :
3325 PM_QOS_DEFAULT_VALUE);
3326}
3327
3328static int cstate_disable_latency(const char *name)
3329{
3330 const struct cpuidle_driver *drv;
3331 int i;
3332
3333 drv = cpuidle_get_driver();
3334 if (!drv)
3335 return 0;
3336
3337 for (i = 0; i < drv->state_count; i++) {
3338 const struct cpuidle_state *state = &drv->states[i];
3339
3340 if (!strcmp(state->name, name))
3341 return state->exit_latency ?
3342 state->exit_latency - 1 : 0;
3343 }
3344
3345 return 0;
3346}
3347
3348static void i945gm_vblank_work_init(struct drm_i915_private *dev_priv)
3349{
3350 INIT_WORK(&dev_priv->i945gm_vblank.work,
3351 i945gm_vblank_work_func);
3352
3353 dev_priv->i945gm_vblank.c3_disable_latency =
3354 cstate_disable_latency("C3");
3355 pm_qos_add_request(&dev_priv->i945gm_vblank.pm_qos,
3356 PM_QOS_CPU_DMA_LATENCY,
3357 PM_QOS_DEFAULT_VALUE);
3358}
3359
3360static void i945gm_vblank_work_fini(struct drm_i915_private *dev_priv)
3361{
3362 cancel_work_sync(&dev_priv->i945gm_vblank.work);
3363 pm_qos_remove_request(&dev_priv->i945gm_vblank.pm_qos);
3364}
3365
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003366static void ibx_irq_reset(struct drm_i915_private *dev_priv)
Paulo Zanoni91738a92013-06-05 14:21:51 -03003367{
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003368 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni91738a92013-06-05 14:21:51 -03003369 return;
3370
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003371 GEN3_IRQ_RESET(SDE);
Paulo Zanoni105b1222014-04-01 15:37:17 -03003372
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003373 if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Paulo Zanoni105b1222014-04-01 15:37:17 -03003374 I915_WRITE(SERR_INT, 0xffffffff);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003375}
Paulo Zanoni105b1222014-04-01 15:37:17 -03003376
Paulo Zanoni622364b2014-04-01 15:37:22 -03003377/*
3378 * SDEIER is also touched by the interrupt handler to work around missed PCH
3379 * interrupts. Hence we can't update it after the interrupt handler is enabled -
3380 * instead we unconditionally enable all PCH interrupt sources here, but then
3381 * only unmask them as needed with SDEIMR.
3382 *
3383 * This function needs to be called before interrupts are enabled.
3384 */
3385static void ibx_irq_pre_postinstall(struct drm_device *dev)
3386{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003387 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03003388
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003389 if (HAS_PCH_NOP(dev_priv))
Paulo Zanoni622364b2014-04-01 15:37:22 -03003390 return;
3391
3392 WARN_ON(I915_READ(SDEIER) != 0);
Paulo Zanoni91738a92013-06-05 14:21:51 -03003393 I915_WRITE(SDEIER, 0xffffffff);
3394 POSTING_READ(SDEIER);
3395}
3396
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003397static void gen5_gt_irq_reset(struct drm_i915_private *dev_priv)
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003398{
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003399 GEN3_IRQ_RESET(GT);
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003400 if (INTEL_GEN(dev_priv) >= 6)
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003401 GEN3_IRQ_RESET(GEN6_PM);
Daniel Vetterd18ea1b2013-07-12 22:43:25 +02003402}
3403
Ville Syrjälä70591a42014-10-30 19:42:58 +02003404static void vlv_display_irq_reset(struct drm_i915_private *dev_priv)
3405{
Ville Syrjälä71b8b412016-04-11 16:56:31 +03003406 if (IS_CHERRYVIEW(dev_priv))
3407 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK_CHV);
3408 else
3409 I915_WRITE(DPINVGTT, DPINVGTT_STATUS_MASK);
3410
Ville Syrjäläad22d102016-04-12 18:56:14 +03003411 i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003412 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
3413
Ville Syrjälä44d92412017-08-18 21:36:51 +03003414 i9xx_pipestat_irq_reset(dev_priv);
Ville Syrjälä70591a42014-10-30 19:42:58 +02003415
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003416 GEN3_IRQ_RESET(VLV_);
Chris Wilson8bd099a2017-11-30 12:52:53 +00003417 dev_priv->irq_mask = ~0u;
Ville Syrjälä70591a42014-10-30 19:42:58 +02003418}
3419
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003420static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv)
3421{
3422 u32 pipestat_mask;
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003423 u32 enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003424 enum pipe pipe;
3425
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003426 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003427
3428 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
3429 for_each_pipe(dev_priv, pipe)
3430 i915_enable_pipestat(dev_priv, pipe, pipestat_mask);
3431
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003432 enable_mask = I915_DISPLAY_PORT_INTERRUPT |
3433 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003434 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
3435 I915_LPE_PIPE_A_INTERRUPT |
3436 I915_LPE_PIPE_B_INTERRUPT;
3437
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003438 if (IS_CHERRYVIEW(dev_priv))
Ville Syrjäläebf5f922017-04-27 19:02:22 +03003439 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT |
3440 I915_LPE_PIPE_C_INTERRUPT;
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003441
Chris Wilson8bd099a2017-11-30 12:52:53 +00003442 WARN_ON(dev_priv->irq_mask != ~0u);
Ville Syrjälä6b7eafc2016-04-11 16:56:29 +03003443
Ville Syrjälä9ab981f2016-04-11 16:56:28 +03003444 dev_priv->irq_mask = ~enable_mask;
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003445
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003446 GEN3_IRQ_INIT(VLV_, dev_priv->irq_mask, enable_mask);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003447}
3448
3449/* drm_dma.h hooks
3450*/
3451static void ironlake_irq_reset(struct drm_device *dev)
3452{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003453 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003454
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003455 GEN3_IRQ_RESET(DE);
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003456 if (IS_GEN(dev_priv, 7))
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003457 I915_WRITE(GEN7_ERR_INT, 0xffffffff);
3458
Daniel Vetterfc340442018-04-05 15:00:23 -07003459 if (IS_HASWELL(dev_priv)) {
3460 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3461 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3462 }
3463
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003464 gen5_gt_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003465
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003466 ibx_irq_reset(dev_priv);
Ville Syrjälä8bb61302016-04-12 18:56:44 +03003467}
3468
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003469static void valleyview_irq_reset(struct drm_device *dev)
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003470{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003471 struct drm_i915_private *dev_priv = to_i915(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003472
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03003473 I915_WRITE(VLV_MASTER_IER, 0);
3474 POSTING_READ(VLV_MASTER_IER);
3475
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003476 gen5_gt_irq_reset(dev_priv);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003477
Ville Syrjäläad22d102016-04-12 18:56:14 +03003478 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003479 if (dev_priv->display_irqs_enabled)
3480 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003481 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07003482}
3483
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003484static void gen8_gt_irq_reset(struct drm_i915_private *dev_priv)
3485{
3486 GEN8_IRQ_RESET_NDX(GT, 0);
3487 GEN8_IRQ_RESET_NDX(GT, 1);
3488 GEN8_IRQ_RESET_NDX(GT, 2);
3489 GEN8_IRQ_RESET_NDX(GT, 3);
3490}
3491
Paulo Zanoni823f6b32014-04-01 15:37:26 -03003492static void gen8_irq_reset(struct drm_device *dev)
Ben Widawskyabd58f02013-11-02 21:07:09 -07003493{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003494 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003495 int pipe;
3496
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003497 gen8_master_intr_disable(dev_priv->uncore.regs);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003498
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003499 gen8_gt_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003500
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07003501 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3502 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3503
Damien Lespiau055e3932014-08-18 13:49:10 +01003504 for_each_pipe(dev_priv, pipe)
Daniel Vetterf458ebb2014-09-30 10:56:39 +02003505 if (intel_display_power_is_enabled(dev_priv,
3506 POWER_DOMAIN_PIPE(pipe)))
Paulo Zanoni813bde42014-07-04 11:50:29 -03003507 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003508
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003509 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3510 GEN3_IRQ_RESET(GEN8_DE_MISC_);
3511 GEN3_IRQ_RESET(GEN8_PCU_);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003512
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003513 if (HAS_PCH_SPLIT(dev_priv))
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003514 ibx_irq_reset(dev_priv);
Ben Widawskyabd58f02013-11-02 21:07:09 -07003515}
Ben Widawskyabd58f02013-11-02 21:07:09 -07003516
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003517static void gen11_gt_irq_reset(struct drm_i915_private *dev_priv)
3518{
3519 /* Disable RCS, BCS, VCS and VECS class engines. */
3520 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, 0);
3521 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, 0);
3522
3523 /* Restore masks irqs on RCS, BCS, VCS and VECS engines. */
3524 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~0);
3525 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~0);
3526 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~0);
3527 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~0);
3528 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~0);
Oscar Mateod02b98b2018-04-05 17:00:50 +03003529
3530 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
3531 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003532}
3533
3534static void gen11_irq_reset(struct drm_device *dev)
3535{
3536 struct drm_i915_private *dev_priv = dev->dev_private;
3537 int pipe;
3538
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07003539 gen11_master_intr_disable(dev_priv->uncore.regs);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003540
3541 gen11_gt_irq_reset(dev_priv);
3542
3543 I915_WRITE(GEN11_DISPLAY_INT_CTL, 0);
3544
José Roberto de Souza62819df2018-11-06 11:08:42 -08003545 I915_WRITE(EDP_PSR_IMR, 0xffffffff);
3546 I915_WRITE(EDP_PSR_IIR, 0xffffffff);
3547
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003548 for_each_pipe(dev_priv, pipe)
3549 if (intel_display_power_is_enabled(dev_priv,
3550 POWER_DOMAIN_PIPE(pipe)))
3551 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
3552
3553 GEN3_IRQ_RESET(GEN8_DE_PORT_);
3554 GEN3_IRQ_RESET(GEN8_DE_MISC_);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003555 GEN3_IRQ_RESET(GEN11_DE_HPD_);
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07003556 GEN3_IRQ_RESET(GEN11_GU_MISC_);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003557 GEN3_IRQ_RESET(GEN8_PCU_);
Anusha Srivatsa31604222018-06-26 13:52:23 -07003558
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07003559 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07003560 GEN3_IRQ_RESET(SDE);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02003561}
3562
Damien Lespiau4c6c03b2015-03-06 18:50:48 +00003563void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003564 u8 pipe_mask)
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003565{
Jani Nikulaa9c287c2019-01-16 11:15:24 +02003566 u32 extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN;
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003567 enum pipe pipe;
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003568
Daniel Vetter13321782014-09-15 14:55:29 +02003569 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003570
3571 if (!intel_irqs_enabled(dev_priv)) {
3572 spin_unlock_irq(&dev_priv->irq_lock);
3573 return;
3574 }
3575
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003576 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3577 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
3578 dev_priv->de_irq_mask[pipe],
3579 ~dev_priv->de_irq_mask[pipe] | extra_ier);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003580
Daniel Vetter13321782014-09-15 14:55:29 +02003581 spin_unlock_irq(&dev_priv->irq_lock);
Paulo Zanonid49bdb02014-07-04 11:50:31 -03003582}
3583
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003584void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv,
Imre Deak001bd2c2017-07-12 18:54:13 +03003585 u8 pipe_mask)
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003586{
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003587 enum pipe pipe;
3588
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003589 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003590
3591 if (!intel_irqs_enabled(dev_priv)) {
3592 spin_unlock_irq(&dev_priv->irq_lock);
3593 return;
3594 }
3595
Ville Syrjälä6831f3e2016-02-19 20:47:31 +02003596 for_each_pipe_masked(dev_priv, pipe, pipe_mask)
3597 GEN8_IRQ_RESET_NDX(DE_PIPE, pipe);
Imre Deak9dfe2e32017-09-28 13:06:24 +03003598
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003599 spin_unlock_irq(&dev_priv->irq_lock);
3600
3601 /* make sure we're done processing display irqs */
Chris Wilson91c8a322016-07-05 10:40:23 +01003602 synchronize_irq(dev_priv->drm.irq);
Ville Syrjäläaae8ba82016-02-19 20:47:30 +02003603}
3604
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03003605static void cherryview_irq_reset(struct drm_device *dev)
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003606{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003607 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003608
3609 I915_WRITE(GEN8_MASTER_IRQ, 0);
3610 POSTING_READ(GEN8_MASTER_IRQ);
3611
Daniel Vetterd6e3cca2014-05-22 22:18:22 +02003612 gen8_gt_irq_reset(dev_priv);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003613
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003614 GEN3_IRQ_RESET(GEN8_PCU_);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003615
Ville Syrjäläad22d102016-04-12 18:56:14 +03003616 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03003617 if (dev_priv->display_irqs_enabled)
3618 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003619 spin_unlock_irq(&dev_priv->irq_lock);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03003620}
3621
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003622static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv,
Ville Syrjälä87a02102015-08-27 23:55:57 +03003623 const u32 hpd[HPD_NUM_PINS])
3624{
Ville Syrjälä87a02102015-08-27 23:55:57 +03003625 struct intel_encoder *encoder;
3626 u32 enabled_irqs = 0;
3627
Chris Wilson91c8a322016-07-05 10:40:23 +01003628 for_each_intel_encoder(&dev_priv->drm, encoder)
Ville Syrjälä87a02102015-08-27 23:55:57 +03003629 if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED)
3630 enabled_irqs |= hpd[encoder->hpd_pin];
3631
3632 return enabled_irqs;
3633}
3634
Imre Deak1a56b1a2017-01-27 11:39:21 +02003635static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv)
3636{
3637 u32 hotplug;
3638
3639 /*
3640 * Enable digital hotplug on the PCH, and configure the DP short pulse
3641 * duration to 2ms (which is the minimum in the Display Port spec).
3642 * The pulse duration bits are reserved on LPT+.
3643 */
3644 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3645 hotplug &= ~(PORTB_PULSE_DURATION_MASK |
3646 PORTC_PULSE_DURATION_MASK |
3647 PORTD_PULSE_DURATION_MASK);
3648 hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms;
3649 hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms;
3650 hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms;
3651 /*
3652 * When CPU and PCH are on the same package, port A
3653 * HPD must be enabled in both north and south.
3654 */
3655 if (HAS_PCH_LPT_LP(dev_priv))
3656 hotplug |= PORTA_HOTPLUG_ENABLE;
3657 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3658}
3659
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003660static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv)
Keith Packard7fe0b972011-09-19 13:31:02 -07003661{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003662 u32 hotplug_irqs, enabled_irqs;
Keith Packard7fe0b972011-09-19 13:31:02 -07003663
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003664 if (HAS_PCH_IBX(dev_priv)) {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003665 hotplug_irqs = SDE_HOTPLUG_MASK;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003666 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003667 } else {
Daniel Vetterfee884e2013-07-04 23:35:21 +02003668 hotplug_irqs = SDE_HOTPLUG_MASK_CPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003669 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003670 }
3671
Daniel Vetterfee884e2013-07-04 23:35:21 +02003672 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003673
Imre Deak1a56b1a2017-01-27 11:39:21 +02003674 ibx_hpd_detection_setup(dev_priv);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003675}
Xiong Zhang26951ca2015-08-17 15:55:50 +08003676
Anusha Srivatsa31604222018-06-26 13:52:23 -07003677static void icp_hpd_detection_setup(struct drm_i915_private *dev_priv)
3678{
3679 u32 hotplug;
3680
3681 hotplug = I915_READ(SHOTPLUG_CTL_DDI);
3682 hotplug |= ICP_DDIA_HPD_ENABLE |
3683 ICP_DDIB_HPD_ENABLE;
3684 I915_WRITE(SHOTPLUG_CTL_DDI, hotplug);
3685
3686 hotplug = I915_READ(SHOTPLUG_CTL_TC);
3687 hotplug |= ICP_TC_HPD_ENABLE(PORT_TC1) |
3688 ICP_TC_HPD_ENABLE(PORT_TC2) |
3689 ICP_TC_HPD_ENABLE(PORT_TC3) |
3690 ICP_TC_HPD_ENABLE(PORT_TC4);
3691 I915_WRITE(SHOTPLUG_CTL_TC, hotplug);
3692}
3693
3694static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv)
3695{
3696 u32 hotplug_irqs, enabled_irqs;
3697
3698 hotplug_irqs = SDE_DDI_MASK_ICP | SDE_TC_MASK_ICP;
3699 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_icp);
3700
3701 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3702
3703 icp_hpd_detection_setup(dev_priv);
3704}
3705
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003706static void gen11_hpd_detection_setup(struct drm_i915_private *dev_priv)
3707{
3708 u32 hotplug;
3709
3710 hotplug = I915_READ(GEN11_TC_HOTPLUG_CTL);
3711 hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) |
3712 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) |
3713 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) |
3714 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4);
3715 I915_WRITE(GEN11_TC_HOTPLUG_CTL, hotplug);
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07003716
3717 hotplug = I915_READ(GEN11_TBT_HOTPLUG_CTL);
3718 hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) |
3719 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) |
3720 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) |
3721 GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4);
3722 I915_WRITE(GEN11_TBT_HOTPLUG_CTL, hotplug);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003723}
3724
3725static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv)
3726{
3727 u32 hotplug_irqs, enabled_irqs;
3728 u32 val;
3729
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07003730 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_gen11);
3731 hotplug_irqs = GEN11_DE_TC_HOTPLUG_MASK | GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003732
3733 val = I915_READ(GEN11_DE_HPD_IMR);
3734 val &= ~hotplug_irqs;
3735 I915_WRITE(GEN11_DE_HPD_IMR, val);
3736 POSTING_READ(GEN11_DE_HPD_IMR);
3737
3738 gen11_hpd_detection_setup(dev_priv);
Anusha Srivatsa31604222018-06-26 13:52:23 -07003739
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07003740 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07003741 icp_hpd_irq_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07003742}
3743
Imre Deak2a57d9c2017-01-27 11:39:18 +02003744static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3745{
Rodrigo Vivi3b92e262017-09-19 14:57:03 -07003746 u32 val, hotplug;
3747
3748 /* Display WA #1179 WaHardHangonHotPlug: cnp */
3749 if (HAS_PCH_CNP(dev_priv)) {
3750 val = I915_READ(SOUTH_CHICKEN1);
3751 val &= ~CHASSIS_CLK_REQ_DURATION_MASK;
3752 val |= CHASSIS_CLK_REQ_DURATION(0xf);
3753 I915_WRITE(SOUTH_CHICKEN1, val);
3754 }
Imre Deak2a57d9c2017-01-27 11:39:18 +02003755
3756 /* Enable digital hotplug on the PCH */
3757 hotplug = I915_READ(PCH_PORT_HOTPLUG);
3758 hotplug |= PORTA_HOTPLUG_ENABLE |
3759 PORTB_HOTPLUG_ENABLE |
3760 PORTC_HOTPLUG_ENABLE |
3761 PORTD_HOTPLUG_ENABLE;
3762 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
3763
3764 hotplug = I915_READ(PCH_PORT_HOTPLUG2);
3765 hotplug |= PORTE_HOTPLUG_ENABLE;
3766 I915_WRITE(PCH_PORT_HOTPLUG2, hotplug);
3767}
3768
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003769static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003770{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003771 u32 hotplug_irqs, enabled_irqs;
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003772
3773 hotplug_irqs = SDE_HOTPLUG_MASK_SPT;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003774 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt);
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03003775
3776 ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs);
3777
Imre Deak2a57d9c2017-01-27 11:39:18 +02003778 spt_hpd_detection_setup(dev_priv);
Keith Packard7fe0b972011-09-19 13:31:02 -07003779}
3780
Imre Deak1a56b1a2017-01-27 11:39:21 +02003781static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv)
3782{
3783 u32 hotplug;
3784
3785 /*
3786 * Enable digital hotplug on the CPU, and configure the DP short pulse
3787 * duration to 2ms (which is the minimum in the Display Port spec)
3788 * The pulse duration bits are reserved on HSW+.
3789 */
3790 hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL);
3791 hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK;
3792 hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE |
3793 DIGITAL_PORTA_PULSE_DURATION_2ms;
3794 I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug);
3795}
3796
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003797static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv)
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003798{
Imre Deak1a56b1a2017-01-27 11:39:21 +02003799 u32 hotplug_irqs, enabled_irqs;
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003800
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003801 if (INTEL_GEN(dev_priv) >= 8) {
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003802 hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003803 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003804
3805 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003806 } else if (INTEL_GEN(dev_priv) >= 7) {
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003807 hotplug_irqs = DE_DP_A_HOTPLUG_IVB;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003808 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb);
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003809
3810 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003811 } else {
3812 hotplug_irqs = DE_DP_A_HOTPLUG;
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003813 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003814
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03003815 ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs);
3816 }
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003817
Imre Deak1a56b1a2017-01-27 11:39:21 +02003818 ilk_hpd_detection_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003819
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01003820 ibx_hpd_irq_setup(dev_priv);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003821}
3822
Imre Deak2a57d9c2017-01-27 11:39:18 +02003823static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv,
3824 u32 enabled_irqs)
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003825{
Imre Deak2a57d9c2017-01-27 11:39:18 +02003826 u32 hotplug;
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003827
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003828 hotplug = I915_READ(PCH_PORT_HOTPLUG);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003829 hotplug |= PORTA_HOTPLUG_ENABLE |
3830 PORTB_HOTPLUG_ENABLE |
3831 PORTC_HOTPLUG_ENABLE;
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303832
3833 DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n",
3834 hotplug, enabled_irqs);
3835 hotplug &= ~BXT_DDI_HPD_INVERT_MASK;
3836
3837 /*
3838 * For BXT invert bit has to be set based on AOB design
3839 * for HPD detection logic, update it based on VBT fields.
3840 */
Shubhangi Shrivastavad252bf62016-03-31 16:11:47 +05303841 if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) &&
3842 intel_bios_is_port_hpd_inverted(dev_priv, PORT_A))
3843 hotplug |= BXT_DDIA_HPD_INVERT;
3844 if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) &&
3845 intel_bios_is_port_hpd_inverted(dev_priv, PORT_B))
3846 hotplug |= BXT_DDIB_HPD_INVERT;
3847 if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) &&
3848 intel_bios_is_port_hpd_inverted(dev_priv, PORT_C))
3849 hotplug |= BXT_DDIC_HPD_INVERT;
3850
Ville Syrjäläa52bb152015-08-27 23:56:11 +03003851 I915_WRITE(PCH_PORT_HOTPLUG, hotplug);
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02003852}
3853
Imre Deak2a57d9c2017-01-27 11:39:18 +02003854static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv)
3855{
3856 __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK);
3857}
3858
3859static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv)
3860{
3861 u32 hotplug_irqs, enabled_irqs;
3862
3863 enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt);
3864 hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK;
3865
3866 bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs);
3867
3868 __bxt_hpd_detection_setup(dev_priv, enabled_irqs);
3869}
3870
Paulo Zanonid46da432013-02-08 17:35:15 -02003871static void ibx_irq_postinstall(struct drm_device *dev)
3872{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003873 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter82a28bc2013-03-27 15:55:01 +01003874 u32 mask;
Paulo Zanonid46da432013-02-08 17:35:15 -02003875
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003876 if (HAS_PCH_NOP(dev_priv))
Daniel Vetter692a04c2013-05-29 21:43:05 +02003877 return;
3878
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01003879 if (HAS_PCH_IBX(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003880 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003881 else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv))
Daniel Vetter5c673b62014-03-07 20:34:46 +01003882 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT;
Dhinakaran Pandiyan4ebc6502017-09-08 17:42:55 -07003883 else
3884 mask = SDE_GMBUS_CPT;
Paulo Zanoni86642812013-04-12 17:57:57 -03003885
Paulo Zanoni65f42cd2019-04-10 16:53:43 -07003886 gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR);
Paulo Zanonid46da432013-02-08 17:35:15 -02003887 I915_WRITE(SDEIMR, ~mask);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003888
3889 if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) ||
3890 HAS_PCH_LPT(dev_priv))
Imre Deak1a56b1a2017-01-27 11:39:21 +02003891 ibx_hpd_detection_setup(dev_priv);
Imre Deak2a57d9c2017-01-27 11:39:18 +02003892 else
3893 spt_hpd_detection_setup(dev_priv);
Paulo Zanonid46da432013-02-08 17:35:15 -02003894}
3895
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003896static void gen5_gt_irq_postinstall(struct drm_device *dev)
3897{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003898 struct drm_i915_private *dev_priv = to_i915(dev);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003899 u32 pm_irqs, gt_irqs;
3900
3901 pm_irqs = gt_irqs = 0;
3902
3903 dev_priv->gt_irq_mask = ~0;
Tvrtko Ursulin3c9192b2016-10-13 11:03:05 +01003904 if (HAS_L3_DPF(dev_priv)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003905 /* L3 parity interrupt is always unmasked. */
Tvrtko Ursulin772c2a52016-10-13 11:03:01 +01003906 dev_priv->gt_irq_mask = ~GT_PARITY_ERROR(dev_priv);
3907 gt_irqs |= GT_PARITY_ERROR(dev_priv);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003908 }
3909
3910 gt_irqs |= GT_RENDER_USER_INTERRUPT;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08003911 if (IS_GEN(dev_priv, 5)) {
Chris Wilsonf8973c22016-07-01 17:23:21 +01003912 gt_irqs |= ILK_BSD_USER_INTERRUPT;
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003913 } else {
3914 gt_irqs |= GT_BLT_USER_INTERRUPT | GT_BSD_USER_INTERRUPT;
3915 }
3916
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003917 GEN3_IRQ_INIT(GT, dev_priv->gt_irq_mask, gt_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003918
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003919 if (INTEL_GEN(dev_priv) >= 6) {
Imre Deak78e68d32014-12-15 18:59:27 +02003920 /*
3921 * RPS interrupts will get enabled/disabled on demand when RPS
3922 * itself is enabled/disabled.
3923 */
Chris Wilson8a68d462019-03-05 18:03:30 +00003924 if (HAS_ENGINE(dev_priv, VECS0)) {
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003925 pm_irqs |= PM_VEBOX_USER_INTERRUPT;
Akash Goelf4e9af42016-10-12 21:54:30 +05303926 dev_priv->pm_ier |= PM_VEBOX_USER_INTERRUPT;
3927 }
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003928
Akash Goelf4e9af42016-10-12 21:54:30 +05303929 dev_priv->pm_imr = 0xffffffff;
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003930 GEN3_IRQ_INIT(GEN6_PM, dev_priv->pm_imr, pm_irqs);
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003931 }
3932}
3933
Jesse Barnesf71d4af2011-06-28 13:00:41 -07003934static int ironlake_irq_postinstall(struct drm_device *dev)
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003935{
Chris Wilsonfac5e232016-07-04 11:34:36 +01003936 struct drm_i915_private *dev_priv = to_i915(dev);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003937 u32 display_mask, extra_mask;
3938
Tvrtko Ursulinb243f532016-11-16 08:55:38 +00003939 if (INTEL_GEN(dev_priv) >= 7) {
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003940 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003941 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003942 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB |
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03003943 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB |
3944 DE_DP_A_HOTPLUG_IVB);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003945 } else {
3946 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT |
Ville Syrjälä842ebf72017-08-18 21:36:50 +03003947 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE |
3948 DE_PIPEA_CRC_DONE | DE_POISON);
Ville Syrjäläe4ce95a2015-08-27 23:56:03 +03003949 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT |
3950 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN |
3951 DE_DP_A_HOTPLUG);
Paulo Zanoni8e76f8d2013-07-12 20:01:56 -03003952 }
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003953
Daniel Vetterfc340442018-04-05 15:00:23 -07003954 if (IS_HASWELL(dev_priv)) {
Paulo Zanoni65f42cd2019-04-10 16:53:43 -07003955 gen3_assert_iir_is_zero(&dev_priv->uncore, EDP_PSR_IIR);
Dhinakaran Pandiyan1aeb1b52018-08-21 15:11:56 -07003956 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Daniel Vetterfc340442018-04-05 15:00:23 -07003957 display_mask |= DE_EDP_PSR_INT_HSW;
3958 }
3959
Chris Wilson1ec14ad2010-12-04 11:30:53 +00003960 dev_priv->irq_mask = ~display_mask;
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003961
Paulo Zanoni622364b2014-04-01 15:37:22 -03003962 ibx_irq_pre_postinstall(dev);
3963
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03003964 GEN3_IRQ_INIT(DE, dev_priv->irq_mask, display_mask | extra_mask);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003965
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02003966 gen5_gt_irq_postinstall(dev);
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003967
Imre Deak1a56b1a2017-01-27 11:39:21 +02003968 ilk_hpd_detection_setup(dev_priv);
3969
Paulo Zanonid46da432013-02-08 17:35:15 -02003970 ibx_irq_postinstall(dev);
Keith Packard7fe0b972011-09-19 13:31:02 -07003971
Tvrtko Ursulin50a0bc92016-10-13 11:02:58 +01003972 if (IS_IRONLAKE_M(dev_priv)) {
Daniel Vetter6005ce42013-06-27 13:44:59 +02003973 /* Enable PCU event interrupts
3974 *
3975 * spinlocking not required here for correctness since interrupt
Daniel Vetter4bc9d432013-06-27 13:44:58 +02003976 * setup is guaranteed to run in single-threaded context. But we
3977 * need it to make the assert_spin_locked happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02003978 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjäläfbdedaea2015-11-23 18:06:16 +02003979 ilk_enable_display_irq(dev_priv, DE_PCU_EVENT);
Daniel Vetterd6207432014-09-15 14:55:27 +02003980 spin_unlock_irq(&dev_priv->irq_lock);
Jesse Barnesf97108d2010-01-29 11:27:07 -08003981 }
3982
Zhenyu Wang036a4a72009-06-08 14:40:19 +08003983 return 0;
3984}
3985
Imre Deakf8b79e52014-03-04 19:23:07 +02003986void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv)
3987{
Chris Wilson67520412017-03-02 13:28:01 +00003988 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02003989
3990 if (dev_priv->display_irqs_enabled)
3991 return;
3992
3993 dev_priv->display_irqs_enabled = true;
3994
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003995 if (intel_irqs_enabled(dev_priv)) {
3996 vlv_display_irq_reset(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03003997 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläd6c69802016-04-11 16:56:27 +03003998 }
Imre Deakf8b79e52014-03-04 19:23:07 +02003999}
4000
4001void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv)
4002{
Chris Wilson67520412017-03-02 13:28:01 +00004003 lockdep_assert_held(&dev_priv->irq_lock);
Imre Deakf8b79e52014-03-04 19:23:07 +02004004
4005 if (!dev_priv->display_irqs_enabled)
4006 return;
4007
4008 dev_priv->display_irqs_enabled = false;
4009
Imre Deak950eaba2014-09-08 15:21:09 +03004010 if (intel_irqs_enabled(dev_priv))
Ville Syrjäläad22d102016-04-12 18:56:14 +03004011 vlv_display_irq_reset(dev_priv);
Imre Deakf8b79e52014-03-04 19:23:07 +02004012}
4013
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02004014
4015static int valleyview_irq_postinstall(struct drm_device *dev)
4016{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004017 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä0e6c9a92014-10-30 19:43:00 +02004018
Daniel Vetter0a9a8c92013-07-12 22:43:26 +02004019 gen5_gt_irq_postinstall(dev);
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004020
Ville Syrjäläad22d102016-04-12 18:56:14 +03004021 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004022 if (dev_priv->display_irqs_enabled)
4023 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004024 spin_unlock_irq(&dev_priv->irq_lock);
4025
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004026 I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE);
Ville Syrjälä34c7b8a2016-04-13 21:19:48 +03004027 POSTING_READ(VLV_MASTER_IER);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004028
4029 return 0;
4030}
4031
Ben Widawskyabd58f02013-11-02 21:07:09 -07004032static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
4033{
Ben Widawskyabd58f02013-11-02 21:07:09 -07004034 /* These are interrupts we'll toggle with the ring mask register */
Jani Nikulaa9c287c2019-01-16 11:15:24 +02004035 u32 gt_interrupts[] = {
Chris Wilson8a68d462019-03-05 18:03:30 +00004036 (GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
4037 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
4038 GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
4039 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT),
4040
4041 (GT_RENDER_USER_INTERRUPT << GEN8_VCS0_IRQ_SHIFT |
4042 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS0_IRQ_SHIFT |
4043 GT_RENDER_USER_INTERRUPT << GEN8_VCS1_IRQ_SHIFT |
4044 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VCS1_IRQ_SHIFT),
4045
Ben Widawskyabd58f02013-11-02 21:07:09 -07004046 0,
Chris Wilson8a68d462019-03-05 18:03:30 +00004047
4048 (GT_RENDER_USER_INTERRUPT << GEN8_VECS_IRQ_SHIFT |
4049 GT_CONTEXT_SWITCH_INTERRUPT << GEN8_VECS_IRQ_SHIFT)
4050 };
Ben Widawskyabd58f02013-11-02 21:07:09 -07004051
Akash Goelf4e9af42016-10-12 21:54:30 +05304052 dev_priv->pm_ier = 0x0;
4053 dev_priv->pm_imr = ~dev_priv->pm_ier;
Deepak S9a2d2d82014-08-22 08:32:40 +05304054 GEN8_IRQ_INIT_NDX(GT, 0, ~gt_interrupts[0], gt_interrupts[0]);
4055 GEN8_IRQ_INIT_NDX(GT, 1, ~gt_interrupts[1], gt_interrupts[1]);
Imre Deak78e68d32014-12-15 18:59:27 +02004056 /*
4057 * RPS interrupts will get enabled/disabled on demand when RPS itself
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304058 * is enabled/disabled. Same wil be the case for GuC interrupts.
Imre Deak78e68d32014-12-15 18:59:27 +02004059 */
Akash Goelf4e9af42016-10-12 21:54:30 +05304060 GEN8_IRQ_INIT_NDX(GT, 2, dev_priv->pm_imr, dev_priv->pm_ier);
Deepak S9a2d2d82014-08-22 08:32:40 +05304061 GEN8_IRQ_INIT_NDX(GT, 3, ~gt_interrupts[3], gt_interrupts[3]);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004062}
4063
4064static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv)
4065{
Jani Nikulaa9c287c2019-01-16 11:15:24 +02004066 u32 de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE;
4067 u32 de_pipe_enables;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004068 u32 de_port_masked = GEN8_AUX_CHANNEL_A;
4069 u32 de_port_enables;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004070 u32 de_misc_masked = GEN8_DE_EDP_PSR;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004071 enum pipe pipe;
Damien Lespiau770de83d2014-03-20 20:45:01 +00004072
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004073 if (INTEL_GEN(dev_priv) <= 10)
4074 de_misc_masked |= GEN8_DE_MISC_GSE;
4075
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004076 if (INTEL_GEN(dev_priv) >= 9) {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004077 de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004078 de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C |
4079 GEN9_AUX_CHANNEL_D;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004080 if (IS_GEN9_LP(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004081 de_port_masked |= BXT_DE_PORT_GMBUS;
4082 } else {
Ville Syrjälä842ebf72017-08-18 21:36:50 +03004083 de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS;
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004084 }
Damien Lespiau770de83d2014-03-20 20:45:01 +00004085
James Ausmusbb187e92018-06-11 17:25:12 -07004086 if (INTEL_GEN(dev_priv) >= 11)
4087 de_port_masked |= ICL_AUX_CHANNEL_E;
4088
Dhinakaran Pandiyan9bb635d2018-05-21 17:25:35 -07004089 if (IS_CNL_WITH_PORT_F(dev_priv) || INTEL_GEN(dev_priv) >= 11)
Rodrigo Vivia324fca2018-01-29 15:22:15 -08004090 de_port_masked |= CNL_AUX_CHANNEL_F;
4091
Damien Lespiau770de83d2014-03-20 20:45:01 +00004092 de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK |
4093 GEN8_PIPE_FIFO_UNDERRUN;
4094
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004095 de_port_enables = de_port_masked;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004096 if (IS_GEN9_LP(dev_priv))
Ville Syrjäläa52bb152015-08-27 23:56:11 +03004097 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK;
4098 else if (IS_BROADWELL(dev_priv))
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004099 de_port_enables |= GEN8_PORT_DP_A_HOTPLUG;
4100
Paulo Zanoni65f42cd2019-04-10 16:53:43 -07004101 gen3_assert_iir_is_zero(&dev_priv->uncore, EDP_PSR_IIR);
Dhinakaran Pandiyan54fd3142018-04-04 18:37:17 -07004102 intel_psr_irq_control(dev_priv, dev_priv->psr.debug);
Ville Syrjäläe04f7ec2018-04-03 14:24:18 -07004103
Mika Kahola0a195c02017-10-10 13:17:04 +03004104 for_each_pipe(dev_priv, pipe) {
4105 dev_priv->de_irq_mask[pipe] = ~de_pipe_masked;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004106
Daniel Vetterf458ebb2014-09-30 10:56:39 +02004107 if (intel_display_power_is_enabled(dev_priv,
Paulo Zanoni813bde42014-07-04 11:50:29 -03004108 POWER_DOMAIN_PIPE(pipe)))
4109 GEN8_IRQ_INIT_NDX(DE_PIPE, pipe,
4110 dev_priv->de_irq_mask[pipe],
4111 de_pipe_enables);
Mika Kahola0a195c02017-10-10 13:17:04 +03004112 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07004113
Ville Syrjälä3488d4e2017-08-18 21:36:52 +03004114 GEN3_IRQ_INIT(GEN8_DE_PORT_, ~de_port_masked, de_port_enables);
4115 GEN3_IRQ_INIT(GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked);
Imre Deak2a57d9c2017-01-27 11:39:18 +02004116
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004117 if (INTEL_GEN(dev_priv) >= 11) {
4118 u32 de_hpd_masked = 0;
Dhinakaran Pandiyanb796b972018-06-15 17:05:30 -07004119 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK |
4120 GEN11_DE_TBT_HOTPLUG_MASK;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004121
4122 GEN3_IRQ_INIT(GEN11_DE_HPD_, ~de_hpd_masked, de_hpd_enables);
4123 gen11_hpd_detection_setup(dev_priv);
4124 } else if (IS_GEN9_LP(dev_priv)) {
Imre Deak2a57d9c2017-01-27 11:39:18 +02004125 bxt_hpd_detection_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004126 } else if (IS_BROADWELL(dev_priv)) {
Imre Deak1a56b1a2017-01-27 11:39:21 +02004127 ilk_hpd_detection_setup(dev_priv);
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004128 }
Ben Widawskyabd58f02013-11-02 21:07:09 -07004129}
4130
4131static int gen8_irq_postinstall(struct drm_device *dev)
4132{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004133 struct drm_i915_private *dev_priv = to_i915(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004134
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004135 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05304136 ibx_irq_pre_postinstall(dev);
Paulo Zanoni622364b2014-04-01 15:37:22 -03004137
Ben Widawskyabd58f02013-11-02 21:07:09 -07004138 gen8_gt_irq_postinstall(dev_priv);
4139 gen8_de_irq_postinstall(dev_priv);
4140
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004141 if (HAS_PCH_SPLIT(dev_priv))
Shashank Sharma266ea3d2014-08-22 17:40:42 +05304142 ibx_irq_postinstall(dev);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004143
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07004144 gen8_master_intr_enable(dev_priv->uncore.regs);
Ben Widawskyabd58f02013-11-02 21:07:09 -07004145
4146 return 0;
4147}
4148
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004149static void gen11_gt_irq_postinstall(struct drm_i915_private *dev_priv)
4150{
4151 const u32 irqs = GT_RENDER_USER_INTERRUPT | GT_CONTEXT_SWITCH_INTERRUPT;
4152
4153 BUILD_BUG_ON(irqs & 0xffff0000);
4154
4155 /* Enable RCS, BCS, VCS and VECS class interrupts. */
4156 I915_WRITE(GEN11_RENDER_COPY_INTR_ENABLE, irqs << 16 | irqs);
4157 I915_WRITE(GEN11_VCS_VECS_INTR_ENABLE, irqs << 16 | irqs);
4158
4159 /* Unmask irqs on RCS, BCS, VCS and VECS engines. */
4160 I915_WRITE(GEN11_RCS0_RSVD_INTR_MASK, ~(irqs << 16));
4161 I915_WRITE(GEN11_BCS_RSVD_INTR_MASK, ~(irqs << 16));
4162 I915_WRITE(GEN11_VCS0_VCS1_INTR_MASK, ~(irqs | irqs << 16));
4163 I915_WRITE(GEN11_VCS2_VCS3_INTR_MASK, ~(irqs | irqs << 16));
4164 I915_WRITE(GEN11_VECS0_VECS1_INTR_MASK, ~(irqs | irqs << 16));
4165
Oscar Mateod02b98b2018-04-05 17:00:50 +03004166 /*
4167 * RPS interrupts will get enabled/disabled on demand when RPS itself
4168 * is enabled/disabled.
4169 */
4170 dev_priv->pm_ier = 0x0;
4171 dev_priv->pm_imr = ~dev_priv->pm_ier;
4172 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_ENABLE, 0);
4173 I915_WRITE(GEN11_GPM_WGBOXPERF_INTR_MASK, ~0);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004174}
4175
Anusha Srivatsa31604222018-06-26 13:52:23 -07004176static void icp_irq_postinstall(struct drm_device *dev)
4177{
4178 struct drm_i915_private *dev_priv = to_i915(dev);
4179 u32 mask = SDE_GMBUS_ICP;
4180
4181 WARN_ON(I915_READ(SDEIER) != 0);
4182 I915_WRITE(SDEIER, 0xffffffff);
4183 POSTING_READ(SDEIER);
4184
Paulo Zanoni65f42cd2019-04-10 16:53:43 -07004185 gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR);
Anusha Srivatsa31604222018-06-26 13:52:23 -07004186 I915_WRITE(SDEIMR, ~mask);
4187
4188 icp_hpd_detection_setup(dev_priv);
4189}
4190
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004191static int gen11_irq_postinstall(struct drm_device *dev)
4192{
4193 struct drm_i915_private *dev_priv = dev->dev_private;
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004194 u32 gu_misc_masked = GEN11_GU_MISC_GSE;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004195
Rodrigo Vivi29b43ae2019-03-13 14:43:07 -07004196 if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP)
Anusha Srivatsa31604222018-06-26 13:52:23 -07004197 icp_irq_postinstall(dev);
4198
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004199 gen11_gt_irq_postinstall(dev_priv);
4200 gen8_de_irq_postinstall(dev_priv);
4201
Dhinakaran Pandiyandf0d28c2018-06-15 17:05:28 -07004202 GEN3_IRQ_INIT(GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked);
4203
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004204 I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE);
4205
Daniele Ceraolo Spurio25286aa2019-03-19 11:35:40 -07004206 gen11_master_intr_enable(dev_priv->uncore.regs);
Daniele Ceraolo Spurioc25f0c62019-01-22 18:32:27 -08004207 POSTING_READ(GEN11_GFX_MSTR_IRQ);
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004208
4209 return 0;
4210}
4211
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004212static int cherryview_irq_postinstall(struct drm_device *dev)
4213{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004214 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004215
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004216 gen8_gt_irq_postinstall(dev_priv);
4217
Ville Syrjäläad22d102016-04-12 18:56:14 +03004218 spin_lock_irq(&dev_priv->irq_lock);
Ville Syrjälä99182712016-04-11 16:56:25 +03004219 if (dev_priv->display_irqs_enabled)
4220 vlv_display_irq_postinstall(dev_priv);
Ville Syrjäläad22d102016-04-12 18:56:14 +03004221 spin_unlock_irq(&dev_priv->irq_lock);
4222
Ville Syrjäläe5328c42016-04-13 21:19:47 +03004223 I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL);
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004224 POSTING_READ(GEN8_MASTER_IRQ);
4225
4226 return 0;
4227}
4228
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004229static void i8xx_irq_reset(struct drm_device *dev)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004230{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004231 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004232
Ville Syrjälä44d92412017-08-18 21:36:51 +03004233 i9xx_pipestat_irq_reset(dev_priv);
4234
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004235 GEN2_IRQ_RESET();
Chris Wilsonc2798b12012-04-22 21:13:57 +01004236}
4237
4238static int i8xx_irq_postinstall(struct drm_device *dev)
4239{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004240 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004241 u16 enable_mask;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004242
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004243 I915_WRITE16(EMR, ~(I915_ERROR_PAGE_TABLE |
4244 I915_ERROR_MEMORY_REFRESH));
Chris Wilsonc2798b12012-04-22 21:13:57 +01004245
4246 /* Unmask the interrupts that we always want on. */
4247 dev_priv->irq_mask =
4248 ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004249 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4250 I915_MASTER_ERROR_INTERRUPT);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004251
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004252 enable_mask =
4253 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4254 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004255 I915_MASTER_ERROR_INTERRUPT |
Ville Syrjäläe9e98482017-08-18 21:36:54 +03004256 I915_USER_INTERRUPT;
4257
Paulo Zanoni2918c3c2019-04-10 16:53:41 -07004258 GEN2_IRQ_INIT(dev_priv->irq_mask, enable_mask);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004259
Daniel Vetter379ef822013-10-16 22:55:56 +02004260 /* Interrupt setup is already guaranteed to be single-threaded, this is
4261 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004262 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004263 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4264 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004265 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004266
Chris Wilsonc2798b12012-04-22 21:13:57 +01004267 return 0;
4268}
4269
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004270static void i8xx_error_irq_ack(struct drm_i915_private *dev_priv,
4271 u16 *eir, u16 *eir_stuck)
4272{
4273 u16 emr;
4274
4275 *eir = I915_READ16(EIR);
4276
4277 if (*eir)
4278 I915_WRITE16(EIR, *eir);
4279
4280 *eir_stuck = I915_READ16(EIR);
4281 if (*eir_stuck == 0)
4282 return;
4283
4284 /*
4285 * Toggle all EMR bits to make sure we get an edge
4286 * in the ISR master error bit if we don't clear
4287 * all the EIR bits. Otherwise the edge triggered
4288 * IIR on i965/g4x wouldn't notice that an interrupt
4289 * is still pending. Also some EIR bits can't be
4290 * cleared except by handling the underlying error
4291 * (or by a GPU reset) so we mask any bit that
4292 * remains set.
4293 */
4294 emr = I915_READ16(EMR);
4295 I915_WRITE16(EMR, 0xffff);
4296 I915_WRITE16(EMR, emr | *eir_stuck);
4297}
4298
4299static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv,
4300 u16 eir, u16 eir_stuck)
4301{
4302 DRM_DEBUG("Master Error: EIR 0x%04x\n", eir);
4303
4304 if (eir_stuck)
4305 DRM_DEBUG_DRIVER("EIR stuck: 0x%04x, masked\n", eir_stuck);
4306}
4307
4308static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv,
4309 u32 *eir, u32 *eir_stuck)
4310{
4311 u32 emr;
4312
4313 *eir = I915_READ(EIR);
4314
4315 I915_WRITE(EIR, *eir);
4316
4317 *eir_stuck = I915_READ(EIR);
4318 if (*eir_stuck == 0)
4319 return;
4320
4321 /*
4322 * Toggle all EMR bits to make sure we get an edge
4323 * in the ISR master error bit if we don't clear
4324 * all the EIR bits. Otherwise the edge triggered
4325 * IIR on i965/g4x wouldn't notice that an interrupt
4326 * is still pending. Also some EIR bits can't be
4327 * cleared except by handling the underlying error
4328 * (or by a GPU reset) so we mask any bit that
4329 * remains set.
4330 */
4331 emr = I915_READ(EMR);
4332 I915_WRITE(EMR, 0xffffffff);
4333 I915_WRITE(EMR, emr | *eir_stuck);
4334}
4335
4336static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv,
4337 u32 eir, u32 eir_stuck)
4338{
4339 DRM_DEBUG("Master Error, EIR 0x%08x\n", eir);
4340
4341 if (eir_stuck)
4342 DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masked\n", eir_stuck);
4343}
4344
Daniel Vetterff1f5252012-10-02 15:10:55 +02004345static irqreturn_t i8xx_irq_handler(int irq, void *arg)
Chris Wilsonc2798b12012-04-22 21:13:57 +01004346{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004347 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004348 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004349 irqreturn_t ret = IRQ_NONE;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004350
Imre Deak2dd2a882015-02-24 11:14:30 +02004351 if (!intel_irqs_enabled(dev_priv))
4352 return IRQ_NONE;
4353
Imre Deak1f814da2015-12-16 02:52:19 +02004354 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4355 disable_rpm_wakeref_asserts(dev_priv);
4356
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004357 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004358 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004359 u16 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004360 u16 iir;
Ville Syrjäläeb643432017-08-18 21:36:59 +03004361
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004362 iir = I915_READ16(GEN2_IIR);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004363 if (iir == 0)
4364 break;
4365
4366 ret = IRQ_HANDLED;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004367
Ville Syrjäläeb643432017-08-18 21:36:59 +03004368 /* Call regardless, as some status bits might not be
4369 * signalled in iir */
4370 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004371
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004372 if (iir & I915_MASTER_ERROR_INTERRUPT)
4373 i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4374
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004375 I915_WRITE16(GEN2_IIR, iir);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004376
Chris Wilsonc2798b12012-04-22 21:13:57 +01004377 if (iir & I915_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004378 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004379
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004380 if (iir & I915_MASTER_ERROR_INTERRUPT)
4381 i8xx_error_irq_handler(dev_priv, eir, eir_stuck);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004382
Ville Syrjäläeb643432017-08-18 21:36:59 +03004383 i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004384 } while (0);
Chris Wilsonc2798b12012-04-22 21:13:57 +01004385
Imre Deak1f814da2015-12-16 02:52:19 +02004386 enable_rpm_wakeref_asserts(dev_priv);
4387
4388 return ret;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004389}
4390
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004391static void i915_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004392{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004393 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004394
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004395 if (I915_HAS_HOTPLUG(dev_priv)) {
Egbert Eich0706f172015-09-23 16:15:27 +02004396 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004397 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
4398 }
4399
Ville Syrjälä44d92412017-08-18 21:36:51 +03004400 i9xx_pipestat_irq_reset(dev_priv);
4401
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004402 GEN3_IRQ_RESET(GEN2_);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004403}
4404
4405static int i915_irq_postinstall(struct drm_device *dev)
4406{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004407 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilson38bde182012-04-24 22:59:50 +01004408 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004409
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004410 I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE |
4411 I915_ERROR_MEMORY_REFRESH));
Chris Wilson38bde182012-04-24 22:59:50 +01004412
4413 /* Unmask the interrupts that we always want on. */
4414 dev_priv->irq_mask =
4415 ~(I915_ASLE_INTERRUPT |
4416 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004417 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
4418 I915_MASTER_ERROR_INTERRUPT);
Chris Wilson38bde182012-04-24 22:59:50 +01004419
4420 enable_mask =
4421 I915_ASLE_INTERRUPT |
4422 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4423 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä16659bc2018-06-11 23:02:58 +03004424 I915_MASTER_ERROR_INTERRUPT |
Chris Wilson38bde182012-04-24 22:59:50 +01004425 I915_USER_INTERRUPT;
4426
Tvrtko Ursulin56b857a2016-11-07 09:29:20 +00004427 if (I915_HAS_HOTPLUG(dev_priv)) {
Chris Wilsona266c7d2012-04-24 22:59:44 +01004428 /* Enable in IER... */
4429 enable_mask |= I915_DISPLAY_PORT_INTERRUPT;
4430 /* and unmask in IMR */
4431 dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT;
4432 }
4433
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004434 GEN3_IRQ_INIT(GEN2_, dev_priv->irq_mask, enable_mask);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004435
Daniel Vetter379ef822013-10-16 22:55:56 +02004436 /* Interrupt setup is already guaranteed to be single-threaded, this is
4437 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004438 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004439 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4440 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004441 spin_unlock_irq(&dev_priv->irq_lock);
Daniel Vetter379ef822013-10-16 22:55:56 +02004442
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004443 i915_enable_asle_pipestat(dev_priv);
4444
Daniel Vetter20afbda2012-12-11 14:05:07 +01004445 return 0;
4446}
4447
Daniel Vetterff1f5252012-10-02 15:10:55 +02004448static irqreturn_t i915_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004449{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004450 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004451 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004452 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004453
Imre Deak2dd2a882015-02-24 11:14:30 +02004454 if (!intel_irqs_enabled(dev_priv))
4455 return IRQ_NONE;
4456
Imre Deak1f814da2015-12-16 02:52:19 +02004457 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4458 disable_rpm_wakeref_asserts(dev_priv);
4459
Chris Wilson38bde182012-04-24 22:59:50 +01004460 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004461 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004462 u32 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004463 u32 hotplug_status = 0;
4464 u32 iir;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004465
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004466 iir = I915_READ(GEN2_IIR);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004467 if (iir == 0)
4468 break;
4469
4470 ret = IRQ_HANDLED;
4471
4472 if (I915_HAS_HOTPLUG(dev_priv) &&
4473 iir & I915_DISPLAY_PORT_INTERRUPT)
4474 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004475
Ville Syrjäläeb643432017-08-18 21:36:59 +03004476 /* Call regardless, as some status bits might not be
4477 * signalled in iir */
4478 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004479
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004480 if (iir & I915_MASTER_ERROR_INTERRUPT)
4481 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4482
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004483 I915_WRITE(GEN2_IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004484
Chris Wilsona266c7d2012-04-24 22:59:44 +01004485 if (iir & I915_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004486 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004487
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004488 if (iir & I915_MASTER_ERROR_INTERRUPT)
4489 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004490
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004491 if (hotplug_status)
4492 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4493
4494 i915_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4495 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004496
Imre Deak1f814da2015-12-16 02:52:19 +02004497 enable_rpm_wakeref_asserts(dev_priv);
4498
Chris Wilsona266c7d2012-04-24 22:59:44 +01004499 return ret;
4500}
4501
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004502static void i965_irq_reset(struct drm_device *dev)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004503{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004504 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004505
Egbert Eich0706f172015-09-23 16:15:27 +02004506 i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0);
Chris Wilsonadca4732012-05-11 18:01:31 +01004507 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
Chris Wilsona266c7d2012-04-24 22:59:44 +01004508
Ville Syrjälä44d92412017-08-18 21:36:51 +03004509 i9xx_pipestat_irq_reset(dev_priv);
4510
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004511 GEN3_IRQ_RESET(GEN2_);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004512}
4513
4514static int i965_irq_postinstall(struct drm_device *dev)
4515{
Chris Wilsonfac5e232016-07-04 11:34:36 +01004516 struct drm_i915_private *dev_priv = to_i915(dev);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004517 u32 enable_mask;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004518 u32 error_mask;
4519
Ville Syrjälä045cebd2017-08-18 21:36:55 +03004520 /*
4521 * Enable some error detection, note the instruction error mask
4522 * bit is reserved, so we leave it masked.
4523 */
4524 if (IS_G4X(dev_priv)) {
4525 error_mask = ~(GM45_ERROR_PAGE_TABLE |
4526 GM45_ERROR_MEM_PRIV |
4527 GM45_ERROR_CP_PRIV |
4528 I915_ERROR_MEMORY_REFRESH);
4529 } else {
4530 error_mask = ~(I915_ERROR_PAGE_TABLE |
4531 I915_ERROR_MEMORY_REFRESH);
4532 }
4533 I915_WRITE(EMR, error_mask);
4534
Chris Wilsona266c7d2012-04-24 22:59:44 +01004535 /* Unmask the interrupts that we always want on. */
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004536 dev_priv->irq_mask =
4537 ~(I915_ASLE_INTERRUPT |
4538 I915_DISPLAY_PORT_INTERRUPT |
4539 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4540 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004541 I915_MASTER_ERROR_INTERRUPT);
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004542
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004543 enable_mask =
4544 I915_ASLE_INTERRUPT |
4545 I915_DISPLAY_PORT_INTERRUPT |
4546 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT |
4547 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT |
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004548 I915_MASTER_ERROR_INTERRUPT |
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004549 I915_USER_INTERRUPT;
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004550
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004551 if (IS_G4X(dev_priv))
Chris Wilsonbbba0a92012-04-24 22:59:51 +01004552 enable_mask |= I915_BSD_USER_INTERRUPT;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004553
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004554 GEN3_IRQ_INIT(GEN2_, dev_priv->irq_mask, enable_mask);
Ville Syrjäläc30bb1f2017-08-18 21:36:57 +03004555
Daniel Vetterb79480b2013-06-27 17:52:10 +02004556 /* Interrupt setup is already guaranteed to be single-threaded, this is
4557 * just to make the assert_spin_locked check happy. */
Daniel Vetterd6207432014-09-15 14:55:27 +02004558 spin_lock_irq(&dev_priv->irq_lock);
Imre Deak755e9012014-02-10 18:42:47 +02004559 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS);
4560 i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS);
4561 i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS);
Daniel Vetterd6207432014-09-15 14:55:27 +02004562 spin_unlock_irq(&dev_priv->irq_lock);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004563
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004564 i915_enable_asle_pipestat(dev_priv);
Daniel Vetter20afbda2012-12-11 14:05:07 +01004565
4566 return 0;
4567}
4568
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004569static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv)
Daniel Vetter20afbda2012-12-11 14:05:07 +01004570{
Daniel Vetter20afbda2012-12-11 14:05:07 +01004571 u32 hotplug_en;
4572
Chris Wilson67520412017-03-02 13:28:01 +00004573 lockdep_assert_held(&dev_priv->irq_lock);
Daniel Vetterb5ea2d52013-06-27 17:52:15 +02004574
Ville Syrjälä778eb332015-01-09 14:21:13 +02004575 /* Note HDMI and DP share hotplug bits */
4576 /* enable bits are the same for all generations */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004577 hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915);
Ville Syrjälä778eb332015-01-09 14:21:13 +02004578 /* Programming the CRT detection parameters tends
4579 to generate a spurious hotplug event about three
4580 seconds later. So just do it once.
4581 */
Tvrtko Ursulin91d14252016-05-06 14:48:28 +01004582 if (IS_G4X(dev_priv))
Ville Syrjälä778eb332015-01-09 14:21:13 +02004583 hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64;
Ville Syrjälä778eb332015-01-09 14:21:13 +02004584 hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004585
Ville Syrjälä778eb332015-01-09 14:21:13 +02004586 /* Ignore TV since it's buggy */
Egbert Eich0706f172015-09-23 16:15:27 +02004587 i915_hotplug_interrupt_update_locked(dev_priv,
Jani Nikulaf9e3dc72015-10-21 17:22:43 +03004588 HOTPLUG_INT_EN_MASK |
4589 CRT_HOTPLUG_VOLTAGE_COMPARE_MASK |
4590 CRT_HOTPLUG_ACTIVATION_PERIOD_64,
4591 hotplug_en);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004592}
4593
Daniel Vetterff1f5252012-10-02 15:10:55 +02004594static irqreturn_t i965_irq_handler(int irq, void *arg)
Chris Wilsona266c7d2012-04-24 22:59:44 +01004595{
Daniel Vetter45a83f82014-05-12 19:17:55 +02004596 struct drm_device *dev = arg;
Chris Wilsonfac5e232016-07-04 11:34:36 +01004597 struct drm_i915_private *dev_priv = to_i915(dev);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004598 irqreturn_t ret = IRQ_NONE;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004599
Imre Deak2dd2a882015-02-24 11:14:30 +02004600 if (!intel_irqs_enabled(dev_priv))
4601 return IRQ_NONE;
4602
Imre Deak1f814da2015-12-16 02:52:19 +02004603 /* IRQs are synced during runtime_suspend, we don't require a wakeref */
4604 disable_rpm_wakeref_asserts(dev_priv);
4605
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004606 do {
Ville Syrjäläeb643432017-08-18 21:36:59 +03004607 u32 pipe_stats[I915_MAX_PIPES] = {};
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004608 u32 eir = 0, eir_stuck = 0;
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004609 u32 hotplug_status = 0;
4610 u32 iir;
Chris Wilson2c8ba292012-04-24 22:59:46 +01004611
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004612 iir = I915_READ(GEN2_IIR);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004613 if (iir == 0)
4614 break;
4615
4616 ret = IRQ_HANDLED;
4617
4618 if (iir & I915_DISPLAY_PORT_INTERRUPT)
4619 hotplug_status = i9xx_hpd_irq_ack(dev_priv);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004620
Ville Syrjäläeb643432017-08-18 21:36:59 +03004621 /* Call regardless, as some status bits might not be
4622 * signalled in iir */
4623 i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004624
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004625 if (iir & I915_MASTER_ERROR_INTERRUPT)
4626 i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck);
4627
Paulo Zanoni9d9523d2019-04-10 16:53:42 -07004628 I915_WRITE(GEN2_IIR, iir);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004629
Chris Wilsona266c7d2012-04-24 22:59:44 +01004630 if (iir & I915_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004631 intel_engine_breadcrumbs_irq(dev_priv->engine[RCS0]);
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004632
Chris Wilsona266c7d2012-04-24 22:59:44 +01004633 if (iir & I915_BSD_USER_INTERRUPT)
Chris Wilson8a68d462019-03-05 18:03:30 +00004634 intel_engine_breadcrumbs_irq(dev_priv->engine[VCS0]);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004635
Ville Syrjälä78c357d2018-06-11 23:02:57 +03004636 if (iir & I915_MASTER_ERROR_INTERRUPT)
4637 i9xx_error_irq_handler(dev_priv, eir, eir_stuck);
Daniel Vetter515ac2b2012-12-01 13:53:44 +01004638
Ville Syrjäläaf722d22017-08-18 21:37:00 +03004639 if (hotplug_status)
4640 i9xx_hpd_irq_handler(dev_priv, hotplug_status);
4641
4642 i965_pipestat_irq_handler(dev_priv, iir, pipe_stats);
4643 } while (0);
Chris Wilsona266c7d2012-04-24 22:59:44 +01004644
Imre Deak1f814da2015-12-16 02:52:19 +02004645 enable_rpm_wakeref_asserts(dev_priv);
4646
Chris Wilsona266c7d2012-04-24 22:59:44 +01004647 return ret;
4648}
4649
Daniel Vetterfca52a52014-09-30 10:56:45 +02004650/**
4651 * intel_irq_init - initializes irq support
4652 * @dev_priv: i915 device instance
4653 *
4654 * This function initializes all the irq support including work items, timers
4655 * and all the vtables. It does not setup the interrupt itself though.
4656 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004657void intel_irq_init(struct drm_i915_private *dev_priv)
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004658{
Chris Wilson91c8a322016-07-05 10:40:23 +01004659 struct drm_device *dev = &dev_priv->drm;
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004660 struct intel_rps *rps = &dev_priv->gt_pm.rps;
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004661 int i;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004662
Ville Syrjäläd938da62019-03-22 20:08:03 +02004663 if (IS_I945GM(dev_priv))
4664 i945gm_vblank_work_init(dev_priv);
4665
Jani Nikula77913b32015-06-18 13:06:16 +03004666 intel_hpd_init_work(dev_priv);
4667
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004668 INIT_WORK(&rps->work, gen6_pm_rps_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004669
Daniel Vettera4da4fa2012-11-02 19:55:07 +01004670 INIT_WORK(&dev_priv->l3_parity.error_work, ivybridge_parity_work);
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004671 for (i = 0; i < MAX_L3_SLICES; ++i)
4672 dev_priv->l3_parity.remap_info[i] = NULL;
Chris Wilson8b2e3262012-04-24 22:59:41 +01004673
Tvrtko Ursulin4805fe82016-11-04 14:42:46 +00004674 if (HAS_GUC_SCHED(dev_priv))
Sagar Arun Kamble26705e22016-10-12 21:54:31 +05304675 dev_priv->pm_guc_events = GEN9_GUC_TO_HOST_INT_EVENT;
4676
Deepak Sa6706b42014-03-15 20:23:22 +05304677 /* Let's track the enabled rps events */
Wayne Boyer666a4532015-12-09 12:29:35 -08004678 if (IS_VALLEYVIEW(dev_priv))
Ville Syrjälä6c65a5872014-08-29 14:14:07 +03004679 /* WaGsvRC0ResidencyMethod:vlv */
Chris Wilsone0e8c7c2017-03-09 21:12:30 +00004680 dev_priv->pm_rps_events = GEN6_PM_RP_UP_EI_EXPIRED;
Deepak S31685c22014-07-03 17:33:01 -04004681 else
Chris Wilson4668f692018-08-02 11:06:30 +01004682 dev_priv->pm_rps_events = (GEN6_PM_RP_UP_THRESHOLD |
4683 GEN6_PM_RP_DOWN_THRESHOLD |
4684 GEN6_PM_RP_DOWN_TIMEOUT);
Deepak Sa6706b42014-03-15 20:23:22 +05304685
Mika Kuoppala917dc6b2019-04-10 13:59:22 +03004686 /* We share the register with other engine */
4687 if (INTEL_GEN(dev_priv) > 9)
4688 GEM_WARN_ON(dev_priv->pm_rps_events & 0xffff0000);
4689
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004690 rps->pm_intrmsk_mbz = 0;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304691
4692 /*
Mika Kuoppalaacf2dc22017-04-13 14:15:27 +03004693 * SNB,IVB,HSW can while VLV,CHV may hard hang on looping batchbuffer
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304694 * if GEN6_PM_UP_EI_EXPIRED is masked.
4695 *
4696 * TODO: verify if this can be reproduced on VLV,CHV.
4697 */
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004698 if (INTEL_GEN(dev_priv) <= 7)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004699 rps->pm_intrmsk_mbz |= GEN6_PM_RP_UP_EI_EXPIRED;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304700
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004701 if (INTEL_GEN(dev_priv) >= 8)
Sagar Arun Kamble562d9ba2017-10-10 22:30:06 +01004702 rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
Sagar Arun Kamble1800ad22016-05-31 13:58:27 +05304703
Ville Syrjälä32db0b62018-11-27 22:05:50 +02004704 if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv))
Ville Syrjäläfd8f507c2015-09-18 20:03:42 +03004705 dev->driver->get_vblank_counter = g4x_get_vblank_counter;
Ville Syrjälä32db0b62018-11-27 22:05:50 +02004706 else if (INTEL_GEN(dev_priv) >= 3)
Ville Syrjälä391f75e2013-09-25 19:55:26 +03004707 dev->driver->get_vblank_counter = i915_get_vblank_counter;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004708
Ville Syrjälä0df3f092019-03-22 20:08:04 +02004709 dev->vblank_disable_immediate = true;
Ville Syrjälä21da2702014-08-06 14:49:55 +03004710
Chris Wilson262fd482017-02-15 13:15:47 +00004711 /* Most platforms treat the display irq block as an always-on
4712 * power domain. vlv/chv can disable it at runtime and need
4713 * special care to avoid writing any of the display block registers
4714 * outside of the power domain. We defer setting up the display irqs
4715 * in this case to the runtime pm.
4716 */
4717 dev_priv->display_irqs_enabled = true;
4718 if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv))
4719 dev_priv->display_irqs_enabled = false;
4720
Lyude317eaa92017-02-03 21:18:25 -05004721 dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD;
Lyude Paul9a64c652018-11-06 16:30:16 -05004722 /* If we have MST support, we want to avoid doing short HPD IRQ storm
4723 * detection, as short HPD storms will occur as a natural part of
4724 * sideband messaging with MST.
4725 * On older platforms however, IRQ storms can occur with both long and
4726 * short pulses, as seen on some G4x systems.
4727 */
4728 dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv);
Lyude317eaa92017-02-03 21:18:25 -05004729
Daniel Vetter1bf6ad62017-05-09 16:03:28 +02004730 dev->driver->get_vblank_timestamp = drm_calc_vbltimestamp_from_scanoutpos;
Daniel Vetterf3a5c3f2015-02-13 21:03:44 +01004731 dev->driver->get_scanout_position = i915_get_crtc_scanoutpos;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004732
Daniel Vetterb9632912014-09-30 10:56:44 +02004733 if (IS_CHERRYVIEW(dev_priv)) {
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004734 dev->driver->irq_handler = cherryview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004735 dev->driver->irq_preinstall = cherryview_irq_reset;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004736 dev->driver->irq_postinstall = cherryview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004737 dev->driver->irq_uninstall = cherryview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004738 dev->driver->enable_vblank = i965_enable_vblank;
4739 dev->driver->disable_vblank = i965_disable_vblank;
Ville Syrjälä43f328d2014-04-09 20:40:52 +03004740 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Daniel Vetterb9632912014-09-30 10:56:44 +02004741 } else if (IS_VALLEYVIEW(dev_priv)) {
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004742 dev->driver->irq_handler = valleyview_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004743 dev->driver->irq_preinstall = valleyview_irq_reset;
Jesse Barnes7e231dbe2012-03-28 13:39:38 -07004744 dev->driver->irq_postinstall = valleyview_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004745 dev->driver->irq_uninstall = valleyview_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004746 dev->driver->enable_vblank = i965_enable_vblank;
4747 dev->driver->disable_vblank = i965_disable_vblank;
Egbert Eichfa00abe2013-02-25 12:06:48 -05004748 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Mika Kuoppala51951ae2018-02-28 12:11:53 +02004749 } else if (INTEL_GEN(dev_priv) >= 11) {
4750 dev->driver->irq_handler = gen11_irq_handler;
4751 dev->driver->irq_preinstall = gen11_irq_reset;
4752 dev->driver->irq_postinstall = gen11_irq_postinstall;
4753 dev->driver->irq_uninstall = gen11_irq_reset;
4754 dev->driver->enable_vblank = gen8_enable_vblank;
4755 dev->driver->disable_vblank = gen8_disable_vblank;
Dhinakaran Pandiyan121e7582018-06-15 17:05:29 -07004756 dev_priv->display.hpd_irq_setup = gen11_hpd_irq_setup;
Pandiyan, Dhinakaranbca2bf22017-07-18 11:28:00 -07004757 } else if (INTEL_GEN(dev_priv) >= 8) {
Ben Widawskyabd58f02013-11-02 21:07:09 -07004758 dev->driver->irq_handler = gen8_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004759 dev->driver->irq_preinstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004760 dev->driver->irq_postinstall = gen8_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004761 dev->driver->irq_uninstall = gen8_irq_reset;
Ben Widawskyabd58f02013-11-02 21:07:09 -07004762 dev->driver->enable_vblank = gen8_enable_vblank;
4763 dev->driver->disable_vblank = gen8_disable_vblank;
Ander Conselvan de Oliveiracc3f90f2016-12-02 10:23:49 +02004764 if (IS_GEN9_LP(dev_priv))
Shashank Sharmae0a20ad2015-03-27 14:54:14 +02004765 dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup;
Rodrigo Vivic6c30b92019-03-08 13:43:00 -08004766 else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT)
Ville Syrjälä6dbf30c2015-08-27 23:56:02 +03004767 dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup;
4768 else
Ville Syrjälä3a3b3c72015-08-27 23:56:06 +03004769 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Tvrtko Ursulin6e266952016-10-13 11:02:53 +01004770 } else if (HAS_PCH_SPLIT(dev_priv)) {
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004771 dev->driver->irq_handler = ironlake_irq_handler;
Daniel Vetter723761b2014-05-22 17:56:34 +02004772 dev->driver->irq_preinstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004773 dev->driver->irq_postinstall = ironlake_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004774 dev->driver->irq_uninstall = ironlake_irq_reset;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004775 dev->driver->enable_vblank = ironlake_enable_vblank;
4776 dev->driver->disable_vblank = ironlake_disable_vblank;
Ville Syrjälä23bb4cb2015-08-27 23:56:04 +03004777 dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004778 } else {
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004779 if (IS_GEN(dev_priv, 2)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004780 dev->driver->irq_preinstall = i8xx_irq_reset;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004781 dev->driver->irq_postinstall = i8xx_irq_postinstall;
4782 dev->driver->irq_handler = i8xx_irq_handler;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004783 dev->driver->irq_uninstall = i8xx_irq_reset;
Chris Wilson86e83e32016-10-07 20:49:52 +01004784 dev->driver->enable_vblank = i8xx_enable_vblank;
4785 dev->driver->disable_vblank = i8xx_disable_vblank;
Ville Syrjäläd938da62019-03-22 20:08:03 +02004786 } else if (IS_I945GM(dev_priv)) {
4787 dev->driver->irq_preinstall = i915_irq_reset;
4788 dev->driver->irq_postinstall = i915_irq_postinstall;
4789 dev->driver->irq_uninstall = i915_irq_reset;
4790 dev->driver->irq_handler = i915_irq_handler;
4791 dev->driver->enable_vblank = i945gm_enable_vblank;
4792 dev->driver->disable_vblank = i945gm_disable_vblank;
Lucas De Marchicf819ef2018-12-12 10:10:43 -08004793 } else if (IS_GEN(dev_priv, 3)) {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004794 dev->driver->irq_preinstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004795 dev->driver->irq_postinstall = i915_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004796 dev->driver->irq_uninstall = i915_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004797 dev->driver->irq_handler = i915_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004798 dev->driver->enable_vblank = i8xx_enable_vblank;
4799 dev->driver->disable_vblank = i8xx_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004800 } else {
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004801 dev->driver->irq_preinstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004802 dev->driver->irq_postinstall = i965_irq_postinstall;
Ville Syrjälä6bcdb1c2017-08-18 21:37:04 +03004803 dev->driver->irq_uninstall = i965_irq_reset;
Chris Wilsona266c7d2012-04-24 22:59:44 +01004804 dev->driver->irq_handler = i965_irq_handler;
Chris Wilson86e83e32016-10-07 20:49:52 +01004805 dev->driver->enable_vblank = i965_enable_vblank;
4806 dev->driver->disable_vblank = i965_disable_vblank;
Chris Wilsonc2798b12012-04-22 21:13:57 +01004807 }
Ville Syrjälä778eb332015-01-09 14:21:13 +02004808 if (I915_HAS_HOTPLUG(dev_priv))
4809 dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup;
Jesse Barnesf71d4af2011-06-28 13:00:41 -07004810 }
4811}
Daniel Vetter20afbda2012-12-11 14:05:07 +01004812
Daniel Vetterfca52a52014-09-30 10:56:45 +02004813/**
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004814 * intel_irq_fini - deinitializes IRQ support
4815 * @i915: i915 device instance
4816 *
4817 * This function deinitializes all the IRQ support.
4818 */
4819void intel_irq_fini(struct drm_i915_private *i915)
4820{
4821 int i;
4822
Ville Syrjäläd938da62019-03-22 20:08:03 +02004823 if (IS_I945GM(i915))
4824 i945gm_vblank_work_fini(i915);
4825
Joonas Lahtinencefcff82017-04-28 10:58:39 +03004826 for (i = 0; i < MAX_L3_SLICES; ++i)
4827 kfree(i915->l3_parity.remap_info[i]);
4828}
4829
4830/**
Daniel Vetterfca52a52014-09-30 10:56:45 +02004831 * intel_irq_install - enables the hardware interrupt
4832 * @dev_priv: i915 device instance
4833 *
4834 * This function enables the hardware interrupt handling, but leaves the hotplug
4835 * handling still disabled. It is called after intel_irq_init().
4836 *
4837 * In the driver load and resume code we need working interrupts in a few places
4838 * but don't want to deal with the hassle of concurrent probe and hotplug
4839 * workers. Hence the split into this two-stage approach.
4840 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004841int intel_irq_install(struct drm_i915_private *dev_priv)
4842{
4843 /*
4844 * We enable some interrupt sources in our postinstall hooks, so mark
4845 * interrupts as enabled _before_ actually enabling them to avoid
4846 * special cases in our ordering checks.
4847 */
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004848 dev_priv->runtime_pm.irqs_enabled = true;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004849
Chris Wilson91c8a322016-07-05 10:40:23 +01004850 return drm_irq_install(&dev_priv->drm, dev_priv->drm.pdev->irq);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004851}
4852
Daniel Vetterfca52a52014-09-30 10:56:45 +02004853/**
4854 * intel_irq_uninstall - finilizes all irq handling
4855 * @dev_priv: i915 device instance
4856 *
4857 * This stops interrupt and hotplug handling and unregisters and frees all
4858 * resources acquired in the init functions.
4859 */
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004860void intel_irq_uninstall(struct drm_i915_private *dev_priv)
4861{
Chris Wilson91c8a322016-07-05 10:40:23 +01004862 drm_irq_uninstall(&dev_priv->drm);
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004863 intel_hpd_cancel_work(dev_priv);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004864 dev_priv->runtime_pm.irqs_enabled = false;
Daniel Vetter2aeb7d32014-09-30 10:56:43 +02004865}
4866
Daniel Vetterfca52a52014-09-30 10:56:45 +02004867/**
4868 * intel_runtime_pm_disable_interrupts - runtime interrupt disabling
4869 * @dev_priv: i915 device instance
4870 *
4871 * This function is used to disable interrupts at runtime, both in the runtime
4872 * pm and the system suspend/resume code.
4873 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004874void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004875{
Chris Wilson91c8a322016-07-05 10:40:23 +01004876 dev_priv->drm.driver->irq_uninstall(&dev_priv->drm);
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004877 dev_priv->runtime_pm.irqs_enabled = false;
Chris Wilson91c8a322016-07-05 10:40:23 +01004878 synchronize_irq(dev_priv->drm.irq);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004879}
4880
Daniel Vetterfca52a52014-09-30 10:56:45 +02004881/**
4882 * intel_runtime_pm_enable_interrupts - runtime interrupt enabling
4883 * @dev_priv: i915 device instance
4884 *
4885 * This function is used to enable interrupts at runtime, both in the runtime
4886 * pm and the system suspend/resume code.
4887 */
Daniel Vetterb9632912014-09-30 10:56:44 +02004888void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv)
Paulo Zanonic67a4702013-08-19 13:18:09 -03004889{
Sagar Arun Kamblead1443f2017-10-10 22:30:04 +01004890 dev_priv->runtime_pm.irqs_enabled = true;
Chris Wilson91c8a322016-07-05 10:40:23 +01004891 dev_priv->drm.driver->irq_preinstall(&dev_priv->drm);
4892 dev_priv->drm.driver->irq_postinstall(&dev_priv->drm);
Paulo Zanonic67a4702013-08-19 13:18:09 -03004893}