1 1.25 riastrad /* $NetBSD: i915_irq.c,v 1.25 2021/12/19 11:45:01 riastradh Exp $ */ 2 1.11 riastrad 3 1.1 riastrad /* i915_irq.c -- IRQ support for the I915 -*- linux-c -*- 4 1.1 riastrad */ 5 1.1 riastrad /* 6 1.1 riastrad * Copyright 2003 Tungsten Graphics, Inc., Cedar Park, Texas. 7 1.1 riastrad * All Rights Reserved. 8 1.1 riastrad * 9 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining a 10 1.1 riastrad * copy of this software and associated documentation files (the 11 1.1 riastrad * "Software"), to deal in the Software without restriction, including 12 1.1 riastrad * without limitation the rights to use, copy, modify, merge, publish, 13 1.1 riastrad * distribute, sub license, and/or sell copies of the Software, and to 14 1.1 riastrad * permit persons to whom the Software is furnished to do so, subject to 15 1.1 riastrad * the following conditions: 16 1.1 riastrad * 17 1.1 riastrad * The above copyright notice and this permission notice (including the 18 1.1 riastrad * next paragraph) shall be included in all copies or substantial portions 19 1.1 riastrad * of the Software. 20 1.1 riastrad * 21 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 22 1.1 riastrad * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 23 1.1 riastrad * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 24 1.1 riastrad * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 25 1.1 riastrad * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 26 1.1 riastrad * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 27 1.1 riastrad * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 28 1.1 riastrad * 29 1.1 riastrad */ 30 1.1 riastrad 31 1.11 riastrad #include <sys/cdefs.h> 32 1.25 riastrad __KERNEL_RCSID(0, "$NetBSD: i915_irq.c,v 1.25 2021/12/19 11:45:01 riastradh Exp $"); 33 1.11 riastrad 34 1.1 riastrad #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 35 1.1 riastrad 36 1.20 riastrad #include <linux/circ_buf.h> 37 1.20 riastrad #include <linux/slab.h> 38 1.1 riastrad #include <linux/sysrq.h> 39 1.20 riastrad 40 1.20 riastrad #include <drm/drm_drv.h> 41 1.20 riastrad #include <drm/drm_irq.h> 42 1.1 riastrad #include <drm/i915_drm.h> 43 1.20 riastrad 44 1.20 riastrad #include "display/intel_display_types.h" 45 1.20 riastrad #include "display/intel_fifo_underrun.h" 46 1.20 riastrad #include "display/intel_hotplug.h" 47 1.20 riastrad #include "display/intel_lpe_audio.h" 48 1.20 riastrad #include "display/intel_psr.h" 49 1.20 riastrad 50 1.20 riastrad #include "gt/intel_gt.h" 51 1.20 riastrad #include "gt/intel_gt_irq.h" 52 1.20 riastrad #include "gt/intel_gt_pm_irq.h" 53 1.20 riastrad #include "gt/intel_rps.h" 54 1.20 riastrad 55 1.1 riastrad #include "i915_drv.h" 56 1.20 riastrad #include "i915_irq.h" 57 1.1 riastrad #include "i915_trace.h" 58 1.20 riastrad #include "intel_pm.h" 59 1.1 riastrad 60 1.11 riastrad /** 61 1.11 riastrad * DOC: interrupt handling 62 1.11 riastrad * 63 1.11 riastrad * These functions provide the basic support for enabling and disabling the 64 1.11 riastrad * interrupt handling support. There's a lot more functionality in i915_irq.c 65 1.11 riastrad * and related files, but that will be described in separate chapters. 66 1.11 riastrad */ 67 1.11 riastrad 68 1.20 riastrad typedef bool (*long_pulse_detect_func)(enum hpd_pin pin, u32 val); 69 1.20 riastrad 70 1.11 riastrad static const u32 hpd_ilk[HPD_NUM_PINS] = { 71 1.11 riastrad [HPD_PORT_A] = DE_DP_A_HOTPLUG, 72 1.11 riastrad }; 73 1.11 riastrad 74 1.11 riastrad static const u32 hpd_ivb[HPD_NUM_PINS] = { 75 1.11 riastrad [HPD_PORT_A] = DE_DP_A_HOTPLUG_IVB, 76 1.11 riastrad }; 77 1.11 riastrad 78 1.11 riastrad static const u32 hpd_bdw[HPD_NUM_PINS] = { 79 1.11 riastrad [HPD_PORT_A] = GEN8_PORT_DP_A_HOTPLUG, 80 1.11 riastrad }; 81 1.11 riastrad 82 1.11 riastrad static const u32 hpd_ibx[HPD_NUM_PINS] = { 83 1.5 riastrad [HPD_CRT] = SDE_CRT_HOTPLUG, 84 1.5 riastrad [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG, 85 1.5 riastrad [HPD_PORT_B] = SDE_PORTB_HOTPLUG, 86 1.5 riastrad [HPD_PORT_C] = SDE_PORTC_HOTPLUG, 87 1.5 riastrad [HPD_PORT_D] = SDE_PORTD_HOTPLUG 88 1.5 riastrad }; 89 1.5 riastrad 90 1.11 riastrad static const u32 hpd_cpt[HPD_NUM_PINS] = { 91 1.5 riastrad [HPD_CRT] = SDE_CRT_HOTPLUG_CPT, 92 1.5 riastrad [HPD_SDVO_B] = SDE_SDVOB_HOTPLUG_CPT, 93 1.5 riastrad [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 94 1.5 riastrad [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 95 1.5 riastrad [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT 96 1.5 riastrad }; 97 1.5 riastrad 98 1.11 riastrad static const u32 hpd_spt[HPD_NUM_PINS] = { 99 1.11 riastrad [HPD_PORT_A] = SDE_PORTA_HOTPLUG_SPT, 100 1.11 riastrad [HPD_PORT_B] = SDE_PORTB_HOTPLUG_CPT, 101 1.11 riastrad [HPD_PORT_C] = SDE_PORTC_HOTPLUG_CPT, 102 1.11 riastrad [HPD_PORT_D] = SDE_PORTD_HOTPLUG_CPT, 103 1.11 riastrad [HPD_PORT_E] = SDE_PORTE_HOTPLUG_SPT 104 1.11 riastrad }; 105 1.11 riastrad 106 1.11 riastrad static const u32 hpd_mask_i915[HPD_NUM_PINS] = { 107 1.5 riastrad [HPD_CRT] = CRT_HOTPLUG_INT_EN, 108 1.5 riastrad [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_EN, 109 1.5 riastrad [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_EN, 110 1.5 riastrad [HPD_PORT_B] = PORTB_HOTPLUG_INT_EN, 111 1.5 riastrad [HPD_PORT_C] = PORTC_HOTPLUG_INT_EN, 112 1.5 riastrad [HPD_PORT_D] = PORTD_HOTPLUG_INT_EN 113 1.5 riastrad }; 114 1.5 riastrad 115 1.11 riastrad static const u32 hpd_status_g4x[HPD_NUM_PINS] = { 116 1.5 riastrad [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 117 1.5 riastrad [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_G4X, 118 1.5 riastrad [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_G4X, 119 1.5 riastrad [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 120 1.5 riastrad [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 121 1.5 riastrad [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 122 1.5 riastrad }; 123 1.5 riastrad 124 1.11 riastrad static const u32 hpd_status_i915[HPD_NUM_PINS] = { 125 1.5 riastrad [HPD_CRT] = CRT_HOTPLUG_INT_STATUS, 126 1.5 riastrad [HPD_SDVO_B] = SDVOB_HOTPLUG_INT_STATUS_I915, 127 1.5 riastrad [HPD_SDVO_C] = SDVOC_HOTPLUG_INT_STATUS_I915, 128 1.5 riastrad [HPD_PORT_B] = PORTB_HOTPLUG_INT_STATUS, 129 1.5 riastrad [HPD_PORT_C] = PORTC_HOTPLUG_INT_STATUS, 130 1.5 riastrad [HPD_PORT_D] = PORTD_HOTPLUG_INT_STATUS 131 1.5 riastrad }; 132 1.5 riastrad 133 1.11 riastrad /* BXT hpd list */ 134 1.11 riastrad static const u32 hpd_bxt[HPD_NUM_PINS] = { 135 1.11 riastrad [HPD_PORT_A] = BXT_DE_PORT_HP_DDIA, 136 1.11 riastrad [HPD_PORT_B] = BXT_DE_PORT_HP_DDIB, 137 1.11 riastrad [HPD_PORT_C] = BXT_DE_PORT_HP_DDIC 138 1.11 riastrad }; 139 1.11 riastrad 140 1.20 riastrad static const u32 hpd_gen11[HPD_NUM_PINS] = { 141 1.20 riastrad [HPD_PORT_C] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG, 142 1.20 riastrad [HPD_PORT_D] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG, 143 1.20 riastrad [HPD_PORT_E] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG, 144 1.20 riastrad [HPD_PORT_F] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG 145 1.20 riastrad }; 146 1.20 riastrad 147 1.20 riastrad static const u32 hpd_gen12[HPD_NUM_PINS] = { 148 1.20 riastrad [HPD_PORT_D] = GEN11_TC1_HOTPLUG | GEN11_TBT1_HOTPLUG, 149 1.20 riastrad [HPD_PORT_E] = GEN11_TC2_HOTPLUG | GEN11_TBT2_HOTPLUG, 150 1.20 riastrad [HPD_PORT_F] = GEN11_TC3_HOTPLUG | GEN11_TBT3_HOTPLUG, 151 1.20 riastrad [HPD_PORT_G] = GEN11_TC4_HOTPLUG | GEN11_TBT4_HOTPLUG, 152 1.20 riastrad [HPD_PORT_H] = GEN12_TC5_HOTPLUG | GEN12_TBT5_HOTPLUG, 153 1.20 riastrad [HPD_PORT_I] = GEN12_TC6_HOTPLUG | GEN12_TBT6_HOTPLUG 154 1.20 riastrad }; 155 1.20 riastrad 156 1.20 riastrad static const u32 hpd_icp[HPD_NUM_PINS] = { 157 1.20 riastrad [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(PORT_A), 158 1.20 riastrad [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(PORT_B), 159 1.20 riastrad [HPD_PORT_C] = SDE_TC_HOTPLUG_ICP(PORT_TC1), 160 1.20 riastrad [HPD_PORT_D] = SDE_TC_HOTPLUG_ICP(PORT_TC2), 161 1.20 riastrad [HPD_PORT_E] = SDE_TC_HOTPLUG_ICP(PORT_TC3), 162 1.20 riastrad [HPD_PORT_F] = SDE_TC_HOTPLUG_ICP(PORT_TC4), 163 1.20 riastrad }; 164 1.20 riastrad 165 1.20 riastrad static const u32 hpd_tgp[HPD_NUM_PINS] = { 166 1.20 riastrad [HPD_PORT_A] = SDE_DDI_HOTPLUG_ICP(PORT_A), 167 1.20 riastrad [HPD_PORT_B] = SDE_DDI_HOTPLUG_ICP(PORT_B), 168 1.20 riastrad [HPD_PORT_C] = SDE_DDI_HOTPLUG_ICP(PORT_C), 169 1.20 riastrad [HPD_PORT_D] = SDE_TC_HOTPLUG_ICP(PORT_TC1), 170 1.20 riastrad [HPD_PORT_E] = SDE_TC_HOTPLUG_ICP(PORT_TC2), 171 1.20 riastrad [HPD_PORT_F] = SDE_TC_HOTPLUG_ICP(PORT_TC3), 172 1.20 riastrad [HPD_PORT_G] = SDE_TC_HOTPLUG_ICP(PORT_TC4), 173 1.20 riastrad [HPD_PORT_H] = SDE_TC_HOTPLUG_ICP(PORT_TC5), 174 1.20 riastrad [HPD_PORT_I] = SDE_TC_HOTPLUG_ICP(PORT_TC6), 175 1.20 riastrad }; 176 1.20 riastrad 177 1.20 riastrad void gen3_irq_reset(struct intel_uncore *uncore, i915_reg_t imr, 178 1.20 riastrad i915_reg_t iir, i915_reg_t ier) 179 1.20 riastrad { 180 1.20 riastrad intel_uncore_write(uncore, imr, 0xffffffff); 181 1.20 riastrad intel_uncore_posting_read(uncore, imr); 182 1.20 riastrad 183 1.20 riastrad intel_uncore_write(uncore, ier, 0); 184 1.20 riastrad 185 1.20 riastrad /* IIR can theoretically queue up two events. Be paranoid. */ 186 1.20 riastrad intel_uncore_write(uncore, iir, 0xffffffff); 187 1.20 riastrad intel_uncore_posting_read(uncore, iir); 188 1.20 riastrad intel_uncore_write(uncore, iir, 0xffffffff); 189 1.20 riastrad intel_uncore_posting_read(uncore, iir); 190 1.20 riastrad } 191 1.20 riastrad 192 1.20 riastrad void gen2_irq_reset(struct intel_uncore *uncore) 193 1.20 riastrad { 194 1.20 riastrad intel_uncore_write16(uncore, GEN2_IMR, 0xffff); 195 1.20 riastrad intel_uncore_posting_read16(uncore, GEN2_IMR); 196 1.20 riastrad 197 1.20 riastrad intel_uncore_write16(uncore, GEN2_IER, 0); 198 1.20 riastrad 199 1.20 riastrad /* IIR can theoretically queue up two events. Be paranoid. */ 200 1.20 riastrad intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 201 1.20 riastrad intel_uncore_posting_read16(uncore, GEN2_IIR); 202 1.20 riastrad intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 203 1.20 riastrad intel_uncore_posting_read16(uncore, GEN2_IIR); 204 1.20 riastrad } 205 1.11 riastrad 206 1.11 riastrad /* 207 1.11 riastrad * We should clear IMR at preinstall/uninstall, and just check at postinstall. 208 1.11 riastrad */ 209 1.20 riastrad static void gen3_assert_iir_is_zero(struct intel_uncore *uncore, i915_reg_t reg) 210 1.20 riastrad { 211 1.20 riastrad u32 val = intel_uncore_read(uncore, reg); 212 1.20 riastrad 213 1.20 riastrad if (val == 0) 214 1.20 riastrad return; 215 1.20 riastrad 216 1.20 riastrad WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 217 1.20 riastrad i915_mmio_reg_offset(reg), val); 218 1.20 riastrad intel_uncore_write(uncore, reg, 0xffffffff); 219 1.20 riastrad intel_uncore_posting_read(uncore, reg); 220 1.20 riastrad intel_uncore_write(uncore, reg, 0xffffffff); 221 1.20 riastrad intel_uncore_posting_read(uncore, reg); 222 1.20 riastrad } 223 1.20 riastrad 224 1.20 riastrad static void gen2_assert_iir_is_zero(struct intel_uncore *uncore) 225 1.11 riastrad { 226 1.20 riastrad u16 val = intel_uncore_read16(uncore, GEN2_IIR); 227 1.11 riastrad 228 1.11 riastrad if (val == 0) 229 1.11 riastrad return; 230 1.11 riastrad 231 1.11 riastrad WARN(1, "Interrupt register 0x%x is not zero: 0x%08x\n", 232 1.20 riastrad i915_mmio_reg_offset(GEN2_IIR), val); 233 1.20 riastrad intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 234 1.20 riastrad intel_uncore_posting_read16(uncore, GEN2_IIR); 235 1.20 riastrad intel_uncore_write16(uncore, GEN2_IIR, 0xffff); 236 1.20 riastrad intel_uncore_posting_read16(uncore, GEN2_IIR); 237 1.20 riastrad } 238 1.20 riastrad 239 1.20 riastrad void gen3_irq_init(struct intel_uncore *uncore, 240 1.20 riastrad i915_reg_t imr, u32 imr_val, 241 1.20 riastrad i915_reg_t ier, u32 ier_val, 242 1.20 riastrad i915_reg_t iir) 243 1.20 riastrad { 244 1.20 riastrad gen3_assert_iir_is_zero(uncore, iir); 245 1.20 riastrad 246 1.20 riastrad intel_uncore_write(uncore, ier, ier_val); 247 1.20 riastrad intel_uncore_write(uncore, imr, imr_val); 248 1.20 riastrad intel_uncore_posting_read(uncore, imr); 249 1.11 riastrad } 250 1.11 riastrad 251 1.20 riastrad void gen2_irq_init(struct intel_uncore *uncore, 252 1.20 riastrad u32 imr_val, u32 ier_val) 253 1.20 riastrad { 254 1.20 riastrad gen2_assert_iir_is_zero(uncore); 255 1.11 riastrad 256 1.20 riastrad intel_uncore_write16(uncore, GEN2_IER, ier_val); 257 1.20 riastrad intel_uncore_write16(uncore, GEN2_IMR, imr_val); 258 1.20 riastrad intel_uncore_posting_read16(uncore, GEN2_IMR); 259 1.20 riastrad } 260 1.11 riastrad 261 1.1 riastrad /* For display hotplug interrupt */ 262 1.11 riastrad static inline void 263 1.11 riastrad i915_hotplug_interrupt_update_locked(struct drm_i915_private *dev_priv, 264 1.20 riastrad u32 mask, 265 1.20 riastrad u32 bits) 266 1.1 riastrad { 267 1.20 riastrad u32 val; 268 1.11 riastrad 269 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 270 1.11 riastrad WARN_ON(bits & ~mask); 271 1.5 riastrad 272 1.11 riastrad val = I915_READ(PORT_HOTPLUG_EN); 273 1.11 riastrad val &= ~mask; 274 1.11 riastrad val |= bits; 275 1.11 riastrad I915_WRITE(PORT_HOTPLUG_EN, val); 276 1.11 riastrad } 277 1.5 riastrad 278 1.11 riastrad /** 279 1.11 riastrad * i915_hotplug_interrupt_update - update hotplug interrupt enable 280 1.11 riastrad * @dev_priv: driver private 281 1.11 riastrad * @mask: bits to update 282 1.11 riastrad * @bits: bits to enable 283 1.11 riastrad * NOTE: the HPD enable bits are modified both inside and outside 284 1.11 riastrad * of an interrupt context. To avoid that read-modify-write cycles 285 1.11 riastrad * interfer, these bits are protected by a spinlock. Since this 286 1.11 riastrad * function is usually not called from a context where the lock is 287 1.11 riastrad * held already, this function acquires the lock itself. A non-locking 288 1.11 riastrad * version is also available. 289 1.11 riastrad */ 290 1.11 riastrad void i915_hotplug_interrupt_update(struct drm_i915_private *dev_priv, 291 1.20 riastrad u32 mask, 292 1.20 riastrad u32 bits) 293 1.11 riastrad { 294 1.11 riastrad spin_lock_irq(&dev_priv->irq_lock); 295 1.11 riastrad i915_hotplug_interrupt_update_locked(dev_priv, mask, bits); 296 1.11 riastrad spin_unlock_irq(&dev_priv->irq_lock); 297 1.1 riastrad } 298 1.1 riastrad 299 1.11 riastrad /** 300 1.11 riastrad * ilk_update_display_irq - update DEIMR 301 1.11 riastrad * @dev_priv: driver private 302 1.11 riastrad * @interrupt_mask: mask of interrupt bits to update 303 1.11 riastrad * @enabled_irq_mask: mask of interrupt bits to enable 304 1.11 riastrad */ 305 1.20 riastrad void ilk_update_display_irq(struct drm_i915_private *dev_priv, 306 1.20 riastrad u32 interrupt_mask, 307 1.20 riastrad u32 enabled_irq_mask) 308 1.1 riastrad { 309 1.20 riastrad u32 new_val; 310 1.11 riastrad 311 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 312 1.5 riastrad 313 1.11 riastrad WARN_ON(enabled_irq_mask & ~interrupt_mask); 314 1.11 riastrad 315 1.11 riastrad if (WARN_ON(!intel_irqs_enabled(dev_priv))) 316 1.5 riastrad return; 317 1.5 riastrad 318 1.11 riastrad new_val = dev_priv->irq_mask; 319 1.11 riastrad new_val &= ~interrupt_mask; 320 1.11 riastrad new_val |= (~enabled_irq_mask & interrupt_mask); 321 1.11 riastrad 322 1.11 riastrad if (new_val != dev_priv->irq_mask) { 323 1.11 riastrad dev_priv->irq_mask = new_val; 324 1.1 riastrad I915_WRITE(DEIMR, dev_priv->irq_mask); 325 1.1 riastrad POSTING_READ(DEIMR); 326 1.1 riastrad } 327 1.1 riastrad } 328 1.1 riastrad 329 1.5 riastrad /** 330 1.20 riastrad * bdw_update_port_irq - update DE port interrupt 331 1.5 riastrad * @dev_priv: driver private 332 1.5 riastrad * @interrupt_mask: mask of interrupt bits to update 333 1.5 riastrad * @enabled_irq_mask: mask of interrupt bits to enable 334 1.5 riastrad */ 335 1.20 riastrad static void bdw_update_port_irq(struct drm_i915_private *dev_priv, 336 1.20 riastrad u32 interrupt_mask, 337 1.20 riastrad u32 enabled_irq_mask) 338 1.5 riastrad { 339 1.20 riastrad u32 new_val; 340 1.20 riastrad u32 old_val; 341 1.20 riastrad 342 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 343 1.5 riastrad 344 1.11 riastrad WARN_ON(enabled_irq_mask & ~interrupt_mask); 345 1.11 riastrad 346 1.11 riastrad if (WARN_ON(!intel_irqs_enabled(dev_priv))) 347 1.5 riastrad return; 348 1.5 riastrad 349 1.20 riastrad old_val = I915_READ(GEN8_DE_PORT_IMR); 350 1.5 riastrad 351 1.20 riastrad new_val = old_val; 352 1.5 riastrad new_val &= ~interrupt_mask; 353 1.5 riastrad new_val |= (~enabled_irq_mask & interrupt_mask); 354 1.5 riastrad 355 1.20 riastrad if (new_val != old_val) { 356 1.20 riastrad I915_WRITE(GEN8_DE_PORT_IMR, new_val); 357 1.20 riastrad POSTING_READ(GEN8_DE_PORT_IMR); 358 1.5 riastrad } 359 1.5 riastrad } 360 1.5 riastrad 361 1.11 riastrad /** 362 1.20 riastrad * bdw_update_pipe_irq - update DE pipe interrupt 363 1.20 riastrad * @dev_priv: driver private 364 1.20 riastrad * @pipe: pipe whose interrupt to update 365 1.20 riastrad * @interrupt_mask: mask of interrupt bits to update 366 1.20 riastrad * @enabled_irq_mask: mask of interrupt bits to enable 367 1.20 riastrad */ 368 1.20 riastrad void bdw_update_pipe_irq(struct drm_i915_private *dev_priv, 369 1.20 riastrad enum pipe pipe, 370 1.20 riastrad u32 interrupt_mask, 371 1.20 riastrad u32 enabled_irq_mask) 372 1.5 riastrad { 373 1.20 riastrad u32 new_val; 374 1.5 riastrad 375 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 376 1.5 riastrad 377 1.11 riastrad WARN_ON(enabled_irq_mask & ~interrupt_mask); 378 1.11 riastrad 379 1.11 riastrad if (WARN_ON(!intel_irqs_enabled(dev_priv))) 380 1.11 riastrad return; 381 1.11 riastrad 382 1.20 riastrad new_val = dev_priv->de_irq_mask[pipe]; 383 1.11 riastrad new_val &= ~interrupt_mask; 384 1.11 riastrad new_val |= (~enabled_irq_mask & interrupt_mask); 385 1.11 riastrad 386 1.20 riastrad if (new_val != dev_priv->de_irq_mask[pipe]) { 387 1.20 riastrad dev_priv->de_irq_mask[pipe] = new_val; 388 1.20 riastrad I915_WRITE(GEN8_DE_PIPE_IMR(pipe), dev_priv->de_irq_mask[pipe]); 389 1.20 riastrad POSTING_READ(GEN8_DE_PIPE_IMR(pipe)); 390 1.11 riastrad } 391 1.5 riastrad } 392 1.5 riastrad 393 1.5 riastrad /** 394 1.5 riastrad * ibx_display_interrupt_update - update SDEIMR 395 1.5 riastrad * @dev_priv: driver private 396 1.5 riastrad * @interrupt_mask: mask of interrupt bits to update 397 1.5 riastrad * @enabled_irq_mask: mask of interrupt bits to enable 398 1.5 riastrad */ 399 1.11 riastrad void ibx_display_interrupt_update(struct drm_i915_private *dev_priv, 400 1.20 riastrad u32 interrupt_mask, 401 1.20 riastrad u32 enabled_irq_mask) 402 1.5 riastrad { 403 1.20 riastrad u32 sdeimr = I915_READ(SDEIMR); 404 1.5 riastrad sdeimr &= ~interrupt_mask; 405 1.5 riastrad sdeimr |= (~enabled_irq_mask & interrupt_mask); 406 1.5 riastrad 407 1.11 riastrad WARN_ON(enabled_irq_mask & ~interrupt_mask); 408 1.11 riastrad 409 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 410 1.5 riastrad 411 1.11 riastrad if (WARN_ON(!intel_irqs_enabled(dev_priv))) 412 1.5 riastrad return; 413 1.5 riastrad 414 1.5 riastrad I915_WRITE(SDEIMR, sdeimr); 415 1.5 riastrad POSTING_READ(SDEIMR); 416 1.5 riastrad } 417 1.5 riastrad 418 1.20 riastrad u32 i915_pipestat_enable_mask(struct drm_i915_private *dev_priv, 419 1.20 riastrad enum pipe pipe) 420 1.5 riastrad { 421 1.20 riastrad u32 status_mask = dev_priv->pipestat_irq_mask[pipe]; 422 1.20 riastrad u32 enable_mask = status_mask << 16; 423 1.5 riastrad 424 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 425 1.5 riastrad 426 1.20 riastrad if (INTEL_GEN(dev_priv) < 5) 427 1.20 riastrad goto out; 428 1.5 riastrad 429 1.5 riastrad /* 430 1.11 riastrad * On pipe A we don't support the PSR interrupt yet, 431 1.11 riastrad * on pipe B and C the same bit MBZ. 432 1.5 riastrad */ 433 1.5 riastrad if (WARN_ON_ONCE(status_mask & PIPE_A_PSR_STATUS_VLV)) 434 1.5 riastrad return 0; 435 1.11 riastrad /* 436 1.11 riastrad * On pipe B and C we don't support the PSR interrupt yet, on pipe 437 1.11 riastrad * A the same bit is for perf counters which we don't use either. 438 1.11 riastrad */ 439 1.11 riastrad if (WARN_ON_ONCE(status_mask & PIPE_B_PSR_STATUS_VLV)) 440 1.11 riastrad return 0; 441 1.5 riastrad 442 1.5 riastrad enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 443 1.5 riastrad SPRITE0_FLIP_DONE_INT_EN_VLV | 444 1.5 riastrad SPRITE1_FLIP_DONE_INT_EN_VLV); 445 1.5 riastrad if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 446 1.5 riastrad enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 447 1.5 riastrad if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 448 1.5 riastrad enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 449 1.5 riastrad 450 1.20 riastrad out: 451 1.20 riastrad WARN_ONCE(enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 452 1.20 riastrad status_mask & ~PIPESTAT_INT_STATUS_MASK, 453 1.20 riastrad "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 454 1.20 riastrad pipe_name(pipe), enable_mask, status_mask); 455 1.20 riastrad 456 1.5 riastrad return enable_mask; 457 1.5 riastrad } 458 1.5 riastrad 459 1.20 riastrad void i915_enable_pipestat(struct drm_i915_private *dev_priv, 460 1.20 riastrad enum pipe pipe, u32 status_mask) 461 1.1 riastrad { 462 1.20 riastrad i915_reg_t reg = PIPESTAT(pipe); 463 1.5 riastrad u32 enable_mask; 464 1.1 riastrad 465 1.20 riastrad WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK, 466 1.20 riastrad "pipe %c: status_mask=0x%x\n", 467 1.20 riastrad pipe_name(pipe), status_mask); 468 1.20 riastrad 469 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 470 1.20 riastrad WARN_ON(!intel_irqs_enabled(dev_priv)); 471 1.20 riastrad 472 1.20 riastrad if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == status_mask) 473 1.20 riastrad return; 474 1.20 riastrad 475 1.20 riastrad dev_priv->pipestat_irq_mask[pipe] |= status_mask; 476 1.20 riastrad enable_mask = i915_pipestat_enable_mask(dev_priv, pipe); 477 1.20 riastrad 478 1.20 riastrad I915_WRITE(reg, enable_mask | status_mask); 479 1.20 riastrad POSTING_READ(reg); 480 1.1 riastrad } 481 1.1 riastrad 482 1.20 riastrad void i915_disable_pipestat(struct drm_i915_private *dev_priv, 483 1.20 riastrad enum pipe pipe, u32 status_mask) 484 1.1 riastrad { 485 1.20 riastrad i915_reg_t reg = PIPESTAT(pipe); 486 1.5 riastrad u32 enable_mask; 487 1.1 riastrad 488 1.20 riastrad WARN_ONCE(status_mask & ~PIPESTAT_INT_STATUS_MASK, 489 1.20 riastrad "pipe %c: status_mask=0x%x\n", 490 1.20 riastrad pipe_name(pipe), status_mask); 491 1.20 riastrad 492 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 493 1.20 riastrad WARN_ON(!intel_irqs_enabled(dev_priv)); 494 1.20 riastrad 495 1.20 riastrad if ((dev_priv->pipestat_irq_mask[pipe] & status_mask) == 0) 496 1.20 riastrad return; 497 1.20 riastrad 498 1.20 riastrad dev_priv->pipestat_irq_mask[pipe] &= ~status_mask; 499 1.20 riastrad enable_mask = i915_pipestat_enable_mask(dev_priv, pipe); 500 1.20 riastrad 501 1.20 riastrad I915_WRITE(reg, enable_mask | status_mask); 502 1.20 riastrad POSTING_READ(reg); 503 1.20 riastrad } 504 1.20 riastrad 505 1.20 riastrad static bool i915_has_asle(struct drm_i915_private *dev_priv) 506 1.20 riastrad { 507 1.20 riastrad if (!dev_priv->opregion.asle) 508 1.20 riastrad return false; 509 1.20 riastrad 510 1.20 riastrad return IS_PINEVIEW(dev_priv) || IS_MOBILE(dev_priv); 511 1.1 riastrad } 512 1.1 riastrad 513 1.1 riastrad /** 514 1.5 riastrad * i915_enable_asle_pipestat - enable ASLE pipestat for OpRegion 515 1.20 riastrad * @dev_priv: i915 device private 516 1.1 riastrad */ 517 1.20 riastrad static void i915_enable_asle_pipestat(struct drm_i915_private *dev_priv) 518 1.1 riastrad { 519 1.20 riastrad if (!i915_has_asle(dev_priv)) 520 1.1 riastrad return; 521 1.1 riastrad 522 1.11 riastrad spin_lock_irq(&dev_priv->irq_lock); 523 1.1 riastrad 524 1.5 riastrad i915_enable_pipestat(dev_priv, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 525 1.20 riastrad if (INTEL_GEN(dev_priv) >= 4) 526 1.5 riastrad i915_enable_pipestat(dev_priv, PIPE_A, 527 1.5 riastrad PIPE_LEGACY_BLC_EVENT_STATUS); 528 1.1 riastrad 529 1.11 riastrad spin_unlock_irq(&dev_priv->irq_lock); 530 1.1 riastrad } 531 1.1 riastrad 532 1.11 riastrad /* 533 1.11 riastrad * This timing diagram depicts the video signal in and 534 1.11 riastrad * around the vertical blanking period. 535 1.11 riastrad * 536 1.11 riastrad * Assumptions about the fictitious mode used in this example: 537 1.11 riastrad * vblank_start >= 3 538 1.11 riastrad * vsync_start = vblank_start + 1 539 1.11 riastrad * vsync_end = vblank_start + 2 540 1.11 riastrad * vtotal = vblank_start + 3 541 1.11 riastrad * 542 1.11 riastrad * start of vblank: 543 1.11 riastrad * latch double buffered registers 544 1.11 riastrad * increment frame counter (ctg+) 545 1.11 riastrad * generate start of vblank interrupt (gen4+) 546 1.11 riastrad * | 547 1.11 riastrad * | frame start: 548 1.11 riastrad * | generate frame start interrupt (aka. vblank interrupt) (gmch) 549 1.11 riastrad * | may be shifted forward 1-3 extra lines via PIPECONF 550 1.11 riastrad * | | 551 1.11 riastrad * | | start of vsync: 552 1.11 riastrad * | | generate vsync interrupt 553 1.11 riastrad * | | | 554 1.11 riastrad * ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx___ ___xxxx 555 1.11 riastrad * . \hs/ . \hs/ \hs/ \hs/ . \hs/ 556 1.11 riastrad * ----va---> <-----------------vb--------------------> <--------va------------- 557 1.11 riastrad * | | <----vs-----> | 558 1.11 riastrad * -vbs-----> <---vbs+1---> <---vbs+2---> <-----0-----> <-----1-----> <-----2--- (scanline counter gen2) 559 1.11 riastrad * -vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2---> <-----0--- (scanline counter gen3+) 560 1.11 riastrad * -vbs-2---> <---vbs-2---> <---vbs-1---> <---vbs-----> <---vbs+1---> <---vbs+2- (scanline counter hsw+ hdmi) 561 1.11 riastrad * | | | 562 1.11 riastrad * last visible pixel first visible pixel 563 1.11 riastrad * | increment frame counter (gen3/4) 564 1.11 riastrad * pixel counter = vblank_start * htotal pixel counter = 0 (gen3/4) 565 1.11 riastrad * 566 1.11 riastrad * x = horizontal active 567 1.11 riastrad * _ = horizontal blanking 568 1.11 riastrad * hs = horizontal sync 569 1.11 riastrad * va = vertical active 570 1.11 riastrad * vb = vertical blanking 571 1.11 riastrad * vs = vertical sync 572 1.11 riastrad * vbs = vblank_start (number) 573 1.1 riastrad * 574 1.11 riastrad * Summary: 575 1.11 riastrad * - most events happen at the start of horizontal sync 576 1.11 riastrad * - frame start happens at the start of horizontal blank, 1-4 lines 577 1.11 riastrad * (depending on PIPECONF settings) after the start of vblank 578 1.11 riastrad * - gen3/4 pixel and frame counter are synchronized with the start 579 1.11 riastrad * of horizontal active on the first line of vertical active 580 1.1 riastrad */ 581 1.5 riastrad 582 1.1 riastrad /* Called from drm generic code, passed a 'crtc', which 583 1.1 riastrad * we use as a pipe index 584 1.1 riastrad */ 585 1.20 riastrad u32 i915_get_vblank_counter(struct drm_crtc *crtc) 586 1.1 riastrad { 587 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 588 1.20 riastrad struct drm_vblank_crtc *vblank = &dev_priv->drm.vblank[drm_crtc_index(crtc)]; 589 1.20 riastrad const struct drm_display_mode *mode = &vblank->hwmode; 590 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 591 1.20 riastrad i915_reg_t high_frame, low_frame; 592 1.11 riastrad u32 high1, high2, low, pixel, vbl_start, hsync_start, htotal; 593 1.20 riastrad unsigned long irqflags; 594 1.20 riastrad 595 1.20 riastrad /* 596 1.20 riastrad * On i965gm TV output the frame counter only works up to 597 1.20 riastrad * the point when we enable the TV encoder. After that the 598 1.20 riastrad * frame counter ceases to work and reads zero. We need a 599 1.20 riastrad * vblank wait before enabling the TV encoder and so we 600 1.20 riastrad * have to enable vblank interrupts while the frame counter 601 1.20 riastrad * is still in a working state. However the core vblank code 602 1.20 riastrad * does not like us returning non-zero frame counter values 603 1.20 riastrad * when we've told it that we don't have a working frame 604 1.20 riastrad * counter. Thus we must stop non-zero values leaking out. 605 1.20 riastrad */ 606 1.20 riastrad if (!vblank->max_vblank_count) 607 1.20 riastrad return 0; 608 1.1 riastrad 609 1.11 riastrad htotal = mode->crtc_htotal; 610 1.11 riastrad hsync_start = mode->crtc_hsync_start; 611 1.11 riastrad vbl_start = mode->crtc_vblank_start; 612 1.11 riastrad if (mode->flags & DRM_MODE_FLAG_INTERLACE) 613 1.11 riastrad vbl_start = DIV_ROUND_UP(vbl_start, 2); 614 1.5 riastrad 615 1.11 riastrad /* Convert to pixel count */ 616 1.11 riastrad vbl_start *= htotal; 617 1.5 riastrad 618 1.11 riastrad /* Start of vblank event occurs at start of hsync */ 619 1.11 riastrad vbl_start -= htotal - hsync_start; 620 1.5 riastrad 621 1.1 riastrad high_frame = PIPEFRAME(pipe); 622 1.1 riastrad low_frame = PIPEFRAMEPIXEL(pipe); 623 1.1 riastrad 624 1.20 riastrad spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 625 1.20 riastrad 626 1.1 riastrad /* 627 1.1 riastrad * High & low register fields aren't synchronized, so make sure 628 1.1 riastrad * we get a low value that's stable across two reads of the high 629 1.1 riastrad * register. 630 1.1 riastrad */ 631 1.1 riastrad do { 632 1.20 riastrad high1 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK; 633 1.20 riastrad low = I915_READ_FW(low_frame); 634 1.20 riastrad high2 = I915_READ_FW(high_frame) & PIPE_FRAME_HIGH_MASK; 635 1.1 riastrad } while (high1 != high2); 636 1.1 riastrad 637 1.20 riastrad spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 638 1.20 riastrad 639 1.1 riastrad high1 >>= PIPE_FRAME_HIGH_SHIFT; 640 1.5 riastrad pixel = low & PIPE_PIXEL_MASK; 641 1.1 riastrad low >>= PIPE_FRAME_LOW_SHIFT; 642 1.5 riastrad 643 1.5 riastrad /* 644 1.5 riastrad * The frame counter increments at beginning of active. 645 1.5 riastrad * Cook up a vblank counter by also checking the pixel 646 1.5 riastrad * counter against vblank start. 647 1.5 riastrad */ 648 1.5 riastrad return (((high1 << 8) | low) + (pixel >= vbl_start)) & 0xffffff; 649 1.1 riastrad } 650 1.1 riastrad 651 1.20 riastrad u32 g4x_get_vblank_counter(struct drm_crtc *crtc) 652 1.1 riastrad { 653 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 654 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 655 1.1 riastrad 656 1.11 riastrad return I915_READ(PIPE_FRMCOUNT_G4X(pipe)); 657 1.1 riastrad } 658 1.1 riastrad 659 1.20 riastrad /* 660 1.20 riastrad * On certain encoders on certain platforms, pipe 661 1.20 riastrad * scanline register will not work to get the scanline, 662 1.20 riastrad * since the timings are driven from the PORT or issues 663 1.20 riastrad * with scanline register updates. 664 1.20 riastrad * This function will use Framestamp and current 665 1.20 riastrad * timestamp registers to calculate the scanline. 666 1.20 riastrad */ 667 1.20 riastrad static u32 __intel_get_crtc_scanline_from_timestamp(struct intel_crtc *crtc) 668 1.20 riastrad { 669 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 670 1.20 riastrad struct drm_vblank_crtc *vblank = 671 1.20 riastrad &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)]; 672 1.20 riastrad const struct drm_display_mode *mode = &vblank->hwmode; 673 1.20 riastrad u32 vblank_start = mode->crtc_vblank_start; 674 1.20 riastrad u32 vtotal = mode->crtc_vtotal; 675 1.20 riastrad u32 htotal = mode->crtc_htotal; 676 1.20 riastrad u32 clock = mode->crtc_clock; 677 1.20 riastrad u32 scanline, scan_prev_time, scan_curr_time, scan_post_time; 678 1.20 riastrad 679 1.20 riastrad /* 680 1.20 riastrad * To avoid the race condition where we might cross into the 681 1.20 riastrad * next vblank just between the PIPE_FRMTMSTMP and TIMESTAMP_CTR 682 1.20 riastrad * reads. We make sure we read PIPE_FRMTMSTMP and TIMESTAMP_CTR 683 1.20 riastrad * during the same frame. 684 1.20 riastrad */ 685 1.20 riastrad do { 686 1.20 riastrad /* 687 1.20 riastrad * This field provides read back of the display 688 1.20 riastrad * pipe frame time stamp. The time stamp value 689 1.20 riastrad * is sampled at every start of vertical blank. 690 1.20 riastrad */ 691 1.20 riastrad scan_prev_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe)); 692 1.20 riastrad 693 1.20 riastrad /* 694 1.20 riastrad * The TIMESTAMP_CTR register has the current 695 1.20 riastrad * time stamp value. 696 1.20 riastrad */ 697 1.20 riastrad scan_curr_time = I915_READ_FW(IVB_TIMESTAMP_CTR); 698 1.20 riastrad 699 1.20 riastrad scan_post_time = I915_READ_FW(PIPE_FRMTMSTMP(crtc->pipe)); 700 1.20 riastrad } while (scan_post_time != scan_prev_time); 701 1.20 riastrad 702 1.20 riastrad scanline = div_u64(mul_u32_u32(scan_curr_time - scan_prev_time, 703 1.20 riastrad clock), 1000 * htotal); 704 1.20 riastrad scanline = min(scanline, vtotal - 1); 705 1.20 riastrad scanline = (scanline + vblank_start) % vtotal; 706 1.20 riastrad 707 1.20 riastrad return scanline; 708 1.20 riastrad } 709 1.5 riastrad 710 1.20 riastrad /* I915_READ_FW, only for fast reads of display block, no need for forcewake etc. */ 711 1.11 riastrad static int __intel_get_crtc_scanline(struct intel_crtc *crtc) 712 1.5 riastrad { 713 1.11 riastrad struct drm_device *dev = crtc->base.dev; 714 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 715 1.20 riastrad const struct drm_display_mode *mode; 716 1.20 riastrad struct drm_vblank_crtc *vblank; 717 1.18 riastrad enum pipe pipe = crtc->pipe; 718 1.11 riastrad int position, vtotal; 719 1.11 riastrad 720 1.20 riastrad if (!crtc->active) 721 1.20 riastrad return -1; 722 1.20 riastrad 723 1.20 riastrad vblank = &crtc->base.dev->vblank[drm_crtc_index(&crtc->base)]; 724 1.20 riastrad mode = &vblank->hwmode; 725 1.20 riastrad 726 1.20 riastrad if (mode->private_flags & I915_MODE_FLAG_GET_SCANLINE_FROM_TIMESTAMP) 727 1.20 riastrad return __intel_get_crtc_scanline_from_timestamp(crtc); 728 1.20 riastrad 729 1.11 riastrad vtotal = mode->crtc_vtotal; 730 1.11 riastrad if (mode->flags & DRM_MODE_FLAG_INTERLACE) 731 1.11 riastrad vtotal /= 2; 732 1.11 riastrad 733 1.20 riastrad if (IS_GEN(dev_priv, 2)) 734 1.20 riastrad position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN2; 735 1.11 riastrad else 736 1.20 riastrad position = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 737 1.11 riastrad 738 1.11 riastrad /* 739 1.11 riastrad * On HSW, the DSL reg (0x70000) appears to return 0 if we 740 1.11 riastrad * read it just before the start of vblank. So try it again 741 1.11 riastrad * so we don't accidentally end up spanning a vblank frame 742 1.11 riastrad * increment, causing the pipe_update_end() code to squak at us. 743 1.11 riastrad * 744 1.11 riastrad * The nature of this problem means we can't simply check the ISR 745 1.11 riastrad * bit and return the vblank start value; nor can we use the scanline 746 1.11 riastrad * debug register in the transcoder as it appears to have the same 747 1.11 riastrad * problem. We may need to extend this to include other platforms, 748 1.11 riastrad * but so far testing only shows the problem on HSW. 749 1.11 riastrad */ 750 1.20 riastrad if (HAS_DDI(dev_priv) && !position) { 751 1.11 riastrad int i, temp; 752 1.5 riastrad 753 1.11 riastrad for (i = 0; i < 100; i++) { 754 1.11 riastrad udelay(1); 755 1.20 riastrad temp = I915_READ_FW(PIPEDSL(pipe)) & DSL_LINEMASK_GEN3; 756 1.11 riastrad if (temp != position) { 757 1.11 riastrad position = temp; 758 1.11 riastrad break; 759 1.11 riastrad } 760 1.11 riastrad } 761 1.5 riastrad } 762 1.5 riastrad 763 1.11 riastrad /* 764 1.11 riastrad * See update_scanline_offset() for the details on the 765 1.11 riastrad * scanline_offset adjustment. 766 1.11 riastrad */ 767 1.11 riastrad return (position + crtc->scanline_offset) % vtotal; 768 1.5 riastrad } 769 1.5 riastrad 770 1.20 riastrad bool i915_get_crtc_scanoutpos(struct drm_device *dev, unsigned int index, 771 1.20 riastrad bool in_vblank_irq, int *vpos, int *hpos, 772 1.20 riastrad ktime_t *stime, ktime_t *etime, 773 1.20 riastrad const struct drm_display_mode *mode) 774 1.1 riastrad { 775 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(dev); 776 1.20 riastrad struct intel_crtc *crtc = to_intel_crtc(drm_crtc_from_index(dev, index)); 777 1.20 riastrad enum pipe pipe = crtc->pipe; 778 1.5 riastrad int position; 779 1.11 riastrad int vbl_start, vbl_end, hsync_start, htotal, vtotal; 780 1.5 riastrad unsigned long irqflags; 781 1.20 riastrad bool use_scanline_counter = INTEL_GEN(dev_priv) >= 5 || 782 1.20 riastrad IS_G4X(dev_priv) || IS_GEN(dev_priv, 2) || 783 1.20 riastrad mode->private_flags & I915_MODE_FLAG_USE_SCANLINE_COUNTER; 784 1.1 riastrad 785 1.11 riastrad if (WARN_ON(!mode->crtc_clock)) { 786 1.1 riastrad DRM_DEBUG_DRIVER("trying to get scanoutpos for disabled " 787 1.1 riastrad "pipe %c\n", pipe_name(pipe)); 788 1.20 riastrad return false; 789 1.1 riastrad } 790 1.1 riastrad 791 1.5 riastrad htotal = mode->crtc_htotal; 792 1.11 riastrad hsync_start = mode->crtc_hsync_start; 793 1.5 riastrad vtotal = mode->crtc_vtotal; 794 1.5 riastrad vbl_start = mode->crtc_vblank_start; 795 1.5 riastrad vbl_end = mode->crtc_vblank_end; 796 1.5 riastrad 797 1.5 riastrad if (mode->flags & DRM_MODE_FLAG_INTERLACE) { 798 1.5 riastrad vbl_start = DIV_ROUND_UP(vbl_start, 2); 799 1.5 riastrad vbl_end /= 2; 800 1.5 riastrad vtotal /= 2; 801 1.5 riastrad } 802 1.5 riastrad 803 1.5 riastrad /* 804 1.5 riastrad * Lock uncore.lock, as we will do multiple timing critical raw 805 1.5 riastrad * register reads, potentially with preemption disabled, so the 806 1.5 riastrad * following code must not block on uncore.lock. 807 1.5 riastrad */ 808 1.5 riastrad spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 809 1.11 riastrad 810 1.5 riastrad /* preempt_disable_rt() should go right here in PREEMPT_RT patchset. */ 811 1.5 riastrad 812 1.5 riastrad /* Get optional system timestamp before query. */ 813 1.5 riastrad if (stime) 814 1.5 riastrad *stime = ktime_get(); 815 1.5 riastrad 816 1.20 riastrad if (use_scanline_counter) { 817 1.1 riastrad /* No obvious pixelcount register. Only query vertical 818 1.1 riastrad * scanout position from Display scan line register. 819 1.1 riastrad */ 820 1.20 riastrad position = __intel_get_crtc_scanline(crtc); 821 1.1 riastrad } else { 822 1.1 riastrad /* Have access to pixelcount since start of frame. 823 1.1 riastrad * We can split this into vertical and horizontal 824 1.1 riastrad * scanout position. 825 1.1 riastrad */ 826 1.20 riastrad position = (I915_READ_FW(PIPEFRAMEPIXEL(pipe)) & PIPE_PIXEL_MASK) >> PIPE_PIXEL_SHIFT; 827 1.5 riastrad 828 1.5 riastrad /* convert to pixel counts */ 829 1.5 riastrad vbl_start *= htotal; 830 1.5 riastrad vbl_end *= htotal; 831 1.5 riastrad vtotal *= htotal; 832 1.11 riastrad 833 1.11 riastrad /* 834 1.11 riastrad * In interlaced modes, the pixel counter counts all pixels, 835 1.11 riastrad * so one field will have htotal more pixels. In order to avoid 836 1.11 riastrad * the reported position from jumping backwards when the pixel 837 1.11 riastrad * counter is beyond the length of the shorter field, just 838 1.11 riastrad * clamp the position the length of the shorter field. This 839 1.11 riastrad * matches how the scanline counter based position works since 840 1.11 riastrad * the scanline counter doesn't count the two half lines. 841 1.11 riastrad */ 842 1.11 riastrad if (position >= vtotal) 843 1.11 riastrad position = vtotal - 1; 844 1.11 riastrad 845 1.11 riastrad /* 846 1.11 riastrad * Start of vblank interrupt is triggered at start of hsync, 847 1.11 riastrad * just prior to the first active line of vblank. However we 848 1.11 riastrad * consider lines to start at the leading edge of horizontal 849 1.11 riastrad * active. So, should we get here before we've crossed into 850 1.11 riastrad * the horizontal active of the first line in vblank, we would 851 1.11 riastrad * not set the DRM_SCANOUTPOS_INVBL flag. In order to fix that, 852 1.11 riastrad * always add htotal-hsync_start to the current pixel position. 853 1.11 riastrad */ 854 1.11 riastrad position = (position + htotal - hsync_start) % vtotal; 855 1.5 riastrad } 856 1.5 riastrad 857 1.5 riastrad /* Get optional system timestamp after query. */ 858 1.5 riastrad if (etime) 859 1.5 riastrad *etime = ktime_get(); 860 1.5 riastrad 861 1.5 riastrad /* preempt_enable_rt() should go right here in PREEMPT_RT patchset. */ 862 1.1 riastrad 863 1.5 riastrad spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 864 1.5 riastrad 865 1.5 riastrad /* 866 1.5 riastrad * While in vblank, position will be negative 867 1.5 riastrad * counting up towards 0 at vbl_end. And outside 868 1.5 riastrad * vblank, position will be positive counting 869 1.5 riastrad * up since vbl_end. 870 1.5 riastrad */ 871 1.5 riastrad if (position >= vbl_start) 872 1.5 riastrad position -= vbl_end; 873 1.5 riastrad else 874 1.5 riastrad position += vtotal - vbl_end; 875 1.5 riastrad 876 1.20 riastrad if (use_scanline_counter) { 877 1.5 riastrad *vpos = position; 878 1.5 riastrad *hpos = 0; 879 1.5 riastrad } else { 880 1.1 riastrad *vpos = position / htotal; 881 1.1 riastrad *hpos = position - (*vpos * htotal); 882 1.1 riastrad } 883 1.1 riastrad 884 1.20 riastrad return true; 885 1.1 riastrad } 886 1.1 riastrad 887 1.11 riastrad int intel_get_crtc_scanline(struct intel_crtc *crtc) 888 1.1 riastrad { 889 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->base.dev); 890 1.11 riastrad unsigned long irqflags; 891 1.11 riastrad int position; 892 1.1 riastrad 893 1.11 riastrad spin_lock_irqsave(&dev_priv->uncore.lock, irqflags); 894 1.11 riastrad position = __intel_get_crtc_scanline(crtc); 895 1.11 riastrad spin_unlock_irqrestore(&dev_priv->uncore.lock, irqflags); 896 1.1 riastrad 897 1.11 riastrad return position; 898 1.5 riastrad } 899 1.5 riastrad 900 1.20 riastrad /** 901 1.20 riastrad * ivb_parity_work - Workqueue called when a parity error interrupt 902 1.20 riastrad * occurred. 903 1.20 riastrad * @work: workqueue struct 904 1.20 riastrad * 905 1.20 riastrad * Doesn't actually do anything except notify userspace. As a consequence of 906 1.20 riastrad * this event, userspace should try to remap the bad rows since statistically 907 1.1 riastrad * it is likely the same row is more likely to go bad again. 908 1.1 riastrad */ 909 1.20 riastrad static void ivb_parity_work(struct work_struct *work) 910 1.1 riastrad { 911 1.5 riastrad struct drm_i915_private *dev_priv = 912 1.20 riastrad container_of(work, typeof(*dev_priv), l3_parity.error_work); 913 1.20 riastrad struct intel_gt *gt = &dev_priv->gt; 914 1.1 riastrad u32 error_status, row, bank, subbank; 915 1.2 riastrad #ifndef __NetBSD__ /* XXX kobject uevent...? */ 916 1.5 riastrad char *parity_event[6]; 917 1.2 riastrad #endif 918 1.20 riastrad u32 misccpctl; 919 1.20 riastrad u8 slice = 0; 920 1.1 riastrad 921 1.1 riastrad /* We must turn off DOP level clock gating to access the L3 registers. 922 1.1 riastrad * In order to prevent a get/put style interface, acquire struct mutex 923 1.1 riastrad * any time we access those registers. 924 1.1 riastrad */ 925 1.20 riastrad mutex_lock(&dev_priv->drm.struct_mutex); 926 1.1 riastrad 927 1.5 riastrad /* If we've screwed up tracking, just let the interrupt fire again */ 928 1.5 riastrad if (WARN_ON(!dev_priv->l3_parity.which_slice)) 929 1.5 riastrad goto out; 930 1.5 riastrad 931 1.1 riastrad misccpctl = I915_READ(GEN7_MISCCPCTL); 932 1.1 riastrad I915_WRITE(GEN7_MISCCPCTL, misccpctl & ~GEN7_DOP_CLOCK_GATE_ENABLE); 933 1.1 riastrad POSTING_READ(GEN7_MISCCPCTL); 934 1.1 riastrad 935 1.5 riastrad while ((slice = ffs(dev_priv->l3_parity.which_slice)) != 0) { 936 1.20 riastrad i915_reg_t reg; 937 1.1 riastrad 938 1.5 riastrad slice--; 939 1.20 riastrad if (WARN_ON_ONCE(slice >= NUM_L3_SLICES(dev_priv))) 940 1.5 riastrad break; 941 1.5 riastrad 942 1.5 riastrad dev_priv->l3_parity.which_slice &= ~(1<<slice); 943 1.5 riastrad 944 1.20 riastrad reg = GEN7_L3CDERRST1(slice); 945 1.1 riastrad 946 1.5 riastrad error_status = I915_READ(reg); 947 1.5 riastrad row = GEN7_PARITY_ERROR_ROW(error_status); 948 1.5 riastrad bank = GEN7_PARITY_ERROR_BANK(error_status); 949 1.5 riastrad subbank = GEN7_PARITY_ERROR_SUBBANK(error_status); 950 1.1 riastrad 951 1.5 riastrad I915_WRITE(reg, GEN7_PARITY_ERROR_VALID | GEN7_L3CDERRST1_ENABLE); 952 1.5 riastrad POSTING_READ(reg); 953 1.1 riastrad 954 1.2 riastrad #ifndef __NetBSD__ /* XXX kobject uevent...? */ 955 1.5 riastrad parity_event[0] = I915_L3_PARITY_UEVENT "=1"; 956 1.5 riastrad parity_event[1] = kasprintf(GFP_KERNEL, "ROW=%d", row); 957 1.5 riastrad parity_event[2] = kasprintf(GFP_KERNEL, "BANK=%d", bank); 958 1.5 riastrad parity_event[3] = kasprintf(GFP_KERNEL, "SUBBANK=%d", subbank); 959 1.5 riastrad parity_event[4] = kasprintf(GFP_KERNEL, "SLICE=%d", slice); 960 1.5 riastrad parity_event[5] = NULL; 961 1.1 riastrad 962 1.20 riastrad kobject_uevent_env(&dev_priv->drm.primary->kdev->kobj, 963 1.5 riastrad KOBJ_CHANGE, parity_event); 964 1.3 riastrad #endif 965 1.1 riastrad 966 1.5 riastrad DRM_DEBUG("Parity error: Slice = %d, Row = %d, Bank = %d, Sub bank = %d.\n", 967 1.5 riastrad slice, row, bank, subbank); 968 1.1 riastrad 969 1.3 riastrad #ifndef __NetBSD__ /* XXX kobject uevent...? */ 970 1.5 riastrad kfree(parity_event[4]); 971 1.5 riastrad kfree(parity_event[3]); 972 1.5 riastrad kfree(parity_event[2]); 973 1.5 riastrad kfree(parity_event[1]); 974 1.2 riastrad #endif 975 1.5 riastrad } 976 1.5 riastrad 977 1.5 riastrad I915_WRITE(GEN7_MISCCPCTL, misccpctl); 978 1.5 riastrad 979 1.5 riastrad out: 980 1.5 riastrad WARN_ON(dev_priv->l3_parity.which_slice); 981 1.20 riastrad spin_lock_irq(>->irq_lock); 982 1.20 riastrad gen5_gt_enable_irq(gt, GT_PARITY_ERROR(dev_priv)); 983 1.20 riastrad spin_unlock_irq(>->irq_lock); 984 1.20 riastrad 985 1.20 riastrad mutex_unlock(&dev_priv->drm.struct_mutex); 986 1.20 riastrad } 987 1.20 riastrad 988 1.20 riastrad static bool gen11_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 989 1.20 riastrad { 990 1.20 riastrad switch (pin) { 991 1.20 riastrad case HPD_PORT_C: 992 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1); 993 1.20 riastrad case HPD_PORT_D: 994 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2); 995 1.20 riastrad case HPD_PORT_E: 996 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3); 997 1.20 riastrad case HPD_PORT_F: 998 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4); 999 1.20 riastrad default: 1000 1.20 riastrad return false; 1001 1.20 riastrad } 1002 1.1 riastrad } 1003 1.1 riastrad 1004 1.20 riastrad static bool gen12_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1005 1.1 riastrad { 1006 1.20 riastrad switch (pin) { 1007 1.20 riastrad case HPD_PORT_D: 1008 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC1); 1009 1.20 riastrad case HPD_PORT_E: 1010 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC2); 1011 1.20 riastrad case HPD_PORT_F: 1012 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC3); 1013 1.20 riastrad case HPD_PORT_G: 1014 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC4); 1015 1.20 riastrad case HPD_PORT_H: 1016 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC5); 1017 1.20 riastrad case HPD_PORT_I: 1018 1.20 riastrad return val & GEN11_HOTPLUG_CTL_LONG_DETECT(PORT_TC6); 1019 1.20 riastrad default: 1020 1.20 riastrad return false; 1021 1.20 riastrad } 1022 1.1 riastrad } 1023 1.1 riastrad 1024 1.20 riastrad static bool bxt_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1025 1.5 riastrad { 1026 1.20 riastrad switch (pin) { 1027 1.20 riastrad case HPD_PORT_A: 1028 1.20 riastrad return val & PORTA_HOTPLUG_LONG_DETECT; 1029 1.20 riastrad case HPD_PORT_B: 1030 1.20 riastrad return val & PORTB_HOTPLUG_LONG_DETECT; 1031 1.20 riastrad case HPD_PORT_C: 1032 1.20 riastrad return val & PORTC_HOTPLUG_LONG_DETECT; 1033 1.20 riastrad default: 1034 1.20 riastrad return false; 1035 1.20 riastrad } 1036 1.5 riastrad } 1037 1.5 riastrad 1038 1.20 riastrad static bool icp_ddi_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1039 1.1 riastrad { 1040 1.20 riastrad switch (pin) { 1041 1.20 riastrad case HPD_PORT_A: 1042 1.20 riastrad return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(PORT_A); 1043 1.20 riastrad case HPD_PORT_B: 1044 1.20 riastrad return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(PORT_B); 1045 1.20 riastrad case HPD_PORT_C: 1046 1.20 riastrad return val & SHOTPLUG_CTL_DDI_HPD_LONG_DETECT(PORT_C); 1047 1.20 riastrad default: 1048 1.20 riastrad return false; 1049 1.20 riastrad } 1050 1.1 riastrad } 1051 1.1 riastrad 1052 1.20 riastrad static bool icp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1053 1.1 riastrad { 1054 1.20 riastrad switch (pin) { 1055 1.20 riastrad case HPD_PORT_C: 1056 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1); 1057 1.20 riastrad case HPD_PORT_D: 1058 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2); 1059 1.20 riastrad case HPD_PORT_E: 1060 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3); 1061 1.20 riastrad case HPD_PORT_F: 1062 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4); 1063 1.20 riastrad default: 1064 1.20 riastrad return false; 1065 1.5 riastrad } 1066 1.5 riastrad } 1067 1.1 riastrad 1068 1.20 riastrad static bool tgp_tc_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1069 1.11 riastrad { 1070 1.20 riastrad switch (pin) { 1071 1.20 riastrad case HPD_PORT_D: 1072 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC1); 1073 1.20 riastrad case HPD_PORT_E: 1074 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC2); 1075 1.20 riastrad case HPD_PORT_F: 1076 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC3); 1077 1.20 riastrad case HPD_PORT_G: 1078 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC4); 1079 1.20 riastrad case HPD_PORT_H: 1080 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC5); 1081 1.20 riastrad case HPD_PORT_I: 1082 1.20 riastrad return val & ICP_TC_HPD_LONG_DETECT(PORT_TC6); 1083 1.11 riastrad default: 1084 1.11 riastrad return false; 1085 1.11 riastrad } 1086 1.11 riastrad } 1087 1.11 riastrad 1088 1.20 riastrad static bool spt_port_hotplug2_long_detect(enum hpd_pin pin, u32 val) 1089 1.11 riastrad { 1090 1.20 riastrad switch (pin) { 1091 1.20 riastrad case HPD_PORT_E: 1092 1.11 riastrad return val & PORTE_HOTPLUG_LONG_DETECT; 1093 1.11 riastrad default: 1094 1.11 riastrad return false; 1095 1.11 riastrad } 1096 1.11 riastrad } 1097 1.1 riastrad 1098 1.20 riastrad static bool spt_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1099 1.1 riastrad { 1100 1.20 riastrad switch (pin) { 1101 1.20 riastrad case HPD_PORT_A: 1102 1.11 riastrad return val & PORTA_HOTPLUG_LONG_DETECT; 1103 1.20 riastrad case HPD_PORT_B: 1104 1.11 riastrad return val & PORTB_HOTPLUG_LONG_DETECT; 1105 1.20 riastrad case HPD_PORT_C: 1106 1.11 riastrad return val & PORTC_HOTPLUG_LONG_DETECT; 1107 1.20 riastrad case HPD_PORT_D: 1108 1.11 riastrad return val & PORTD_HOTPLUG_LONG_DETECT; 1109 1.11 riastrad default: 1110 1.11 riastrad return false; 1111 1.11 riastrad } 1112 1.11 riastrad } 1113 1.1 riastrad 1114 1.20 riastrad static bool ilk_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1115 1.11 riastrad { 1116 1.20 riastrad switch (pin) { 1117 1.20 riastrad case HPD_PORT_A: 1118 1.11 riastrad return val & DIGITAL_PORTA_HOTPLUG_LONG_DETECT; 1119 1.11 riastrad default: 1120 1.11 riastrad return false; 1121 1.11 riastrad } 1122 1.11 riastrad } 1123 1.1 riastrad 1124 1.20 riastrad static bool pch_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1125 1.11 riastrad { 1126 1.20 riastrad switch (pin) { 1127 1.20 riastrad case HPD_PORT_B: 1128 1.11 riastrad return val & PORTB_HOTPLUG_LONG_DETECT; 1129 1.20 riastrad case HPD_PORT_C: 1130 1.11 riastrad return val & PORTC_HOTPLUG_LONG_DETECT; 1131 1.20 riastrad case HPD_PORT_D: 1132 1.11 riastrad return val & PORTD_HOTPLUG_LONG_DETECT; 1133 1.11 riastrad default: 1134 1.11 riastrad return false; 1135 1.11 riastrad } 1136 1.11 riastrad } 1137 1.1 riastrad 1138 1.20 riastrad static bool i9xx_port_hotplug_long_detect(enum hpd_pin pin, u32 val) 1139 1.11 riastrad { 1140 1.20 riastrad switch (pin) { 1141 1.20 riastrad case HPD_PORT_B: 1142 1.11 riastrad return val & PORTB_HOTPLUG_INT_LONG_PULSE; 1143 1.20 riastrad case HPD_PORT_C: 1144 1.11 riastrad return val & PORTC_HOTPLUG_INT_LONG_PULSE; 1145 1.20 riastrad case HPD_PORT_D: 1146 1.11 riastrad return val & PORTD_HOTPLUG_INT_LONG_PULSE; 1147 1.11 riastrad default: 1148 1.11 riastrad return false; 1149 1.11 riastrad } 1150 1.11 riastrad } 1151 1.1 riastrad 1152 1.11 riastrad /* 1153 1.11 riastrad * Get a bit mask of pins that have triggered, and which ones may be long. 1154 1.11 riastrad * This can be called multiple times with the same masks to accumulate 1155 1.11 riastrad * hotplug detection results from several registers. 1156 1.11 riastrad * 1157 1.11 riastrad * Note that the caller is expected to zero out the masks initially. 1158 1.11 riastrad */ 1159 1.20 riastrad static void intel_get_hpd_pins(struct drm_i915_private *dev_priv, 1160 1.20 riastrad u32 *pin_mask, u32 *long_mask, 1161 1.20 riastrad u32 hotplug_trigger, u32 dig_hotplug_reg, 1162 1.20 riastrad const u32 hpd[HPD_NUM_PINS], 1163 1.20 riastrad bool long_pulse_detect(enum hpd_pin pin, u32 val)) 1164 1.11 riastrad { 1165 1.20 riastrad enum hpd_pin pin; 1166 1.20 riastrad 1167 1.20 riastrad BUILD_BUG_ON(BITS_PER_TYPE(*pin_mask) < HPD_NUM_PINS); 1168 1.5 riastrad 1169 1.20 riastrad for_each_hpd_pin(pin) { 1170 1.20 riastrad if ((hpd[pin] & hotplug_trigger) == 0) 1171 1.5 riastrad continue; 1172 1.1 riastrad 1173 1.20 riastrad *pin_mask |= BIT(pin); 1174 1.1 riastrad 1175 1.20 riastrad if (long_pulse_detect(pin, dig_hotplug_reg)) 1176 1.20 riastrad *long_mask |= BIT(pin); 1177 1.5 riastrad } 1178 1.5 riastrad 1179 1.20 riastrad DRM_DEBUG_DRIVER("hotplug event received, stat 0x%08x, dig 0x%08x, pins 0x%08x, long 0x%08x\n", 1180 1.20 riastrad hotplug_trigger, dig_hotplug_reg, *pin_mask, *long_mask); 1181 1.1 riastrad 1182 1.5 riastrad } 1183 1.5 riastrad 1184 1.20 riastrad static void gmbus_irq_handler(struct drm_i915_private *dev_priv) 1185 1.5 riastrad { 1186 1.5 riastrad 1187 1.6 riastrad spin_lock(&dev_priv->gmbus_wait_lock); 1188 1.6 riastrad DRM_SPIN_WAKEUP_ALL(&dev_priv->gmbus_wait_queue, 1189 1.6 riastrad &dev_priv->gmbus_wait_lock); 1190 1.6 riastrad spin_unlock(&dev_priv->gmbus_wait_lock); 1191 1.5 riastrad } 1192 1.1 riastrad 1193 1.20 riastrad static void dp_aux_irq_handler(struct drm_i915_private *dev_priv) 1194 1.5 riastrad { 1195 1.1 riastrad 1196 1.6 riastrad spin_lock(&dev_priv->gmbus_wait_lock); 1197 1.6 riastrad DRM_SPIN_WAKEUP_ALL(&dev_priv->gmbus_wait_queue, 1198 1.6 riastrad &dev_priv->gmbus_wait_lock); 1199 1.6 riastrad spin_unlock(&dev_priv->gmbus_wait_lock); 1200 1.5 riastrad } 1201 1.1 riastrad 1202 1.5 riastrad #if defined(CONFIG_DEBUG_FS) 1203 1.20 riastrad static void display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 1204 1.20 riastrad enum pipe pipe, 1205 1.20 riastrad u32 crc0, u32 crc1, 1206 1.20 riastrad u32 crc2, u32 crc3, 1207 1.20 riastrad u32 crc4) 1208 1.5 riastrad { 1209 1.5 riastrad struct intel_pipe_crc *pipe_crc = &dev_priv->pipe_crc[pipe]; 1210 1.20 riastrad struct intel_crtc *crtc = intel_get_crtc_for_pipe(dev_priv, pipe); 1211 1.20 riastrad u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 }; 1212 1.20 riastrad 1213 1.20 riastrad trace_intel_pipe_crc(crtc, crcs); 1214 1.5 riastrad 1215 1.5 riastrad spin_lock(&pipe_crc->lock); 1216 1.20 riastrad /* 1217 1.20 riastrad * For some not yet identified reason, the first CRC is 1218 1.20 riastrad * bonkers. So let's just wait for the next vblank and read 1219 1.20 riastrad * out the buggy result. 1220 1.20 riastrad * 1221 1.20 riastrad * On GEN8+ sometimes the second CRC is bonkers as well, so 1222 1.20 riastrad * don't trust that one either. 1223 1.20 riastrad */ 1224 1.20 riastrad if (pipe_crc->skipped <= 0 || 1225 1.20 riastrad (INTEL_GEN(dev_priv) >= 8 && pipe_crc->skipped == 1)) { 1226 1.20 riastrad pipe_crc->skipped++; 1227 1.5 riastrad spin_unlock(&pipe_crc->lock); 1228 1.5 riastrad return; 1229 1.1 riastrad } 1230 1.5 riastrad spin_unlock(&pipe_crc->lock); 1231 1.5 riastrad 1232 1.20 riastrad drm_crtc_add_crc_entry(&crtc->base, true, 1233 1.20 riastrad drm_crtc_accurate_vblank_count(&crtc->base), 1234 1.20 riastrad crcs); 1235 1.1 riastrad } 1236 1.5 riastrad #else 1237 1.5 riastrad static inline void 1238 1.20 riastrad display_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 1239 1.20 riastrad enum pipe pipe, 1240 1.20 riastrad u32 crc0, u32 crc1, 1241 1.20 riastrad u32 crc2, u32 crc3, 1242 1.20 riastrad u32 crc4) {} 1243 1.5 riastrad #endif 1244 1.1 riastrad 1245 1.5 riastrad 1246 1.20 riastrad static void hsw_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 1247 1.20 riastrad enum pipe pipe) 1248 1.1 riastrad { 1249 1.20 riastrad display_pipe_crc_irq_handler(dev_priv, pipe, 1250 1.5 riastrad I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1251 1.5 riastrad 0, 0, 0, 0); 1252 1.5 riastrad } 1253 1.1 riastrad 1254 1.20 riastrad static void ivb_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 1255 1.20 riastrad enum pipe pipe) 1256 1.5 riastrad { 1257 1.20 riastrad display_pipe_crc_irq_handler(dev_priv, pipe, 1258 1.5 riastrad I915_READ(PIPE_CRC_RES_1_IVB(pipe)), 1259 1.5 riastrad I915_READ(PIPE_CRC_RES_2_IVB(pipe)), 1260 1.5 riastrad I915_READ(PIPE_CRC_RES_3_IVB(pipe)), 1261 1.5 riastrad I915_READ(PIPE_CRC_RES_4_IVB(pipe)), 1262 1.5 riastrad I915_READ(PIPE_CRC_RES_5_IVB(pipe))); 1263 1.5 riastrad } 1264 1.1 riastrad 1265 1.20 riastrad static void i9xx_pipe_crc_irq_handler(struct drm_i915_private *dev_priv, 1266 1.20 riastrad enum pipe pipe) 1267 1.5 riastrad { 1268 1.20 riastrad u32 res1, res2; 1269 1.1 riastrad 1270 1.20 riastrad if (INTEL_GEN(dev_priv) >= 3) 1271 1.5 riastrad res1 = I915_READ(PIPE_CRC_RES_RES1_I915(pipe)); 1272 1.5 riastrad else 1273 1.5 riastrad res1 = 0; 1274 1.1 riastrad 1275 1.20 riastrad if (INTEL_GEN(dev_priv) >= 5 || IS_G4X(dev_priv)) 1276 1.5 riastrad res2 = I915_READ(PIPE_CRC_RES_RES2_G4X(pipe)); 1277 1.5 riastrad else 1278 1.5 riastrad res2 = 0; 1279 1.1 riastrad 1280 1.20 riastrad display_pipe_crc_irq_handler(dev_priv, pipe, 1281 1.5 riastrad I915_READ(PIPE_CRC_RES_RED(pipe)), 1282 1.5 riastrad I915_READ(PIPE_CRC_RES_GREEN(pipe)), 1283 1.5 riastrad I915_READ(PIPE_CRC_RES_BLUE(pipe)), 1284 1.5 riastrad res1, res2); 1285 1.5 riastrad } 1286 1.1 riastrad 1287 1.20 riastrad static void i9xx_pipestat_irq_reset(struct drm_i915_private *dev_priv) 1288 1.20 riastrad { 1289 1.20 riastrad enum pipe pipe; 1290 1.1 riastrad 1291 1.20 riastrad for_each_pipe(dev_priv, pipe) { 1292 1.20 riastrad I915_WRITE(PIPESTAT(pipe), 1293 1.20 riastrad PIPESTAT_INT_STATUS_MASK | 1294 1.20 riastrad PIPE_FIFO_UNDERRUN_STATUS); 1295 1.1 riastrad 1296 1.20 riastrad dev_priv->pipestat_irq_mask[pipe] = 0; 1297 1.5 riastrad } 1298 1.1 riastrad } 1299 1.1 riastrad 1300 1.20 riastrad static void i9xx_pipestat_irq_ack(struct drm_i915_private *dev_priv, 1301 1.20 riastrad u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1302 1.11 riastrad { 1303 1.20 riastrad enum pipe pipe; 1304 1.11 riastrad 1305 1.20 riastrad spin_lock(&dev_priv->irq_lock); 1306 1.11 riastrad 1307 1.20 riastrad if (!dev_priv->display_irqs_enabled) { 1308 1.20 riastrad spin_unlock(&dev_priv->irq_lock); 1309 1.20 riastrad return; 1310 1.20 riastrad } 1311 1.1 riastrad 1312 1.11 riastrad for_each_pipe(dev_priv, pipe) { 1313 1.20 riastrad i915_reg_t reg; 1314 1.20 riastrad u32 status_mask, enable_mask, iir_bit = 0; 1315 1.5 riastrad 1316 1.5 riastrad /* 1317 1.5 riastrad * PIPESTAT bits get signalled even when the interrupt is 1318 1.5 riastrad * disabled with the mask bits, and some of the status bits do 1319 1.5 riastrad * not generate interrupts at all (like the underrun bit). Hence 1320 1.5 riastrad * we need to be careful that we only handle what we want to 1321 1.5 riastrad * handle. 1322 1.5 riastrad */ 1323 1.11 riastrad 1324 1.11 riastrad /* fifo underruns are filterered in the underrun handler. */ 1325 1.20 riastrad status_mask = PIPE_FIFO_UNDERRUN_STATUS; 1326 1.5 riastrad 1327 1.5 riastrad switch (pipe) { 1328 1.20 riastrad default: 1329 1.5 riastrad case PIPE_A: 1330 1.5 riastrad iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 1331 1.5 riastrad break; 1332 1.5 riastrad case PIPE_B: 1333 1.5 riastrad iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 1334 1.5 riastrad break; 1335 1.11 riastrad case PIPE_C: 1336 1.11 riastrad iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 1337 1.11 riastrad break; 1338 1.5 riastrad } 1339 1.5 riastrad if (iir & iir_bit) 1340 1.20 riastrad status_mask |= dev_priv->pipestat_irq_mask[pipe]; 1341 1.5 riastrad 1342 1.20 riastrad if (!status_mask) 1343 1.5 riastrad continue; 1344 1.5 riastrad 1345 1.5 riastrad reg = PIPESTAT(pipe); 1346 1.20 riastrad pipe_stats[pipe] = I915_READ(reg) & status_mask; 1347 1.20 riastrad enable_mask = i915_pipestat_enable_mask(dev_priv, pipe); 1348 1.1 riastrad 1349 1.5 riastrad /* 1350 1.5 riastrad * Clear the PIPE*STAT regs before the IIR 1351 1.20 riastrad * 1352 1.20 riastrad * Toggle the enable bits to make sure we get an 1353 1.20 riastrad * edge in the ISR pipe event bit if we don't clear 1354 1.20 riastrad * all the enabled status bits. Otherwise the edge 1355 1.20 riastrad * triggered IIR on i965/g4x wouldn't notice that 1356 1.20 riastrad * an interrupt is still pending. 1357 1.5 riastrad */ 1358 1.20 riastrad if (pipe_stats[pipe]) { 1359 1.5 riastrad I915_WRITE(reg, pipe_stats[pipe]); 1360 1.20 riastrad I915_WRITE(reg, enable_mask); 1361 1.20 riastrad } 1362 1.5 riastrad } 1363 1.5 riastrad spin_unlock(&dev_priv->irq_lock); 1364 1.20 riastrad } 1365 1.20 riastrad 1366 1.20 riastrad static void i8xx_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1367 1.20 riastrad u16 iir, u32 pipe_stats[I915_MAX_PIPES]) 1368 1.20 riastrad { 1369 1.20 riastrad enum pipe pipe; 1370 1.20 riastrad 1371 1.20 riastrad for_each_pipe(dev_priv, pipe) { 1372 1.20 riastrad if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 1373 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 1374 1.20 riastrad 1375 1.20 riastrad if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1376 1.20 riastrad i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1377 1.20 riastrad 1378 1.20 riastrad if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1379 1.20 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1380 1.20 riastrad } 1381 1.20 riastrad } 1382 1.20 riastrad 1383 1.20 riastrad static void i915_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1384 1.20 riastrad u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1385 1.20 riastrad { 1386 1.20 riastrad bool blc_event = false; 1387 1.20 riastrad enum pipe pipe; 1388 1.20 riastrad 1389 1.20 riastrad for_each_pipe(dev_priv, pipe) { 1390 1.20 riastrad if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 1391 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 1392 1.20 riastrad 1393 1.20 riastrad if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 1394 1.20 riastrad blc_event = true; 1395 1.20 riastrad 1396 1.20 riastrad if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1397 1.20 riastrad i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1398 1.20 riastrad 1399 1.20 riastrad if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1400 1.20 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1401 1.20 riastrad } 1402 1.20 riastrad 1403 1.20 riastrad if (blc_event || (iir & I915_ASLE_INTERRUPT)) 1404 1.20 riastrad intel_opregion_asle_intr(dev_priv); 1405 1.20 riastrad } 1406 1.20 riastrad 1407 1.20 riastrad static void i965_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1408 1.20 riastrad u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 1409 1.20 riastrad { 1410 1.20 riastrad bool blc_event = false; 1411 1.20 riastrad enum pipe pipe; 1412 1.20 riastrad 1413 1.20 riastrad for_each_pipe(dev_priv, pipe) { 1414 1.20 riastrad if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 1415 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 1416 1.20 riastrad 1417 1.20 riastrad if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 1418 1.20 riastrad blc_event = true; 1419 1.20 riastrad 1420 1.20 riastrad if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1421 1.20 riastrad i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1422 1.20 riastrad 1423 1.20 riastrad if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1424 1.20 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1425 1.20 riastrad } 1426 1.20 riastrad 1427 1.20 riastrad if (blc_event || (iir & I915_ASLE_INTERRUPT)) 1428 1.20 riastrad intel_opregion_asle_intr(dev_priv); 1429 1.20 riastrad 1430 1.20 riastrad if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1431 1.20 riastrad gmbus_irq_handler(dev_priv); 1432 1.20 riastrad } 1433 1.20 riastrad 1434 1.20 riastrad static void valleyview_pipestat_irq_handler(struct drm_i915_private *dev_priv, 1435 1.20 riastrad u32 pipe_stats[I915_MAX_PIPES]) 1436 1.20 riastrad { 1437 1.20 riastrad enum pipe pipe; 1438 1.1 riastrad 1439 1.11 riastrad for_each_pipe(dev_priv, pipe) { 1440 1.20 riastrad if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 1441 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 1442 1.1 riastrad 1443 1.5 riastrad if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 1444 1.20 riastrad i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1445 1.1 riastrad 1446 1.11 riastrad if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 1447 1.11 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1448 1.5 riastrad } 1449 1.1 riastrad 1450 1.5 riastrad if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 1451 1.20 riastrad gmbus_irq_handler(dev_priv); 1452 1.1 riastrad } 1453 1.1 riastrad 1454 1.20 riastrad static u32 i9xx_hpd_irq_ack(struct drm_i915_private *dev_priv) 1455 1.11 riastrad { 1456 1.20 riastrad u32 hotplug_status = 0, hotplug_status_mask; 1457 1.20 riastrad int i; 1458 1.11 riastrad 1459 1.20 riastrad if (IS_G4X(dev_priv) || 1460 1.20 riastrad IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 1461 1.20 riastrad hotplug_status_mask = HOTPLUG_INT_STATUS_G4X | 1462 1.20 riastrad DP_AUX_CHANNEL_MASK_INT_STATUS_G4X; 1463 1.20 riastrad else 1464 1.20 riastrad hotplug_status_mask = HOTPLUG_INT_STATUS_I915; 1465 1.11 riastrad 1466 1.11 riastrad /* 1467 1.20 riastrad * We absolutely have to clear all the pending interrupt 1468 1.20 riastrad * bits in PORT_HOTPLUG_STAT. Otherwise the ISR port 1469 1.20 riastrad * interrupt bit won't have an edge, and the i965/g4x 1470 1.20 riastrad * edge triggered IIR will not notice that an interrupt 1471 1.20 riastrad * is still pending. We can't use PORT_HOTPLUG_EN to 1472 1.20 riastrad * guarantee the edge as the act of toggling the enable 1473 1.20 riastrad * bits can itself generate a new hotplug interrupt :( 1474 1.11 riastrad */ 1475 1.20 riastrad for (i = 0; i < 10; i++) { 1476 1.20 riastrad u32 tmp = I915_READ(PORT_HOTPLUG_STAT) & hotplug_status_mask; 1477 1.20 riastrad 1478 1.20 riastrad if (tmp == 0) 1479 1.20 riastrad return hotplug_status; 1480 1.11 riastrad 1481 1.20 riastrad hotplug_status |= tmp; 1482 1.20 riastrad I915_WRITE(PORT_HOTPLUG_STAT, hotplug_status); 1483 1.20 riastrad } 1484 1.20 riastrad 1485 1.20 riastrad WARN_ONCE(1, 1486 1.20 riastrad "PORT_HOTPLUG_STAT did not clear (0x%08x)\n", 1487 1.20 riastrad I915_READ(PORT_HOTPLUG_STAT)); 1488 1.20 riastrad 1489 1.20 riastrad return hotplug_status; 1490 1.20 riastrad } 1491 1.20 riastrad 1492 1.20 riastrad static void i9xx_hpd_irq_handler(struct drm_i915_private *dev_priv, 1493 1.20 riastrad u32 hotplug_status) 1494 1.20 riastrad { 1495 1.20 riastrad u32 pin_mask = 0, long_mask = 0; 1496 1.20 riastrad 1497 1.20 riastrad if (IS_G4X(dev_priv) || IS_VALLEYVIEW(dev_priv) || 1498 1.20 riastrad IS_CHERRYVIEW(dev_priv)) { 1499 1.11 riastrad u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_G4X; 1500 1.11 riastrad 1501 1.11 riastrad if (hotplug_trigger) { 1502 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1503 1.20 riastrad hotplug_trigger, hotplug_trigger, 1504 1.20 riastrad hpd_status_g4x, 1505 1.11 riastrad i9xx_port_hotplug_long_detect); 1506 1.11 riastrad 1507 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1508 1.11 riastrad } 1509 1.11 riastrad 1510 1.11 riastrad if (hotplug_status & DP_AUX_CHANNEL_MASK_INT_STATUS_G4X) 1511 1.20 riastrad dp_aux_irq_handler(dev_priv); 1512 1.11 riastrad } else { 1513 1.11 riastrad u32 hotplug_trigger = hotplug_status & HOTPLUG_INT_STATUS_I915; 1514 1.11 riastrad 1515 1.11 riastrad if (hotplug_trigger) { 1516 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1517 1.20 riastrad hotplug_trigger, hotplug_trigger, 1518 1.20 riastrad hpd_status_i915, 1519 1.11 riastrad i9xx_port_hotplug_long_detect); 1520 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1521 1.11 riastrad } 1522 1.11 riastrad } 1523 1.11 riastrad } 1524 1.11 riastrad 1525 1.5 riastrad static irqreturn_t valleyview_irq_handler(DRM_IRQ_ARGS) 1526 1.1 riastrad { 1527 1.20 riastrad struct drm_i915_private *dev_priv = arg; 1528 1.1 riastrad irqreturn_t ret = IRQ_NONE; 1529 1.1 riastrad 1530 1.11 riastrad if (!intel_irqs_enabled(dev_priv)) 1531 1.11 riastrad return IRQ_NONE; 1532 1.11 riastrad 1533 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 1534 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 1535 1.20 riastrad 1536 1.20 riastrad do { 1537 1.20 riastrad u32 iir, gt_iir, pm_iir; 1538 1.20 riastrad u32 pipe_stats[I915_MAX_PIPES] = {}; 1539 1.20 riastrad u32 hotplug_status = 0; 1540 1.20 riastrad u32 ier = 0; 1541 1.11 riastrad 1542 1.5 riastrad gt_iir = I915_READ(GTIIR); 1543 1.20 riastrad pm_iir = I915_READ(GEN6_PMIIR); 1544 1.20 riastrad iir = I915_READ(VLV_IIR); 1545 1.11 riastrad 1546 1.20 riastrad if (gt_iir == 0 && pm_iir == 0 && iir == 0) 1547 1.20 riastrad break; 1548 1.20 riastrad 1549 1.20 riastrad ret = IRQ_HANDLED; 1550 1.20 riastrad 1551 1.20 riastrad /* 1552 1.20 riastrad * Theory on interrupt generation, based on empirical evidence: 1553 1.20 riastrad * 1554 1.20 riastrad * x = ((VLV_IIR & VLV_IER) || 1555 1.20 riastrad * (((GT_IIR & GT_IER) || (GEN6_PMIIR & GEN6_PMIER)) && 1556 1.20 riastrad * (VLV_MASTER_IER & MASTER_INTERRUPT_ENABLE))); 1557 1.20 riastrad * 1558 1.20 riastrad * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 1559 1.20 riastrad * Hence we clear MASTER_INTERRUPT_ENABLE and VLV_IER to 1560 1.20 riastrad * guarantee the CPU interrupt will be raised again even if we 1561 1.20 riastrad * don't end up clearing all the VLV_IIR, GT_IIR, GEN6_PMIIR 1562 1.20 riastrad * bits this time around. 1563 1.20 riastrad */ 1564 1.20 riastrad I915_WRITE(VLV_MASTER_IER, 0); 1565 1.20 riastrad ier = I915_READ(VLV_IER); 1566 1.20 riastrad I915_WRITE(VLV_IER, 0); 1567 1.20 riastrad 1568 1.20 riastrad if (gt_iir) 1569 1.20 riastrad I915_WRITE(GTIIR, gt_iir); 1570 1.11 riastrad if (pm_iir) 1571 1.11 riastrad I915_WRITE(GEN6_PMIIR, pm_iir); 1572 1.11 riastrad 1573 1.20 riastrad if (iir & I915_DISPLAY_PORT_INTERRUPT) 1574 1.20 riastrad hotplug_status = i9xx_hpd_irq_ack(dev_priv); 1575 1.20 riastrad 1576 1.20 riastrad /* Call regardless, as some status bits might not be 1577 1.20 riastrad * signalled in iir */ 1578 1.20 riastrad i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 1579 1.20 riastrad 1580 1.20 riastrad if (iir & (I915_LPE_PIPE_A_INTERRUPT | 1581 1.20 riastrad I915_LPE_PIPE_B_INTERRUPT)) 1582 1.20 riastrad intel_lpe_audio_irq_handler(dev_priv); 1583 1.20 riastrad 1584 1.20 riastrad /* 1585 1.20 riastrad * VLV_IIR is single buffered, and reflects the level 1586 1.20 riastrad * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 1587 1.20 riastrad */ 1588 1.20 riastrad if (iir) 1589 1.11 riastrad I915_WRITE(VLV_IIR, iir); 1590 1.1 riastrad 1591 1.20 riastrad I915_WRITE(VLV_IER, ier); 1592 1.20 riastrad I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 1593 1.1 riastrad 1594 1.11 riastrad if (gt_iir) 1595 1.20 riastrad gen6_gt_irq_handler(&dev_priv->gt, gt_iir); 1596 1.11 riastrad if (pm_iir) 1597 1.20 riastrad gen6_rps_irq_handler(&dev_priv->gt.rps, pm_iir); 1598 1.20 riastrad 1599 1.20 riastrad if (hotplug_status) 1600 1.20 riastrad i9xx_hpd_irq_handler(dev_priv, hotplug_status); 1601 1.20 riastrad 1602 1.20 riastrad valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 1603 1.20 riastrad } while (0); 1604 1.20 riastrad 1605 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 1606 1.11 riastrad 1607 1.11 riastrad return ret; 1608 1.11 riastrad } 1609 1.11 riastrad 1610 1.14 riastrad static irqreturn_t cherryview_irq_handler(DRM_IRQ_ARGS) 1611 1.11 riastrad { 1612 1.20 riastrad struct drm_i915_private *dev_priv = arg; 1613 1.11 riastrad irqreturn_t ret = IRQ_NONE; 1614 1.11 riastrad 1615 1.11 riastrad if (!intel_irqs_enabled(dev_priv)) 1616 1.11 riastrad return IRQ_NONE; 1617 1.11 riastrad 1618 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 1619 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 1620 1.20 riastrad 1621 1.20 riastrad do { 1622 1.20 riastrad u32 master_ctl, iir; 1623 1.20 riastrad u32 pipe_stats[I915_MAX_PIPES] = {}; 1624 1.20 riastrad u32 hotplug_status = 0; 1625 1.20 riastrad u32 gt_iir[4]; 1626 1.20 riastrad u32 ier = 0; 1627 1.20 riastrad 1628 1.11 riastrad master_ctl = I915_READ(GEN8_MASTER_IRQ) & ~GEN8_MASTER_IRQ_CONTROL; 1629 1.11 riastrad iir = I915_READ(VLV_IIR); 1630 1.1 riastrad 1631 1.11 riastrad if (master_ctl == 0 && iir == 0) 1632 1.11 riastrad break; 1633 1.1 riastrad 1634 1.11 riastrad ret = IRQ_HANDLED; 1635 1.1 riastrad 1636 1.20 riastrad /* 1637 1.20 riastrad * Theory on interrupt generation, based on empirical evidence: 1638 1.20 riastrad * 1639 1.20 riastrad * x = ((VLV_IIR & VLV_IER) || 1640 1.20 riastrad * ((GEN8_MASTER_IRQ & ~GEN8_MASTER_IRQ_CONTROL) && 1641 1.20 riastrad * (GEN8_MASTER_IRQ & GEN8_MASTER_IRQ_CONTROL))); 1642 1.20 riastrad * 1643 1.20 riastrad * A CPU interrupt will only be raised when 'x' has a 0->1 edge. 1644 1.20 riastrad * Hence we clear GEN8_MASTER_IRQ_CONTROL and VLV_IER to 1645 1.20 riastrad * guarantee the CPU interrupt will be raised again even if we 1646 1.20 riastrad * don't end up clearing all the VLV_IIR and GEN8_MASTER_IRQ_CONTROL 1647 1.20 riastrad * bits this time around. 1648 1.20 riastrad */ 1649 1.11 riastrad I915_WRITE(GEN8_MASTER_IRQ, 0); 1650 1.20 riastrad ier = I915_READ(VLV_IER); 1651 1.20 riastrad I915_WRITE(VLV_IER, 0); 1652 1.20 riastrad 1653 1.20 riastrad gen8_gt_irq_ack(&dev_priv->gt, master_ctl, gt_iir); 1654 1.20 riastrad 1655 1.20 riastrad if (iir & I915_DISPLAY_PORT_INTERRUPT) 1656 1.20 riastrad hotplug_status = i9xx_hpd_irq_ack(dev_priv); 1657 1.1 riastrad 1658 1.20 riastrad /* Call regardless, as some status bits might not be 1659 1.20 riastrad * signalled in iir */ 1660 1.20 riastrad i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 1661 1.1 riastrad 1662 1.20 riastrad if (iir & (I915_LPE_PIPE_A_INTERRUPT | 1663 1.20 riastrad I915_LPE_PIPE_B_INTERRUPT | 1664 1.20 riastrad I915_LPE_PIPE_C_INTERRUPT)) 1665 1.20 riastrad intel_lpe_audio_irq_handler(dev_priv); 1666 1.20 riastrad 1667 1.20 riastrad /* 1668 1.20 riastrad * VLV_IIR is single buffered, and reflects the level 1669 1.20 riastrad * from PIPESTAT/PORT_HOTPLUG_STAT, hence clear it last. 1670 1.20 riastrad */ 1671 1.20 riastrad if (iir) 1672 1.11 riastrad I915_WRITE(VLV_IIR, iir); 1673 1.1 riastrad 1674 1.20 riastrad I915_WRITE(VLV_IER, ier); 1675 1.20 riastrad I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 1676 1.20 riastrad 1677 1.20 riastrad gen8_gt_irq_handler(&dev_priv->gt, master_ctl, gt_iir); 1678 1.20 riastrad 1679 1.20 riastrad if (hotplug_status) 1680 1.20 riastrad i9xx_hpd_irq_handler(dev_priv, hotplug_status); 1681 1.1 riastrad 1682 1.20 riastrad valleyview_pipestat_irq_handler(dev_priv, pipe_stats); 1683 1.20 riastrad } while (0); 1684 1.5 riastrad 1685 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 1686 1.1 riastrad 1687 1.1 riastrad return ret; 1688 1.1 riastrad } 1689 1.1 riastrad 1690 1.20 riastrad static void ibx_hpd_irq_handler(struct drm_i915_private *dev_priv, 1691 1.20 riastrad u32 hotplug_trigger, 1692 1.11 riastrad const u32 hpd[HPD_NUM_PINS]) 1693 1.11 riastrad { 1694 1.11 riastrad u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 1695 1.11 riastrad 1696 1.20 riastrad /* 1697 1.20 riastrad * Somehow the PCH doesn't seem to really ack the interrupt to the CPU 1698 1.20 riastrad * unless we touch the hotplug register, even if hotplug_trigger is 1699 1.20 riastrad * zero. Not acking leads to "The master control interrupt lied (SDE)!" 1700 1.20 riastrad * errors. 1701 1.20 riastrad */ 1702 1.11 riastrad dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 1703 1.20 riastrad if (!hotplug_trigger) { 1704 1.20 riastrad u32 mask = PORTA_HOTPLUG_STATUS_MASK | 1705 1.20 riastrad PORTD_HOTPLUG_STATUS_MASK | 1706 1.20 riastrad PORTC_HOTPLUG_STATUS_MASK | 1707 1.20 riastrad PORTB_HOTPLUG_STATUS_MASK; 1708 1.20 riastrad dig_hotplug_reg &= ~mask; 1709 1.20 riastrad } 1710 1.20 riastrad 1711 1.11 riastrad I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 1712 1.20 riastrad if (!hotplug_trigger) 1713 1.20 riastrad return; 1714 1.11 riastrad 1715 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 1716 1.11 riastrad dig_hotplug_reg, hpd, 1717 1.11 riastrad pch_port_hotplug_long_detect); 1718 1.11 riastrad 1719 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1720 1.11 riastrad } 1721 1.11 riastrad 1722 1.20 riastrad static void ibx_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 1723 1.1 riastrad { 1724 1.20 riastrad enum pipe pipe; 1725 1.5 riastrad u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 1726 1.1 riastrad 1727 1.20 riastrad ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ibx); 1728 1.1 riastrad 1729 1.5 riastrad if (pch_iir & SDE_AUDIO_POWER_MASK) { 1730 1.5 riastrad int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 1731 1.5 riastrad SDE_AUDIO_POWER_SHIFT); 1732 1.5 riastrad DRM_DEBUG_DRIVER("PCH audio power change on port %d\n", 1733 1.5 riastrad port_name(port)); 1734 1.5 riastrad } 1735 1.1 riastrad 1736 1.5 riastrad if (pch_iir & SDE_AUX_MASK) 1737 1.20 riastrad dp_aux_irq_handler(dev_priv); 1738 1.1 riastrad 1739 1.5 riastrad if (pch_iir & SDE_GMBUS) 1740 1.20 riastrad gmbus_irq_handler(dev_priv); 1741 1.1 riastrad 1742 1.5 riastrad if (pch_iir & SDE_AUDIO_HDCP_MASK) 1743 1.5 riastrad DRM_DEBUG_DRIVER("PCH HDCP audio interrupt\n"); 1744 1.1 riastrad 1745 1.5 riastrad if (pch_iir & SDE_AUDIO_TRANS_MASK) 1746 1.5 riastrad DRM_DEBUG_DRIVER("PCH transcoder audio interrupt\n"); 1747 1.1 riastrad 1748 1.5 riastrad if (pch_iir & SDE_POISON) 1749 1.5 riastrad DRM_ERROR("PCH poison interrupt\n"); 1750 1.1 riastrad 1751 1.5 riastrad if (pch_iir & SDE_FDI_MASK) 1752 1.11 riastrad for_each_pipe(dev_priv, pipe) 1753 1.5 riastrad DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 1754 1.5 riastrad pipe_name(pipe), 1755 1.5 riastrad I915_READ(FDI_RX_IIR(pipe))); 1756 1.1 riastrad 1757 1.5 riastrad if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 1758 1.5 riastrad DRM_DEBUG_DRIVER("PCH transcoder CRC done interrupt\n"); 1759 1.1 riastrad 1760 1.5 riastrad if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 1761 1.5 riastrad DRM_DEBUG_DRIVER("PCH transcoder CRC error interrupt\n"); 1762 1.1 riastrad 1763 1.5 riastrad if (pch_iir & SDE_TRANSA_FIFO_UNDER) 1764 1.20 riastrad intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_A); 1765 1.1 riastrad 1766 1.5 riastrad if (pch_iir & SDE_TRANSB_FIFO_UNDER) 1767 1.20 riastrad intel_pch_fifo_underrun_irq_handler(dev_priv, PIPE_B); 1768 1.5 riastrad } 1769 1.1 riastrad 1770 1.20 riastrad static void ivb_err_int_handler(struct drm_i915_private *dev_priv) 1771 1.5 riastrad { 1772 1.5 riastrad u32 err_int = I915_READ(GEN7_ERR_INT); 1773 1.18 riastrad enum pipe pipe; 1774 1.1 riastrad 1775 1.5 riastrad if (err_int & ERR_INT_POISON) 1776 1.5 riastrad DRM_ERROR("Poison interrupt\n"); 1777 1.1 riastrad 1778 1.11 riastrad for_each_pipe(dev_priv, pipe) { 1779 1.11 riastrad if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) 1780 1.11 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1781 1.1 riastrad 1782 1.5 riastrad if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 1783 1.20 riastrad if (IS_IVYBRIDGE(dev_priv)) 1784 1.20 riastrad ivb_pipe_crc_irq_handler(dev_priv, pipe); 1785 1.5 riastrad else 1786 1.20 riastrad hsw_pipe_crc_irq_handler(dev_priv, pipe); 1787 1.5 riastrad } 1788 1.5 riastrad } 1789 1.1 riastrad 1790 1.5 riastrad I915_WRITE(GEN7_ERR_INT, err_int); 1791 1.1 riastrad } 1792 1.1 riastrad 1793 1.20 riastrad static void cpt_serr_int_handler(struct drm_i915_private *dev_priv) 1794 1.1 riastrad { 1795 1.5 riastrad u32 serr_int = I915_READ(SERR_INT); 1796 1.20 riastrad enum pipe pipe; 1797 1.5 riastrad 1798 1.5 riastrad if (serr_int & SERR_INT_POISON) 1799 1.5 riastrad DRM_ERROR("PCH poison interrupt\n"); 1800 1.1 riastrad 1801 1.20 riastrad for_each_pipe(dev_priv, pipe) 1802 1.20 riastrad if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe)) 1803 1.20 riastrad intel_pch_fifo_underrun_irq_handler(dev_priv, pipe); 1804 1.1 riastrad 1805 1.5 riastrad I915_WRITE(SERR_INT, serr_int); 1806 1.1 riastrad } 1807 1.1 riastrad 1808 1.20 riastrad static void cpt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 1809 1.1 riastrad { 1810 1.20 riastrad enum pipe pipe; 1811 1.5 riastrad u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 1812 1.5 riastrad 1813 1.20 riastrad ibx_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_cpt); 1814 1.1 riastrad 1815 1.5 riastrad if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 1816 1.5 riastrad int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 1817 1.5 riastrad SDE_AUDIO_POWER_SHIFT_CPT); 1818 1.5 riastrad DRM_DEBUG_DRIVER("PCH audio power change on port %c\n", 1819 1.5 riastrad port_name(port)); 1820 1.1 riastrad } 1821 1.1 riastrad 1822 1.5 riastrad if (pch_iir & SDE_AUX_MASK_CPT) 1823 1.20 riastrad dp_aux_irq_handler(dev_priv); 1824 1.1 riastrad 1825 1.5 riastrad if (pch_iir & SDE_GMBUS_CPT) 1826 1.20 riastrad gmbus_irq_handler(dev_priv); 1827 1.1 riastrad 1828 1.5 riastrad if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 1829 1.5 riastrad DRM_DEBUG_DRIVER("Audio CP request interrupt\n"); 1830 1.1 riastrad 1831 1.5 riastrad if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 1832 1.5 riastrad DRM_DEBUG_DRIVER("Audio CP change interrupt\n"); 1833 1.1 riastrad 1834 1.5 riastrad if (pch_iir & SDE_FDI_MASK_CPT) 1835 1.11 riastrad for_each_pipe(dev_priv, pipe) 1836 1.5 riastrad DRM_DEBUG_DRIVER(" pipe %c FDI IIR: 0x%08x\n", 1837 1.5 riastrad pipe_name(pipe), 1838 1.5 riastrad I915_READ(FDI_RX_IIR(pipe))); 1839 1.1 riastrad 1840 1.5 riastrad if (pch_iir & SDE_ERROR_CPT) 1841 1.20 riastrad cpt_serr_int_handler(dev_priv); 1842 1.20 riastrad } 1843 1.20 riastrad 1844 1.20 riastrad static void icp_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 1845 1.20 riastrad { 1846 1.20 riastrad u32 ddi_hotplug_trigger, tc_hotplug_trigger; 1847 1.20 riastrad u32 pin_mask = 0, long_mask = 0; 1848 1.20 riastrad bool (*tc_port_hotplug_long_detect)(enum hpd_pin pin, u32 val); 1849 1.20 riastrad const u32 *pins; 1850 1.20 riastrad 1851 1.20 riastrad if (HAS_PCH_TGP(dev_priv)) { 1852 1.20 riastrad ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_TGP; 1853 1.20 riastrad tc_hotplug_trigger = pch_iir & SDE_TC_MASK_TGP; 1854 1.20 riastrad tc_port_hotplug_long_detect = tgp_tc_port_hotplug_long_detect; 1855 1.20 riastrad pins = hpd_tgp; 1856 1.20 riastrad } else if (HAS_PCH_JSP(dev_priv)) { 1857 1.20 riastrad ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_TGP; 1858 1.20 riastrad tc_hotplug_trigger = 0; 1859 1.20 riastrad pins = hpd_tgp; 1860 1.20 riastrad } else if (HAS_PCH_MCC(dev_priv)) { 1861 1.20 riastrad ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP; 1862 1.20 riastrad tc_hotplug_trigger = pch_iir & SDE_TC_HOTPLUG_ICP(PORT_TC1); 1863 1.20 riastrad tc_port_hotplug_long_detect = icp_tc_port_hotplug_long_detect; 1864 1.20 riastrad pins = hpd_icp; 1865 1.20 riastrad } else { 1866 1.20 riastrad WARN(!HAS_PCH_ICP(dev_priv), 1867 1.20 riastrad "Unrecognized PCH type 0x%x\n", INTEL_PCH_TYPE(dev_priv)); 1868 1.20 riastrad 1869 1.20 riastrad ddi_hotplug_trigger = pch_iir & SDE_DDI_MASK_ICP; 1870 1.20 riastrad tc_hotplug_trigger = pch_iir & SDE_TC_MASK_ICP; 1871 1.20 riastrad tc_port_hotplug_long_detect = icp_tc_port_hotplug_long_detect; 1872 1.20 riastrad pins = hpd_icp; 1873 1.20 riastrad } 1874 1.20 riastrad 1875 1.20 riastrad if (ddi_hotplug_trigger) { 1876 1.20 riastrad u32 dig_hotplug_reg; 1877 1.20 riastrad 1878 1.20 riastrad dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_DDI); 1879 1.20 riastrad I915_WRITE(SHOTPLUG_CTL_DDI, dig_hotplug_reg); 1880 1.20 riastrad 1881 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1882 1.20 riastrad ddi_hotplug_trigger, 1883 1.20 riastrad dig_hotplug_reg, pins, 1884 1.20 riastrad icp_ddi_port_hotplug_long_detect); 1885 1.20 riastrad } 1886 1.20 riastrad 1887 1.20 riastrad if (tc_hotplug_trigger) { 1888 1.20 riastrad u32 dig_hotplug_reg; 1889 1.20 riastrad 1890 1.20 riastrad dig_hotplug_reg = I915_READ(SHOTPLUG_CTL_TC); 1891 1.20 riastrad I915_WRITE(SHOTPLUG_CTL_TC, dig_hotplug_reg); 1892 1.20 riastrad 1893 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1894 1.20 riastrad tc_hotplug_trigger, 1895 1.20 riastrad dig_hotplug_reg, pins, 1896 1.20 riastrad tc_port_hotplug_long_detect); 1897 1.20 riastrad } 1898 1.20 riastrad 1899 1.20 riastrad if (pin_mask) 1900 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1901 1.20 riastrad 1902 1.20 riastrad if (pch_iir & SDE_GMBUS_ICP) 1903 1.20 riastrad gmbus_irq_handler(dev_priv); 1904 1.5 riastrad } 1905 1.1 riastrad 1906 1.20 riastrad static void spt_irq_handler(struct drm_i915_private *dev_priv, u32 pch_iir) 1907 1.11 riastrad { 1908 1.11 riastrad u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_SPT & 1909 1.11 riastrad ~SDE_PORTE_HOTPLUG_SPT; 1910 1.11 riastrad u32 hotplug2_trigger = pch_iir & SDE_PORTE_HOTPLUG_SPT; 1911 1.11 riastrad u32 pin_mask = 0, long_mask = 0; 1912 1.11 riastrad 1913 1.11 riastrad if (hotplug_trigger) { 1914 1.11 riastrad u32 dig_hotplug_reg; 1915 1.11 riastrad 1916 1.11 riastrad dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 1917 1.11 riastrad I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 1918 1.11 riastrad 1919 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1920 1.20 riastrad hotplug_trigger, dig_hotplug_reg, hpd_spt, 1921 1.11 riastrad spt_port_hotplug_long_detect); 1922 1.11 riastrad } 1923 1.11 riastrad 1924 1.11 riastrad if (hotplug2_trigger) { 1925 1.11 riastrad u32 dig_hotplug_reg; 1926 1.11 riastrad 1927 1.11 riastrad dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG2); 1928 1.11 riastrad I915_WRITE(PCH_PORT_HOTPLUG2, dig_hotplug_reg); 1929 1.11 riastrad 1930 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, 1931 1.20 riastrad hotplug2_trigger, dig_hotplug_reg, hpd_spt, 1932 1.11 riastrad spt_port_hotplug2_long_detect); 1933 1.11 riastrad } 1934 1.11 riastrad 1935 1.11 riastrad if (pin_mask) 1936 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1937 1.11 riastrad 1938 1.11 riastrad if (pch_iir & SDE_GMBUS_CPT) 1939 1.20 riastrad gmbus_irq_handler(dev_priv); 1940 1.11 riastrad } 1941 1.11 riastrad 1942 1.20 riastrad static void ilk_hpd_irq_handler(struct drm_i915_private *dev_priv, 1943 1.20 riastrad u32 hotplug_trigger, 1944 1.11 riastrad const u32 hpd[HPD_NUM_PINS]) 1945 1.11 riastrad { 1946 1.11 riastrad u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 1947 1.11 riastrad 1948 1.11 riastrad dig_hotplug_reg = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 1949 1.11 riastrad I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, dig_hotplug_reg); 1950 1.11 riastrad 1951 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 1952 1.11 riastrad dig_hotplug_reg, hpd, 1953 1.11 riastrad ilk_port_hotplug_long_detect); 1954 1.11 riastrad 1955 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 1956 1.11 riastrad } 1957 1.11 riastrad 1958 1.20 riastrad static void ilk_display_irq_handler(struct drm_i915_private *dev_priv, 1959 1.20 riastrad u32 de_iir) 1960 1.5 riastrad { 1961 1.18 riastrad enum pipe pipe; 1962 1.11 riastrad u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; 1963 1.11 riastrad 1964 1.11 riastrad if (hotplug_trigger) 1965 1.20 riastrad ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ilk); 1966 1.1 riastrad 1967 1.5 riastrad if (de_iir & DE_AUX_CHANNEL_A) 1968 1.20 riastrad dp_aux_irq_handler(dev_priv); 1969 1.1 riastrad 1970 1.5 riastrad if (de_iir & DE_GSE) 1971 1.20 riastrad intel_opregion_asle_intr(dev_priv); 1972 1.1 riastrad 1973 1.5 riastrad if (de_iir & DE_POISON) 1974 1.5 riastrad DRM_ERROR("Poison interrupt\n"); 1975 1.1 riastrad 1976 1.11 riastrad for_each_pipe(dev_priv, pipe) { 1977 1.20 riastrad if (de_iir & DE_PIPE_VBLANK(pipe)) 1978 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 1979 1.1 riastrad 1980 1.5 riastrad if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 1981 1.11 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 1982 1.5 riastrad 1983 1.5 riastrad if (de_iir & DE_PIPE_CRC_DONE(pipe)) 1984 1.20 riastrad i9xx_pipe_crc_irq_handler(dev_priv, pipe); 1985 1.1 riastrad } 1986 1.1 riastrad 1987 1.5 riastrad /* check event from PCH */ 1988 1.5 riastrad if (de_iir & DE_PCH_EVENT) { 1989 1.5 riastrad u32 pch_iir = I915_READ(SDEIIR); 1990 1.1 riastrad 1991 1.20 riastrad if (HAS_PCH_CPT(dev_priv)) 1992 1.20 riastrad cpt_irq_handler(dev_priv, pch_iir); 1993 1.5 riastrad else 1994 1.20 riastrad ibx_irq_handler(dev_priv, pch_iir); 1995 1.1 riastrad 1996 1.5 riastrad /* should clear PCH hotplug event before clear CPU irq */ 1997 1.5 riastrad I915_WRITE(SDEIIR, pch_iir); 1998 1.5 riastrad } 1999 1.1 riastrad 2000 1.20 riastrad if (IS_GEN(dev_priv, 5) && de_iir & DE_PCU_EVENT) 2001 1.20 riastrad gen5_rps_irq_handler(&dev_priv->gt.rps); 2002 1.1 riastrad } 2003 1.1 riastrad 2004 1.20 riastrad static void ivb_display_irq_handler(struct drm_i915_private *dev_priv, 2005 1.20 riastrad u32 de_iir) 2006 1.1 riastrad { 2007 1.18 riastrad enum pipe pipe; 2008 1.11 riastrad u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; 2009 1.11 riastrad 2010 1.11 riastrad if (hotplug_trigger) 2011 1.20 riastrad ilk_hpd_irq_handler(dev_priv, hotplug_trigger, hpd_ivb); 2012 1.1 riastrad 2013 1.5 riastrad if (de_iir & DE_ERR_INT_IVB) 2014 1.20 riastrad ivb_err_int_handler(dev_priv); 2015 1.20 riastrad 2016 1.20 riastrad if (de_iir & DE_EDP_PSR_INT_HSW) { 2017 1.20 riastrad u32 psr_iir = I915_READ(EDP_PSR_IIR); 2018 1.20 riastrad 2019 1.20 riastrad intel_psr_irq_handler(dev_priv, psr_iir); 2020 1.20 riastrad I915_WRITE(EDP_PSR_IIR, psr_iir); 2021 1.20 riastrad } 2022 1.1 riastrad 2023 1.5 riastrad if (de_iir & DE_AUX_CHANNEL_A_IVB) 2024 1.20 riastrad dp_aux_irq_handler(dev_priv); 2025 1.1 riastrad 2026 1.5 riastrad if (de_iir & DE_GSE_IVB) 2027 1.20 riastrad intel_opregion_asle_intr(dev_priv); 2028 1.1 riastrad 2029 1.11 riastrad for_each_pipe(dev_priv, pipe) { 2030 1.20 riastrad if (de_iir & (DE_PIPE_VBLANK_IVB(pipe))) 2031 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 2032 1.1 riastrad } 2033 1.1 riastrad 2034 1.5 riastrad /* check event from PCH */ 2035 1.20 riastrad if (!HAS_PCH_NOP(dev_priv) && (de_iir & DE_PCH_EVENT_IVB)) { 2036 1.5 riastrad u32 pch_iir = I915_READ(SDEIIR); 2037 1.1 riastrad 2038 1.20 riastrad cpt_irq_handler(dev_priv, pch_iir); 2039 1.1 riastrad 2040 1.5 riastrad /* clear PCH hotplug event before clear CPU irq */ 2041 1.5 riastrad I915_WRITE(SDEIIR, pch_iir); 2042 1.1 riastrad } 2043 1.1 riastrad } 2044 1.1 riastrad 2045 1.11 riastrad /* 2046 1.11 riastrad * To handle irqs with the minimum potential races with fresh interrupts, we: 2047 1.11 riastrad * 1 - Disable Master Interrupt Control. 2048 1.11 riastrad * 2 - Find the source(s) of the interrupt. 2049 1.11 riastrad * 3 - Clear the Interrupt Identity bits (IIR). 2050 1.11 riastrad * 4 - Process the interrupt(s) that had bits set in the IIRs. 2051 1.11 riastrad * 5 - Re-enable Master Interrupt Control. 2052 1.11 riastrad */ 2053 1.20 riastrad static irqreturn_t ilk_irq_handler(DRM_IRQ_ARGS) 2054 1.1 riastrad { 2055 1.20 riastrad struct drm_i915_private *dev_priv = arg; 2056 1.5 riastrad u32 de_iir, gt_iir, de_ier, sde_ier = 0; 2057 1.5 riastrad irqreturn_t ret = IRQ_NONE; 2058 1.1 riastrad 2059 1.11 riastrad if (!intel_irqs_enabled(dev_priv)) 2060 1.11 riastrad return IRQ_NONE; 2061 1.11 riastrad 2062 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2063 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 2064 1.1 riastrad 2065 1.5 riastrad /* disable master interrupt before clearing iir */ 2066 1.5 riastrad de_ier = I915_READ(DEIER); 2067 1.5 riastrad I915_WRITE(DEIER, de_ier & ~DE_MASTER_IRQ_CONTROL); 2068 1.1 riastrad 2069 1.5 riastrad /* Disable south interrupts. We'll only write to SDEIIR once, so further 2070 1.5 riastrad * interrupts will will be stored on its back queue, and then we'll be 2071 1.5 riastrad * able to process them after we restore SDEIER (as soon as we restore 2072 1.5 riastrad * it, we'll get an interrupt if SDEIIR still has something to process 2073 1.5 riastrad * due to its back queue). */ 2074 1.20 riastrad if (!HAS_PCH_NOP(dev_priv)) { 2075 1.5 riastrad sde_ier = I915_READ(SDEIER); 2076 1.5 riastrad I915_WRITE(SDEIER, 0); 2077 1.5 riastrad } 2078 1.1 riastrad 2079 1.11 riastrad /* Find, clear, then process each source of interrupt */ 2080 1.11 riastrad 2081 1.5 riastrad gt_iir = I915_READ(GTIIR); 2082 1.5 riastrad if (gt_iir) { 2083 1.11 riastrad I915_WRITE(GTIIR, gt_iir); 2084 1.11 riastrad ret = IRQ_HANDLED; 2085 1.20 riastrad if (INTEL_GEN(dev_priv) >= 6) 2086 1.20 riastrad gen6_gt_irq_handler(&dev_priv->gt, gt_iir); 2087 1.5 riastrad else 2088 1.20 riastrad gen5_gt_irq_handler(&dev_priv->gt, gt_iir); 2089 1.1 riastrad } 2090 1.1 riastrad 2091 1.5 riastrad de_iir = I915_READ(DEIIR); 2092 1.5 riastrad if (de_iir) { 2093 1.11 riastrad I915_WRITE(DEIIR, de_iir); 2094 1.11 riastrad ret = IRQ_HANDLED; 2095 1.20 riastrad if (INTEL_GEN(dev_priv) >= 7) 2096 1.20 riastrad ivb_display_irq_handler(dev_priv, de_iir); 2097 1.5 riastrad else 2098 1.20 riastrad ilk_display_irq_handler(dev_priv, de_iir); 2099 1.5 riastrad } 2100 1.1 riastrad 2101 1.20 riastrad if (INTEL_GEN(dev_priv) >= 6) { 2102 1.5 riastrad u32 pm_iir = I915_READ(GEN6_PMIIR); 2103 1.5 riastrad if (pm_iir) { 2104 1.5 riastrad I915_WRITE(GEN6_PMIIR, pm_iir); 2105 1.5 riastrad ret = IRQ_HANDLED; 2106 1.20 riastrad gen6_rps_irq_handler(&dev_priv->gt.rps, pm_iir); 2107 1.5 riastrad } 2108 1.5 riastrad } 2109 1.1 riastrad 2110 1.5 riastrad I915_WRITE(DEIER, de_ier); 2111 1.20 riastrad if (!HAS_PCH_NOP(dev_priv)) 2112 1.5 riastrad I915_WRITE(SDEIER, sde_ier); 2113 1.20 riastrad 2114 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2115 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 2116 1.11 riastrad 2117 1.11 riastrad return ret; 2118 1.11 riastrad } 2119 1.11 riastrad 2120 1.20 riastrad static void bxt_hpd_irq_handler(struct drm_i915_private *dev_priv, 2121 1.20 riastrad u32 hotplug_trigger, 2122 1.11 riastrad const u32 hpd[HPD_NUM_PINS]) 2123 1.11 riastrad { 2124 1.11 riastrad u32 dig_hotplug_reg, pin_mask = 0, long_mask = 0; 2125 1.11 riastrad 2126 1.11 riastrad dig_hotplug_reg = I915_READ(PCH_PORT_HOTPLUG); 2127 1.11 riastrad I915_WRITE(PCH_PORT_HOTPLUG, dig_hotplug_reg); 2128 1.11 riastrad 2129 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, hotplug_trigger, 2130 1.11 riastrad dig_hotplug_reg, hpd, 2131 1.11 riastrad bxt_port_hotplug_long_detect); 2132 1.1 riastrad 2133 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2134 1.1 riastrad } 2135 1.1 riastrad 2136 1.23 riastrad static void gen11_hpd_irq_handler(struct drm_i915_private *dev_priv, u32 iir) 2137 1.1 riastrad { 2138 1.20 riastrad u32 pin_mask = 0, long_mask = 0; 2139 1.20 riastrad u32 trigger_tc = iir & GEN11_DE_TC_HOTPLUG_MASK; 2140 1.20 riastrad u32 trigger_tbt = iir & GEN11_DE_TBT_HOTPLUG_MASK; 2141 1.20 riastrad long_pulse_detect_func long_pulse_detect; 2142 1.20 riastrad const u32 *hpd; 2143 1.20 riastrad 2144 1.20 riastrad if (INTEL_GEN(dev_priv) >= 12) { 2145 1.20 riastrad long_pulse_detect = gen12_port_hotplug_long_detect; 2146 1.20 riastrad hpd = hpd_gen12; 2147 1.20 riastrad } else { 2148 1.20 riastrad long_pulse_detect = gen11_port_hotplug_long_detect; 2149 1.20 riastrad hpd = hpd_gen11; 2150 1.20 riastrad } 2151 1.20 riastrad 2152 1.20 riastrad if (trigger_tc) { 2153 1.20 riastrad u32 dig_hotplug_reg; 2154 1.20 riastrad 2155 1.20 riastrad dig_hotplug_reg = I915_READ(GEN11_TC_HOTPLUG_CTL); 2156 1.20 riastrad I915_WRITE(GEN11_TC_HOTPLUG_CTL, dig_hotplug_reg); 2157 1.20 riastrad 2158 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tc, 2159 1.20 riastrad dig_hotplug_reg, hpd, long_pulse_detect); 2160 1.20 riastrad } 2161 1.20 riastrad 2162 1.20 riastrad if (trigger_tbt) { 2163 1.20 riastrad u32 dig_hotplug_reg; 2164 1.20 riastrad 2165 1.20 riastrad dig_hotplug_reg = I915_READ(GEN11_TBT_HOTPLUG_CTL); 2166 1.20 riastrad I915_WRITE(GEN11_TBT_HOTPLUG_CTL, dig_hotplug_reg); 2167 1.20 riastrad 2168 1.20 riastrad intel_get_hpd_pins(dev_priv, &pin_mask, &long_mask, trigger_tbt, 2169 1.20 riastrad dig_hotplug_reg, hpd, long_pulse_detect); 2170 1.20 riastrad } 2171 1.20 riastrad 2172 1.20 riastrad if (pin_mask) 2173 1.20 riastrad intel_hpd_irq_handler(dev_priv, pin_mask, long_mask); 2174 1.20 riastrad else 2175 1.20 riastrad DRM_ERROR("Unexpected DE HPD interrupt 0x%08x\n", iir); 2176 1.20 riastrad } 2177 1.11 riastrad 2178 1.20 riastrad static u32 gen8_de_port_aux_mask(struct drm_i915_private *dev_priv) 2179 1.20 riastrad { 2180 1.20 riastrad u32 mask; 2181 1.11 riastrad 2182 1.20 riastrad if (INTEL_GEN(dev_priv) >= 12) 2183 1.20 riastrad return TGL_DE_PORT_AUX_DDIA | 2184 1.20 riastrad TGL_DE_PORT_AUX_DDIB | 2185 1.20 riastrad TGL_DE_PORT_AUX_DDIC | 2186 1.20 riastrad TGL_DE_PORT_AUX_USBC1 | 2187 1.20 riastrad TGL_DE_PORT_AUX_USBC2 | 2188 1.20 riastrad TGL_DE_PORT_AUX_USBC3 | 2189 1.20 riastrad TGL_DE_PORT_AUX_USBC4 | 2190 1.20 riastrad TGL_DE_PORT_AUX_USBC5 | 2191 1.20 riastrad TGL_DE_PORT_AUX_USBC6; 2192 1.20 riastrad 2193 1.20 riastrad 2194 1.20 riastrad mask = GEN8_AUX_CHANNEL_A; 2195 1.20 riastrad if (INTEL_GEN(dev_priv) >= 9) 2196 1.20 riastrad mask |= GEN9_AUX_CHANNEL_B | 2197 1.20 riastrad GEN9_AUX_CHANNEL_C | 2198 1.11 riastrad GEN9_AUX_CHANNEL_D; 2199 1.1 riastrad 2200 1.20 riastrad if (IS_CNL_WITH_PORT_F(dev_priv) || IS_GEN(dev_priv, 11)) 2201 1.20 riastrad mask |= CNL_AUX_CHANNEL_F; 2202 1.20 riastrad 2203 1.20 riastrad if (IS_GEN(dev_priv, 11)) 2204 1.20 riastrad mask |= ICL_AUX_CHANNEL_E; 2205 1.20 riastrad 2206 1.20 riastrad return mask; 2207 1.20 riastrad } 2208 1.20 riastrad 2209 1.20 riastrad static u32 gen8_de_pipe_fault_mask(struct drm_i915_private *dev_priv) 2210 1.20 riastrad { 2211 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11) 2212 1.20 riastrad return GEN11_DE_PIPE_IRQ_FAULT_ERRORS; 2213 1.20 riastrad else if (INTEL_GEN(dev_priv) >= 9) 2214 1.20 riastrad return GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 2215 1.20 riastrad else 2216 1.20 riastrad return GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 2217 1.20 riastrad } 2218 1.20 riastrad 2219 1.20 riastrad static void 2220 1.20 riastrad gen8_de_misc_irq_handler(struct drm_i915_private *dev_priv, u32 iir) 2221 1.20 riastrad { 2222 1.20 riastrad bool found = false; 2223 1.20 riastrad 2224 1.20 riastrad if (iir & GEN8_DE_MISC_GSE) { 2225 1.20 riastrad intel_opregion_asle_intr(dev_priv); 2226 1.20 riastrad found = true; 2227 1.20 riastrad } 2228 1.20 riastrad 2229 1.20 riastrad if (iir & GEN8_DE_EDP_PSR) { 2230 1.20 riastrad u32 psr_iir; 2231 1.20 riastrad i915_reg_t iir_reg; 2232 1.20 riastrad 2233 1.20 riastrad if (INTEL_GEN(dev_priv) >= 12) 2234 1.20 riastrad iir_reg = TRANS_PSR_IIR(dev_priv->psr.transcoder); 2235 1.20 riastrad else 2236 1.20 riastrad iir_reg = EDP_PSR_IIR; 2237 1.20 riastrad 2238 1.20 riastrad psr_iir = I915_READ(iir_reg); 2239 1.20 riastrad I915_WRITE(iir_reg, psr_iir); 2240 1.20 riastrad 2241 1.20 riastrad if (psr_iir) 2242 1.20 riastrad found = true; 2243 1.1 riastrad 2244 1.20 riastrad intel_psr_irq_handler(dev_priv, psr_iir); 2245 1.20 riastrad } 2246 1.11 riastrad 2247 1.20 riastrad if (!found) 2248 1.20 riastrad DRM_ERROR("Unexpected DE Misc interrupt\n"); 2249 1.20 riastrad } 2250 1.1 riastrad 2251 1.20 riastrad static irqreturn_t 2252 1.20 riastrad gen8_de_irq_handler(struct drm_i915_private *dev_priv, u32 master_ctl) 2253 1.20 riastrad { 2254 1.20 riastrad irqreturn_t ret = IRQ_NONE; 2255 1.20 riastrad u32 iir; 2256 1.20 riastrad enum pipe pipe; 2257 1.1 riastrad 2258 1.5 riastrad if (master_ctl & GEN8_DE_MISC_IRQ) { 2259 1.20 riastrad iir = I915_READ(GEN8_DE_MISC_IIR); 2260 1.20 riastrad if (iir) { 2261 1.20 riastrad I915_WRITE(GEN8_DE_MISC_IIR, iir); 2262 1.5 riastrad ret = IRQ_HANDLED; 2263 1.20 riastrad gen8_de_misc_irq_handler(dev_priv, iir); 2264 1.20 riastrad } else { 2265 1.20 riastrad DRM_ERROR("The master control interrupt lied (DE MISC)!\n"); 2266 1.20 riastrad } 2267 1.20 riastrad } 2268 1.20 riastrad 2269 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) { 2270 1.20 riastrad iir = I915_READ(GEN11_DE_HPD_IIR); 2271 1.20 riastrad if (iir) { 2272 1.20 riastrad I915_WRITE(GEN11_DE_HPD_IIR, iir); 2273 1.20 riastrad ret = IRQ_HANDLED; 2274 1.20 riastrad gen11_hpd_irq_handler(dev_priv, iir); 2275 1.20 riastrad } else { 2276 1.20 riastrad DRM_ERROR("The master control interrupt lied, (DE HPD)!\n"); 2277 1.5 riastrad } 2278 1.5 riastrad } 2279 1.1 riastrad 2280 1.5 riastrad if (master_ctl & GEN8_DE_PORT_IRQ) { 2281 1.20 riastrad iir = I915_READ(GEN8_DE_PORT_IIR); 2282 1.20 riastrad if (iir) { 2283 1.20 riastrad u32 tmp_mask; 2284 1.11 riastrad bool found = false; 2285 1.11 riastrad 2286 1.20 riastrad I915_WRITE(GEN8_DE_PORT_IIR, iir); 2287 1.5 riastrad ret = IRQ_HANDLED; 2288 1.11 riastrad 2289 1.20 riastrad if (iir & gen8_de_port_aux_mask(dev_priv)) { 2290 1.20 riastrad dp_aux_irq_handler(dev_priv); 2291 1.11 riastrad found = true; 2292 1.11 riastrad } 2293 1.11 riastrad 2294 1.20 riastrad if (IS_GEN9_LP(dev_priv)) { 2295 1.20 riastrad tmp_mask = iir & BXT_DE_PORT_HOTPLUG_MASK; 2296 1.20 riastrad if (tmp_mask) { 2297 1.20 riastrad bxt_hpd_irq_handler(dev_priv, tmp_mask, 2298 1.20 riastrad hpd_bxt); 2299 1.20 riastrad found = true; 2300 1.20 riastrad } 2301 1.20 riastrad } else if (IS_BROADWELL(dev_priv)) { 2302 1.20 riastrad tmp_mask = iir & GEN8_PORT_DP_A_HOTPLUG; 2303 1.20 riastrad if (tmp_mask) { 2304 1.20 riastrad ilk_hpd_irq_handler(dev_priv, 2305 1.20 riastrad tmp_mask, hpd_bdw); 2306 1.20 riastrad found = true; 2307 1.20 riastrad } 2308 1.11 riastrad } 2309 1.11 riastrad 2310 1.20 riastrad if (IS_GEN9_LP(dev_priv) && (iir & BXT_DE_PORT_GMBUS)) { 2311 1.20 riastrad gmbus_irq_handler(dev_priv); 2312 1.11 riastrad found = true; 2313 1.11 riastrad } 2314 1.11 riastrad 2315 1.11 riastrad if (!found) 2316 1.11 riastrad DRM_ERROR("Unexpected DE Port interrupt\n"); 2317 1.5 riastrad } 2318 1.11 riastrad else 2319 1.11 riastrad DRM_ERROR("The master control interrupt lied (DE PORT)!\n"); 2320 1.5 riastrad } 2321 1.1 riastrad 2322 1.11 riastrad for_each_pipe(dev_priv, pipe) { 2323 1.20 riastrad u32 fault_errors; 2324 1.1 riastrad 2325 1.5 riastrad if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 2326 1.1 riastrad continue; 2327 1.5 riastrad 2328 1.20 riastrad iir = I915_READ(GEN8_DE_PIPE_IIR(pipe)); 2329 1.20 riastrad if (!iir) { 2330 1.20 riastrad DRM_ERROR("The master control interrupt lied (DE PIPE)!\n"); 2331 1.20 riastrad continue; 2332 1.20 riastrad } 2333 1.11 riastrad 2334 1.20 riastrad ret = IRQ_HANDLED; 2335 1.20 riastrad I915_WRITE(GEN8_DE_PIPE_IIR(pipe), iir); 2336 1.11 riastrad 2337 1.20 riastrad if (iir & GEN8_PIPE_VBLANK) 2338 1.20 riastrad drm_handle_vblank(&dev_priv->drm, pipe); 2339 1.11 riastrad 2340 1.20 riastrad if (iir & GEN8_PIPE_CDCLK_CRC_DONE) 2341 1.20 riastrad hsw_pipe_crc_irq_handler(dev_priv, pipe); 2342 1.5 riastrad 2343 1.20 riastrad if (iir & GEN8_PIPE_FIFO_UNDERRUN) 2344 1.20 riastrad intel_cpu_fifo_underrun_irq_handler(dev_priv, pipe); 2345 1.1 riastrad 2346 1.20 riastrad fault_errors = iir & gen8_de_pipe_fault_mask(dev_priv); 2347 1.20 riastrad if (fault_errors) 2348 1.20 riastrad DRM_ERROR("Fault errors on pipe %c: 0x%08x\n", 2349 1.20 riastrad pipe_name(pipe), 2350 1.20 riastrad fault_errors); 2351 1.1 riastrad } 2352 1.1 riastrad 2353 1.20 riastrad if (HAS_PCH_SPLIT(dev_priv) && !HAS_PCH_NOP(dev_priv) && 2354 1.11 riastrad master_ctl & GEN8_DE_PCH_IRQ) { 2355 1.5 riastrad /* 2356 1.5 riastrad * FIXME(BDW): Assume for now that the new interrupt handling 2357 1.5 riastrad * scheme also closed the SDE interrupt handling race we've seen 2358 1.5 riastrad * on older pch-split platforms. But this needs testing. 2359 1.5 riastrad */ 2360 1.20 riastrad iir = I915_READ(SDEIIR); 2361 1.20 riastrad if (iir) { 2362 1.20 riastrad I915_WRITE(SDEIIR, iir); 2363 1.5 riastrad ret = IRQ_HANDLED; 2364 1.11 riastrad 2365 1.20 riastrad if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 2366 1.20 riastrad icp_irq_handler(dev_priv, iir); 2367 1.20 riastrad else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT) 2368 1.20 riastrad spt_irq_handler(dev_priv, iir); 2369 1.11 riastrad else 2370 1.20 riastrad cpt_irq_handler(dev_priv, iir); 2371 1.11 riastrad } else { 2372 1.11 riastrad /* 2373 1.11 riastrad * Like on previous PCH there seems to be something 2374 1.11 riastrad * fishy going on with forwarding PCH interrupts. 2375 1.11 riastrad */ 2376 1.11 riastrad DRM_DEBUG_DRIVER("The master control interrupt lied (SDE)!\n"); 2377 1.5 riastrad } 2378 1.5 riastrad } 2379 1.1 riastrad 2380 1.5 riastrad return ret; 2381 1.5 riastrad } 2382 1.1 riastrad 2383 1.24 riastrad static inline u32 gen8_master_intr_disable(struct intel_uncore *regs) 2384 1.5 riastrad { 2385 1.20 riastrad raw_reg_write(regs, GEN8_MASTER_IRQ, 0); 2386 1.1 riastrad 2387 1.5 riastrad /* 2388 1.20 riastrad * Now with master disabled, get a sample of level indications 2389 1.20 riastrad * for this interrupt. Indications will be cleared on related acks. 2390 1.20 riastrad * New indications can and will light up during processing, 2391 1.20 riastrad * and will generate new interrupt after enabling master. 2392 1.5 riastrad */ 2393 1.20 riastrad return raw_reg_read(regs, GEN8_MASTER_IRQ); 2394 1.20 riastrad } 2395 1.20 riastrad 2396 1.24 riastrad static inline void gen8_master_intr_enable(struct intel_uncore *regs) 2397 1.20 riastrad { 2398 1.20 riastrad raw_reg_write(regs, GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 2399 1.20 riastrad } 2400 1.20 riastrad 2401 1.22 riastrad static irqreturn_t gen8_irq_handler(DRM_IRQ_ARGS) 2402 1.20 riastrad { 2403 1.20 riastrad struct drm_i915_private *dev_priv = arg; 2404 1.20 riastrad u32 master_ctl; 2405 1.20 riastrad u32 gt_iir[4]; 2406 1.1 riastrad 2407 1.20 riastrad if (!intel_irqs_enabled(dev_priv)) 2408 1.20 riastrad return IRQ_NONE; 2409 1.20 riastrad 2410 1.21 riastrad master_ctl = gen8_master_intr_disable(&dev_priv->uncore); 2411 1.20 riastrad if (!master_ctl) { 2412 1.21 riastrad gen8_master_intr_enable(&dev_priv->uncore); 2413 1.20 riastrad return IRQ_NONE; 2414 1.15 riastrad } 2415 1.6 riastrad 2416 1.20 riastrad /* Find, clear, then process each source of interrupt */ 2417 1.20 riastrad gen8_gt_irq_ack(&dev_priv->gt, master_ctl, gt_iir); 2418 1.20 riastrad 2419 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2420 1.20 riastrad if (master_ctl & ~GEN8_GT_IRQS) { 2421 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 2422 1.20 riastrad gen8_de_irq_handler(dev_priv, master_ctl); 2423 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 2424 1.6 riastrad } 2425 1.1 riastrad 2426 1.21 riastrad gen8_master_intr_enable(&dev_priv->uncore); 2427 1.20 riastrad 2428 1.20 riastrad gen8_gt_irq_handler(&dev_priv->gt, master_ctl, gt_iir); 2429 1.1 riastrad 2430 1.20 riastrad return IRQ_HANDLED; 2431 1.5 riastrad } 2432 1.1 riastrad 2433 1.20 riastrad static u32 2434 1.20 riastrad gen11_gu_misc_irq_ack(struct intel_gt *gt, const u32 master_ctl) 2435 1.5 riastrad { 2436 1.20 riastrad u32 iir; 2437 1.1 riastrad 2438 1.20 riastrad if (!(master_ctl & GEN11_GU_MISC_IRQ)) 2439 1.20 riastrad return 0; 2440 1.1 riastrad 2441 1.21 riastrad iir = raw_reg_read(gt->uncore, GEN11_GU_MISC_IIR); 2442 1.20 riastrad if (likely(iir)) 2443 1.21 riastrad raw_reg_write(gt->uncore, GEN11_GU_MISC_IIR, iir); 2444 1.1 riastrad 2445 1.20 riastrad return iir; 2446 1.20 riastrad } 2447 1.11 riastrad 2448 1.20 riastrad static void 2449 1.20 riastrad gen11_gu_misc_irq_handler(struct intel_gt *gt, const u32 iir) 2450 1.20 riastrad { 2451 1.20 riastrad if (iir & GEN11_GU_MISC_GSE) 2452 1.20 riastrad intel_opregion_asle_intr(gt->i915); 2453 1.20 riastrad } 2454 1.11 riastrad 2455 1.24 riastrad static inline u32 gen11_master_intr_disable(struct intel_uncore *regs) 2456 1.20 riastrad { 2457 1.20 riastrad raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, 0); 2458 1.1 riastrad 2459 1.20 riastrad /* 2460 1.20 riastrad * Now with master disabled, get a sample of level indications 2461 1.20 riastrad * for this interrupt. Indications will be cleared on related acks. 2462 1.20 riastrad * New indications can and will light up during processing, 2463 1.20 riastrad * and will generate new interrupt after enabling master. 2464 1.20 riastrad */ 2465 1.20 riastrad return raw_reg_read(regs, GEN11_GFX_MSTR_IRQ); 2466 1.20 riastrad } 2467 1.11 riastrad 2468 1.24 riastrad static inline void gen11_master_intr_enable(struct intel_uncore *regs) 2469 1.20 riastrad { 2470 1.20 riastrad raw_reg_write(regs, GEN11_GFX_MSTR_IRQ, GEN11_MASTER_IRQ); 2471 1.20 riastrad } 2472 1.1 riastrad 2473 1.20 riastrad static void 2474 1.20 riastrad gen11_display_irq_handler(struct drm_i915_private *i915) 2475 1.20 riastrad { 2476 1.21 riastrad const u32 disp_ctl = raw_reg_read(&i915->uncore, GEN11_DISPLAY_INT_CTL); 2477 1.1 riastrad 2478 1.20 riastrad disable_rpm_wakeref_asserts(&i915->runtime_pm); 2479 1.20 riastrad /* 2480 1.20 riastrad * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ 2481 1.20 riastrad * for the display related bits. 2482 1.20 riastrad */ 2483 1.21 riastrad raw_reg_write(&i915->uncore, GEN11_DISPLAY_INT_CTL, 0x0); 2484 1.20 riastrad gen8_de_irq_handler(i915, disp_ctl); 2485 1.21 riastrad raw_reg_write(&i915->uncore, GEN11_DISPLAY_INT_CTL, 2486 1.20 riastrad GEN11_DISPLAY_IRQ_ENABLE); 2487 1.1 riastrad 2488 1.20 riastrad enable_rpm_wakeref_asserts(&i915->runtime_pm); 2489 1.1 riastrad } 2490 1.1 riastrad 2491 1.20 riastrad static __always_inline irqreturn_t 2492 1.20 riastrad __gen11_irq_handler(struct drm_i915_private * const i915, 2493 1.24 riastrad u32 (*intr_disable)(struct intel_uncore *regs), 2494 1.24 riastrad void (*intr_enable)(struct intel_uncore *regs)) 2495 1.1 riastrad { 2496 1.20 riastrad struct intel_gt *gt = &i915->gt; 2497 1.20 riastrad u32 master_ctl; 2498 1.20 riastrad u32 gu_misc_iir; 2499 1.1 riastrad 2500 1.20 riastrad if (!intel_irqs_enabled(i915)) 2501 1.20 riastrad return IRQ_NONE; 2502 1.1 riastrad 2503 1.21 riastrad master_ctl = intr_disable(&i915->uncore); 2504 1.20 riastrad if (!master_ctl) { 2505 1.21 riastrad intr_enable(&i915->uncore); 2506 1.20 riastrad return IRQ_NONE; 2507 1.20 riastrad } 2508 1.1 riastrad 2509 1.20 riastrad /* Find, clear, then process each source of interrupt. */ 2510 1.20 riastrad gen11_gt_irq_handler(gt, master_ctl); 2511 1.1 riastrad 2512 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 2513 1.20 riastrad if (master_ctl & GEN11_DISPLAY_IRQ) 2514 1.20 riastrad gen11_display_irq_handler(i915); 2515 1.1 riastrad 2516 1.20 riastrad gu_misc_iir = gen11_gu_misc_irq_ack(gt, master_ctl); 2517 1.1 riastrad 2518 1.21 riastrad intr_enable(&i915->uncore); 2519 1.1 riastrad 2520 1.20 riastrad gen11_gu_misc_irq_handler(gt, gu_misc_iir); 2521 1.1 riastrad 2522 1.20 riastrad return IRQ_HANDLED; 2523 1.1 riastrad } 2524 1.1 riastrad 2525 1.24 riastrad static irqreturn_t gen11_irq_handler(DRM_IRQ_ARGS) 2526 1.1 riastrad { 2527 1.20 riastrad return __gen11_irq_handler(arg, 2528 1.20 riastrad gen11_master_intr_disable, 2529 1.20 riastrad gen11_master_intr_enable); 2530 1.1 riastrad } 2531 1.1 riastrad 2532 1.1 riastrad /* Called from drm generic code, passed 'crtc' which 2533 1.1 riastrad * we use as a pipe index 2534 1.1 riastrad */ 2535 1.20 riastrad int i8xx_enable_vblank(struct drm_crtc *crtc) 2536 1.1 riastrad { 2537 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2538 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2539 1.1 riastrad unsigned long irqflags; 2540 1.1 riastrad 2541 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2542 1.20 riastrad i915_enable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 2543 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2544 1.1 riastrad 2545 1.1 riastrad return 0; 2546 1.1 riastrad } 2547 1.1 riastrad 2548 1.20 riastrad int i915gm_enable_vblank(struct drm_crtc *crtc) 2549 1.20 riastrad { 2550 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2551 1.20 riastrad 2552 1.20 riastrad /* 2553 1.20 riastrad * Vblank interrupts fail to wake the device up from C2+. 2554 1.20 riastrad * Disabling render clock gating during C-states avoids 2555 1.20 riastrad * the problem. There is a small power cost so we do this 2556 1.20 riastrad * only when vblank interrupts are actually enabled. 2557 1.20 riastrad */ 2558 1.20 riastrad if (dev_priv->vblank_enabled++ == 0) 2559 1.20 riastrad I915_WRITE(SCPD0, _MASKED_BIT_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 2560 1.20 riastrad 2561 1.20 riastrad return i8xx_enable_vblank(crtc); 2562 1.20 riastrad } 2563 1.20 riastrad 2564 1.20 riastrad int i965_enable_vblank(struct drm_crtc *crtc) 2565 1.1 riastrad { 2566 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2567 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2568 1.1 riastrad unsigned long irqflags; 2569 1.1 riastrad 2570 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2571 1.20 riastrad i915_enable_pipestat(dev_priv, pipe, 2572 1.20 riastrad PIPE_START_VBLANK_INTERRUPT_STATUS); 2573 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2574 1.1 riastrad 2575 1.1 riastrad return 0; 2576 1.1 riastrad } 2577 1.1 riastrad 2578 1.20 riastrad int ilk_enable_vblank(struct drm_crtc *crtc) 2579 1.1 riastrad { 2580 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2581 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2582 1.1 riastrad unsigned long irqflags; 2583 1.20 riastrad u32 bit = INTEL_GEN(dev_priv) >= 7 ? 2584 1.20 riastrad DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 2585 1.1 riastrad 2586 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2587 1.20 riastrad ilk_enable_display_irq(dev_priv, bit); 2588 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2589 1.1 riastrad 2590 1.20 riastrad /* Even though there is no DMC, frame counter can get stuck when 2591 1.20 riastrad * PSR is active as no frames are generated. 2592 1.20 riastrad */ 2593 1.20 riastrad if (HAS_PSR(dev_priv)) 2594 1.20 riastrad drm_crtc_vblank_restore(crtc); 2595 1.20 riastrad 2596 1.1 riastrad return 0; 2597 1.1 riastrad } 2598 1.1 riastrad 2599 1.20 riastrad int bdw_enable_vblank(struct drm_crtc *crtc) 2600 1.1 riastrad { 2601 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2602 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2603 1.1 riastrad unsigned long irqflags; 2604 1.1 riastrad 2605 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2606 1.20 riastrad bdw_enable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2607 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2608 1.20 riastrad 2609 1.20 riastrad /* Even if there is no DMC, frame counter can get stuck when 2610 1.20 riastrad * PSR is active as no frames are generated, so check only for PSR. 2611 1.20 riastrad */ 2612 1.20 riastrad if (HAS_PSR(dev_priv)) 2613 1.20 riastrad drm_crtc_vblank_restore(crtc); 2614 1.20 riastrad 2615 1.1 riastrad return 0; 2616 1.1 riastrad } 2617 1.1 riastrad 2618 1.1 riastrad /* Called from drm generic code, passed 'crtc' which 2619 1.1 riastrad * we use as a pipe index 2620 1.1 riastrad */ 2621 1.20 riastrad void i8xx_disable_vblank(struct drm_crtc *crtc) 2622 1.1 riastrad { 2623 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2624 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2625 1.1 riastrad unsigned long irqflags; 2626 1.1 riastrad 2627 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2628 1.20 riastrad i915_disable_pipestat(dev_priv, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 2629 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2630 1.1 riastrad } 2631 1.1 riastrad 2632 1.20 riastrad void i915gm_disable_vblank(struct drm_crtc *crtc) 2633 1.1 riastrad { 2634 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2635 1.20 riastrad 2636 1.20 riastrad i8xx_disable_vblank(crtc); 2637 1.1 riastrad 2638 1.20 riastrad if (--dev_priv->vblank_enabled == 0) 2639 1.20 riastrad I915_WRITE(SCPD0, _MASKED_BIT_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 2640 1.1 riastrad } 2641 1.1 riastrad 2642 1.20 riastrad void i965_disable_vblank(struct drm_crtc *crtc) 2643 1.1 riastrad { 2644 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2645 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2646 1.1 riastrad unsigned long irqflags; 2647 1.1 riastrad 2648 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2649 1.5 riastrad i915_disable_pipestat(dev_priv, pipe, 2650 1.5 riastrad PIPE_START_VBLANK_INTERRUPT_STATUS); 2651 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2652 1.1 riastrad } 2653 1.1 riastrad 2654 1.20 riastrad void ilk_disable_vblank(struct drm_crtc *crtc) 2655 1.1 riastrad { 2656 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2657 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2658 1.1 riastrad unsigned long irqflags; 2659 1.20 riastrad u32 bit = INTEL_GEN(dev_priv) >= 7 ? 2660 1.20 riastrad DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 2661 1.5 riastrad 2662 1.1 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2663 1.20 riastrad ilk_disable_display_irq(dev_priv, bit); 2664 1.1 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2665 1.1 riastrad } 2666 1.1 riastrad 2667 1.20 riastrad void bdw_disable_vblank(struct drm_crtc *crtc) 2668 1.1 riastrad { 2669 1.20 riastrad struct drm_i915_private *dev_priv = to_i915(crtc->dev); 2670 1.20 riastrad enum pipe pipe = to_intel_crtc(crtc)->pipe; 2671 1.20 riastrad unsigned long irqflags; 2672 1.20 riastrad 2673 1.20 riastrad spin_lock_irqsave(&dev_priv->irq_lock, irqflags); 2674 1.20 riastrad bdw_disable_pipe_irq(dev_priv, pipe, GEN8_PIPE_VBLANK); 2675 1.20 riastrad spin_unlock_irqrestore(&dev_priv->irq_lock, irqflags); 2676 1.1 riastrad } 2677 1.1 riastrad 2678 1.20 riastrad static void ibx_irq_reset(struct drm_i915_private *dev_priv) 2679 1.11 riastrad { 2680 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2681 1.20 riastrad 2682 1.20 riastrad if (HAS_PCH_NOP(dev_priv)) 2683 1.20 riastrad return; 2684 1.20 riastrad 2685 1.20 riastrad GEN3_IRQ_RESET(uncore, SDE); 2686 1.20 riastrad 2687 1.20 riastrad if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 2688 1.20 riastrad I915_WRITE(SERR_INT, 0xffffffff); 2689 1.11 riastrad } 2690 1.11 riastrad 2691 1.20 riastrad /* 2692 1.20 riastrad * SDEIER is also touched by the interrupt handler to work around missed PCH 2693 1.20 riastrad * interrupts. Hence we can't update it after the interrupt handler is enabled - 2694 1.20 riastrad * instead we unconditionally enable all PCH interrupt sources here, but then 2695 1.20 riastrad * only unmask them as needed with SDEIMR. 2696 1.20 riastrad * 2697 1.20 riastrad * This function needs to be called before interrupts are enabled. 2698 1.20 riastrad */ 2699 1.20 riastrad static void ibx_irq_pre_postinstall(struct drm_i915_private *dev_priv) 2700 1.5 riastrad { 2701 1.20 riastrad if (HAS_PCH_NOP(dev_priv)) 2702 1.20 riastrad return; 2703 1.11 riastrad 2704 1.20 riastrad WARN_ON(I915_READ(SDEIER) != 0); 2705 1.20 riastrad I915_WRITE(SDEIER, 0xffffffff); 2706 1.20 riastrad POSTING_READ(SDEIER); 2707 1.20 riastrad } 2708 1.11 riastrad 2709 1.20 riastrad static void vlv_display_irq_reset(struct drm_i915_private *dev_priv) 2710 1.20 riastrad { 2711 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2712 1.11 riastrad 2713 1.20 riastrad if (IS_CHERRYVIEW(dev_priv)) 2714 1.20 riastrad intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 2715 1.20 riastrad else 2716 1.20 riastrad intel_uncore_write(uncore, DPINVGTT, DPINVGTT_STATUS_MASK); 2717 1.11 riastrad 2718 1.20 riastrad i915_hotplug_interrupt_update_locked(dev_priv, 0xffffffff, 0); 2719 1.20 riastrad intel_uncore_write(uncore, PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 2720 1.11 riastrad 2721 1.20 riastrad i9xx_pipestat_irq_reset(dev_priv); 2722 1.11 riastrad 2723 1.20 riastrad GEN3_IRQ_RESET(uncore, VLV_); 2724 1.20 riastrad dev_priv->irq_mask = ~0u; 2725 1.5 riastrad } 2726 1.5 riastrad 2727 1.20 riastrad static void vlv_display_irq_postinstall(struct drm_i915_private *dev_priv) 2728 1.1 riastrad { 2729 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2730 1.11 riastrad 2731 1.20 riastrad u32 pipestat_mask; 2732 1.20 riastrad u32 enable_mask; 2733 1.20 riastrad enum pipe pipe; 2734 1.5 riastrad 2735 1.20 riastrad pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS; 2736 1.5 riastrad 2737 1.20 riastrad i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 2738 1.20 riastrad for_each_pipe(dev_priv, pipe) 2739 1.20 riastrad i915_enable_pipestat(dev_priv, pipe, pipestat_mask); 2740 1.5 riastrad 2741 1.20 riastrad enable_mask = I915_DISPLAY_PORT_INTERRUPT | 2742 1.20 riastrad I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2743 1.20 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2744 1.20 riastrad I915_LPE_PIPE_A_INTERRUPT | 2745 1.20 riastrad I915_LPE_PIPE_B_INTERRUPT; 2746 1.5 riastrad 2747 1.20 riastrad if (IS_CHERRYVIEW(dev_priv)) 2748 1.20 riastrad enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT | 2749 1.20 riastrad I915_LPE_PIPE_C_INTERRUPT; 2750 1.5 riastrad 2751 1.20 riastrad WARN_ON(dev_priv->irq_mask != ~0u); 2752 1.5 riastrad 2753 1.20 riastrad dev_priv->irq_mask = ~enable_mask; 2754 1.5 riastrad 2755 1.20 riastrad GEN3_IRQ_INIT(uncore, VLV_, dev_priv->irq_mask, enable_mask); 2756 1.5 riastrad } 2757 1.5 riastrad 2758 1.20 riastrad /* drm_dma.h hooks 2759 1.20 riastrad */ 2760 1.20 riastrad static void ilk_irq_reset(struct drm_i915_private *dev_priv) 2761 1.5 riastrad { 2762 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2763 1.5 riastrad 2764 1.20 riastrad GEN3_IRQ_RESET(uncore, DE); 2765 1.20 riastrad if (IS_GEN(dev_priv, 7)) 2766 1.20 riastrad intel_uncore_write(uncore, GEN7_ERR_INT, 0xffffffff); 2767 1.5 riastrad 2768 1.20 riastrad if (IS_HASWELL(dev_priv)) { 2769 1.20 riastrad intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 2770 1.20 riastrad intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 2771 1.20 riastrad } 2772 1.5 riastrad 2773 1.20 riastrad gen5_gt_irq_reset(&dev_priv->gt); 2774 1.5 riastrad 2775 1.20 riastrad ibx_irq_reset(dev_priv); 2776 1.1 riastrad } 2777 1.1 riastrad 2778 1.20 riastrad static void valleyview_irq_reset(struct drm_i915_private *dev_priv) 2779 1.1 riastrad { 2780 1.20 riastrad I915_WRITE(VLV_MASTER_IER, 0); 2781 1.20 riastrad POSTING_READ(VLV_MASTER_IER); 2782 1.20 riastrad 2783 1.20 riastrad gen5_gt_irq_reset(&dev_priv->gt); 2784 1.5 riastrad 2785 1.20 riastrad spin_lock_irq(&dev_priv->irq_lock); 2786 1.20 riastrad if (dev_priv->display_irqs_enabled) 2787 1.20 riastrad vlv_display_irq_reset(dev_priv); 2788 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 2789 1.1 riastrad } 2790 1.1 riastrad 2791 1.20 riastrad static void gen8_irq_reset(struct drm_i915_private *dev_priv) 2792 1.1 riastrad { 2793 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2794 1.20 riastrad enum pipe pipe; 2795 1.1 riastrad 2796 1.24 riastrad gen8_master_intr_disable(&dev_priv->uncore); 2797 1.11 riastrad 2798 1.20 riastrad gen8_gt_irq_reset(&dev_priv->gt); 2799 1.1 riastrad 2800 1.20 riastrad intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 2801 1.20 riastrad intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 2802 1.1 riastrad 2803 1.20 riastrad for_each_pipe(dev_priv, pipe) 2804 1.20 riastrad if (intel_display_power_is_enabled(dev_priv, 2805 1.20 riastrad POWER_DOMAIN_PIPE(pipe))) 2806 1.20 riastrad GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 2807 1.1 riastrad 2808 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_); 2809 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_); 2810 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_PCU_); 2811 1.1 riastrad 2812 1.20 riastrad if (HAS_PCH_SPLIT(dev_priv)) 2813 1.20 riastrad ibx_irq_reset(dev_priv); 2814 1.1 riastrad } 2815 1.1 riastrad 2816 1.20 riastrad static void gen11_display_irq_reset(struct drm_i915_private *dev_priv) 2817 1.1 riastrad { 2818 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2819 1.20 riastrad enum pipe pipe; 2820 1.20 riastrad 2821 1.20 riastrad intel_uncore_write(uncore, GEN11_DISPLAY_INT_CTL, 0); 2822 1.1 riastrad 2823 1.20 riastrad if (INTEL_GEN(dev_priv) >= 12) { 2824 1.20 riastrad enum transcoder trans; 2825 1.1 riastrad 2826 1.20 riastrad for (trans = TRANSCODER_A; trans <= TRANSCODER_D; trans++) { 2827 1.20 riastrad enum intel_display_power_domain domain; 2828 1.5 riastrad 2829 1.20 riastrad domain = POWER_DOMAIN_TRANSCODER(trans); 2830 1.20 riastrad if (!intel_display_power_is_enabled(dev_priv, domain)) 2831 1.20 riastrad continue; 2832 1.11 riastrad 2833 1.20 riastrad intel_uncore_write(uncore, TRANS_PSR_IMR(trans), 0xffffffff); 2834 1.20 riastrad intel_uncore_write(uncore, TRANS_PSR_IIR(trans), 0xffffffff); 2835 1.5 riastrad } 2836 1.20 riastrad } else { 2837 1.20 riastrad intel_uncore_write(uncore, EDP_PSR_IMR, 0xffffffff); 2838 1.20 riastrad intel_uncore_write(uncore, EDP_PSR_IIR, 0xffffffff); 2839 1.5 riastrad } 2840 1.5 riastrad 2841 1.20 riastrad for_each_pipe(dev_priv, pipe) 2842 1.20 riastrad if (intel_display_power_is_enabled(dev_priv, 2843 1.20 riastrad POWER_DOMAIN_PIPE(pipe))) 2844 1.20 riastrad GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 2845 1.1 riastrad 2846 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_DE_PORT_); 2847 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_DE_MISC_); 2848 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN11_DE_HPD_); 2849 1.5 riastrad 2850 1.20 riastrad if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 2851 1.20 riastrad GEN3_IRQ_RESET(uncore, SDE); 2852 1.5 riastrad } 2853 1.5 riastrad 2854 1.20 riastrad static void gen11_irq_reset(struct drm_i915_private *dev_priv) 2855 1.5 riastrad { 2856 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2857 1.11 riastrad 2858 1.24 riastrad gen11_master_intr_disable(&dev_priv->uncore); 2859 1.11 riastrad 2860 1.20 riastrad gen11_gt_irq_reset(&dev_priv->gt); 2861 1.20 riastrad gen11_display_irq_reset(dev_priv); 2862 1.11 riastrad 2863 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN11_GU_MISC_); 2864 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_PCU_); 2865 1.11 riastrad } 2866 1.11 riastrad 2867 1.20 riastrad void gen8_irq_power_well_post_enable(struct drm_i915_private *dev_priv, 2868 1.20 riastrad u8 pipe_mask) 2869 1.11 riastrad { 2870 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2871 1.20 riastrad 2872 1.20 riastrad u32 extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN; 2873 1.20 riastrad enum pipe pipe; 2874 1.20 riastrad 2875 1.20 riastrad spin_lock_irq(&dev_priv->irq_lock); 2876 1.11 riastrad 2877 1.20 riastrad if (!intel_irqs_enabled(dev_priv)) { 2878 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 2879 1.5 riastrad return; 2880 1.20 riastrad } 2881 1.5 riastrad 2882 1.20 riastrad for_each_pipe_masked(dev_priv, pipe, pipe_mask) 2883 1.20 riastrad GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe, 2884 1.20 riastrad dev_priv->de_irq_mask[pipe], 2885 1.20 riastrad ~dev_priv->de_irq_mask[pipe] | extra_ier); 2886 1.11 riastrad 2887 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 2888 1.5 riastrad } 2889 1.1 riastrad 2890 1.20 riastrad void gen8_irq_power_well_pre_disable(struct drm_i915_private *dev_priv, 2891 1.20 riastrad u8 pipe_mask) 2892 1.5 riastrad { 2893 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2894 1.20 riastrad enum pipe pipe; 2895 1.20 riastrad 2896 1.20 riastrad spin_lock_irq(&dev_priv->irq_lock); 2897 1.1 riastrad 2898 1.20 riastrad if (!intel_irqs_enabled(dev_priv)) { 2899 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 2900 1.1 riastrad return; 2901 1.20 riastrad } 2902 1.1 riastrad 2903 1.20 riastrad for_each_pipe_masked(dev_priv, pipe, pipe_mask) 2904 1.20 riastrad GEN8_IRQ_RESET_NDX(uncore, DE_PIPE, pipe); 2905 1.5 riastrad 2906 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 2907 1.5 riastrad 2908 1.20 riastrad /* make sure we're done processing display irqs */ 2909 1.20 riastrad intel_synchronize_irq(dev_priv); 2910 1.1 riastrad } 2911 1.1 riastrad 2912 1.20 riastrad static void cherryview_irq_reset(struct drm_i915_private *dev_priv) 2913 1.1 riastrad { 2914 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 2915 1.1 riastrad 2916 1.20 riastrad I915_WRITE(GEN8_MASTER_IRQ, 0); 2917 1.20 riastrad POSTING_READ(GEN8_MASTER_IRQ); 2918 1.11 riastrad 2919 1.20 riastrad gen8_gt_irq_reset(&dev_priv->gt); 2920 1.11 riastrad 2921 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN8_PCU_); 2922 1.11 riastrad 2923 1.20 riastrad spin_lock_irq(&dev_priv->irq_lock); 2924 1.20 riastrad if (dev_priv->display_irqs_enabled) 2925 1.20 riastrad vlv_display_irq_reset(dev_priv); 2926 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 2927 1.11 riastrad } 2928 1.11 riastrad 2929 1.20 riastrad static u32 intel_hpd_enabled_irqs(struct drm_i915_private *dev_priv, 2930 1.20 riastrad const u32 hpd[HPD_NUM_PINS]) 2931 1.11 riastrad { 2932 1.20 riastrad struct intel_encoder *encoder; 2933 1.20 riastrad u32 enabled_irqs = 0; 2934 1.20 riastrad 2935 1.20 riastrad for_each_intel_encoder(&dev_priv->drm, encoder) 2936 1.20 riastrad if (dev_priv->hotplug.stats[encoder->hpd_pin].state == HPD_ENABLED) 2937 1.20 riastrad enabled_irqs |= hpd[encoder->hpd_pin]; 2938 1.1 riastrad 2939 1.20 riastrad return enabled_irqs; 2940 1.20 riastrad } 2941 1.1 riastrad 2942 1.20 riastrad static void ibx_hpd_detection_setup(struct drm_i915_private *dev_priv) 2943 1.20 riastrad { 2944 1.20 riastrad u32 hotplug; 2945 1.1 riastrad 2946 1.20 riastrad /* 2947 1.20 riastrad * Enable digital hotplug on the PCH, and configure the DP short pulse 2948 1.20 riastrad * duration to 2ms (which is the minimum in the Display Port spec). 2949 1.20 riastrad * The pulse duration bits are reserved on LPT+. 2950 1.20 riastrad */ 2951 1.20 riastrad hotplug = I915_READ(PCH_PORT_HOTPLUG); 2952 1.20 riastrad hotplug &= ~(PORTB_PULSE_DURATION_MASK | 2953 1.20 riastrad PORTC_PULSE_DURATION_MASK | 2954 1.20 riastrad PORTD_PULSE_DURATION_MASK); 2955 1.20 riastrad hotplug |= PORTB_HOTPLUG_ENABLE | PORTB_PULSE_DURATION_2ms; 2956 1.20 riastrad hotplug |= PORTC_HOTPLUG_ENABLE | PORTC_PULSE_DURATION_2ms; 2957 1.20 riastrad hotplug |= PORTD_HOTPLUG_ENABLE | PORTD_PULSE_DURATION_2ms; 2958 1.20 riastrad /* 2959 1.20 riastrad * When CPU and PCH are on the same package, port A 2960 1.20 riastrad * HPD must be enabled in both north and south. 2961 1.20 riastrad */ 2962 1.20 riastrad if (HAS_PCH_LPT_LP(dev_priv)) 2963 1.20 riastrad hotplug |= PORTA_HOTPLUG_ENABLE; 2964 1.20 riastrad I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 2965 1.1 riastrad } 2966 1.1 riastrad 2967 1.20 riastrad static void ibx_hpd_irq_setup(struct drm_i915_private *dev_priv) 2968 1.1 riastrad { 2969 1.20 riastrad u32 hotplug_irqs, enabled_irqs; 2970 1.1 riastrad 2971 1.20 riastrad if (HAS_PCH_IBX(dev_priv)) { 2972 1.20 riastrad hotplug_irqs = SDE_HOTPLUG_MASK; 2973 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ibx); 2974 1.20 riastrad } else { 2975 1.20 riastrad hotplug_irqs = SDE_HOTPLUG_MASK_CPT; 2976 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_cpt); 2977 1.20 riastrad } 2978 1.1 riastrad 2979 1.20 riastrad ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 2980 1.5 riastrad 2981 1.20 riastrad ibx_hpd_detection_setup(dev_priv); 2982 1.11 riastrad } 2983 1.1 riastrad 2984 1.20 riastrad static void icp_hpd_detection_setup(struct drm_i915_private *dev_priv, 2985 1.20 riastrad u32 ddi_hotplug_enable_mask, 2986 1.20 riastrad u32 tc_hotplug_enable_mask) 2987 1.11 riastrad { 2988 1.20 riastrad u32 hotplug; 2989 1.20 riastrad 2990 1.20 riastrad hotplug = I915_READ(SHOTPLUG_CTL_DDI); 2991 1.20 riastrad hotplug |= ddi_hotplug_enable_mask; 2992 1.20 riastrad I915_WRITE(SHOTPLUG_CTL_DDI, hotplug); 2993 1.20 riastrad 2994 1.20 riastrad if (tc_hotplug_enable_mask) { 2995 1.20 riastrad hotplug = I915_READ(SHOTPLUG_CTL_TC); 2996 1.20 riastrad hotplug |= tc_hotplug_enable_mask; 2997 1.20 riastrad I915_WRITE(SHOTPLUG_CTL_TC, hotplug); 2998 1.20 riastrad } 2999 1.1 riastrad } 3000 1.1 riastrad 3001 1.20 riastrad static void icp_hpd_irq_setup(struct drm_i915_private *dev_priv, 3002 1.20 riastrad u32 sde_ddi_mask, u32 sde_tc_mask, 3003 1.20 riastrad u32 ddi_enable_mask, u32 tc_enable_mask, 3004 1.20 riastrad const u32 *pins) 3005 1.5 riastrad { 3006 1.20 riastrad u32 hotplug_irqs, enabled_irqs; 3007 1.5 riastrad 3008 1.20 riastrad hotplug_irqs = sde_ddi_mask | sde_tc_mask; 3009 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, pins); 3010 1.5 riastrad 3011 1.20 riastrad I915_WRITE(SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ); 3012 1.11 riastrad 3013 1.20 riastrad ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 3014 1.11 riastrad 3015 1.20 riastrad icp_hpd_detection_setup(dev_priv, ddi_enable_mask, tc_enable_mask); 3016 1.20 riastrad } 3017 1.11 riastrad 3018 1.20 riastrad /* 3019 1.20 riastrad * EHL doesn't need most of gen11_hpd_irq_setup, it's handling only the 3020 1.20 riastrad * equivalent of SDE. 3021 1.20 riastrad */ 3022 1.20 riastrad static void mcc_hpd_irq_setup(struct drm_i915_private *dev_priv) 3023 1.20 riastrad { 3024 1.20 riastrad icp_hpd_irq_setup(dev_priv, 3025 1.20 riastrad SDE_DDI_MASK_ICP, SDE_TC_HOTPLUG_ICP(PORT_TC1), 3026 1.20 riastrad ICP_DDI_HPD_ENABLE_MASK, ICP_TC_HPD_ENABLE(PORT_TC1), 3027 1.20 riastrad hpd_icp); 3028 1.11 riastrad } 3029 1.11 riastrad 3030 1.20 riastrad /* 3031 1.20 riastrad * JSP behaves exactly the same as MCC above except that port C is mapped to 3032 1.20 riastrad * the DDI-C pins instead of the TC1 pins. This means we should follow TGP's 3033 1.20 riastrad * masks & tables rather than ICP's masks & tables. 3034 1.20 riastrad */ 3035 1.20 riastrad static void jsp_hpd_irq_setup(struct drm_i915_private *dev_priv) 3036 1.11 riastrad { 3037 1.20 riastrad icp_hpd_irq_setup(dev_priv, 3038 1.20 riastrad SDE_DDI_MASK_TGP, 0, 3039 1.20 riastrad TGP_DDI_HPD_ENABLE_MASK, 0, 3040 1.20 riastrad hpd_tgp); 3041 1.11 riastrad } 3042 1.11 riastrad 3043 1.20 riastrad static void gen11_hpd_detection_setup(struct drm_i915_private *dev_priv) 3044 1.11 riastrad { 3045 1.20 riastrad u32 hotplug; 3046 1.11 riastrad 3047 1.20 riastrad hotplug = I915_READ(GEN11_TC_HOTPLUG_CTL); 3048 1.20 riastrad hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) | 3049 1.20 riastrad GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) | 3050 1.20 riastrad GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) | 3051 1.20 riastrad GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4); 3052 1.20 riastrad I915_WRITE(GEN11_TC_HOTPLUG_CTL, hotplug); 3053 1.11 riastrad 3054 1.20 riastrad hotplug = I915_READ(GEN11_TBT_HOTPLUG_CTL); 3055 1.20 riastrad hotplug |= GEN11_HOTPLUG_CTL_ENABLE(PORT_TC1) | 3056 1.20 riastrad GEN11_HOTPLUG_CTL_ENABLE(PORT_TC2) | 3057 1.20 riastrad GEN11_HOTPLUG_CTL_ENABLE(PORT_TC3) | 3058 1.20 riastrad GEN11_HOTPLUG_CTL_ENABLE(PORT_TC4); 3059 1.20 riastrad I915_WRITE(GEN11_TBT_HOTPLUG_CTL, hotplug); 3060 1.20 riastrad } 3061 1.11 riastrad 3062 1.20 riastrad static void gen11_hpd_irq_setup(struct drm_i915_private *dev_priv) 3063 1.20 riastrad { 3064 1.24 riastrad u32 hotplug_irqs, enabled_irqs __unused; 3065 1.20 riastrad const u32 *hpd; 3066 1.20 riastrad u32 val; 3067 1.11 riastrad 3068 1.20 riastrad hpd = INTEL_GEN(dev_priv) >= 12 ? hpd_gen12 : hpd_gen11; 3069 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd); 3070 1.20 riastrad hotplug_irqs = GEN11_DE_TC_HOTPLUG_MASK | GEN11_DE_TBT_HOTPLUG_MASK; 3071 1.11 riastrad 3072 1.20 riastrad val = I915_READ(GEN11_DE_HPD_IMR); 3073 1.20 riastrad val &= ~hotplug_irqs; 3074 1.20 riastrad I915_WRITE(GEN11_DE_HPD_IMR, val); 3075 1.20 riastrad POSTING_READ(GEN11_DE_HPD_IMR); 3076 1.5 riastrad 3077 1.20 riastrad gen11_hpd_detection_setup(dev_priv); 3078 1.5 riastrad 3079 1.20 riastrad if (INTEL_PCH_TYPE(dev_priv) >= PCH_TGP) 3080 1.20 riastrad icp_hpd_irq_setup(dev_priv, SDE_DDI_MASK_TGP, SDE_TC_MASK_TGP, 3081 1.20 riastrad TGP_DDI_HPD_ENABLE_MASK, 3082 1.20 riastrad TGP_TC_HPD_ENABLE_MASK, hpd_tgp); 3083 1.20 riastrad else if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 3084 1.20 riastrad icp_hpd_irq_setup(dev_priv, SDE_DDI_MASK_ICP, SDE_TC_MASK_ICP, 3085 1.20 riastrad ICP_DDI_HPD_ENABLE_MASK, 3086 1.20 riastrad ICP_TC_HPD_ENABLE_MASK, hpd_icp); 3087 1.5 riastrad } 3088 1.1 riastrad 3089 1.20 riastrad static void spt_hpd_detection_setup(struct drm_i915_private *dev_priv) 3090 1.1 riastrad { 3091 1.20 riastrad u32 val, hotplug; 3092 1.1 riastrad 3093 1.20 riastrad /* Display WA #1179 WaHardHangonHotPlug: cnp */ 3094 1.20 riastrad if (HAS_PCH_CNP(dev_priv)) { 3095 1.20 riastrad val = I915_READ(SOUTH_CHICKEN1); 3096 1.20 riastrad val &= ~CHASSIS_CLK_REQ_DURATION_MASK; 3097 1.20 riastrad val |= CHASSIS_CLK_REQ_DURATION(0xf); 3098 1.20 riastrad I915_WRITE(SOUTH_CHICKEN1, val); 3099 1.5 riastrad } 3100 1.5 riastrad 3101 1.20 riastrad /* Enable digital hotplug on the PCH */ 3102 1.11 riastrad hotplug = I915_READ(PCH_PORT_HOTPLUG); 3103 1.20 riastrad hotplug |= PORTA_HOTPLUG_ENABLE | 3104 1.20 riastrad PORTB_HOTPLUG_ENABLE | 3105 1.20 riastrad PORTC_HOTPLUG_ENABLE | 3106 1.20 riastrad PORTD_HOTPLUG_ENABLE; 3107 1.11 riastrad I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 3108 1.20 riastrad 3109 1.20 riastrad hotplug = I915_READ(PCH_PORT_HOTPLUG2); 3110 1.20 riastrad hotplug |= PORTE_HOTPLUG_ENABLE; 3111 1.20 riastrad I915_WRITE(PCH_PORT_HOTPLUG2, hotplug); 3112 1.11 riastrad } 3113 1.11 riastrad 3114 1.20 riastrad static void spt_hpd_irq_setup(struct drm_i915_private *dev_priv) 3115 1.11 riastrad { 3116 1.20 riastrad u32 hotplug_irqs, enabled_irqs; 3117 1.20 riastrad 3118 1.20 riastrad if (INTEL_PCH_TYPE(dev_priv) >= PCH_CNP) 3119 1.20 riastrad I915_WRITE(SHPD_FILTER_CNT, SHPD_FILTER_CNT_500_ADJ); 3120 1.11 riastrad 3121 1.11 riastrad hotplug_irqs = SDE_HOTPLUG_MASK_SPT; 3122 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_spt); 3123 1.11 riastrad 3124 1.11 riastrad ibx_display_interrupt_update(dev_priv, hotplug_irqs, enabled_irqs); 3125 1.11 riastrad 3126 1.20 riastrad spt_hpd_detection_setup(dev_priv); 3127 1.20 riastrad } 3128 1.20 riastrad 3129 1.20 riastrad static void ilk_hpd_detection_setup(struct drm_i915_private *dev_priv) 3130 1.20 riastrad { 3131 1.20 riastrad u32 hotplug; 3132 1.11 riastrad 3133 1.20 riastrad /* 3134 1.20 riastrad * Enable digital hotplug on the CPU, and configure the DP short pulse 3135 1.20 riastrad * duration to 2ms (which is the minimum in the Display Port spec) 3136 1.20 riastrad * The pulse duration bits are reserved on HSW+. 3137 1.20 riastrad */ 3138 1.20 riastrad hotplug = I915_READ(DIGITAL_PORT_HOTPLUG_CNTRL); 3139 1.20 riastrad hotplug &= ~DIGITAL_PORTA_PULSE_DURATION_MASK; 3140 1.20 riastrad hotplug |= DIGITAL_PORTA_HOTPLUG_ENABLE | 3141 1.20 riastrad DIGITAL_PORTA_PULSE_DURATION_2ms; 3142 1.20 riastrad I915_WRITE(DIGITAL_PORT_HOTPLUG_CNTRL, hotplug); 3143 1.11 riastrad } 3144 1.11 riastrad 3145 1.20 riastrad static void ilk_hpd_irq_setup(struct drm_i915_private *dev_priv) 3146 1.11 riastrad { 3147 1.20 riastrad u32 hotplug_irqs, enabled_irqs; 3148 1.11 riastrad 3149 1.20 riastrad if (INTEL_GEN(dev_priv) >= 8) { 3150 1.11 riastrad hotplug_irqs = GEN8_PORT_DP_A_HOTPLUG; 3151 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bdw); 3152 1.11 riastrad 3153 1.11 riastrad bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 3154 1.20 riastrad } else if (INTEL_GEN(dev_priv) >= 7) { 3155 1.11 riastrad hotplug_irqs = DE_DP_A_HOTPLUG_IVB; 3156 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ivb); 3157 1.11 riastrad 3158 1.11 riastrad ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 3159 1.11 riastrad } else { 3160 1.11 riastrad hotplug_irqs = DE_DP_A_HOTPLUG; 3161 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_ilk); 3162 1.11 riastrad 3163 1.11 riastrad ilk_update_display_irq(dev_priv, hotplug_irqs, enabled_irqs); 3164 1.11 riastrad } 3165 1.11 riastrad 3166 1.20 riastrad ilk_hpd_detection_setup(dev_priv); 3167 1.20 riastrad 3168 1.20 riastrad ibx_hpd_irq_setup(dev_priv); 3169 1.20 riastrad } 3170 1.20 riastrad 3171 1.20 riastrad static void __bxt_hpd_detection_setup(struct drm_i915_private *dev_priv, 3172 1.20 riastrad u32 enabled_irqs) 3173 1.20 riastrad { 3174 1.20 riastrad u32 hotplug; 3175 1.20 riastrad 3176 1.20 riastrad hotplug = I915_READ(PCH_PORT_HOTPLUG); 3177 1.20 riastrad hotplug |= PORTA_HOTPLUG_ENABLE | 3178 1.20 riastrad PORTB_HOTPLUG_ENABLE | 3179 1.20 riastrad PORTC_HOTPLUG_ENABLE; 3180 1.20 riastrad 3181 1.20 riastrad DRM_DEBUG_KMS("Invert bit setting: hp_ctl:%x hp_port:%x\n", 3182 1.20 riastrad hotplug, enabled_irqs); 3183 1.20 riastrad hotplug &= ~BXT_DDI_HPD_INVERT_MASK; 3184 1.20 riastrad 3185 1.11 riastrad /* 3186 1.20 riastrad * For BXT invert bit has to be set based on AOB design 3187 1.20 riastrad * for HPD detection logic, update it based on VBT fields. 3188 1.11 riastrad */ 3189 1.20 riastrad if ((enabled_irqs & BXT_DE_PORT_HP_DDIA) && 3190 1.20 riastrad intel_bios_is_port_hpd_inverted(dev_priv, PORT_A)) 3191 1.20 riastrad hotplug |= BXT_DDIA_HPD_INVERT; 3192 1.20 riastrad if ((enabled_irqs & BXT_DE_PORT_HP_DDIB) && 3193 1.20 riastrad intel_bios_is_port_hpd_inverted(dev_priv, PORT_B)) 3194 1.20 riastrad hotplug |= BXT_DDIB_HPD_INVERT; 3195 1.20 riastrad if ((enabled_irqs & BXT_DE_PORT_HP_DDIC) && 3196 1.20 riastrad intel_bios_is_port_hpd_inverted(dev_priv, PORT_C)) 3197 1.20 riastrad hotplug |= BXT_DDIC_HPD_INVERT; 3198 1.20 riastrad 3199 1.20 riastrad I915_WRITE(PCH_PORT_HOTPLUG, hotplug); 3200 1.20 riastrad } 3201 1.11 riastrad 3202 1.20 riastrad static void bxt_hpd_detection_setup(struct drm_i915_private *dev_priv) 3203 1.20 riastrad { 3204 1.20 riastrad __bxt_hpd_detection_setup(dev_priv, BXT_DE_PORT_HOTPLUG_MASK); 3205 1.11 riastrad } 3206 1.11 riastrad 3207 1.20 riastrad static void bxt_hpd_irq_setup(struct drm_i915_private *dev_priv) 3208 1.11 riastrad { 3209 1.20 riastrad u32 hotplug_irqs, enabled_irqs; 3210 1.11 riastrad 3211 1.20 riastrad enabled_irqs = intel_hpd_enabled_irqs(dev_priv, hpd_bxt); 3212 1.11 riastrad hotplug_irqs = BXT_DE_PORT_HOTPLUG_MASK; 3213 1.11 riastrad 3214 1.11 riastrad bdw_update_port_irq(dev_priv, hotplug_irqs, enabled_irqs); 3215 1.11 riastrad 3216 1.20 riastrad __bxt_hpd_detection_setup(dev_priv, enabled_irqs); 3217 1.1 riastrad } 3218 1.1 riastrad 3219 1.20 riastrad static void ibx_irq_postinstall(struct drm_i915_private *dev_priv) 3220 1.1 riastrad { 3221 1.5 riastrad u32 mask; 3222 1.5 riastrad 3223 1.20 riastrad if (HAS_PCH_NOP(dev_priv)) 3224 1.5 riastrad return; 3225 1.5 riastrad 3226 1.20 riastrad if (HAS_PCH_IBX(dev_priv)) 3227 1.5 riastrad mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 3228 1.20 riastrad else if (HAS_PCH_CPT(dev_priv) || HAS_PCH_LPT(dev_priv)) 3229 1.20 riastrad mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 3230 1.11 riastrad else 3231 1.20 riastrad mask = SDE_GMBUS_CPT; 3232 1.5 riastrad 3233 1.20 riastrad gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR); 3234 1.5 riastrad I915_WRITE(SDEIMR, ~mask); 3235 1.1 riastrad 3236 1.20 riastrad if (HAS_PCH_IBX(dev_priv) || HAS_PCH_CPT(dev_priv) || 3237 1.20 riastrad HAS_PCH_LPT(dev_priv)) 3238 1.20 riastrad ibx_hpd_detection_setup(dev_priv); 3239 1.20 riastrad else 3240 1.20 riastrad spt_hpd_detection_setup(dev_priv); 3241 1.5 riastrad } 3242 1.5 riastrad 3243 1.20 riastrad static void ilk_irq_postinstall(struct drm_i915_private *dev_priv) 3244 1.5 riastrad { 3245 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3246 1.5 riastrad u32 display_mask, extra_mask; 3247 1.5 riastrad 3248 1.20 riastrad if (INTEL_GEN(dev_priv) >= 7) { 3249 1.5 riastrad display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 3250 1.20 riastrad DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB); 3251 1.5 riastrad extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 3252 1.11 riastrad DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | 3253 1.11 riastrad DE_DP_A_HOTPLUG_IVB); 3254 1.1 riastrad } else { 3255 1.5 riastrad display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | 3256 1.20 riastrad DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE | 3257 1.20 riastrad DE_PIPEA_CRC_DONE | DE_POISON); 3258 1.11 riastrad extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | DE_PCU_EVENT | 3259 1.11 riastrad DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 3260 1.11 riastrad DE_DP_A_HOTPLUG); 3261 1.1 riastrad } 3262 1.1 riastrad 3263 1.20 riastrad if (IS_HASWELL(dev_priv)) { 3264 1.20 riastrad gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR); 3265 1.20 riastrad display_mask |= DE_EDP_PSR_INT_HSW; 3266 1.20 riastrad } 3267 1.20 riastrad 3268 1.5 riastrad dev_priv->irq_mask = ~display_mask; 3269 1.5 riastrad 3270 1.20 riastrad ibx_irq_pre_postinstall(dev_priv); 3271 1.11 riastrad 3272 1.20 riastrad GEN3_IRQ_INIT(uncore, DE, dev_priv->irq_mask, 3273 1.20 riastrad display_mask | extra_mask); 3274 1.11 riastrad 3275 1.20 riastrad gen5_gt_irq_postinstall(&dev_priv->gt); 3276 1.1 riastrad 3277 1.20 riastrad ilk_hpd_detection_setup(dev_priv); 3278 1.1 riastrad 3279 1.20 riastrad ibx_irq_postinstall(dev_priv); 3280 1.1 riastrad 3281 1.20 riastrad if (IS_IRONLAKE_M(dev_priv)) { 3282 1.5 riastrad /* Enable PCU event interrupts 3283 1.5 riastrad * 3284 1.5 riastrad * spinlocking not required here for correctness since interrupt 3285 1.5 riastrad * setup is guaranteed to run in single-threaded context. But we 3286 1.5 riastrad * need it to make the assert_spin_locked happy. */ 3287 1.11 riastrad spin_lock_irq(&dev_priv->irq_lock); 3288 1.20 riastrad ilk_enable_display_irq(dev_priv, DE_PCU_EVENT); 3289 1.11 riastrad spin_unlock_irq(&dev_priv->irq_lock); 3290 1.1 riastrad } 3291 1.5 riastrad } 3292 1.1 riastrad 3293 1.5 riastrad void valleyview_enable_display_irqs(struct drm_i915_private *dev_priv) 3294 1.5 riastrad { 3295 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 3296 1.1 riastrad 3297 1.5 riastrad if (dev_priv->display_irqs_enabled) 3298 1.5 riastrad return; 3299 1.1 riastrad 3300 1.5 riastrad dev_priv->display_irqs_enabled = true; 3301 1.1 riastrad 3302 1.20 riastrad if (intel_irqs_enabled(dev_priv)) { 3303 1.20 riastrad vlv_display_irq_reset(dev_priv); 3304 1.20 riastrad vlv_display_irq_postinstall(dev_priv); 3305 1.20 riastrad } 3306 1.5 riastrad } 3307 1.1 riastrad 3308 1.5 riastrad void valleyview_disable_display_irqs(struct drm_i915_private *dev_priv) 3309 1.5 riastrad { 3310 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 3311 1.1 riastrad 3312 1.5 riastrad if (!dev_priv->display_irqs_enabled) 3313 1.5 riastrad return; 3314 1.1 riastrad 3315 1.5 riastrad dev_priv->display_irqs_enabled = false; 3316 1.1 riastrad 3317 1.11 riastrad if (intel_irqs_enabled(dev_priv)) 3318 1.20 riastrad vlv_display_irq_reset(dev_priv); 3319 1.1 riastrad } 3320 1.1 riastrad 3321 1.20 riastrad 3322 1.20 riastrad static void valleyview_irq_postinstall(struct drm_i915_private *dev_priv) 3323 1.1 riastrad { 3324 1.20 riastrad gen5_gt_irq_postinstall(&dev_priv->gt); 3325 1.1 riastrad 3326 1.11 riastrad spin_lock_irq(&dev_priv->irq_lock); 3327 1.5 riastrad if (dev_priv->display_irqs_enabled) 3328 1.20 riastrad vlv_display_irq_postinstall(dev_priv); 3329 1.11 riastrad spin_unlock_irq(&dev_priv->irq_lock); 3330 1.1 riastrad 3331 1.1 riastrad I915_WRITE(VLV_MASTER_IER, MASTER_INTERRUPT_ENABLE); 3332 1.20 riastrad POSTING_READ(VLV_MASTER_IER); 3333 1.5 riastrad } 3334 1.5 riastrad 3335 1.20 riastrad static void gen8_de_irq_postinstall(struct drm_i915_private *dev_priv) 3336 1.5 riastrad { 3337 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3338 1.5 riastrad 3339 1.20 riastrad u32 de_pipe_masked = GEN8_PIPE_CDCLK_CRC_DONE; 3340 1.20 riastrad u32 de_pipe_enables; 3341 1.11 riastrad u32 de_port_masked = GEN8_AUX_CHANNEL_A; 3342 1.11 riastrad u32 de_port_enables; 3343 1.20 riastrad u32 de_misc_masked = GEN8_DE_EDP_PSR; 3344 1.18 riastrad enum pipe pipe; 3345 1.11 riastrad 3346 1.20 riastrad if (INTEL_GEN(dev_priv) <= 10) 3347 1.20 riastrad de_misc_masked |= GEN8_DE_MISC_GSE; 3348 1.20 riastrad 3349 1.20 riastrad if (INTEL_GEN(dev_priv) >= 9) { 3350 1.20 riastrad de_pipe_masked |= GEN9_DE_PIPE_IRQ_FAULT_ERRORS; 3351 1.11 riastrad de_port_masked |= GEN9_AUX_CHANNEL_B | GEN9_AUX_CHANNEL_C | 3352 1.11 riastrad GEN9_AUX_CHANNEL_D; 3353 1.20 riastrad if (IS_GEN9_LP(dev_priv)) 3354 1.11 riastrad de_port_masked |= BXT_DE_PORT_GMBUS; 3355 1.11 riastrad } else { 3356 1.20 riastrad de_pipe_masked |= GEN8_DE_PIPE_IRQ_FAULT_ERRORS; 3357 1.11 riastrad } 3358 1.11 riastrad 3359 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11) 3360 1.20 riastrad de_port_masked |= ICL_AUX_CHANNEL_E; 3361 1.20 riastrad 3362 1.20 riastrad if (IS_CNL_WITH_PORT_F(dev_priv) || INTEL_GEN(dev_priv) >= 11) 3363 1.20 riastrad de_port_masked |= CNL_AUX_CHANNEL_F; 3364 1.20 riastrad 3365 1.11 riastrad de_pipe_enables = de_pipe_masked | GEN8_PIPE_VBLANK | 3366 1.11 riastrad GEN8_PIPE_FIFO_UNDERRUN; 3367 1.11 riastrad 3368 1.11 riastrad de_port_enables = de_port_masked; 3369 1.20 riastrad if (IS_GEN9_LP(dev_priv)) 3370 1.11 riastrad de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; 3371 1.11 riastrad else if (IS_BROADWELL(dev_priv)) 3372 1.11 riastrad de_port_enables |= GEN8_PORT_DP_A_HOTPLUG; 3373 1.11 riastrad 3374 1.20 riastrad if (INTEL_GEN(dev_priv) >= 12) { 3375 1.20 riastrad enum transcoder trans; 3376 1.20 riastrad 3377 1.20 riastrad for (trans = TRANSCODER_A; trans <= TRANSCODER_D; trans++) { 3378 1.20 riastrad enum intel_display_power_domain domain; 3379 1.20 riastrad 3380 1.20 riastrad domain = POWER_DOMAIN_TRANSCODER(trans); 3381 1.20 riastrad if (!intel_display_power_is_enabled(dev_priv, domain)) 3382 1.20 riastrad continue; 3383 1.20 riastrad 3384 1.20 riastrad gen3_assert_iir_is_zero(uncore, TRANS_PSR_IIR(trans)); 3385 1.20 riastrad } 3386 1.20 riastrad } else { 3387 1.20 riastrad gen3_assert_iir_is_zero(uncore, EDP_PSR_IIR); 3388 1.20 riastrad } 3389 1.20 riastrad 3390 1.20 riastrad for_each_pipe(dev_priv, pipe) { 3391 1.20 riastrad dev_priv->de_irq_mask[pipe] = ~de_pipe_masked; 3392 1.5 riastrad 3393 1.11 riastrad if (intel_display_power_is_enabled(dev_priv, 3394 1.11 riastrad POWER_DOMAIN_PIPE(pipe))) 3395 1.20 riastrad GEN8_IRQ_INIT_NDX(uncore, DE_PIPE, pipe, 3396 1.11 riastrad dev_priv->de_irq_mask[pipe], 3397 1.11 riastrad de_pipe_enables); 3398 1.20 riastrad } 3399 1.11 riastrad 3400 1.20 riastrad GEN3_IRQ_INIT(uncore, GEN8_DE_PORT_, ~de_port_masked, de_port_enables); 3401 1.20 riastrad GEN3_IRQ_INIT(uncore, GEN8_DE_MISC_, ~de_misc_masked, de_misc_masked); 3402 1.5 riastrad 3403 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11) { 3404 1.20 riastrad u32 de_hpd_masked = 0; 3405 1.20 riastrad u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK | 3406 1.20 riastrad GEN11_DE_TBT_HOTPLUG_MASK; 3407 1.11 riastrad 3408 1.20 riastrad GEN3_IRQ_INIT(uncore, GEN11_DE_HPD_, ~de_hpd_masked, 3409 1.20 riastrad de_hpd_enables); 3410 1.20 riastrad gen11_hpd_detection_setup(dev_priv); 3411 1.20 riastrad } else if (IS_GEN9_LP(dev_priv)) { 3412 1.20 riastrad bxt_hpd_detection_setup(dev_priv); 3413 1.20 riastrad } else if (IS_BROADWELL(dev_priv)) { 3414 1.20 riastrad ilk_hpd_detection_setup(dev_priv); 3415 1.20 riastrad } 3416 1.1 riastrad } 3417 1.1 riastrad 3418 1.20 riastrad static void gen8_irq_postinstall(struct drm_i915_private *dev_priv) 3419 1.11 riastrad { 3420 1.20 riastrad if (HAS_PCH_SPLIT(dev_priv)) 3421 1.20 riastrad ibx_irq_pre_postinstall(dev_priv); 3422 1.11 riastrad 3423 1.20 riastrad gen8_gt_irq_postinstall(&dev_priv->gt); 3424 1.20 riastrad gen8_de_irq_postinstall(dev_priv); 3425 1.11 riastrad 3426 1.20 riastrad if (HAS_PCH_SPLIT(dev_priv)) 3427 1.20 riastrad ibx_irq_postinstall(dev_priv); 3428 1.11 riastrad 3429 1.24 riastrad gen8_master_intr_enable(&dev_priv->uncore); 3430 1.11 riastrad } 3431 1.11 riastrad 3432 1.20 riastrad static void icp_irq_postinstall(struct drm_i915_private *dev_priv) 3433 1.5 riastrad { 3434 1.20 riastrad u32 mask = SDE_GMBUS_ICP; 3435 1.5 riastrad 3436 1.20 riastrad WARN_ON(I915_READ(SDEIER) != 0); 3437 1.20 riastrad I915_WRITE(SDEIER, 0xffffffff); 3438 1.20 riastrad POSTING_READ(SDEIER); 3439 1.5 riastrad 3440 1.20 riastrad gen3_assert_iir_is_zero(&dev_priv->uncore, SDEIIR); 3441 1.20 riastrad I915_WRITE(SDEIMR, ~mask); 3442 1.11 riastrad 3443 1.20 riastrad if (HAS_PCH_TGP(dev_priv)) 3444 1.20 riastrad icp_hpd_detection_setup(dev_priv, TGP_DDI_HPD_ENABLE_MASK, 3445 1.20 riastrad TGP_TC_HPD_ENABLE_MASK); 3446 1.20 riastrad else if (HAS_PCH_JSP(dev_priv)) 3447 1.20 riastrad icp_hpd_detection_setup(dev_priv, TGP_DDI_HPD_ENABLE_MASK, 0); 3448 1.20 riastrad else if (HAS_PCH_MCC(dev_priv)) 3449 1.20 riastrad icp_hpd_detection_setup(dev_priv, ICP_DDI_HPD_ENABLE_MASK, 3450 1.20 riastrad ICP_TC_HPD_ENABLE(PORT_TC1)); 3451 1.20 riastrad else 3452 1.20 riastrad icp_hpd_detection_setup(dev_priv, ICP_DDI_HPD_ENABLE_MASK, 3453 1.20 riastrad ICP_TC_HPD_ENABLE_MASK); 3454 1.5 riastrad } 3455 1.5 riastrad 3456 1.20 riastrad static void gen11_irq_postinstall(struct drm_i915_private *dev_priv) 3457 1.1 riastrad { 3458 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3459 1.20 riastrad u32 gu_misc_masked = GEN11_GU_MISC_GSE; 3460 1.1 riastrad 3461 1.20 riastrad if (INTEL_PCH_TYPE(dev_priv) >= PCH_ICP) 3462 1.20 riastrad icp_irq_postinstall(dev_priv); 3463 1.1 riastrad 3464 1.20 riastrad gen11_gt_irq_postinstall(&dev_priv->gt); 3465 1.20 riastrad gen8_de_irq_postinstall(dev_priv); 3466 1.5 riastrad 3467 1.20 riastrad GEN3_IRQ_INIT(uncore, GEN11_GU_MISC_, ~gu_misc_masked, gu_misc_masked); 3468 1.1 riastrad 3469 1.20 riastrad I915_WRITE(GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE); 3470 1.5 riastrad 3471 1.24 riastrad gen11_master_intr_enable(uncore); 3472 1.20 riastrad POSTING_READ(GEN11_GFX_MSTR_IRQ); 3473 1.1 riastrad } 3474 1.1 riastrad 3475 1.20 riastrad static void cherryview_irq_postinstall(struct drm_i915_private *dev_priv) 3476 1.1 riastrad { 3477 1.20 riastrad gen8_gt_irq_postinstall(&dev_priv->gt); 3478 1.1 riastrad 3479 1.20 riastrad spin_lock_irq(&dev_priv->irq_lock); 3480 1.20 riastrad if (dev_priv->display_irqs_enabled) 3481 1.20 riastrad vlv_display_irq_postinstall(dev_priv); 3482 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 3483 1.1 riastrad 3484 1.20 riastrad I915_WRITE(GEN8_MASTER_IRQ, GEN8_MASTER_IRQ_CONTROL); 3485 1.11 riastrad POSTING_READ(GEN8_MASTER_IRQ); 3486 1.1 riastrad } 3487 1.1 riastrad 3488 1.20 riastrad static void i8xx_irq_reset(struct drm_i915_private *dev_priv) 3489 1.1 riastrad { 3490 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3491 1.20 riastrad 3492 1.20 riastrad i9xx_pipestat_irq_reset(dev_priv); 3493 1.1 riastrad 3494 1.20 riastrad GEN2_IRQ_RESET(uncore); 3495 1.1 riastrad } 3496 1.1 riastrad 3497 1.20 riastrad static void i8xx_irq_postinstall(struct drm_i915_private *dev_priv) 3498 1.1 riastrad { 3499 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3500 1.20 riastrad u16 enable_mask; 3501 1.1 riastrad 3502 1.20 riastrad intel_uncore_write16(uncore, 3503 1.20 riastrad EMR, 3504 1.20 riastrad ~(I915_ERROR_PAGE_TABLE | 3505 1.20 riastrad I915_ERROR_MEMORY_REFRESH)); 3506 1.1 riastrad 3507 1.1 riastrad /* Unmask the interrupts that we always want on. */ 3508 1.1 riastrad dev_priv->irq_mask = 3509 1.1 riastrad ~(I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3510 1.1 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3511 1.20 riastrad I915_MASTER_ERROR_INTERRUPT); 3512 1.20 riastrad 3513 1.20 riastrad enable_mask = 3514 1.20 riastrad I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3515 1.20 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3516 1.20 riastrad I915_MASTER_ERROR_INTERRUPT | 3517 1.20 riastrad I915_USER_INTERRUPT; 3518 1.20 riastrad 3519 1.20 riastrad GEN2_IRQ_INIT(uncore, dev_priv->irq_mask, enable_mask); 3520 1.1 riastrad 3521 1.5 riastrad /* Interrupt setup is already guaranteed to be single-threaded, this is 3522 1.5 riastrad * just to make the assert_spin_locked check happy. */ 3523 1.11 riastrad spin_lock_irq(&dev_priv->irq_lock); 3524 1.5 riastrad i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3525 1.5 riastrad i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3526 1.11 riastrad spin_unlock_irq(&dev_priv->irq_lock); 3527 1.20 riastrad } 3528 1.20 riastrad 3529 1.20 riastrad static void i8xx_error_irq_ack(struct drm_i915_private *i915, 3530 1.20 riastrad u16 *eir, u16 *eir_stuck) 3531 1.20 riastrad { 3532 1.20 riastrad struct intel_uncore *uncore = &i915->uncore; 3533 1.20 riastrad u16 emr; 3534 1.20 riastrad 3535 1.20 riastrad *eir = intel_uncore_read16(uncore, EIR); 3536 1.20 riastrad 3537 1.20 riastrad if (*eir) 3538 1.20 riastrad intel_uncore_write16(uncore, EIR, *eir); 3539 1.20 riastrad 3540 1.20 riastrad *eir_stuck = intel_uncore_read16(uncore, EIR); 3541 1.20 riastrad if (*eir_stuck == 0) 3542 1.20 riastrad return; 3543 1.20 riastrad 3544 1.20 riastrad /* 3545 1.20 riastrad * Toggle all EMR bits to make sure we get an edge 3546 1.20 riastrad * in the ISR master error bit if we don't clear 3547 1.20 riastrad * all the EIR bits. Otherwise the edge triggered 3548 1.20 riastrad * IIR on i965/g4x wouldn't notice that an interrupt 3549 1.20 riastrad * is still pending. Also some EIR bits can't be 3550 1.20 riastrad * cleared except by handling the underlying error 3551 1.20 riastrad * (or by a GPU reset) so we mask any bit that 3552 1.20 riastrad * remains set. 3553 1.20 riastrad */ 3554 1.20 riastrad emr = intel_uncore_read16(uncore, EMR); 3555 1.20 riastrad intel_uncore_write16(uncore, EMR, 0xffff); 3556 1.20 riastrad intel_uncore_write16(uncore, EMR, emr | *eir_stuck); 3557 1.20 riastrad } 3558 1.20 riastrad 3559 1.20 riastrad static void i8xx_error_irq_handler(struct drm_i915_private *dev_priv, 3560 1.20 riastrad u16 eir, u16 eir_stuck) 3561 1.20 riastrad { 3562 1.20 riastrad DRM_DEBUG("Master Error: EIR 0x%04x\n", eir); 3563 1.5 riastrad 3564 1.20 riastrad if (eir_stuck) 3565 1.20 riastrad DRM_DEBUG_DRIVER("EIR stuck: 0x%04x, masked\n", eir_stuck); 3566 1.1 riastrad } 3567 1.1 riastrad 3568 1.20 riastrad static void i9xx_error_irq_ack(struct drm_i915_private *dev_priv, 3569 1.20 riastrad u32 *eir, u32 *eir_stuck) 3570 1.5 riastrad { 3571 1.20 riastrad u32 emr; 3572 1.20 riastrad 3573 1.20 riastrad *eir = I915_READ(EIR); 3574 1.5 riastrad 3575 1.20 riastrad I915_WRITE(EIR, *eir); 3576 1.5 riastrad 3577 1.20 riastrad *eir_stuck = I915_READ(EIR); 3578 1.20 riastrad if (*eir_stuck == 0) 3579 1.20 riastrad return; 3580 1.5 riastrad 3581 1.20 riastrad /* 3582 1.20 riastrad * Toggle all EMR bits to make sure we get an edge 3583 1.20 riastrad * in the ISR master error bit if we don't clear 3584 1.20 riastrad * all the EIR bits. Otherwise the edge triggered 3585 1.20 riastrad * IIR on i965/g4x wouldn't notice that an interrupt 3586 1.20 riastrad * is still pending. Also some EIR bits can't be 3587 1.20 riastrad * cleared except by handling the underlying error 3588 1.20 riastrad * (or by a GPU reset) so we mask any bit that 3589 1.20 riastrad * remains set. 3590 1.5 riastrad */ 3591 1.20 riastrad emr = I915_READ(EMR); 3592 1.20 riastrad I915_WRITE(EMR, 0xffffffff); 3593 1.20 riastrad I915_WRITE(EMR, emr | *eir_stuck); 3594 1.20 riastrad } 3595 1.5 riastrad 3596 1.20 riastrad static void i9xx_error_irq_handler(struct drm_i915_private *dev_priv, 3597 1.20 riastrad u32 eir, u32 eir_stuck) 3598 1.20 riastrad { 3599 1.20 riastrad DRM_DEBUG("Master Error, EIR 0x%08x\n", eir); 3600 1.5 riastrad 3601 1.20 riastrad if (eir_stuck) 3602 1.20 riastrad DRM_DEBUG_DRIVER("EIR stuck: 0x%08x, masked\n", eir_stuck); 3603 1.5 riastrad } 3604 1.5 riastrad 3605 1.2 riastrad static irqreturn_t i8xx_irq_handler(DRM_IRQ_ARGS) 3606 1.1 riastrad { 3607 1.20 riastrad struct drm_i915_private *dev_priv = arg; 3608 1.20 riastrad irqreturn_t ret = IRQ_NONE; 3609 1.1 riastrad 3610 1.11 riastrad if (!intel_irqs_enabled(dev_priv)) 3611 1.11 riastrad return IRQ_NONE; 3612 1.11 riastrad 3613 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 3614 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 3615 1.20 riastrad 3616 1.20 riastrad do { 3617 1.20 riastrad u32 pipe_stats[I915_MAX_PIPES] = {}; 3618 1.20 riastrad u16 eir = 0, eir_stuck = 0; 3619 1.20 riastrad u16 iir; 3620 1.20 riastrad 3621 1.20 riastrad iir = intel_uncore_read16(&dev_priv->uncore, GEN2_IIR); 3622 1.20 riastrad if (iir == 0) 3623 1.20 riastrad break; 3624 1.20 riastrad 3625 1.20 riastrad ret = IRQ_HANDLED; 3626 1.1 riastrad 3627 1.20 riastrad /* Call regardless, as some status bits might not be 3628 1.20 riastrad * signalled in iir */ 3629 1.20 riastrad i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3630 1.1 riastrad 3631 1.20 riastrad if (iir & I915_MASTER_ERROR_INTERRUPT) 3632 1.20 riastrad i8xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 3633 1.1 riastrad 3634 1.20 riastrad intel_uncore_write16(&dev_priv->uncore, GEN2_IIR, iir); 3635 1.1 riastrad 3636 1.1 riastrad if (iir & I915_USER_INTERRUPT) 3637 1.20 riastrad intel_engine_signal_breadcrumbs(dev_priv->engine[RCS0]); 3638 1.1 riastrad 3639 1.20 riastrad if (iir & I915_MASTER_ERROR_INTERRUPT) 3640 1.20 riastrad i8xx_error_irq_handler(dev_priv, eir, eir_stuck); 3641 1.1 riastrad 3642 1.20 riastrad i8xx_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3643 1.20 riastrad } while (0); 3644 1.1 riastrad 3645 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 3646 1.1 riastrad 3647 1.20 riastrad return ret; 3648 1.1 riastrad } 3649 1.1 riastrad 3650 1.20 riastrad static void i915_irq_reset(struct drm_i915_private *dev_priv) 3651 1.1 riastrad { 3652 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3653 1.1 riastrad 3654 1.20 riastrad if (I915_HAS_HOTPLUG(dev_priv)) { 3655 1.11 riastrad i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 3656 1.1 riastrad I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3657 1.1 riastrad } 3658 1.1 riastrad 3659 1.20 riastrad i9xx_pipestat_irq_reset(dev_priv); 3660 1.20 riastrad 3661 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN2_); 3662 1.1 riastrad } 3663 1.1 riastrad 3664 1.20 riastrad static void i915_irq_postinstall(struct drm_i915_private *dev_priv) 3665 1.1 riastrad { 3666 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3667 1.1 riastrad u32 enable_mask; 3668 1.1 riastrad 3669 1.20 riastrad I915_WRITE(EMR, ~(I915_ERROR_PAGE_TABLE | 3670 1.20 riastrad I915_ERROR_MEMORY_REFRESH)); 3671 1.1 riastrad 3672 1.1 riastrad /* Unmask the interrupts that we always want on. */ 3673 1.1 riastrad dev_priv->irq_mask = 3674 1.1 riastrad ~(I915_ASLE_INTERRUPT | 3675 1.1 riastrad I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3676 1.1 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3677 1.20 riastrad I915_MASTER_ERROR_INTERRUPT); 3678 1.1 riastrad 3679 1.1 riastrad enable_mask = 3680 1.1 riastrad I915_ASLE_INTERRUPT | 3681 1.1 riastrad I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3682 1.1 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3683 1.20 riastrad I915_MASTER_ERROR_INTERRUPT | 3684 1.1 riastrad I915_USER_INTERRUPT; 3685 1.1 riastrad 3686 1.20 riastrad if (I915_HAS_HOTPLUG(dev_priv)) { 3687 1.1 riastrad /* Enable in IER... */ 3688 1.1 riastrad enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 3689 1.1 riastrad /* and unmask in IMR */ 3690 1.1 riastrad dev_priv->irq_mask &= ~I915_DISPLAY_PORT_INTERRUPT; 3691 1.1 riastrad } 3692 1.1 riastrad 3693 1.20 riastrad GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask); 3694 1.5 riastrad 3695 1.5 riastrad /* Interrupt setup is already guaranteed to be single-threaded, this is 3696 1.5 riastrad * just to make the assert_spin_locked check happy. */ 3697 1.11 riastrad spin_lock_irq(&dev_priv->irq_lock); 3698 1.5 riastrad i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3699 1.5 riastrad i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3700 1.11 riastrad spin_unlock_irq(&dev_priv->irq_lock); 3701 1.5 riastrad 3702 1.20 riastrad i915_enable_asle_pipestat(dev_priv); 3703 1.1 riastrad } 3704 1.1 riastrad 3705 1.2 riastrad static irqreturn_t i915_irq_handler(DRM_IRQ_ARGS) 3706 1.1 riastrad { 3707 1.20 riastrad struct drm_i915_private *dev_priv = arg; 3708 1.20 riastrad irqreturn_t ret = IRQ_NONE; 3709 1.1 riastrad 3710 1.11 riastrad if (!intel_irqs_enabled(dev_priv)) 3711 1.11 riastrad return IRQ_NONE; 3712 1.11 riastrad 3713 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 3714 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 3715 1.20 riastrad 3716 1.1 riastrad do { 3717 1.20 riastrad u32 pipe_stats[I915_MAX_PIPES] = {}; 3718 1.20 riastrad u32 eir = 0, eir_stuck = 0; 3719 1.20 riastrad u32 hotplug_status = 0; 3720 1.20 riastrad u32 iir; 3721 1.1 riastrad 3722 1.20 riastrad iir = I915_READ(GEN2_IIR); 3723 1.20 riastrad if (iir == 0) 3724 1.20 riastrad break; 3725 1.1 riastrad 3726 1.20 riastrad ret = IRQ_HANDLED; 3727 1.1 riastrad 3728 1.20 riastrad if (I915_HAS_HOTPLUG(dev_priv) && 3729 1.11 riastrad iir & I915_DISPLAY_PORT_INTERRUPT) 3730 1.20 riastrad hotplug_status = i9xx_hpd_irq_ack(dev_priv); 3731 1.1 riastrad 3732 1.20 riastrad /* Call regardless, as some status bits might not be 3733 1.20 riastrad * signalled in iir */ 3734 1.20 riastrad i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3735 1.1 riastrad 3736 1.20 riastrad if (iir & I915_MASTER_ERROR_INTERRUPT) 3737 1.20 riastrad i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 3738 1.1 riastrad 3739 1.20 riastrad I915_WRITE(GEN2_IIR, iir); 3740 1.1 riastrad 3741 1.20 riastrad if (iir & I915_USER_INTERRUPT) 3742 1.20 riastrad intel_engine_signal_breadcrumbs(dev_priv->engine[RCS0]); 3743 1.1 riastrad 3744 1.20 riastrad if (iir & I915_MASTER_ERROR_INTERRUPT) 3745 1.20 riastrad i9xx_error_irq_handler(dev_priv, eir, eir_stuck); 3746 1.1 riastrad 3747 1.20 riastrad if (hotplug_status) 3748 1.20 riastrad i9xx_hpd_irq_handler(dev_priv, hotplug_status); 3749 1.1 riastrad 3750 1.20 riastrad i915_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3751 1.20 riastrad } while (0); 3752 1.1 riastrad 3753 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 3754 1.1 riastrad 3755 1.20 riastrad return ret; 3756 1.1 riastrad } 3757 1.1 riastrad 3758 1.20 riastrad static void i965_irq_reset(struct drm_i915_private *dev_priv) 3759 1.1 riastrad { 3760 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3761 1.1 riastrad 3762 1.11 riastrad i915_hotplug_interrupt_update(dev_priv, 0xffffffff, 0); 3763 1.1 riastrad I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT)); 3764 1.1 riastrad 3765 1.20 riastrad i9xx_pipestat_irq_reset(dev_priv); 3766 1.20 riastrad 3767 1.20 riastrad GEN3_IRQ_RESET(uncore, GEN2_); 3768 1.1 riastrad } 3769 1.1 riastrad 3770 1.20 riastrad static void i965_irq_postinstall(struct drm_i915_private *dev_priv) 3771 1.1 riastrad { 3772 1.20 riastrad struct intel_uncore *uncore = &dev_priv->uncore; 3773 1.1 riastrad u32 enable_mask; 3774 1.1 riastrad u32 error_mask; 3775 1.1 riastrad 3776 1.1 riastrad /* 3777 1.1 riastrad * Enable some error detection, note the instruction error mask 3778 1.1 riastrad * bit is reserved, so we leave it masked. 3779 1.1 riastrad */ 3780 1.20 riastrad if (IS_G4X(dev_priv)) { 3781 1.1 riastrad error_mask = ~(GM45_ERROR_PAGE_TABLE | 3782 1.1 riastrad GM45_ERROR_MEM_PRIV | 3783 1.1 riastrad GM45_ERROR_CP_PRIV | 3784 1.1 riastrad I915_ERROR_MEMORY_REFRESH); 3785 1.1 riastrad } else { 3786 1.1 riastrad error_mask = ~(I915_ERROR_PAGE_TABLE | 3787 1.1 riastrad I915_ERROR_MEMORY_REFRESH); 3788 1.1 riastrad } 3789 1.1 riastrad I915_WRITE(EMR, error_mask); 3790 1.1 riastrad 3791 1.20 riastrad /* Unmask the interrupts that we always want on. */ 3792 1.20 riastrad dev_priv->irq_mask = 3793 1.20 riastrad ~(I915_ASLE_INTERRUPT | 3794 1.20 riastrad I915_DISPLAY_PORT_INTERRUPT | 3795 1.20 riastrad I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3796 1.20 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3797 1.20 riastrad I915_MASTER_ERROR_INTERRUPT); 3798 1.20 riastrad 3799 1.20 riastrad enable_mask = 3800 1.20 riastrad I915_ASLE_INTERRUPT | 3801 1.20 riastrad I915_DISPLAY_PORT_INTERRUPT | 3802 1.20 riastrad I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 3803 1.20 riastrad I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 3804 1.20 riastrad I915_MASTER_ERROR_INTERRUPT | 3805 1.20 riastrad I915_USER_INTERRUPT; 3806 1.20 riastrad 3807 1.20 riastrad if (IS_G4X(dev_priv)) 3808 1.20 riastrad enable_mask |= I915_BSD_USER_INTERRUPT; 3809 1.1 riastrad 3810 1.20 riastrad GEN3_IRQ_INIT(uncore, GEN2_, dev_priv->irq_mask, enable_mask); 3811 1.5 riastrad 3812 1.20 riastrad /* Interrupt setup is already guaranteed to be single-threaded, this is 3813 1.20 riastrad * just to make the assert_spin_locked check happy. */ 3814 1.20 riastrad spin_lock_irq(&dev_priv->irq_lock); 3815 1.20 riastrad i915_enable_pipestat(dev_priv, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 3816 1.20 riastrad i915_enable_pipestat(dev_priv, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 3817 1.20 riastrad i915_enable_pipestat(dev_priv, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 3818 1.20 riastrad spin_unlock_irq(&dev_priv->irq_lock); 3819 1.5 riastrad 3820 1.20 riastrad i915_enable_asle_pipestat(dev_priv); 3821 1.5 riastrad } 3822 1.5 riastrad 3823 1.20 riastrad static void i915_hpd_irq_setup(struct drm_i915_private *dev_priv) 3824 1.5 riastrad { 3825 1.5 riastrad u32 hotplug_en; 3826 1.5 riastrad 3827 1.20 riastrad lockdep_assert_held(&dev_priv->irq_lock); 3828 1.1 riastrad 3829 1.11 riastrad /* Note HDMI and DP share hotplug bits */ 3830 1.11 riastrad /* enable bits are the same for all generations */ 3831 1.20 riastrad hotplug_en = intel_hpd_enabled_irqs(dev_priv, hpd_mask_i915); 3832 1.11 riastrad /* Programming the CRT detection parameters tends 3833 1.11 riastrad to generate a spurious hotplug event about three 3834 1.11 riastrad seconds later. So just do it once. 3835 1.11 riastrad */ 3836 1.20 riastrad if (IS_G4X(dev_priv)) 3837 1.11 riastrad hotplug_en |= CRT_HOTPLUG_ACTIVATION_PERIOD_64; 3838 1.11 riastrad hotplug_en |= CRT_HOTPLUG_VOLTAGE_COMPARE_50; 3839 1.5 riastrad 3840 1.11 riastrad /* Ignore TV since it's buggy */ 3841 1.11 riastrad i915_hotplug_interrupt_update_locked(dev_priv, 3842 1.11 riastrad HOTPLUG_INT_EN_MASK | 3843 1.11 riastrad CRT_HOTPLUG_VOLTAGE_COMPARE_MASK | 3844 1.11 riastrad CRT_HOTPLUG_ACTIVATION_PERIOD_64, 3845 1.11 riastrad hotplug_en); 3846 1.1 riastrad } 3847 1.1 riastrad 3848 1.2 riastrad static irqreturn_t i965_irq_handler(DRM_IRQ_ARGS) 3849 1.1 riastrad { 3850 1.20 riastrad struct drm_i915_private *dev_priv = arg; 3851 1.20 riastrad irqreturn_t ret = IRQ_NONE; 3852 1.1 riastrad 3853 1.11 riastrad if (!intel_irqs_enabled(dev_priv)) 3854 1.11 riastrad return IRQ_NONE; 3855 1.11 riastrad 3856 1.20 riastrad /* IRQs are synced during runtime_suspend, we don't require a wakeref */ 3857 1.20 riastrad disable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 3858 1.1 riastrad 3859 1.20 riastrad do { 3860 1.20 riastrad u32 pipe_stats[I915_MAX_PIPES] = {}; 3861 1.20 riastrad u32 eir = 0, eir_stuck = 0; 3862 1.20 riastrad u32 hotplug_status = 0; 3863 1.20 riastrad u32 iir; 3864 1.1 riastrad 3865 1.20 riastrad iir = I915_READ(GEN2_IIR); 3866 1.20 riastrad if (iir == 0) 3867 1.1 riastrad break; 3868 1.1 riastrad 3869 1.1 riastrad ret = IRQ_HANDLED; 3870 1.1 riastrad 3871 1.11 riastrad if (iir & I915_DISPLAY_PORT_INTERRUPT) 3872 1.20 riastrad hotplug_status = i9xx_hpd_irq_ack(dev_priv); 3873 1.1 riastrad 3874 1.20 riastrad /* Call regardless, as some status bits might not be 3875 1.20 riastrad * signalled in iir */ 3876 1.20 riastrad i9xx_pipestat_irq_ack(dev_priv, iir, pipe_stats); 3877 1.1 riastrad 3878 1.20 riastrad if (iir & I915_MASTER_ERROR_INTERRUPT) 3879 1.20 riastrad i9xx_error_irq_ack(dev_priv, &eir, &eir_stuck); 3880 1.1 riastrad 3881 1.20 riastrad I915_WRITE(GEN2_IIR, iir); 3882 1.1 riastrad 3883 1.20 riastrad if (iir & I915_USER_INTERRUPT) 3884 1.20 riastrad intel_engine_signal_breadcrumbs(dev_priv->engine[RCS0]); 3885 1.5 riastrad 3886 1.20 riastrad if (iir & I915_BSD_USER_INTERRUPT) 3887 1.20 riastrad intel_engine_signal_breadcrumbs(dev_priv->engine[VCS0]); 3888 1.5 riastrad 3889 1.20 riastrad if (iir & I915_MASTER_ERROR_INTERRUPT) 3890 1.20 riastrad i9xx_error_irq_handler(dev_priv, eir, eir_stuck); 3891 1.1 riastrad 3892 1.20 riastrad if (hotplug_status) 3893 1.20 riastrad i9xx_hpd_irq_handler(dev_priv, hotplug_status); 3894 1.1 riastrad 3895 1.20 riastrad i965_pipestat_irq_handler(dev_priv, iir, pipe_stats); 3896 1.20 riastrad } while (0); 3897 1.5 riastrad 3898 1.20 riastrad enable_rpm_wakeref_asserts(&dev_priv->runtime_pm); 3899 1.1 riastrad 3900 1.1 riastrad return ret; 3901 1.1 riastrad } 3902 1.1 riastrad 3903 1.11 riastrad /** 3904 1.11 riastrad * intel_irq_init - initializes irq support 3905 1.11 riastrad * @dev_priv: i915 device instance 3906 1.11 riastrad * 3907 1.11 riastrad * This function initializes all the irq support including work items, timers 3908 1.11 riastrad * and all the vtables. It does not setup the interrupt itself though. 3909 1.11 riastrad */ 3910 1.11 riastrad void intel_irq_init(struct drm_i915_private *dev_priv) 3911 1.5 riastrad { 3912 1.20 riastrad struct drm_device *dev = &dev_priv->drm; 3913 1.20 riastrad int i; 3914 1.5 riastrad 3915 1.11 riastrad intel_hpd_init_work(dev_priv); 3916 1.1 riastrad 3917 1.20 riastrad INIT_WORK(&dev_priv->l3_parity.error_work, ivb_parity_work); 3918 1.20 riastrad for (i = 0; i < MAX_L3_SLICES; ++i) 3919 1.20 riastrad dev_priv->l3_parity.remap_info[i] = NULL; 3920 1.20 riastrad 3921 1.20 riastrad /* pre-gen11 the guc irqs bits are in the upper 16 bits of the pm reg */ 3922 1.20 riastrad if (HAS_GT_UC(dev_priv) && INTEL_GEN(dev_priv) < 11) 3923 1.20 riastrad dev_priv->gt.pm_guc_events = GUC_INTR_GUC2HOST << 16; 3924 1.20 riastrad 3925 1.20 riastrad dev->vblank_disable_immediate = true; 3926 1.20 riastrad 3927 1.20 riastrad /* Most platforms treat the display irq block as an always-on 3928 1.20 riastrad * power domain. vlv/chv can disable it at runtime and need 3929 1.20 riastrad * special care to avoid writing any of the display block registers 3930 1.20 riastrad * outside of the power domain. We defer setting up the display irqs 3931 1.20 riastrad * in this case to the runtime pm. 3932 1.20 riastrad */ 3933 1.20 riastrad dev_priv->display_irqs_enabled = true; 3934 1.20 riastrad if (IS_VALLEYVIEW(dev_priv) || IS_CHERRYVIEW(dev_priv)) 3935 1.20 riastrad dev_priv->display_irqs_enabled = false; 3936 1.20 riastrad 3937 1.20 riastrad dev_priv->hotplug.hpd_storm_threshold = HPD_STORM_DEFAULT_THRESHOLD; 3938 1.20 riastrad /* If we have MST support, we want to avoid doing short HPD IRQ storm 3939 1.20 riastrad * detection, as short HPD storms will occur as a natural part of 3940 1.20 riastrad * sideband messaging with MST. 3941 1.20 riastrad * On older platforms however, IRQ storms can occur with both long and 3942 1.20 riastrad * short pulses, as seen on some G4x systems. 3943 1.20 riastrad */ 3944 1.20 riastrad dev_priv->hotplug.hpd_short_storm_enabled = !HAS_DP_MST(dev_priv); 3945 1.1 riastrad 3946 1.20 riastrad if (HAS_GMCH(dev_priv)) { 3947 1.20 riastrad if (I915_HAS_HOTPLUG(dev_priv)) 3948 1.20 riastrad dev_priv->display.hpd_irq_setup = i915_hpd_irq_setup; 3949 1.20 riastrad } else { 3950 1.20 riastrad if (HAS_PCH_JSP(dev_priv)) 3951 1.20 riastrad dev_priv->display.hpd_irq_setup = jsp_hpd_irq_setup; 3952 1.20 riastrad else if (HAS_PCH_MCC(dev_priv)) 3953 1.20 riastrad dev_priv->display.hpd_irq_setup = mcc_hpd_irq_setup; 3954 1.20 riastrad else if (INTEL_GEN(dev_priv) >= 11) 3955 1.20 riastrad dev_priv->display.hpd_irq_setup = gen11_hpd_irq_setup; 3956 1.20 riastrad else if (IS_GEN9_LP(dev_priv)) 3957 1.20 riastrad dev_priv->display.hpd_irq_setup = bxt_hpd_irq_setup; 3958 1.20 riastrad else if (INTEL_PCH_TYPE(dev_priv) >= PCH_SPT) 3959 1.20 riastrad dev_priv->display.hpd_irq_setup = spt_hpd_irq_setup; 3960 1.20 riastrad else 3961 1.20 riastrad dev_priv->display.hpd_irq_setup = ilk_hpd_irq_setup; 3962 1.20 riastrad } 3963 1.20 riastrad } 3964 1.5 riastrad 3965 1.20 riastrad /** 3966 1.20 riastrad * intel_irq_fini - deinitializes IRQ support 3967 1.20 riastrad * @i915: i915 device instance 3968 1.20 riastrad * 3969 1.20 riastrad * This function deinitializes all the IRQ support. 3970 1.20 riastrad */ 3971 1.20 riastrad void intel_irq_fini(struct drm_i915_private *i915) 3972 1.20 riastrad { 3973 1.20 riastrad int i; 3974 1.5 riastrad 3975 1.20 riastrad for (i = 0; i < MAX_L3_SLICES; ++i) 3976 1.20 riastrad kfree(i915->l3_parity.remap_info[i]); 3977 1.20 riastrad } 3978 1.5 riastrad 3979 1.20 riastrad static irq_handler_t intel_irq_handler(struct drm_i915_private *dev_priv) 3980 1.20 riastrad { 3981 1.20 riastrad if (HAS_GMCH(dev_priv)) { 3982 1.20 riastrad if (IS_CHERRYVIEW(dev_priv)) 3983 1.20 riastrad return cherryview_irq_handler; 3984 1.20 riastrad else if (IS_VALLEYVIEW(dev_priv)) 3985 1.20 riastrad return valleyview_irq_handler; 3986 1.20 riastrad else if (IS_GEN(dev_priv, 4)) 3987 1.20 riastrad return i965_irq_handler; 3988 1.20 riastrad else if (IS_GEN(dev_priv, 3)) 3989 1.20 riastrad return i915_irq_handler; 3990 1.20 riastrad else 3991 1.20 riastrad return i8xx_irq_handler; 3992 1.5 riastrad } else { 3993 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11) 3994 1.20 riastrad return gen11_irq_handler; 3995 1.20 riastrad else if (INTEL_GEN(dev_priv) >= 8) 3996 1.20 riastrad return gen8_irq_handler; 3997 1.20 riastrad else 3998 1.20 riastrad return ilk_irq_handler; 3999 1.1 riastrad } 4000 1.20 riastrad } 4001 1.1 riastrad 4002 1.20 riastrad static void intel_irq_reset(struct drm_i915_private *dev_priv) 4003 1.20 riastrad { 4004 1.20 riastrad if (HAS_GMCH(dev_priv)) { 4005 1.20 riastrad if (IS_CHERRYVIEW(dev_priv)) 4006 1.20 riastrad cherryview_irq_reset(dev_priv); 4007 1.20 riastrad else if (IS_VALLEYVIEW(dev_priv)) 4008 1.20 riastrad valleyview_irq_reset(dev_priv); 4009 1.20 riastrad else if (IS_GEN(dev_priv, 4)) 4010 1.20 riastrad i965_irq_reset(dev_priv); 4011 1.20 riastrad else if (IS_GEN(dev_priv, 3)) 4012 1.20 riastrad i915_irq_reset(dev_priv); 4013 1.20 riastrad else 4014 1.20 riastrad i8xx_irq_reset(dev_priv); 4015 1.20 riastrad } else { 4016 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11) 4017 1.20 riastrad gen11_irq_reset(dev_priv); 4018 1.20 riastrad else if (INTEL_GEN(dev_priv) >= 8) 4019 1.20 riastrad gen8_irq_reset(dev_priv); 4020 1.20 riastrad else 4021 1.20 riastrad ilk_irq_reset(dev_priv); 4022 1.20 riastrad } 4023 1.20 riastrad } 4024 1.11 riastrad 4025 1.20 riastrad static void intel_irq_postinstall(struct drm_i915_private *dev_priv) 4026 1.20 riastrad { 4027 1.20 riastrad if (HAS_GMCH(dev_priv)) { 4028 1.20 riastrad if (IS_CHERRYVIEW(dev_priv)) 4029 1.20 riastrad cherryview_irq_postinstall(dev_priv); 4030 1.20 riastrad else if (IS_VALLEYVIEW(dev_priv)) 4031 1.20 riastrad valleyview_irq_postinstall(dev_priv); 4032 1.20 riastrad else if (IS_GEN(dev_priv, 4)) 4033 1.20 riastrad i965_irq_postinstall(dev_priv); 4034 1.20 riastrad else if (IS_GEN(dev_priv, 3)) 4035 1.20 riastrad i915_irq_postinstall(dev_priv); 4036 1.11 riastrad else 4037 1.20 riastrad i8xx_irq_postinstall(dev_priv); 4038 1.1 riastrad } else { 4039 1.20 riastrad if (INTEL_GEN(dev_priv) >= 11) 4040 1.20 riastrad gen11_irq_postinstall(dev_priv); 4041 1.20 riastrad else if (INTEL_GEN(dev_priv) >= 8) 4042 1.20 riastrad gen8_irq_postinstall(dev_priv); 4043 1.20 riastrad else 4044 1.20 riastrad ilk_irq_postinstall(dev_priv); 4045 1.1 riastrad } 4046 1.1 riastrad } 4047 1.5 riastrad 4048 1.11 riastrad /** 4049 1.11 riastrad * intel_irq_install - enables the hardware interrupt 4050 1.11 riastrad * @dev_priv: i915 device instance 4051 1.11 riastrad * 4052 1.11 riastrad * This function enables the hardware interrupt handling, but leaves the hotplug 4053 1.11 riastrad * handling still disabled. It is called after intel_irq_init(). 4054 1.11 riastrad * 4055 1.11 riastrad * In the driver load and resume code we need working interrupts in a few places 4056 1.11 riastrad * but don't want to deal with the hassle of concurrent probe and hotplug 4057 1.11 riastrad * workers. Hence the split into this two-stage approach. 4058 1.11 riastrad */ 4059 1.11 riastrad int intel_irq_install(struct drm_i915_private *dev_priv) 4060 1.5 riastrad { 4061 1.24 riastrad #ifndef __NetBSD__ 4062 1.20 riastrad int irq = dev_priv->drm.pdev->irq; 4063 1.24 riastrad #endif 4064 1.20 riastrad int ret; 4065 1.20 riastrad 4066 1.11 riastrad /* 4067 1.11 riastrad * We enable some interrupt sources in our postinstall hooks, so mark 4068 1.11 riastrad * interrupts as enabled _before_ actually enabling them to avoid 4069 1.11 riastrad * special cases in our ordering checks. 4070 1.11 riastrad */ 4071 1.20 riastrad dev_priv->runtime_pm.irqs_enabled = true; 4072 1.20 riastrad 4073 1.20 riastrad dev_priv->drm.irq_enabled = true; 4074 1.5 riastrad 4075 1.20 riastrad intel_irq_reset(dev_priv); 4076 1.20 riastrad 4077 1.24 riastrad #ifdef __NetBSD__ 4078 1.24 riastrad { 4079 1.24 riastrad struct pci_dev *const pdev = dev_priv->drm.pdev; 4080 1.24 riastrad const char *const name = device_xname(pci_dev_dev(pdev)); 4081 1.24 riastrad const struct pci_attach_args *pa = &pdev->pd_pa; 4082 1.24 riastrad const char *intrstr; 4083 1.24 riastrad char intrbuf[PCI_INTRSTR_LEN]; 4084 1.24 riastrad 4085 1.24 riastrad if (pdev->msi_enabled) { 4086 1.24 riastrad if (pdev->pd_intr_handles == NULL) { 4087 1.24 riastrad /* XXX errno NetBSD->Linux */ 4088 1.24 riastrad if ((ret = -pci_msi_alloc_exact(pa, &dev_priv->pci_ihp, 4089 1.24 riastrad 1))) { 4090 1.24 riastrad aprint_error_dev(pci_dev_dev(pdev), 4091 1.24 riastrad "couldn't allocate MSI (%s)\n", name); 4092 1.24 riastrad goto out; 4093 1.24 riastrad } 4094 1.24 riastrad } else { 4095 1.24 riastrad dev_priv->pci_ihp = pdev->pd_intr_handles; 4096 1.24 riastrad pdev->pd_intr_handles = NULL; 4097 1.24 riastrad } 4098 1.24 riastrad } else { 4099 1.24 riastrad /* XXX errno NetBSD->Linux */ 4100 1.24 riastrad if ((ret = -pci_intx_alloc(pa, &dev_priv->pci_ihp))) { 4101 1.24 riastrad aprint_error_dev(pci_dev_dev(pdev), 4102 1.24 riastrad "couldn't allocate INTx interrupt (%s)\n", 4103 1.24 riastrad name); 4104 1.24 riastrad goto out; 4105 1.24 riastrad } 4106 1.24 riastrad } 4107 1.24 riastrad 4108 1.24 riastrad intrstr = pci_intr_string(pa->pa_pc, dev_priv->pci_ihp[0], 4109 1.24 riastrad intrbuf, sizeof(intrbuf)); 4110 1.24 riastrad dev_priv->pci_intrcookie = pci_intr_establish_xname(pa->pa_pc, 4111 1.24 riastrad dev_priv->pci_ihp[0], IPL_DRM, intel_irq_handler(dev_priv), 4112 1.24 riastrad dev_priv, name); 4113 1.24 riastrad if (dev_priv->pci_intrcookie == NULL) { 4114 1.24 riastrad aprint_error_dev(pci_dev_dev(pdev), 4115 1.24 riastrad "couldn't establish interrupt at %s (%s)\n", intrstr, name); 4116 1.24 riastrad pci_intr_release(pa->pa_pc, dev_priv->pci_ihp, 1); 4117 1.24 riastrad dev_priv->pci_ihp = NULL; 4118 1.24 riastrad ret = -EIO; /* XXX er? */ 4119 1.24 riastrad goto out; 4120 1.24 riastrad } 4121 1.24 riastrad 4122 1.24 riastrad /* Success! */ 4123 1.24 riastrad aprint_normal_dev(pci_dev_dev(pdev), "interrupting at %s (%s)\n", 4124 1.24 riastrad intrstr, name); 4125 1.24 riastrad ret = 0; 4126 1.24 riastrad out:; 4127 1.24 riastrad } 4128 1.24 riastrad #else 4129 1.20 riastrad ret = request_irq(irq, intel_irq_handler(dev_priv), 4130 1.20 riastrad IRQF_SHARED, DRIVER_NAME, dev_priv); 4131 1.24 riastrad #endif 4132 1.20 riastrad if (ret < 0) { 4133 1.20 riastrad dev_priv->drm.irq_enabled = false; 4134 1.20 riastrad return ret; 4135 1.20 riastrad } 4136 1.20 riastrad 4137 1.20 riastrad intel_irq_postinstall(dev_priv); 4138 1.20 riastrad 4139 1.20 riastrad return ret; 4140 1.11 riastrad } 4141 1.5 riastrad 4142 1.11 riastrad /** 4143 1.11 riastrad * intel_irq_uninstall - finilizes all irq handling 4144 1.11 riastrad * @dev_priv: i915 device instance 4145 1.11 riastrad * 4146 1.11 riastrad * This stops interrupt and hotplug handling and unregisters and frees all 4147 1.11 riastrad * resources acquired in the init functions. 4148 1.11 riastrad */ 4149 1.11 riastrad void intel_irq_uninstall(struct drm_i915_private *dev_priv) 4150 1.11 riastrad { 4151 1.24 riastrad #ifndef __NetBSD__ 4152 1.20 riastrad int irq = dev_priv->drm.pdev->irq; 4153 1.24 riastrad #endif 4154 1.20 riastrad 4155 1.20 riastrad /* 4156 1.20 riastrad * FIXME we can get called twice during driver probe 4157 1.20 riastrad * error handling as well as during driver remove due to 4158 1.20 riastrad * intel_modeset_driver_remove() calling us out of sequence. 4159 1.20 riastrad * Would be nice if it didn't do that... 4160 1.20 riastrad */ 4161 1.20 riastrad if (!dev_priv->drm.irq_enabled) 4162 1.20 riastrad return; 4163 1.20 riastrad 4164 1.20 riastrad dev_priv->drm.irq_enabled = false; 4165 1.20 riastrad 4166 1.20 riastrad intel_irq_reset(dev_priv); 4167 1.20 riastrad 4168 1.24 riastrad #ifdef __NetBSD__ 4169 1.24 riastrad const struct pci_attach_args *pa = &dev_priv->drm.pdev->pd_pa; 4170 1.24 riastrad if (dev_priv->pci_intrcookie != NULL) { 4171 1.24 riastrad pci_intr_disestablish(pa->pa_pc, dev_priv->pci_intrcookie); 4172 1.24 riastrad dev_priv->pci_intrcookie = NULL; 4173 1.24 riastrad } 4174 1.24 riastrad if (dev_priv->pci_ihp != NULL) { 4175 1.24 riastrad pci_intr_release(pa->pa_pc, dev_priv->pci_ihp, 1); 4176 1.24 riastrad dev_priv->pci_ihp = NULL; 4177 1.24 riastrad } 4178 1.24 riastrad #else 4179 1.20 riastrad free_irq(irq, dev_priv); 4180 1.24 riastrad #endif 4181 1.20 riastrad 4182 1.11 riastrad intel_hpd_cancel_work(dev_priv); 4183 1.20 riastrad dev_priv->runtime_pm.irqs_enabled = false; 4184 1.5 riastrad } 4185 1.5 riastrad 4186 1.11 riastrad /** 4187 1.11 riastrad * intel_runtime_pm_disable_interrupts - runtime interrupt disabling 4188 1.11 riastrad * @dev_priv: i915 device instance 4189 1.11 riastrad * 4190 1.11 riastrad * This function is used to disable interrupts at runtime, both in the runtime 4191 1.11 riastrad * pm and the system suspend/resume code. 4192 1.11 riastrad */ 4193 1.11 riastrad void intel_runtime_pm_disable_interrupts(struct drm_i915_private *dev_priv) 4194 1.5 riastrad { 4195 1.20 riastrad intel_irq_reset(dev_priv); 4196 1.20 riastrad dev_priv->runtime_pm.irqs_enabled = false; 4197 1.20 riastrad intel_synchronize_irq(dev_priv); 4198 1.5 riastrad } 4199 1.5 riastrad 4200 1.11 riastrad /** 4201 1.11 riastrad * intel_runtime_pm_enable_interrupts - runtime interrupt enabling 4202 1.11 riastrad * @dev_priv: i915 device instance 4203 1.11 riastrad * 4204 1.11 riastrad * This function is used to enable interrupts at runtime, both in the runtime 4205 1.11 riastrad * pm and the system suspend/resume code. 4206 1.11 riastrad */ 4207 1.11 riastrad void intel_runtime_pm_enable_interrupts(struct drm_i915_private *dev_priv) 4208 1.5 riastrad { 4209 1.20 riastrad dev_priv->runtime_pm.irqs_enabled = true; 4210 1.20 riastrad intel_irq_reset(dev_priv); 4211 1.20 riastrad intel_irq_postinstall(dev_priv); 4212 1.20 riastrad } 4213 1.20 riastrad 4214 1.20 riastrad bool intel_irqs_enabled(struct drm_i915_private *dev_priv) 4215 1.20 riastrad { 4216 1.20 riastrad /* 4217 1.20 riastrad * We only use drm_irq_uninstall() at unload and VT switch, so 4218 1.20 riastrad * this is the only thing we need to check. 4219 1.20 riastrad */ 4220 1.20 riastrad return dev_priv->runtime_pm.irqs_enabled; 4221 1.20 riastrad } 4222 1.20 riastrad 4223 1.20 riastrad void intel_synchronize_irq(struct drm_i915_private *i915) 4224 1.20 riastrad { 4225 1.24 riastrad #ifdef __NetBSD__ 4226 1.24 riastrad xc_barrier(0); 4227 1.24 riastrad #else 4228 1.20 riastrad synchronize_irq(i915->drm.pdev->irq); 4229 1.24 riastrad #endif 4230 1.5 riastrad } 4231