1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include <drm/drm_print.h> 7 #include <drm/drm_vblank.h> 8 #include <drm/intel/intel_gmd_interrupt_regs.h> 9 10 #include "icl_dsi_regs.h" 11 #include "intel_crtc.h" 12 #include "intel_de.h" 13 #include "intel_display_irq.h" 14 #include "intel_display_regs.h" 15 #include "intel_display_rpm.h" 16 #include "intel_display_rps.h" 17 #include "intel_display_trace.h" 18 #include "intel_display_types.h" 19 #include "intel_dmc.h" 20 #include "intel_dp_aux.h" 21 #include "intel_dsb.h" 22 #include "intel_fdi_regs.h" 23 #include "intel_fifo_underrun.h" 24 #include "intel_gmbus.h" 25 #include "intel_hotplug_irq.h" 26 #include "intel_lpe_audio.h" 27 #include "intel_parent.h" 28 #include "intel_pipe_crc_regs.h" 29 #include "intel_plane.h" 30 #include "intel_pmdemand.h" 31 #include "intel_psr.h" 32 #include "intel_psr_regs.h" 33 34 static void irq_reset(struct intel_display *display, struct intel_irq_regs regs) 35 { 36 intel_de_write(display, regs.imr, 0xffffffff); 37 intel_de_posting_read(display, regs.imr); 38 39 intel_de_write(display, regs.ier, 0); 40 41 /* IIR can theoretically queue up two events. Be paranoid. */ 42 intel_de_write(display, regs.iir, 0xffffffff); 43 intel_de_posting_read(display, regs.iir); 44 intel_de_write(display, regs.iir, 0xffffffff); 45 intel_de_posting_read(display, regs.iir); 46 } 47 48 /* 49 * We should clear IMR at preinstall/uninstall, and just check at postinstall. 50 */ 51 static void assert_iir_is_zero(struct intel_display *display, intel_reg_t reg) 52 { 53 u32 val = intel_de_read(display, reg); 54 55 if (val == 0) 56 return; 57 58 drm_WARN(display->drm, 1, 59 "Interrupt register 0x%x is not zero: 0x%08x\n", 60 intel_reg_offset(reg), val); 61 intel_de_write(display, reg, 0xffffffff); 62 intel_de_posting_read(display, reg); 63 intel_de_write(display, reg, 0xffffffff); 64 intel_de_posting_read(display, reg); 65 } 66 67 static void irq_init(struct intel_display *display, struct intel_irq_regs regs, 68 u32 imr_val, u32 ier_val) 69 { 70 assert_iir_is_zero(display, regs.iir); 71 72 intel_de_write(display, regs.ier, ier_val); 73 intel_de_write(display, regs.imr, imr_val); 74 intel_de_posting_read(display, regs.imr); 75 } 76 77 static void error_reset(struct intel_display *display, struct intel_error_regs regs) 78 { 79 intel_de_write(display, regs.emr, 0xffffffff); 80 intel_de_posting_read(display, regs.emr); 81 82 intel_de_write(display, regs.eir, 0xffffffff); 83 intel_de_posting_read(display, regs.eir); 84 intel_de_write(display, regs.eir, 0xffffffff); 85 intel_de_posting_read(display, regs.eir); 86 } 87 88 static void error_init(struct intel_display *display, struct intel_error_regs regs, 89 u32 emr_val) 90 { 91 intel_de_write(display, regs.eir, 0xffffffff); 92 intel_de_posting_read(display, regs.eir); 93 intel_de_write(display, regs.eir, 0xffffffff); 94 intel_de_posting_read(display, regs.eir); 95 96 intel_de_write(display, regs.emr, emr_val); 97 intel_de_posting_read(display, regs.emr); 98 } 99 100 struct pipe_fault_handler { 101 bool (*handle)(struct intel_crtc *crtc, enum plane_id plane_id); 102 u32 fault; 103 enum plane_id plane_id; 104 }; 105 106 static bool handle_plane_fault(struct intel_crtc *crtc, enum plane_id plane_id) 107 { 108 struct intel_display *display = to_intel_display(crtc); 109 struct intel_plane_error error = {}; 110 struct intel_plane *plane; 111 112 plane = intel_crtc_get_plane(crtc, plane_id); 113 if (!plane || !plane->capture_error) 114 return false; 115 116 plane->capture_error(crtc, plane, &error); 117 118 drm_err_ratelimited(display->drm, 119 "[CRTC:%d:%s][PLANE:%d:%s] fault (CTL=0x%x, SURF=0x%x, SURFLIVE=0x%x)\n", 120 crtc->base.base.id, crtc->base.name, 121 plane->base.base.id, plane->base.name, 122 error.ctl, error.surf, error.surflive); 123 124 return true; 125 } 126 127 static void intel_pipe_fault_irq_handler(struct intel_display *display, 128 const struct pipe_fault_handler *handlers, 129 enum pipe pipe, u32 fault_errors) 130 { 131 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 132 const struct pipe_fault_handler *handler; 133 134 for (handler = handlers; handler && handler->fault; handler++) { 135 if ((fault_errors & handler->fault) == 0) 136 continue; 137 138 if (handler->handle(crtc, handler->plane_id)) 139 fault_errors &= ~handler->fault; 140 } 141 142 WARN_ONCE(fault_errors, "[CRTC:%d:%s] unreported faults 0x%x\n", 143 crtc->base.base.id, crtc->base.name, fault_errors); 144 } 145 146 static void 147 intel_handle_vblank(struct intel_display *display, enum pipe pipe) 148 { 149 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 150 151 drm_crtc_handle_vblank(&crtc->base); 152 } 153 154 /** 155 * ilk_update_display_irq - update DEIMR 156 * @display: display device 157 * @interrupt_mask: mask of interrupt bits to update 158 * @enabled_irq_mask: mask of interrupt bits to enable 159 */ 160 void ilk_update_display_irq(struct intel_display *display, 161 u32 interrupt_mask, u32 enabled_irq_mask) 162 { 163 u32 new_val; 164 165 lockdep_assert_held(&display->irq.lock); 166 drm_WARN_ON(display->drm, enabled_irq_mask & ~interrupt_mask); 167 168 new_val = display->irq.ilk_de_imr_mask; 169 new_val &= ~interrupt_mask; 170 new_val |= (~enabled_irq_mask & interrupt_mask); 171 172 if (new_val != display->irq.ilk_de_imr_mask && 173 !drm_WARN_ON(display->drm, !intel_parent_irq_enabled(display))) { 174 display->irq.ilk_de_imr_mask = new_val; 175 intel_de_write(display, DEIMR, display->irq.ilk_de_imr_mask); 176 intel_de_posting_read(display, DEIMR); 177 } 178 } 179 180 void ilk_enable_display_irq(struct intel_display *display, u32 bits) 181 { 182 ilk_update_display_irq(display, bits, bits); 183 } 184 185 void ilk_disable_display_irq(struct intel_display *display, u32 bits) 186 { 187 ilk_update_display_irq(display, bits, 0); 188 } 189 190 /** 191 * bdw_update_port_irq - update DE port interrupt 192 * @display: display device 193 * @interrupt_mask: mask of interrupt bits to update 194 * @enabled_irq_mask: mask of interrupt bits to enable 195 */ 196 void bdw_update_port_irq(struct intel_display *display, 197 u32 interrupt_mask, u32 enabled_irq_mask) 198 { 199 u32 new_val; 200 u32 old_val; 201 202 lockdep_assert_held(&display->irq.lock); 203 204 drm_WARN_ON(display->drm, enabled_irq_mask & ~interrupt_mask); 205 206 if (drm_WARN_ON(display->drm, !intel_parent_irq_enabled(display))) 207 return; 208 209 old_val = intel_de_read(display, GEN8_DE_PORT_IMR); 210 211 new_val = old_val; 212 new_val &= ~interrupt_mask; 213 new_val |= (~enabled_irq_mask & interrupt_mask); 214 215 if (new_val != old_val) { 216 intel_de_write(display, GEN8_DE_PORT_IMR, new_val); 217 intel_de_posting_read(display, GEN8_DE_PORT_IMR); 218 } 219 } 220 221 /** 222 * bdw_update_pipe_irq - update DE pipe interrupt 223 * @display: display device 224 * @pipe: pipe whose interrupt to update 225 * @interrupt_mask: mask of interrupt bits to update 226 * @enabled_irq_mask: mask of interrupt bits to enable 227 */ 228 static void bdw_update_pipe_irq(struct intel_display *display, 229 enum pipe pipe, u32 interrupt_mask, 230 u32 enabled_irq_mask) 231 { 232 u32 new_val; 233 234 lockdep_assert_held(&display->irq.lock); 235 236 drm_WARN_ON(display->drm, enabled_irq_mask & ~interrupt_mask); 237 238 if (drm_WARN_ON(display->drm, !intel_parent_irq_enabled(display))) 239 return; 240 241 new_val = display->irq.de_pipe_imr_mask[pipe]; 242 new_val &= ~interrupt_mask; 243 new_val |= (~enabled_irq_mask & interrupt_mask); 244 245 if (new_val != display->irq.de_pipe_imr_mask[pipe]) { 246 display->irq.de_pipe_imr_mask[pipe] = new_val; 247 intel_de_write(display, GEN8_DE_PIPE_IMR(pipe), display->irq.de_pipe_imr_mask[pipe]); 248 intel_de_posting_read(display, GEN8_DE_PIPE_IMR(pipe)); 249 } 250 } 251 252 void bdw_enable_pipe_irq(struct intel_display *display, 253 enum pipe pipe, u32 bits) 254 { 255 bdw_update_pipe_irq(display, pipe, bits, bits); 256 } 257 258 void bdw_disable_pipe_irq(struct intel_display *display, 259 enum pipe pipe, u32 bits) 260 { 261 bdw_update_pipe_irq(display, pipe, bits, 0); 262 } 263 264 /** 265 * ibx_display_interrupt_update - update SDEIMR 266 * @display: display device 267 * @interrupt_mask: mask of interrupt bits to update 268 * @enabled_irq_mask: mask of interrupt bits to enable 269 */ 270 void ibx_display_interrupt_update(struct intel_display *display, 271 u32 interrupt_mask, 272 u32 enabled_irq_mask) 273 { 274 u32 sdeimr = intel_de_read(display, SDEIMR); 275 276 sdeimr &= ~interrupt_mask; 277 sdeimr |= (~enabled_irq_mask & interrupt_mask); 278 279 drm_WARN_ON(display->drm, enabled_irq_mask & ~interrupt_mask); 280 281 lockdep_assert_held(&display->irq.lock); 282 283 if (drm_WARN_ON(display->drm, !intel_parent_irq_enabled(display))) 284 return; 285 286 intel_de_write(display, SDEIMR, sdeimr); 287 intel_de_posting_read(display, SDEIMR); 288 } 289 290 void ibx_enable_display_interrupt(struct intel_display *display, u32 bits) 291 { 292 ibx_display_interrupt_update(display, bits, bits); 293 } 294 295 void ibx_disable_display_interrupt(struct intel_display *display, u32 bits) 296 { 297 ibx_display_interrupt_update(display, bits, 0); 298 } 299 300 u32 i915_pipestat_enable_mask(struct intel_display *display, 301 enum pipe pipe) 302 { 303 u32 status_mask = display->irq.pipestat_irq_mask[pipe]; 304 u32 enable_mask = status_mask << 16; 305 306 lockdep_assert_held(&display->irq.lock); 307 308 if (DISPLAY_VER(display) < 5) 309 goto out; 310 311 /* 312 * On pipe A we don't support the PSR interrupt yet, 313 * on pipe B and C the same bit MBZ. 314 */ 315 if (drm_WARN_ON_ONCE(display->drm, 316 status_mask & PIPE_A_PSR_STATUS_VLV)) 317 return 0; 318 /* 319 * On pipe B and C we don't support the PSR interrupt yet, on pipe 320 * A the same bit is for perf counters which we don't use either. 321 */ 322 if (drm_WARN_ON_ONCE(display->drm, 323 status_mask & PIPE_B_PSR_STATUS_VLV)) 324 return 0; 325 326 enable_mask &= ~(PIPE_FIFO_UNDERRUN_STATUS | 327 SPRITE0_FLIP_DONE_INT_EN_VLV | 328 SPRITE1_FLIP_DONE_INT_EN_VLV); 329 if (status_mask & SPRITE0_FLIP_DONE_INT_STATUS_VLV) 330 enable_mask |= SPRITE0_FLIP_DONE_INT_EN_VLV; 331 if (status_mask & SPRITE1_FLIP_DONE_INT_STATUS_VLV) 332 enable_mask |= SPRITE1_FLIP_DONE_INT_EN_VLV; 333 334 out: 335 drm_WARN_ONCE(display->drm, 336 enable_mask & ~PIPESTAT_INT_ENABLE_MASK || 337 status_mask & ~PIPESTAT_INT_STATUS_MASK, 338 "pipe %c: enable_mask=0x%x, status_mask=0x%x\n", 339 pipe_name(pipe), enable_mask, status_mask); 340 341 return enable_mask; 342 } 343 344 void i915_enable_pipestat(struct intel_display *display, 345 enum pipe pipe, u32 status_mask) 346 { 347 intel_reg_t reg = PIPESTAT(display, pipe); 348 u32 enable_mask; 349 350 drm_WARN_ONCE(display->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK, 351 "pipe %c: status_mask=0x%x\n", 352 pipe_name(pipe), status_mask); 353 354 lockdep_assert_held(&display->irq.lock); 355 drm_WARN_ON(display->drm, !intel_parent_irq_enabled(display)); 356 357 if ((display->irq.pipestat_irq_mask[pipe] & status_mask) == status_mask) 358 return; 359 360 display->irq.pipestat_irq_mask[pipe] |= status_mask; 361 enable_mask = i915_pipestat_enable_mask(display, pipe); 362 363 intel_de_write(display, reg, enable_mask | status_mask); 364 intel_de_posting_read(display, reg); 365 } 366 367 void i915_disable_pipestat(struct intel_display *display, 368 enum pipe pipe, u32 status_mask) 369 { 370 intel_reg_t reg = PIPESTAT(display, pipe); 371 u32 enable_mask; 372 373 drm_WARN_ONCE(display->drm, status_mask & ~PIPESTAT_INT_STATUS_MASK, 374 "pipe %c: status_mask=0x%x\n", 375 pipe_name(pipe), status_mask); 376 377 lockdep_assert_held(&display->irq.lock); 378 drm_WARN_ON(display->drm, !intel_parent_irq_enabled(display)); 379 380 if ((display->irq.pipestat_irq_mask[pipe] & status_mask) == 0) 381 return; 382 383 display->irq.pipestat_irq_mask[pipe] &= ~status_mask; 384 enable_mask = i915_pipestat_enable_mask(display, pipe); 385 386 intel_de_write(display, reg, enable_mask | status_mask); 387 intel_de_posting_read(display, reg); 388 } 389 390 static bool i915_has_legacy_blc_interrupt(struct intel_display *display) 391 { 392 if (display->platform.i85x) 393 return true; 394 395 if (display->platform.pineview) 396 return true; 397 398 return IS_DISPLAY_VER(display, 3, 4) && display->platform.mobile; 399 } 400 401 /* enable ASLE pipestat for OpRegion */ 402 static void i915_enable_asle_pipestat(struct intel_display *display) 403 { 404 if (!intel_opregion_asle_present(display)) 405 return; 406 407 if (!i915_has_legacy_blc_interrupt(display)) 408 return; 409 410 spin_lock_irq(&display->irq.lock); 411 412 i915_enable_pipestat(display, PIPE_B, PIPE_LEGACY_BLC_EVENT_STATUS); 413 if (DISPLAY_VER(display) >= 4) 414 i915_enable_pipestat(display, PIPE_A, 415 PIPE_LEGACY_BLC_EVENT_STATUS); 416 417 spin_unlock_irq(&display->irq.lock); 418 } 419 420 #if IS_ENABLED(CONFIG_DEBUG_FS) 421 static void display_pipe_crc_irq_handler(struct intel_display *display, 422 enum pipe pipe, 423 u32 crc0, u32 crc1, 424 u32 crc2, u32 crc3, 425 u32 crc4) 426 { 427 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 428 struct intel_pipe_crc *pipe_crc = &crtc->pipe_crc; 429 u32 crcs[5] = { crc0, crc1, crc2, crc3, crc4 }; 430 431 trace_intel_pipe_crc(crtc, crcs); 432 433 spin_lock(&pipe_crc->lock); 434 /* 435 * For some not yet identified reason, the first CRC is 436 * bonkers. So let's just wait for the next vblank and read 437 * out the buggy result. 438 * 439 * On GEN8+ sometimes the second CRC is bonkers as well, so 440 * don't trust that one either. 441 */ 442 if (pipe_crc->skipped <= 0 || 443 (DISPLAY_VER(display) >= 8 && pipe_crc->skipped == 1)) { 444 pipe_crc->skipped++; 445 spin_unlock(&pipe_crc->lock); 446 return; 447 } 448 spin_unlock(&pipe_crc->lock); 449 450 drm_crtc_add_crc_entry(&crtc->base, true, 451 drm_crtc_accurate_vblank_count(&crtc->base), 452 crcs); 453 } 454 #else 455 static inline void 456 display_pipe_crc_irq_handler(struct intel_display *display, 457 enum pipe pipe, 458 u32 crc0, u32 crc1, 459 u32 crc2, u32 crc3, 460 u32 crc4) {} 461 #endif 462 463 static void flip_done_handler(struct intel_display *display, 464 enum pipe pipe) 465 { 466 struct intel_crtc *crtc = intel_crtc_for_pipe(display, pipe); 467 468 spin_lock(&display->drm->event_lock); 469 470 if (crtc->flip_done_event) { 471 trace_intel_crtc_flip_done(crtc); 472 drm_crtc_send_vblank_event(&crtc->base, crtc->flip_done_event); 473 crtc->flip_done_event = NULL; 474 } 475 476 spin_unlock(&display->drm->event_lock); 477 } 478 479 static void hsw_pipe_crc_irq_handler(struct intel_display *display, 480 enum pipe pipe) 481 { 482 display_pipe_crc_irq_handler(display, pipe, 483 intel_de_read(display, PIPE_CRC_RES_HSW(pipe)), 484 0, 0, 0, 0); 485 } 486 487 static void ivb_pipe_crc_irq_handler(struct intel_display *display, 488 enum pipe pipe) 489 { 490 display_pipe_crc_irq_handler(display, pipe, 491 intel_de_read(display, PIPE_CRC_RES_1_IVB(pipe)), 492 intel_de_read(display, PIPE_CRC_RES_2_IVB(pipe)), 493 intel_de_read(display, PIPE_CRC_RES_3_IVB(pipe)), 494 intel_de_read(display, PIPE_CRC_RES_4_IVB(pipe)), 495 intel_de_read(display, PIPE_CRC_RES_5_IVB(pipe))); 496 } 497 498 static void i9xx_pipe_crc_irq_handler(struct intel_display *display, 499 enum pipe pipe) 500 { 501 u32 res1, res2; 502 503 if (DISPLAY_VER(display) >= 3) 504 res1 = intel_de_read(display, PIPE_CRC_RES_RES1_I915(display, pipe)); 505 else 506 res1 = 0; 507 508 if (DISPLAY_VER(display) >= 5 || display->platform.g4x) 509 res2 = intel_de_read(display, PIPE_CRC_RES_RES2_G4X(display, pipe)); 510 else 511 res2 = 0; 512 513 display_pipe_crc_irq_handler(display, pipe, 514 intel_de_read(display, PIPE_CRC_RES_RED(display, pipe)), 515 intel_de_read(display, PIPE_CRC_RES_GREEN(display, pipe)), 516 intel_de_read(display, PIPE_CRC_RES_BLUE(display, pipe)), 517 res1, res2); 518 } 519 520 static void i9xx_pipestat_irq_reset(struct intel_display *display) 521 { 522 enum pipe pipe; 523 524 for_each_pipe(display, pipe) { 525 intel_de_write(display, 526 PIPESTAT(display, pipe), 527 PIPESTAT_INT_STATUS_MASK | PIPE_FIFO_UNDERRUN_STATUS); 528 529 display->irq.pipestat_irq_mask[pipe] = 0; 530 } 531 } 532 533 static void i9xx_pipestat_irq_ack(struct intel_display *display, 534 u32 iir, u32 pipe_stats[I915_MAX_PIPES]) 535 { 536 enum pipe pipe; 537 538 spin_lock(&display->irq.lock); 539 540 if ((display->platform.valleyview || display->platform.cherryview) && 541 !display->irq.vlv_display_irqs_enabled) { 542 spin_unlock(&display->irq.lock); 543 return; 544 } 545 546 for_each_pipe(display, pipe) { 547 intel_reg_t reg; 548 u32 status_mask, enable_mask, iir_bit = 0; 549 550 /* 551 * PIPESTAT bits get signalled even when the interrupt is 552 * disabled with the mask bits, and some of the status bits do 553 * not generate interrupts at all (like the underrun bit). Hence 554 * we need to be careful that we only handle what we want to 555 * handle. 556 */ 557 558 /* fifo underruns are filterered in the underrun handler. */ 559 status_mask = PIPE_FIFO_UNDERRUN_STATUS; 560 561 switch (pipe) { 562 default: 563 case PIPE_A: 564 iir_bit = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT; 565 break; 566 case PIPE_B: 567 iir_bit = I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 568 break; 569 case PIPE_C: 570 iir_bit = I915_DISPLAY_PIPE_C_EVENT_INTERRUPT; 571 break; 572 } 573 if (iir & iir_bit) 574 status_mask |= display->irq.pipestat_irq_mask[pipe]; 575 576 if (!status_mask) 577 continue; 578 579 reg = PIPESTAT(display, pipe); 580 pipe_stats[pipe] = intel_de_read(display, reg) & status_mask; 581 enable_mask = i915_pipestat_enable_mask(display, pipe); 582 583 /* 584 * Clear the PIPE*STAT regs before the IIR 585 * 586 * Toggle the enable bits to make sure we get an 587 * edge in the ISR pipe event bit if we don't clear 588 * all the enabled status bits. Otherwise the edge 589 * triggered IIR on i965/g4x wouldn't notice that 590 * an interrupt is still pending. 591 */ 592 if (pipe_stats[pipe]) { 593 intel_de_write(display, reg, pipe_stats[pipe]); 594 intel_de_write(display, reg, enable_mask); 595 } 596 } 597 spin_unlock(&display->irq.lock); 598 } 599 600 static void i915_pipestat_irq_handler(struct intel_display *display, 601 u32 iir, const u32 pipe_stats[I915_MAX_PIPES]) 602 { 603 bool blc_event = false; 604 enum pipe pipe; 605 606 for_each_pipe(display, pipe) { 607 if (pipe_stats[pipe] & PIPE_VBLANK_INTERRUPT_STATUS) 608 intel_handle_vblank(display, pipe); 609 610 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 611 blc_event = true; 612 613 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 614 i9xx_pipe_crc_irq_handler(display, pipe); 615 616 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 617 intel_cpu_fifo_underrun_irq_handler(display, pipe); 618 } 619 620 if (blc_event || (iir & I915_ASLE_INTERRUPT)) 621 intel_opregion_asle_intr(display); 622 } 623 624 static void i965_pipestat_irq_handler(struct intel_display *display, 625 u32 iir, const u32 pipe_stats[I915_MAX_PIPES]) 626 { 627 bool blc_event = false; 628 enum pipe pipe; 629 630 for_each_pipe(display, pipe) { 631 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 632 intel_handle_vblank(display, pipe); 633 634 if (pipe_stats[pipe] & PIPE_LEGACY_BLC_EVENT_STATUS) 635 blc_event = true; 636 637 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 638 i9xx_pipe_crc_irq_handler(display, pipe); 639 640 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 641 intel_cpu_fifo_underrun_irq_handler(display, pipe); 642 } 643 644 if (blc_event || (iir & I915_ASLE_INTERRUPT)) 645 intel_opregion_asle_intr(display); 646 647 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 648 intel_gmbus_irq_handler(display); 649 } 650 651 static void valleyview_pipestat_irq_handler(struct intel_display *display, 652 const u32 pipe_stats[I915_MAX_PIPES]) 653 { 654 enum pipe pipe; 655 656 for_each_pipe(display, pipe) { 657 if (pipe_stats[pipe] & PIPE_START_VBLANK_INTERRUPT_STATUS) 658 intel_handle_vblank(display, pipe); 659 660 if (pipe_stats[pipe] & PLANE_FLIP_DONE_INT_STATUS_VLV) 661 flip_done_handler(display, pipe); 662 663 if (pipe_stats[pipe] & PIPE_CRC_DONE_INTERRUPT_STATUS) 664 i9xx_pipe_crc_irq_handler(display, pipe); 665 666 if (pipe_stats[pipe] & PIPE_FIFO_UNDERRUN_STATUS) 667 intel_cpu_fifo_underrun_irq_handler(display, pipe); 668 } 669 670 if (pipe_stats[0] & PIPE_GMBUS_INTERRUPT_STATUS) 671 intel_gmbus_irq_handler(display); 672 } 673 674 static void ibx_irq_handler(struct intel_display *display, u32 pch_iir) 675 { 676 enum pipe pipe; 677 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK; 678 679 ibx_hpd_irq_handler(display, hotplug_trigger); 680 681 if (pch_iir & SDE_AUDIO_POWER_MASK) { 682 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK) >> 683 SDE_AUDIO_POWER_SHIFT); 684 drm_dbg(display->drm, "PCH audio power change on port %d\n", 685 port_name(port)); 686 } 687 688 if (pch_iir & SDE_AUX_MASK) 689 intel_dp_aux_irq_handler(display); 690 691 if (pch_iir & SDE_GMBUS) 692 intel_gmbus_irq_handler(display); 693 694 if (pch_iir & SDE_AUDIO_HDCP_MASK) 695 drm_dbg(display->drm, "PCH HDCP audio interrupt\n"); 696 697 if (pch_iir & SDE_AUDIO_TRANS_MASK) 698 drm_dbg(display->drm, "PCH transcoder audio interrupt\n"); 699 700 if (pch_iir & SDE_POISON) 701 drm_err(display->drm, "PCH poison interrupt\n"); 702 703 if (pch_iir & SDE_FDI_MASK) { 704 for_each_pipe(display, pipe) 705 drm_dbg(display->drm, " pipe %c FDI IIR: 0x%08x\n", 706 pipe_name(pipe), 707 intel_de_read(display, FDI_RX_IIR(pipe))); 708 } 709 710 if (pch_iir & (SDE_TRANSB_CRC_DONE | SDE_TRANSA_CRC_DONE)) 711 drm_dbg(display->drm, "PCH transcoder CRC done interrupt\n"); 712 713 if (pch_iir & (SDE_TRANSB_CRC_ERR | SDE_TRANSA_CRC_ERR)) 714 drm_dbg(display->drm, 715 "PCH transcoder CRC error interrupt\n"); 716 717 if (pch_iir & SDE_TRANSA_FIFO_UNDER) 718 intel_pch_fifo_underrun_irq_handler(display, PIPE_A); 719 720 if (pch_iir & SDE_TRANSB_FIFO_UNDER) 721 intel_pch_fifo_underrun_irq_handler(display, PIPE_B); 722 } 723 724 static u32 ivb_err_int_pipe_fault_mask(enum pipe pipe) 725 { 726 switch (pipe) { 727 case PIPE_A: 728 return ERR_INT_SPRITE_A_FAULT | 729 ERR_INT_PRIMARY_A_FAULT | 730 ERR_INT_CURSOR_A_FAULT; 731 case PIPE_B: 732 return ERR_INT_SPRITE_B_FAULT | 733 ERR_INT_PRIMARY_B_FAULT | 734 ERR_INT_CURSOR_B_FAULT; 735 case PIPE_C: 736 return ERR_INT_SPRITE_C_FAULT | 737 ERR_INT_PRIMARY_C_FAULT | 738 ERR_INT_CURSOR_C_FAULT; 739 default: 740 return 0; 741 } 742 } 743 744 static const struct pipe_fault_handler ivb_pipe_fault_handlers[] = { 745 { .fault = ERR_INT_SPRITE_A_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 746 { .fault = ERR_INT_PRIMARY_A_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 747 { .fault = ERR_INT_CURSOR_A_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 748 { .fault = ERR_INT_SPRITE_B_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 749 { .fault = ERR_INT_PRIMARY_B_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 750 { .fault = ERR_INT_CURSOR_B_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 751 { .fault = ERR_INT_SPRITE_C_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 752 { .fault = ERR_INT_PRIMARY_C_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 753 { .fault = ERR_INT_CURSOR_C_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 754 {} 755 }; 756 757 static void ivb_err_int_handler(struct intel_display *display) 758 { 759 u32 err_int = intel_de_read(display, GEN7_ERR_INT); 760 enum pipe pipe; 761 762 if (err_int & ERR_INT_POISON) 763 drm_err(display->drm, "Poison interrupt\n"); 764 765 if (err_int & ERR_INT_INVALID_GTT_PTE) 766 drm_err_ratelimited(display->drm, "Invalid GTT PTE\n"); 767 768 if (err_int & ERR_INT_INVALID_PTE_DATA) 769 drm_err_ratelimited(display->drm, "Invalid PTE data\n"); 770 771 for_each_pipe(display, pipe) { 772 u32 fault_errors; 773 774 if (err_int & ERR_INT_FIFO_UNDERRUN(pipe)) 775 intel_cpu_fifo_underrun_irq_handler(display, pipe); 776 777 if (err_int & ERR_INT_PIPE_CRC_DONE(pipe)) { 778 if (display->platform.ivybridge) 779 ivb_pipe_crc_irq_handler(display, pipe); 780 else 781 hsw_pipe_crc_irq_handler(display, pipe); 782 } 783 784 fault_errors = err_int & ivb_err_int_pipe_fault_mask(pipe); 785 if (fault_errors) 786 intel_pipe_fault_irq_handler(display, ivb_pipe_fault_handlers, 787 pipe, fault_errors); 788 } 789 790 intel_de_write(display, GEN7_ERR_INT, err_int); 791 } 792 793 static void cpt_serr_int_handler(struct intel_display *display) 794 { 795 u32 serr_int = intel_de_read(display, SERR_INT); 796 enum pipe pipe; 797 798 if (serr_int & SERR_INT_POISON) 799 drm_err(display->drm, "PCH poison interrupt\n"); 800 801 for_each_pipe(display, pipe) 802 if (serr_int & SERR_INT_TRANS_FIFO_UNDERRUN(pipe)) 803 intel_pch_fifo_underrun_irq_handler(display, pipe); 804 805 intel_de_write(display, SERR_INT, serr_int); 806 } 807 808 static void cpt_irq_handler(struct intel_display *display, u32 pch_iir) 809 { 810 enum pipe pipe; 811 u32 hotplug_trigger = pch_iir & SDE_HOTPLUG_MASK_CPT; 812 813 ibx_hpd_irq_handler(display, hotplug_trigger); 814 815 if (pch_iir & SDE_AUDIO_POWER_MASK_CPT) { 816 int port = ffs((pch_iir & SDE_AUDIO_POWER_MASK_CPT) >> 817 SDE_AUDIO_POWER_SHIFT_CPT); 818 drm_dbg(display->drm, "PCH audio power change on port %c\n", 819 port_name(port)); 820 } 821 822 if (pch_iir & SDE_AUX_MASK_CPT) 823 intel_dp_aux_irq_handler(display); 824 825 if (pch_iir & SDE_GMBUS_CPT) 826 intel_gmbus_irq_handler(display); 827 828 if (pch_iir & SDE_AUDIO_CP_REQ_CPT) 829 drm_dbg(display->drm, "Audio CP request interrupt\n"); 830 831 if (pch_iir & SDE_AUDIO_CP_CHG_CPT) 832 drm_dbg(display->drm, "Audio CP change interrupt\n"); 833 834 if (pch_iir & SDE_FDI_MASK_CPT) { 835 for_each_pipe(display, pipe) 836 drm_dbg(display->drm, " pipe %c FDI IIR: 0x%08x\n", 837 pipe_name(pipe), 838 intel_de_read(display, FDI_RX_IIR(pipe))); 839 } 840 841 if (pch_iir & SDE_ERROR_CPT) 842 cpt_serr_int_handler(display); 843 } 844 845 static u32 ilk_gtt_fault_pipe_fault_mask(enum pipe pipe) 846 { 847 switch (pipe) { 848 case PIPE_A: 849 return GTT_FAULT_SPRITE_A_FAULT | 850 GTT_FAULT_PRIMARY_A_FAULT | 851 GTT_FAULT_CURSOR_A_FAULT; 852 case PIPE_B: 853 return GTT_FAULT_SPRITE_B_FAULT | 854 GTT_FAULT_PRIMARY_B_FAULT | 855 GTT_FAULT_CURSOR_B_FAULT; 856 default: 857 return 0; 858 } 859 } 860 861 static const struct pipe_fault_handler ilk_pipe_fault_handlers[] = { 862 { .fault = GTT_FAULT_SPRITE_A_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 863 { .fault = GTT_FAULT_SPRITE_B_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 864 { .fault = GTT_FAULT_PRIMARY_A_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 865 { .fault = GTT_FAULT_PRIMARY_B_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 866 { .fault = GTT_FAULT_CURSOR_A_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 867 { .fault = GTT_FAULT_CURSOR_B_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 868 {} 869 }; 870 871 static void ilk_gtt_fault_irq_handler(struct intel_display *display) 872 { 873 enum pipe pipe; 874 u32 gtt_fault; 875 876 gtt_fault = intel_de_read(display, ILK_GTT_FAULT); 877 intel_de_write(display, ILK_GTT_FAULT, gtt_fault); 878 879 if (gtt_fault & GTT_FAULT_INVALID_GTT_PTE) 880 drm_err_ratelimited(display->drm, "Invalid GTT PTE\n"); 881 882 if (gtt_fault & GTT_FAULT_INVALID_PTE_DATA) 883 drm_err_ratelimited(display->drm, "Invalid PTE data\n"); 884 885 for_each_pipe(display, pipe) { 886 u32 fault_errors; 887 888 fault_errors = gtt_fault & ilk_gtt_fault_pipe_fault_mask(pipe); 889 if (fault_errors) 890 intel_pipe_fault_irq_handler(display, ilk_pipe_fault_handlers, 891 pipe, fault_errors); 892 } 893 } 894 895 static void _ilk_display_irq_handler(struct intel_display *display, u32 de_iir) 896 { 897 enum pipe pipe; 898 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG; 899 900 if (hotplug_trigger) 901 ilk_hpd_irq_handler(display, hotplug_trigger); 902 903 if (de_iir & DE_AUX_CHANNEL_A) 904 intel_dp_aux_irq_handler(display); 905 906 if (de_iir & DE_GSE) 907 intel_opregion_asle_intr(display); 908 909 if (de_iir & DE_POISON) 910 drm_err(display->drm, "Poison interrupt\n"); 911 912 if (de_iir & DE_GTT_FAULT) 913 ilk_gtt_fault_irq_handler(display); 914 915 for_each_pipe(display, pipe) { 916 if (de_iir & DE_PIPE_VBLANK(pipe)) 917 intel_handle_vblank(display, pipe); 918 919 if (de_iir & DE_PLANE_FLIP_DONE(pipe)) 920 flip_done_handler(display, pipe); 921 922 if (de_iir & DE_PIPE_FIFO_UNDERRUN(pipe)) 923 intel_cpu_fifo_underrun_irq_handler(display, pipe); 924 925 if (de_iir & DE_PIPE_CRC_DONE(pipe)) 926 i9xx_pipe_crc_irq_handler(display, pipe); 927 } 928 929 /* check event from PCH */ 930 if (de_iir & DE_PCH_EVENT) { 931 u32 pch_iir = intel_de_read(display, SDEIIR); 932 933 if (HAS_PCH_CPT(display)) 934 cpt_irq_handler(display, pch_iir); 935 else 936 ibx_irq_handler(display, pch_iir); 937 938 /* should clear PCH hotplug event before clear CPU irq */ 939 intel_de_write(display, SDEIIR, pch_iir); 940 } 941 942 if (DISPLAY_VER(display) == 5 && de_iir & DE_PCU_EVENT) 943 ilk_display_rps_irq_handler(display); 944 } 945 946 static void _ivb_display_irq_handler(struct intel_display *display, u32 de_iir) 947 { 948 enum pipe pipe; 949 u32 hotplug_trigger = de_iir & DE_DP_A_HOTPLUG_IVB; 950 951 if (hotplug_trigger) 952 ilk_hpd_irq_handler(display, hotplug_trigger); 953 954 if (de_iir & DE_ERR_INT_IVB) 955 ivb_err_int_handler(display); 956 957 if (de_iir & DE_EDP_PSR_INT_HSW) { 958 struct intel_encoder *encoder; 959 960 for_each_intel_encoder_with_psr(display->drm, encoder) { 961 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 962 u32 psr_iir; 963 964 psr_iir = intel_de_rmw(display, EDP_PSR_IIR, 0, 0); 965 intel_psr_irq_handler(intel_dp, psr_iir); 966 break; 967 } 968 } 969 970 if (de_iir & DE_AUX_CHANNEL_A_IVB) 971 intel_dp_aux_irq_handler(display); 972 973 if (de_iir & DE_GSE_IVB) 974 intel_opregion_asle_intr(display); 975 976 for_each_pipe(display, pipe) { 977 if (de_iir & DE_PIPE_VBLANK_IVB(pipe)) 978 intel_handle_vblank(display, pipe); 979 980 if (de_iir & DE_PLANE_FLIP_DONE_IVB(pipe)) 981 flip_done_handler(display, pipe); 982 } 983 984 /* check event from PCH */ 985 if (!HAS_PCH_NOP(display) && (de_iir & DE_PCH_EVENT_IVB)) { 986 u32 pch_iir = intel_de_read(display, SDEIIR); 987 988 cpt_irq_handler(display, pch_iir); 989 990 /* clear PCH hotplug event before clear CPU irq */ 991 intel_de_write(display, SDEIIR, pch_iir); 992 } 993 } 994 995 void ilk_display_irq_master_disable(struct intel_display *display, u32 *de_ier, u32 *sde_ier) 996 { 997 /* disable master interrupt before clearing iir */ 998 *de_ier = intel_de_read_fw(display, DEIER); 999 intel_de_write_fw(display, DEIER, *de_ier & ~DE_MASTER_IRQ_CONTROL); 1000 1001 /* 1002 * Disable south interrupts. We'll only write to SDEIIR once, so further 1003 * interrupts will be stored on its back queue, and then we'll be able 1004 * to process them after we restore SDEIER (as soon as we restore it, 1005 * we'll get an interrupt if SDEIIR still has something to process due 1006 * to its back queue). 1007 */ 1008 if (!HAS_PCH_NOP(display)) { 1009 *sde_ier = intel_de_read_fw(display, SDEIER); 1010 intel_de_write_fw(display, SDEIER, 0); 1011 } else { 1012 *sde_ier = 0; 1013 } 1014 } 1015 1016 void ilk_display_irq_master_enable(struct intel_display *display, u32 de_ier, u32 sde_ier) 1017 { 1018 intel_de_write_fw(display, DEIER, de_ier); 1019 1020 if (sde_ier) 1021 intel_de_write_fw(display, SDEIER, sde_ier); 1022 } 1023 1024 static bool ilk_display_irq_handler(struct intel_display *display, 1025 const struct intel_display_irq_state *state) 1026 { 1027 u32 de_iir; 1028 bool handled = false; 1029 1030 de_iir = intel_de_read_fw(display, DEIIR); 1031 if (de_iir) { 1032 intel_de_write_fw(display, DEIIR, de_iir); 1033 if (DISPLAY_VER(display) >= 7) 1034 _ivb_display_irq_handler(display, de_iir); 1035 else 1036 _ilk_display_irq_handler(display, de_iir); 1037 handled = true; 1038 } 1039 1040 return handled; 1041 } 1042 1043 static u32 gen8_de_port_aux_mask(struct intel_display *display) 1044 { 1045 u32 mask; 1046 1047 if (DISPLAY_VER(display) >= 20) 1048 return 0; 1049 else if (DISPLAY_VER(display) >= 14) 1050 return TGL_DE_PORT_AUX_DDIA | 1051 TGL_DE_PORT_AUX_DDIB; 1052 else if (DISPLAY_VER(display) >= 13) 1053 return TGL_DE_PORT_AUX_DDIA | 1054 TGL_DE_PORT_AUX_DDIB | 1055 TGL_DE_PORT_AUX_DDIC | 1056 XELPD_DE_PORT_AUX_DDID | 1057 XELPD_DE_PORT_AUX_DDIE | 1058 TGL_DE_PORT_AUX_USBC1 | 1059 TGL_DE_PORT_AUX_USBC2 | 1060 TGL_DE_PORT_AUX_USBC3 | 1061 TGL_DE_PORT_AUX_USBC4; 1062 else if (DISPLAY_VER(display) >= 12) 1063 return TGL_DE_PORT_AUX_DDIA | 1064 TGL_DE_PORT_AUX_DDIB | 1065 TGL_DE_PORT_AUX_DDIC | 1066 TGL_DE_PORT_AUX_USBC1 | 1067 TGL_DE_PORT_AUX_USBC2 | 1068 TGL_DE_PORT_AUX_USBC3 | 1069 TGL_DE_PORT_AUX_USBC4 | 1070 TGL_DE_PORT_AUX_USBC5 | 1071 TGL_DE_PORT_AUX_USBC6; 1072 1073 mask = GEN8_AUX_CHANNEL_A; 1074 if (DISPLAY_VER(display) >= 9) 1075 mask |= GEN9_AUX_CHANNEL_B | 1076 GEN9_AUX_CHANNEL_C | 1077 GEN9_AUX_CHANNEL_D; 1078 1079 if (DISPLAY_VER(display) == 11) { 1080 mask |= ICL_AUX_CHANNEL_F; 1081 mask |= ICL_AUX_CHANNEL_E; 1082 } 1083 1084 return mask; 1085 } 1086 1087 static u32 gen8_de_pipe_fault_mask(struct intel_display *display) 1088 { 1089 if (DISPLAY_VER(display) >= 20) 1090 return MTL_PLANE_ATS_FAULT | 1091 GEN9_PIPE_CURSOR_FAULT | 1092 GEN11_PIPE_PLANE5_FAULT | 1093 GEN9_PIPE_PLANE4_FAULT | 1094 GEN9_PIPE_PLANE3_FAULT | 1095 GEN9_PIPE_PLANE2_FAULT | 1096 GEN9_PIPE_PLANE1_FAULT; 1097 else if (DISPLAY_VER(display) >= 14) 1098 return MTL_PIPEDMC_ATS_FAULT | 1099 MTL_PLANE_ATS_FAULT | 1100 GEN12_PIPEDMC_FAULT | 1101 GEN9_PIPE_CURSOR_FAULT | 1102 GEN11_PIPE_PLANE5_FAULT | 1103 GEN9_PIPE_PLANE4_FAULT | 1104 GEN9_PIPE_PLANE3_FAULT | 1105 GEN9_PIPE_PLANE2_FAULT | 1106 GEN9_PIPE_PLANE1_FAULT; 1107 else if (DISPLAY_VER(display) >= 13 || HAS_D12_PLANE_MINIMIZATION(display)) 1108 return GEN12_PIPEDMC_FAULT | 1109 GEN9_PIPE_CURSOR_FAULT | 1110 GEN11_PIPE_PLANE5_FAULT | 1111 GEN9_PIPE_PLANE4_FAULT | 1112 GEN9_PIPE_PLANE3_FAULT | 1113 GEN9_PIPE_PLANE2_FAULT | 1114 GEN9_PIPE_PLANE1_FAULT; 1115 else if (DISPLAY_VER(display) == 12) 1116 return GEN12_PIPEDMC_FAULT | 1117 GEN9_PIPE_CURSOR_FAULT | 1118 GEN11_PIPE_PLANE7_FAULT | 1119 GEN11_PIPE_PLANE6_FAULT | 1120 GEN11_PIPE_PLANE5_FAULT | 1121 GEN9_PIPE_PLANE4_FAULT | 1122 GEN9_PIPE_PLANE3_FAULT | 1123 GEN9_PIPE_PLANE2_FAULT | 1124 GEN9_PIPE_PLANE1_FAULT; 1125 else if (DISPLAY_VER(display) == 11) 1126 return GEN9_PIPE_CURSOR_FAULT | 1127 GEN11_PIPE_PLANE7_FAULT | 1128 GEN11_PIPE_PLANE6_FAULT | 1129 GEN11_PIPE_PLANE5_FAULT | 1130 GEN9_PIPE_PLANE4_FAULT | 1131 GEN9_PIPE_PLANE3_FAULT | 1132 GEN9_PIPE_PLANE2_FAULT | 1133 GEN9_PIPE_PLANE1_FAULT; 1134 else if (DISPLAY_VER(display) >= 9) 1135 return GEN9_PIPE_CURSOR_FAULT | 1136 GEN9_PIPE_PLANE4_FAULT | 1137 GEN9_PIPE_PLANE3_FAULT | 1138 GEN9_PIPE_PLANE2_FAULT | 1139 GEN9_PIPE_PLANE1_FAULT; 1140 else 1141 return GEN8_PIPE_CURSOR_FAULT | 1142 GEN8_PIPE_SPRITE_FAULT | 1143 GEN8_PIPE_PRIMARY_FAULT; 1144 } 1145 1146 static bool handle_plane_ats_fault(struct intel_crtc *crtc, enum plane_id plane_id) 1147 { 1148 struct intel_display *display = to_intel_display(crtc); 1149 1150 drm_err_ratelimited(display->drm, 1151 "[CRTC:%d:%s] PLANE ATS fault\n", 1152 crtc->base.base.id, crtc->base.name); 1153 1154 return true; 1155 } 1156 1157 static bool handle_pipedmc_ats_fault(struct intel_crtc *crtc, enum plane_id plane_id) 1158 { 1159 struct intel_display *display = to_intel_display(crtc); 1160 1161 drm_err_ratelimited(display->drm, 1162 "[CRTC:%d:%s] PIPEDMC ATS fault\n", 1163 crtc->base.base.id, crtc->base.name); 1164 1165 return true; 1166 } 1167 1168 static bool handle_pipedmc_fault(struct intel_crtc *crtc, enum plane_id plane_id) 1169 { 1170 struct intel_display *display = to_intel_display(crtc); 1171 1172 drm_err_ratelimited(display->drm, 1173 "[CRTC:%d:%s] PIPEDMC fault\n", 1174 crtc->base.base.id, crtc->base.name); 1175 1176 return true; 1177 } 1178 1179 static const struct pipe_fault_handler mtl_pipe_fault_handlers[] = { 1180 { .fault = MTL_PLANE_ATS_FAULT, .handle = handle_plane_ats_fault, }, 1181 { .fault = MTL_PIPEDMC_ATS_FAULT, .handle = handle_pipedmc_ats_fault, }, 1182 { .fault = GEN12_PIPEDMC_FAULT, .handle = handle_pipedmc_fault, }, 1183 { .fault = GEN11_PIPE_PLANE5_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_5, }, 1184 { .fault = GEN9_PIPE_PLANE4_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_4, }, 1185 { .fault = GEN9_PIPE_PLANE3_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_3, }, 1186 { .fault = GEN9_PIPE_PLANE2_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_2, }, 1187 { .fault = GEN9_PIPE_PLANE1_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_1, }, 1188 { .fault = GEN9_PIPE_CURSOR_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1189 {} 1190 }; 1191 1192 static const struct pipe_fault_handler tgl_pipe_fault_handlers[] = { 1193 { .fault = GEN12_PIPEDMC_FAULT, .handle = handle_pipedmc_fault, }, 1194 { .fault = GEN11_PIPE_PLANE7_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_7, }, 1195 { .fault = GEN11_PIPE_PLANE6_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_6, }, 1196 { .fault = GEN11_PIPE_PLANE5_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_5, }, 1197 { .fault = GEN9_PIPE_PLANE4_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_4, }, 1198 { .fault = GEN9_PIPE_PLANE3_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_3, }, 1199 { .fault = GEN9_PIPE_PLANE2_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_2, }, 1200 { .fault = GEN9_PIPE_PLANE1_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_1, }, 1201 { .fault = GEN9_PIPE_CURSOR_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1202 {} 1203 }; 1204 1205 static const struct pipe_fault_handler icl_pipe_fault_handlers[] = { 1206 { .fault = GEN11_PIPE_PLANE7_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_7, }, 1207 { .fault = GEN11_PIPE_PLANE6_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_6, }, 1208 { .fault = GEN11_PIPE_PLANE5_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_5, }, 1209 { .fault = GEN9_PIPE_PLANE4_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_4, }, 1210 { .fault = GEN9_PIPE_PLANE3_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_3, }, 1211 { .fault = GEN9_PIPE_PLANE2_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_2, }, 1212 { .fault = GEN9_PIPE_PLANE1_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_1, }, 1213 { .fault = GEN9_PIPE_CURSOR_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1214 {} 1215 }; 1216 1217 static const struct pipe_fault_handler skl_pipe_fault_handlers[] = { 1218 { .fault = GEN9_PIPE_PLANE4_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_4, }, 1219 { .fault = GEN9_PIPE_PLANE3_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_3, }, 1220 { .fault = GEN9_PIPE_PLANE2_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_2, }, 1221 { .fault = GEN9_PIPE_PLANE1_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_1, }, 1222 { .fault = GEN9_PIPE_CURSOR_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1223 {} 1224 }; 1225 1226 static const struct pipe_fault_handler bdw_pipe_fault_handlers[] = { 1227 { .fault = GEN8_PIPE_SPRITE_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 1228 { .fault = GEN8_PIPE_PRIMARY_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 1229 { .fault = GEN8_PIPE_CURSOR_FAULT, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1230 {} 1231 }; 1232 1233 static const struct pipe_fault_handler * 1234 gen8_pipe_fault_handlers(struct intel_display *display) 1235 { 1236 if (DISPLAY_VER(display) >= 14) 1237 return mtl_pipe_fault_handlers; 1238 else if (DISPLAY_VER(display) >= 12) 1239 return tgl_pipe_fault_handlers; 1240 else if (DISPLAY_VER(display) >= 11) 1241 return icl_pipe_fault_handlers; 1242 else if (DISPLAY_VER(display) >= 9) 1243 return skl_pipe_fault_handlers; 1244 else 1245 return bdw_pipe_fault_handlers; 1246 } 1247 1248 static void intel_pmdemand_irq_handler(struct intel_display *display) 1249 { 1250 wake_up_all(&display->pmdemand.waitqueue); 1251 } 1252 1253 static void 1254 gen8_de_misc_irq_handler(struct intel_display *display, u32 iir) 1255 { 1256 bool found = false; 1257 1258 if (HAS_DBUF_OVERLAP_DETECTION(display)) { 1259 if (iir & XE2LPD_DBUF_OVERLAP_DETECTED) { 1260 drm_warn(display->drm, "DBuf overlap detected\n"); 1261 found = true; 1262 } 1263 } 1264 1265 if (HAS_PMDEMAND(display)) { 1266 if (iir & (XELPDP_PMDEMAND_RSP | 1267 XELPDP_PMDEMAND_RSPTOUT_ERR)) { 1268 if (iir & XELPDP_PMDEMAND_RSPTOUT_ERR) 1269 drm_dbg(display->drm, 1270 "Error waiting for Punit PM Demand Response\n"); 1271 1272 intel_pmdemand_irq_handler(display); 1273 found = true; 1274 } 1275 1276 if (iir & XELPDP_RM_TIMEOUT) { 1277 u32 val = intel_de_read(display, RM_TIMEOUT_REG_CAPTURE); 1278 drm_warn(display->drm, "Register Access Timeout = 0x%x\n", val); 1279 found = true; 1280 } 1281 } else if (iir & GEN8_DE_MISC_GSE) { 1282 intel_opregion_asle_intr(display); 1283 found = true; 1284 } 1285 1286 if (iir & GEN8_DE_EDP_PSR) { 1287 struct intel_encoder *encoder; 1288 u32 psr_iir; 1289 intel_reg_t iir_reg; 1290 1291 for_each_intel_encoder_with_psr(display->drm, encoder) { 1292 struct intel_dp *intel_dp = enc_to_intel_dp(encoder); 1293 1294 if (DISPLAY_VER(display) >= 12) 1295 iir_reg = TRANS_PSR_IIR(display, 1296 intel_dp->psr.transcoder); 1297 else 1298 iir_reg = EDP_PSR_IIR; 1299 1300 psr_iir = intel_de_rmw(display, iir_reg, 0, 0); 1301 1302 if (psr_iir) 1303 found = true; 1304 1305 intel_psr_irq_handler(intel_dp, psr_iir); 1306 1307 /* prior GEN12 only have one EDP PSR */ 1308 if (DISPLAY_VER(display) < 12) 1309 break; 1310 } 1311 } 1312 1313 if (!found) 1314 drm_err(display->drm, "Unexpected DE Misc interrupt: 0x%08x\n", iir); 1315 } 1316 1317 static void gen11_dsi_te_interrupt_handler(struct intel_display *display, 1318 u32 te_trigger) 1319 { 1320 enum pipe pipe = INVALID_PIPE; 1321 enum transcoder dsi_trans; 1322 enum port port; 1323 u32 val; 1324 1325 /* 1326 * Incase of dual link, TE comes from DSI_1 1327 * this is to check if dual link is enabled 1328 */ 1329 val = intel_de_read(display, TRANS_DDI_FUNC_CTL2(display, TRANSCODER_DSI_0)); 1330 val &= PORT_SYNC_MODE_ENABLE; 1331 1332 /* 1333 * if dual link is enabled, then read DSI_0 1334 * transcoder registers 1335 */ 1336 port = ((te_trigger & DSI1_TE && val) || (te_trigger & DSI0_TE)) ? 1337 PORT_A : PORT_B; 1338 dsi_trans = (port == PORT_A) ? TRANSCODER_DSI_0 : TRANSCODER_DSI_1; 1339 1340 /* Check if DSI configured in command mode */ 1341 val = intel_de_read(display, DSI_TRANS_FUNC_CONF(dsi_trans)); 1342 val = val & OP_MODE_MASK; 1343 1344 if (val != CMD_MODE_NO_GATE && val != CMD_MODE_TE_GATE) { 1345 drm_err(display->drm, "DSI trancoder not configured in command mode\n"); 1346 return; 1347 } 1348 1349 /* Get PIPE for handling VBLANK event */ 1350 val = intel_de_read(display, TRANS_DDI_FUNC_CTL(display, dsi_trans)); 1351 switch (val & TRANS_DDI_EDP_INPUT_MASK) { 1352 case TRANS_DDI_EDP_INPUT_A_ON: 1353 pipe = PIPE_A; 1354 break; 1355 case TRANS_DDI_EDP_INPUT_B_ONOFF: 1356 pipe = PIPE_B; 1357 break; 1358 case TRANS_DDI_EDP_INPUT_C_ONOFF: 1359 pipe = PIPE_C; 1360 break; 1361 default: 1362 drm_err(display->drm, "Invalid PIPE\n"); 1363 return; 1364 } 1365 1366 intel_handle_vblank(display, pipe); 1367 1368 /* clear TE in dsi IIR */ 1369 port = (te_trigger & DSI1_TE) ? PORT_B : PORT_A; 1370 intel_de_rmw(display, DSI_INTR_IDENT_REG(port), 0, 0); 1371 } 1372 1373 static u32 gen8_de_pipe_flip_done_mask(struct intel_display *display) 1374 { 1375 if (DISPLAY_VER(display) >= 9) 1376 return GEN9_PIPE_PLANE1_FLIP_DONE; 1377 else 1378 return GEN8_PIPE_PRIMARY_FLIP_DONE; 1379 } 1380 1381 static void gen8_read_and_ack_pch_irqs(struct intel_display *display, u32 *pch_iir, u32 *pica_iir) 1382 { 1383 u32 pica_ier = 0; 1384 1385 *pica_iir = 0; 1386 *pch_iir = intel_de_read(display, SDEIIR); 1387 if (!*pch_iir) 1388 return; 1389 1390 /** 1391 * PICA IER must be disabled/re-enabled around clearing PICA IIR and 1392 * SDEIIR, to avoid losing PICA IRQs and to ensure that such IRQs set 1393 * their flags both in the PICA and SDE IIR. 1394 */ 1395 if (*pch_iir & SDE_PICAINTERRUPT) { 1396 drm_WARN_ON(display->drm, INTEL_PCH_TYPE(display) < PCH_MTL); 1397 1398 pica_ier = intel_de_rmw(display, PICAINTERRUPT_IER, ~0, 0); 1399 *pica_iir = intel_de_read(display, PICAINTERRUPT_IIR); 1400 intel_de_write(display, PICAINTERRUPT_IIR, *pica_iir); 1401 } 1402 1403 intel_de_write(display, SDEIIR, *pch_iir); 1404 1405 if (pica_ier) 1406 intel_de_write(display, PICAINTERRUPT_IER, pica_ier); 1407 } 1408 1409 static void gen8_de_irq_handler(struct intel_display *display, u32 master_ctl) 1410 { 1411 u32 iir; 1412 enum pipe pipe; 1413 1414 drm_WARN_ON_ONCE(display->drm, !HAS_DISPLAY(display)); 1415 1416 if (master_ctl & GEN8_DE_MISC_IRQ) { 1417 iir = intel_de_read(display, GEN8_DE_MISC_IIR); 1418 if (iir) { 1419 intel_de_write(display, GEN8_DE_MISC_IIR, iir); 1420 gen8_de_misc_irq_handler(display, iir); 1421 } else { 1422 drm_err_ratelimited(display->drm, 1423 "The master control interrupt lied (DE MISC)!\n"); 1424 } 1425 } 1426 1427 if (DISPLAY_VER(display) >= 11 && (master_ctl & GEN11_DE_HPD_IRQ)) { 1428 iir = intel_de_read(display, GEN11_DE_HPD_IIR); 1429 if (iir) { 1430 intel_de_write(display, GEN11_DE_HPD_IIR, iir); 1431 gen11_hpd_irq_handler(display, iir); 1432 } else { 1433 drm_err_ratelimited(display->drm, 1434 "The master control interrupt lied, (DE HPD)!\n"); 1435 } 1436 } 1437 1438 if (master_ctl & GEN8_DE_PORT_IRQ) { 1439 iir = intel_de_read(display, GEN8_DE_PORT_IIR); 1440 if (iir) { 1441 bool found = false; 1442 1443 intel_de_write(display, GEN8_DE_PORT_IIR, iir); 1444 1445 if (iir & gen8_de_port_aux_mask(display)) { 1446 intel_dp_aux_irq_handler(display); 1447 found = true; 1448 } 1449 1450 if (display->platform.geminilake || display->platform.broxton) { 1451 u32 hotplug_trigger = iir & BXT_DE_PORT_HOTPLUG_MASK; 1452 1453 if (hotplug_trigger) { 1454 bxt_hpd_irq_handler(display, hotplug_trigger); 1455 found = true; 1456 } 1457 } else if (display->platform.broadwell) { 1458 u32 hotplug_trigger = iir & BDW_DE_PORT_HOTPLUG_MASK; 1459 1460 if (hotplug_trigger) { 1461 ilk_hpd_irq_handler(display, hotplug_trigger); 1462 found = true; 1463 } 1464 } 1465 1466 if ((display->platform.geminilake || display->platform.broxton) && 1467 (iir & BXT_DE_PORT_GMBUS)) { 1468 intel_gmbus_irq_handler(display); 1469 found = true; 1470 } 1471 1472 if (DISPLAY_VER(display) == 35) { 1473 if (iir & CMTG_VBLANK_A) { 1474 intel_handle_vblank(display, PIPE_A); 1475 found = true; 1476 } 1477 1478 if (iir & CMTG_VBLANK_B) { 1479 intel_handle_vblank(display, PIPE_B); 1480 found = true; 1481 } 1482 } 1483 1484 if (DISPLAY_VER(display) >= 11) { 1485 u32 te_trigger = iir & (DSI0_TE | DSI1_TE); 1486 1487 if (te_trigger) { 1488 gen11_dsi_te_interrupt_handler(display, te_trigger); 1489 found = true; 1490 } 1491 } 1492 1493 if (!found) 1494 drm_err_ratelimited(display->drm, 1495 "Unexpected DE Port interrupt\n"); 1496 } else { 1497 drm_err_ratelimited(display->drm, 1498 "The master control interrupt lied (DE PORT)!\n"); 1499 } 1500 } 1501 1502 for_each_pipe(display, pipe) { 1503 u32 fault_errors; 1504 1505 if (!(master_ctl & GEN8_DE_PIPE_IRQ(pipe))) 1506 continue; 1507 1508 iir = intel_de_read(display, GEN8_DE_PIPE_IIR(pipe)); 1509 if (!iir) { 1510 drm_err_ratelimited(display->drm, 1511 "The master control interrupt lied (DE PIPE %c)!\n", 1512 pipe_name(pipe)); 1513 continue; 1514 } 1515 1516 intel_de_write(display, GEN8_DE_PIPE_IIR(pipe), iir); 1517 1518 if (iir & GEN8_PIPE_VBLANK) 1519 intel_handle_vblank(display, pipe); 1520 1521 if (iir & gen8_de_pipe_flip_done_mask(display)) 1522 flip_done_handler(display, pipe); 1523 1524 if (HAS_DSB(display)) { 1525 if (iir & GEN12_DSB_INT(INTEL_DSB_0)) 1526 intel_dsb_irq_handler(display, pipe, INTEL_DSB_0); 1527 1528 if (iir & GEN12_DSB_INT(INTEL_DSB_1)) 1529 intel_dsb_irq_handler(display, pipe, INTEL_DSB_1); 1530 1531 if (iir & GEN12_DSB_INT(INTEL_DSB_2)) 1532 intel_dsb_irq_handler(display, pipe, INTEL_DSB_2); 1533 } 1534 1535 if (HAS_PIPEDMC(display) && iir & GEN12_PIPEDMC_INTERRUPT) 1536 intel_pipedmc_irq_handler(display, pipe); 1537 1538 if (iir & GEN8_PIPE_CDCLK_CRC_DONE) 1539 hsw_pipe_crc_irq_handler(display, pipe); 1540 1541 if (iir & GEN8_PIPE_FIFO_UNDERRUN) 1542 intel_cpu_fifo_underrun_irq_handler(display, pipe); 1543 1544 fault_errors = iir & gen8_de_pipe_fault_mask(display); 1545 if (fault_errors) 1546 intel_pipe_fault_irq_handler(display, 1547 gen8_pipe_fault_handlers(display), 1548 pipe, fault_errors); 1549 } 1550 1551 if (HAS_PCH_SPLIT(display) && !HAS_PCH_NOP(display) && 1552 master_ctl & GEN8_DE_PCH_IRQ) { 1553 u32 pica_iir; 1554 1555 /* 1556 * FIXME(BDW): Assume for now that the new interrupt handling 1557 * scheme also closed the SDE interrupt handling race we've seen 1558 * on older pch-split platforms. But this needs testing. 1559 */ 1560 gen8_read_and_ack_pch_irqs(display, &iir, &pica_iir); 1561 if (iir) { 1562 if (pica_iir) 1563 xelpdp_pica_irq_handler(display, pica_iir); 1564 1565 if (INTEL_PCH_TYPE(display) >= PCH_ICP) 1566 icp_irq_handler(display, iir); 1567 else if (INTEL_PCH_TYPE(display) >= PCH_SPT) 1568 spt_irq_handler(display, iir); 1569 else 1570 cpt_irq_handler(display, iir); 1571 } else { 1572 /* 1573 * Like on previous PCH there seems to be something 1574 * fishy going on with forwarding PCH interrupts. 1575 */ 1576 drm_dbg(display->drm, 1577 "The master control interrupt lied (SDE)!\n"); 1578 } 1579 } 1580 } 1581 1582 static bool gen8_display_irq_handler(struct intel_display *display, 1583 const struct intel_display_irq_state *state) 1584 { 1585 gen8_de_irq_handler(display, state->master_ctl); 1586 1587 return true; 1588 } 1589 1590 u32 gen11_gu_misc_irq_ack(struct intel_display *display, const u32 master_ctl) 1591 { 1592 u32 iir; 1593 1594 if (!(master_ctl & GEN11_GU_MISC_IRQ)) 1595 return 0; 1596 1597 intel_display_rpm_assert_block(display); 1598 1599 iir = intel_de_read(display, GEN11_GU_MISC_IIR); 1600 if (likely(iir)) 1601 intel_de_write(display, GEN11_GU_MISC_IIR, iir); 1602 1603 intel_display_rpm_assert_unblock(display); 1604 1605 return iir; 1606 } 1607 1608 void gen11_gu_misc_irq_handler(struct intel_display *display, const u32 iir) 1609 { 1610 if (iir & GEN11_GU_MISC_GSE) 1611 intel_opregion_asle_intr(display); 1612 } 1613 1614 static bool gen11_display_irq_handler(struct intel_display *display, 1615 const struct intel_display_irq_state *state) 1616 { 1617 u32 disp_ctl; 1618 1619 intel_display_rpm_assert_block(display); 1620 /* 1621 * GEN11_DISPLAY_INT_CTL has same format as GEN8_MASTER_IRQ 1622 * for the display related bits. 1623 */ 1624 disp_ctl = intel_de_read(display, GEN11_DISPLAY_INT_CTL); 1625 1626 intel_de_write(display, GEN11_DISPLAY_INT_CTL, 0); 1627 gen8_de_irq_handler(display, disp_ctl); 1628 intel_de_write(display, GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE); 1629 1630 intel_display_rpm_assert_unblock(display); 1631 1632 return true; 1633 } 1634 1635 static void i915gm_irq_cstate_wa_enable(struct intel_display *display) 1636 { 1637 lockdep_assert_held(&display->drm->vblank_time_lock); 1638 1639 /* 1640 * Vblank/CRC interrupts fail to wake the device up from C2+. 1641 * Disabling render clock gating during C-states avoids 1642 * the problem. There is a small power cost so we do this 1643 * only when vblank/CRC interrupts are actually enabled. 1644 */ 1645 if (display->irq.vblank_enabled++ == 0) 1646 intel_de_write(display, SCPD0, 1647 REG_MASKED_FIELD_ENABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 1648 } 1649 1650 static void i915gm_irq_cstate_wa_disable(struct intel_display *display) 1651 { 1652 lockdep_assert_held(&display->drm->vblank_time_lock); 1653 1654 if (--display->irq.vblank_enabled == 0) 1655 intel_de_write(display, SCPD0, 1656 REG_MASKED_FIELD_DISABLE(CSTATE_RENDER_CLOCK_GATE_DISABLE)); 1657 } 1658 1659 void i915gm_irq_cstate_wa(struct intel_display *display, bool enable) 1660 { 1661 spin_lock_irq(&display->drm->vblank_time_lock); 1662 1663 if (enable) 1664 i915gm_irq_cstate_wa_enable(display); 1665 else 1666 i915gm_irq_cstate_wa_disable(display); 1667 1668 spin_unlock_irq(&display->drm->vblank_time_lock); 1669 } 1670 1671 int i8xx_enable_vblank(struct drm_crtc *crtc) 1672 { 1673 struct intel_display *display = to_intel_display(crtc->dev); 1674 enum pipe pipe = to_intel_crtc(crtc)->pipe; 1675 unsigned long irqflags; 1676 1677 spin_lock_irqsave(&display->irq.lock, irqflags); 1678 i915_enable_pipestat(display, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 1679 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1680 1681 return 0; 1682 } 1683 1684 void i8xx_disable_vblank(struct drm_crtc *crtc) 1685 { 1686 struct intel_display *display = to_intel_display(crtc->dev); 1687 enum pipe pipe = to_intel_crtc(crtc)->pipe; 1688 unsigned long irqflags; 1689 1690 spin_lock_irqsave(&display->irq.lock, irqflags); 1691 i915_disable_pipestat(display, pipe, PIPE_VBLANK_INTERRUPT_STATUS); 1692 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1693 } 1694 1695 int i915gm_enable_vblank(struct drm_crtc *crtc) 1696 { 1697 struct intel_display *display = to_intel_display(crtc->dev); 1698 1699 i915gm_irq_cstate_wa_enable(display); 1700 1701 return i8xx_enable_vblank(crtc); 1702 } 1703 1704 void i915gm_disable_vblank(struct drm_crtc *crtc) 1705 { 1706 struct intel_display *display = to_intel_display(crtc->dev); 1707 1708 i8xx_disable_vblank(crtc); 1709 1710 i915gm_irq_cstate_wa_disable(display); 1711 } 1712 1713 int i965_enable_vblank(struct drm_crtc *crtc) 1714 { 1715 struct intel_display *display = to_intel_display(crtc->dev); 1716 enum pipe pipe = to_intel_crtc(crtc)->pipe; 1717 unsigned long irqflags; 1718 1719 spin_lock_irqsave(&display->irq.lock, irqflags); 1720 i915_enable_pipestat(display, pipe, 1721 PIPE_START_VBLANK_INTERRUPT_STATUS); 1722 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1723 1724 return 0; 1725 } 1726 1727 void i965_disable_vblank(struct drm_crtc *crtc) 1728 { 1729 struct intel_display *display = to_intel_display(crtc->dev); 1730 enum pipe pipe = to_intel_crtc(crtc)->pipe; 1731 unsigned long irqflags; 1732 1733 spin_lock_irqsave(&display->irq.lock, irqflags); 1734 i915_disable_pipestat(display, pipe, 1735 PIPE_START_VBLANK_INTERRUPT_STATUS); 1736 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1737 } 1738 1739 int ilk_enable_vblank(struct drm_crtc *crtc) 1740 { 1741 struct intel_display *display = to_intel_display(crtc->dev); 1742 enum pipe pipe = to_intel_crtc(crtc)->pipe; 1743 unsigned long irqflags; 1744 u32 bit = DISPLAY_VER(display) >= 7 ? 1745 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 1746 1747 spin_lock_irqsave(&display->irq.lock, irqflags); 1748 ilk_enable_display_irq(display, bit); 1749 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1750 1751 /* Even though there is no DMC, frame counter can get stuck when 1752 * PSR is active as no frames are generated. 1753 */ 1754 if (HAS_PSR(display)) 1755 drm_crtc_vblank_restore(crtc); 1756 1757 return 0; 1758 } 1759 1760 void ilk_disable_vblank(struct drm_crtc *crtc) 1761 { 1762 struct intel_display *display = to_intel_display(crtc->dev); 1763 enum pipe pipe = to_intel_crtc(crtc)->pipe; 1764 unsigned long irqflags; 1765 u32 bit = DISPLAY_VER(display) >= 7 ? 1766 DE_PIPE_VBLANK_IVB(pipe) : DE_PIPE_VBLANK(pipe); 1767 1768 spin_lock_irqsave(&display->irq.lock, irqflags); 1769 ilk_disable_display_irq(display, bit); 1770 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1771 } 1772 1773 static bool gen11_dsi_configure_te(struct intel_crtc *intel_crtc, 1774 bool enable) 1775 { 1776 struct intel_display *display = to_intel_display(intel_crtc); 1777 enum port port; 1778 1779 if (!(intel_crtc->mode_flags & 1780 (I915_MODE_FLAG_DSI_USE_TE1 | I915_MODE_FLAG_DSI_USE_TE0))) 1781 return false; 1782 1783 /* for dual link cases we consider TE from slave */ 1784 if (intel_crtc->mode_flags & I915_MODE_FLAG_DSI_USE_TE1) 1785 port = PORT_B; 1786 else 1787 port = PORT_A; 1788 1789 intel_de_rmw(display, DSI_INTR_MASK_REG(port), DSI_TE_EVENT, enable ? 0 : DSI_TE_EVENT); 1790 1791 intel_de_rmw(display, DSI_INTR_IDENT_REG(port), 0, 0); 1792 1793 return true; 1794 } 1795 1796 static void intel_display_vblank_notify_work(struct work_struct *work) 1797 { 1798 struct intel_display *display = 1799 container_of(work, typeof(*display), irq.vblank_notify_work); 1800 int vblank_enable_count = READ_ONCE(display->irq.vblank_enable_count); 1801 bool vblank_status = !!vblank_enable_count; 1802 1803 if (display->irq.vblank_status_last_notified != vblank_status) { 1804 intel_psr_notify_vblank_enable_disable(display, vblank_status); 1805 display->irq.vblank_status_last_notified = vblank_status; 1806 } 1807 } 1808 1809 int bdw_enable_vblank(struct drm_crtc *_crtc) 1810 { 1811 struct intel_crtc *crtc = to_intel_crtc(_crtc); 1812 struct intel_display *display = to_intel_display(crtc); 1813 enum pipe pipe = crtc->pipe; 1814 unsigned long irqflags; 1815 1816 if (gen11_dsi_configure_te(crtc, true)) 1817 return 0; 1818 1819 spin_lock_irqsave(&display->irq.lock, irqflags); 1820 if (crtc->vblank_psr_notify && display->irq.vblank_enable_count++ == 0) 1821 schedule_work(&display->irq.vblank_notify_work); 1822 1823 bdw_enable_pipe_irq(display, pipe, GEN8_PIPE_VBLANK); 1824 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1825 1826 /* Even if there is no DMC, frame counter can get stuck when 1827 * PSR is active as no frames are generated, so check only for PSR. 1828 */ 1829 if (HAS_PSR(display)) 1830 drm_crtc_vblank_restore(&crtc->base); 1831 1832 return 0; 1833 } 1834 1835 void bdw_disable_vblank(struct drm_crtc *_crtc) 1836 { 1837 struct intel_crtc *crtc = to_intel_crtc(_crtc); 1838 struct intel_display *display = to_intel_display(crtc); 1839 enum pipe pipe = crtc->pipe; 1840 unsigned long irqflags; 1841 1842 if (gen11_dsi_configure_te(crtc, false)) 1843 return; 1844 1845 spin_lock_irqsave(&display->irq.lock, irqflags); 1846 bdw_disable_pipe_irq(display, pipe, GEN8_PIPE_VBLANK); 1847 spin_unlock_irqrestore(&display->irq.lock, irqflags); 1848 1849 if (crtc->vblank_psr_notify && --display->irq.vblank_enable_count == 0) 1850 schedule_work(&display->irq.vblank_notify_work); 1851 } 1852 1853 static u32 vlv_dpinvgtt_pipe_fault_mask(enum pipe pipe) 1854 { 1855 switch (pipe) { 1856 case PIPE_A: 1857 return SPRITEB_INVALID_GTT_STATUS | 1858 SPRITEA_INVALID_GTT_STATUS | 1859 PLANEA_INVALID_GTT_STATUS | 1860 CURSORA_INVALID_GTT_STATUS; 1861 case PIPE_B: 1862 return SPRITED_INVALID_GTT_STATUS | 1863 SPRITEC_INVALID_GTT_STATUS | 1864 PLANEB_INVALID_GTT_STATUS | 1865 CURSORB_INVALID_GTT_STATUS; 1866 case PIPE_C: 1867 return SPRITEF_INVALID_GTT_STATUS | 1868 SPRITEE_INVALID_GTT_STATUS | 1869 PLANEC_INVALID_GTT_STATUS | 1870 CURSORC_INVALID_GTT_STATUS; 1871 default: 1872 return 0; 1873 } 1874 } 1875 1876 static const struct pipe_fault_handler vlv_pipe_fault_handlers[] = { 1877 { .fault = SPRITEB_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE1, }, 1878 { .fault = SPRITEA_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 1879 { .fault = PLANEA_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 1880 { .fault = CURSORA_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1881 { .fault = SPRITED_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE1, }, 1882 { .fault = SPRITEC_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 1883 { .fault = PLANEB_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 1884 { .fault = CURSORB_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1885 { .fault = SPRITEF_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE1, }, 1886 { .fault = SPRITEE_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_SPRITE0, }, 1887 { .fault = PLANEC_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_PRIMARY, }, 1888 { .fault = CURSORC_INVALID_GTT_STATUS, .handle = handle_plane_fault, .plane_id = PLANE_CURSOR, }, 1889 {} 1890 }; 1891 1892 static void vlv_page_table_error_irq_ack(struct intel_display *display, u32 *dpinvgtt) 1893 { 1894 u32 status, enable, tmp; 1895 1896 tmp = intel_de_read(display, DPINVGTT); 1897 1898 enable = tmp >> 16; 1899 status = tmp & 0xffff; 1900 1901 /* 1902 * Despite what the docs claim, the status bits seem to get 1903 * stuck permanently (similar the old PGTBL_ER register), so 1904 * we have to disable and ignore them once set. They do get 1905 * reset if the display power well goes down, so no need to 1906 * track the enable mask explicitly. 1907 */ 1908 *dpinvgtt = status & enable; 1909 enable &= ~status; 1910 1911 /* customary ack+disable then re-enable to guarantee an edge */ 1912 intel_de_write(display, DPINVGTT, status); 1913 intel_de_write(display, DPINVGTT, enable << 16); 1914 } 1915 1916 static void vlv_page_table_error_irq_handler(struct intel_display *display, u32 dpinvgtt) 1917 { 1918 enum pipe pipe; 1919 1920 for_each_pipe(display, pipe) { 1921 u32 fault_errors; 1922 1923 fault_errors = dpinvgtt & vlv_dpinvgtt_pipe_fault_mask(pipe); 1924 if (fault_errors) 1925 intel_pipe_fault_irq_handler(display, vlv_pipe_fault_handlers, 1926 pipe, fault_errors); 1927 } 1928 } 1929 1930 static void vlv_display_error_irq_ack(struct intel_display *display, 1931 u32 *eir, u32 *dpinvgtt) 1932 { 1933 u32 emr; 1934 1935 *eir = intel_de_read(display, VLV_EIR); 1936 1937 if (*eir & VLV_ERROR_PAGE_TABLE) 1938 vlv_page_table_error_irq_ack(display, dpinvgtt); 1939 1940 intel_de_write(display, VLV_EIR, *eir); 1941 1942 /* 1943 * Toggle all EMR bits to make sure we get an edge 1944 * in the ISR master error bit if we don't clear 1945 * all the EIR bits. 1946 */ 1947 emr = intel_de_read(display, VLV_EMR); 1948 intel_de_write(display, VLV_EMR, 0xffffffff); 1949 intel_de_write(display, VLV_EMR, emr); 1950 } 1951 1952 static void vlv_display_error_irq_handler(struct intel_display *display, 1953 u32 eir, u32 dpinvgtt) 1954 { 1955 drm_dbg(display->drm, "Master Error, EIR 0x%08x\n", eir); 1956 1957 if (eir & VLV_ERROR_PAGE_TABLE) 1958 vlv_page_table_error_irq_handler(display, dpinvgtt); 1959 } 1960 1961 static void _vlv_display_irq_reset(struct intel_display *display) 1962 { 1963 if (display->platform.cherryview) 1964 intel_de_write(display, DPINVGTT, DPINVGTT_STATUS_MASK_CHV); 1965 else 1966 intel_de_write(display, DPINVGTT, DPINVGTT_STATUS_MASK_VLV); 1967 1968 error_reset(display, VLV_ERROR_REGS); 1969 1970 i915_hotplug_interrupt_update_locked(display, 0xffffffff, 0); 1971 intel_de_rmw(display, PORT_HOTPLUG_STAT(display), 0, 0); 1972 1973 i9xx_pipestat_irq_reset(display); 1974 1975 irq_reset(display, VLV_IRQ_REGS); 1976 display->irq.vlv_imr_mask = ~0u; 1977 } 1978 1979 static void vlv_display_irq_reset(struct intel_display *display) 1980 { 1981 spin_lock_irq(&display->irq.lock); 1982 if (display->irq.vlv_display_irqs_enabled) 1983 _vlv_display_irq_reset(display); 1984 spin_unlock_irq(&display->irq.lock); 1985 } 1986 1987 static void i9xx_display_irq_reset(struct intel_display *display) 1988 { 1989 if (HAS_HOTPLUG(display)) { 1990 i915_hotplug_interrupt_update(display, 0xffffffff, 0); 1991 intel_de_rmw(display, PORT_HOTPLUG_STAT(display), 0, 0); 1992 } 1993 1994 i9xx_pipestat_irq_reset(display); 1995 } 1996 1997 u32 i9xx_display_irq_enable_mask(struct intel_display *display) 1998 { 1999 u32 enable_mask; 2000 2001 enable_mask = I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2002 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT; 2003 2004 if (DISPLAY_VER(display) >= 3) 2005 enable_mask |= I915_ASLE_INTERRUPT; 2006 2007 if (HAS_HOTPLUG(display)) 2008 enable_mask |= I915_DISPLAY_PORT_INTERRUPT; 2009 2010 return enable_mask; 2011 } 2012 2013 static void i915_display_irq_postinstall(struct intel_display *display) 2014 { 2015 /* 2016 * Interrupt setup is already guaranteed to be single-threaded, this is 2017 * just to make the assert_spin_locked check happy. 2018 */ 2019 spin_lock_irq(&display->irq.lock); 2020 i915_enable_pipestat(display, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 2021 i915_enable_pipestat(display, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 2022 spin_unlock_irq(&display->irq.lock); 2023 2024 i915_enable_asle_pipestat(display); 2025 } 2026 2027 static void i965_display_irq_postinstall(struct intel_display *display) 2028 { 2029 /* 2030 * Interrupt setup is already guaranteed to be single-threaded, this is 2031 * just to make the assert_spin_locked check happy. 2032 */ 2033 spin_lock_irq(&display->irq.lock); 2034 i915_enable_pipestat(display, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 2035 i915_enable_pipestat(display, PIPE_A, PIPE_CRC_DONE_INTERRUPT_STATUS); 2036 i915_enable_pipestat(display, PIPE_B, PIPE_CRC_DONE_INTERRUPT_STATUS); 2037 spin_unlock_irq(&display->irq.lock); 2038 2039 i915_enable_asle_pipestat(display); 2040 } 2041 2042 static void i9xx_display_irq_ack(struct intel_display *display, 2043 struct intel_display_irq_state *state) 2044 { 2045 if (state->iir & I915_DISPLAY_PORT_INTERRUPT) 2046 state->hotplug_status = i9xx_hpd_irq_ack(display); 2047 2048 /* Call regardless, as some status bits might not be signalled in IIR */ 2049 i9xx_pipestat_irq_ack(display, state->iir, state->pipe_stats); 2050 } 2051 2052 static bool i965_display_irq_handler(struct intel_display *display, 2053 const struct intel_display_irq_state *state) 2054 { 2055 if (state->hotplug_status) 2056 i9xx_hpd_irq_handler(display, state->hotplug_status); 2057 2058 i965_pipestat_irq_handler(display, state->iir, state->pipe_stats); 2059 2060 return true; 2061 } 2062 2063 static bool i915_display_irq_handler(struct intel_display *display, 2064 const struct intel_display_irq_state *state) 2065 { 2066 if (state->hotplug_status) 2067 i9xx_hpd_irq_handler(display, state->hotplug_status); 2068 2069 i915_pipestat_irq_handler(display, state->iir, state->pipe_stats); 2070 2071 return true; 2072 } 2073 2074 static u32 vlv_error_mask(void) 2075 { 2076 /* TODO enable other errors too? */ 2077 return VLV_ERROR_PAGE_TABLE; 2078 } 2079 2080 static void _vlv_display_irq_postinstall(struct intel_display *display) 2081 { 2082 u32 pipestat_mask; 2083 u32 enable_mask; 2084 enum pipe pipe; 2085 2086 if (display->platform.cherryview) 2087 intel_de_write(display, DPINVGTT, 2088 DPINVGTT_STATUS_MASK_CHV | 2089 DPINVGTT_EN_MASK_CHV); 2090 else 2091 intel_de_write(display, DPINVGTT, 2092 DPINVGTT_STATUS_MASK_VLV | 2093 DPINVGTT_EN_MASK_VLV); 2094 2095 error_init(display, VLV_ERROR_REGS, ~vlv_error_mask()); 2096 2097 pipestat_mask = PIPE_CRC_DONE_INTERRUPT_STATUS; 2098 2099 i915_enable_pipestat(display, PIPE_A, PIPE_GMBUS_INTERRUPT_STATUS); 2100 for_each_pipe(display, pipe) 2101 i915_enable_pipestat(display, pipe, pipestat_mask); 2102 2103 enable_mask = I915_DISPLAY_PORT_INTERRUPT | 2104 I915_DISPLAY_PIPE_A_EVENT_INTERRUPT | 2105 I915_DISPLAY_PIPE_B_EVENT_INTERRUPT | 2106 I915_LPE_PIPE_A_INTERRUPT | 2107 I915_LPE_PIPE_B_INTERRUPT | 2108 I915_MASTER_ERROR_INTERRUPT; 2109 2110 if (display->platform.cherryview) 2111 enable_mask |= I915_DISPLAY_PIPE_C_EVENT_INTERRUPT | 2112 I915_LPE_PIPE_C_INTERRUPT; 2113 2114 drm_WARN_ON(display->drm, display->irq.vlv_imr_mask != ~0u); 2115 2116 display->irq.vlv_imr_mask = ~enable_mask; 2117 2118 irq_init(display, VLV_IRQ_REGS, display->irq.vlv_imr_mask, enable_mask); 2119 } 2120 2121 static void vlv_display_irq_postinstall(struct intel_display *display) 2122 { 2123 spin_lock_irq(&display->irq.lock); 2124 if (display->irq.vlv_display_irqs_enabled) 2125 _vlv_display_irq_postinstall(display); 2126 spin_unlock_irq(&display->irq.lock); 2127 } 2128 2129 static u32 vlv_lpe_irq_mask(struct intel_display *display) 2130 { 2131 if (display->platform.cherryview) 2132 return I915_LPE_PIPE_A_INTERRUPT | I915_LPE_PIPE_B_INTERRUPT | 2133 I915_LPE_PIPE_C_INTERRUPT; 2134 else 2135 return I915_LPE_PIPE_A_INTERRUPT | I915_LPE_PIPE_B_INTERRUPT; 2136 } 2137 2138 static void vlv_display_irq_ack(struct intel_display *display, 2139 struct intel_display_irq_state *state) 2140 { 2141 if (state->iir & I915_DISPLAY_PORT_INTERRUPT) 2142 state->hotplug_status = i9xx_hpd_irq_ack(display); 2143 2144 if (state->iir & I915_MASTER_ERROR_INTERRUPT) 2145 vlv_display_error_irq_ack(display, &state->eir, &state->dpinvgtt); 2146 2147 /* Call regardless, as some status bits might not be signalled in IIR */ 2148 i9xx_pipestat_irq_ack(display, state->iir, state->pipe_stats); 2149 2150 /* The handler acks the irq, so need to call the handler here */ 2151 if (state->iir & vlv_lpe_irq_mask(display)) 2152 intel_lpe_audio_irq_handler(display); 2153 } 2154 2155 static bool vlv_display_irq_handler(struct intel_display *display, 2156 const struct intel_display_irq_state *state) 2157 { 2158 if (state->hotplug_status) 2159 i9xx_hpd_irq_handler(display, state->hotplug_status); 2160 2161 if (state->iir & I915_MASTER_ERROR_INTERRUPT) 2162 vlv_display_error_irq_handler(display, state->eir, state->dpinvgtt); 2163 2164 valleyview_pipestat_irq_handler(display, state->pipe_stats); 2165 2166 return true; 2167 } 2168 2169 static void ibx_display_irq_reset(struct intel_display *display) 2170 { 2171 if (HAS_PCH_NOP(display)) 2172 return; 2173 2174 irq_reset(display, SDE_IRQ_REGS); 2175 2176 if (HAS_PCH_CPT(display) || HAS_PCH_LPT(display)) 2177 intel_de_write(display, SERR_INT, 0xffffffff); 2178 } 2179 2180 static void ilk_display_irq_reset(struct intel_display *display) 2181 { 2182 irq_reset(display, DE_IRQ_REGS); 2183 display->irq.ilk_de_imr_mask = ~0u; 2184 2185 if (DISPLAY_VER(display) == 7) 2186 intel_de_write(display, GEN7_ERR_INT, 0xffffffff); 2187 2188 if (display->platform.haswell) { 2189 intel_de_write(display, EDP_PSR_IMR, 0xffffffff); 2190 intel_de_write(display, EDP_PSR_IIR, 0xffffffff); 2191 } 2192 2193 ibx_display_irq_reset(display); 2194 } 2195 2196 static void gen8_display_irq_reset(struct intel_display *display) 2197 { 2198 enum pipe pipe; 2199 2200 intel_de_write(display, EDP_PSR_IMR, 0xffffffff); 2201 intel_de_write(display, EDP_PSR_IIR, 0xffffffff); 2202 2203 for_each_pipe(display, pipe) 2204 if (intel_display_power_is_enabled(display, 2205 POWER_DOMAIN_PIPE(pipe))) 2206 irq_reset(display, GEN8_DE_PIPE_IRQ_REGS(pipe)); 2207 2208 irq_reset(display, GEN8_DE_PORT_IRQ_REGS); 2209 irq_reset(display, GEN8_DE_MISC_IRQ_REGS); 2210 2211 if (HAS_PCH_SPLIT(display)) 2212 ibx_display_irq_reset(display); 2213 } 2214 2215 static void gen11_display_irq_reset(struct intel_display *display) 2216 { 2217 enum pipe pipe; 2218 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) | 2219 BIT(TRANSCODER_C) | BIT(TRANSCODER_D); 2220 2221 intel_de_write(display, GEN11_DISPLAY_INT_CTL, 0); 2222 2223 if (DISPLAY_VER(display) >= 12) { 2224 enum transcoder trans; 2225 2226 for_each_cpu_transcoder_masked(display, trans, trans_mask) { 2227 enum intel_display_power_domain domain; 2228 2229 domain = POWER_DOMAIN_TRANSCODER(trans); 2230 if (!intel_display_power_is_enabled(display, domain)) 2231 continue; 2232 2233 intel_de_write(display, 2234 TRANS_PSR_IMR(display, trans), 2235 0xffffffff); 2236 intel_de_write(display, 2237 TRANS_PSR_IIR(display, trans), 2238 0xffffffff); 2239 } 2240 } else { 2241 intel_de_write(display, EDP_PSR_IMR, 0xffffffff); 2242 intel_de_write(display, EDP_PSR_IIR, 0xffffffff); 2243 } 2244 2245 for_each_pipe(display, pipe) 2246 if (intel_display_power_is_enabled(display, 2247 POWER_DOMAIN_PIPE(pipe))) 2248 irq_reset(display, GEN8_DE_PIPE_IRQ_REGS(pipe)); 2249 2250 irq_reset(display, GEN8_DE_PORT_IRQ_REGS); 2251 irq_reset(display, GEN8_DE_MISC_IRQ_REGS); 2252 2253 if (DISPLAY_VER(display) >= 14) 2254 irq_reset(display, PICAINTERRUPT_IRQ_REGS); 2255 else 2256 irq_reset(display, GEN11_DE_HPD_IRQ_REGS); 2257 2258 if (INTEL_PCH_TYPE(display) >= PCH_ICP) 2259 irq_reset(display, SDE_IRQ_REGS); 2260 } 2261 2262 void gen8_irq_power_well_post_enable(struct intel_display *display, 2263 u8 pipe_mask) 2264 { 2265 u32 extra_ier = GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN | 2266 gen8_de_pipe_flip_done_mask(display); 2267 enum pipe pipe; 2268 2269 spin_lock_irq(&display->irq.lock); 2270 2271 if (!intel_parent_irq_enabled(display)) { 2272 spin_unlock_irq(&display->irq.lock); 2273 return; 2274 } 2275 2276 for_each_pipe_masked(display, pipe, pipe_mask) 2277 irq_init(display, GEN8_DE_PIPE_IRQ_REGS(pipe), 2278 display->irq.de_pipe_imr_mask[pipe], 2279 ~display->irq.de_pipe_imr_mask[pipe] | extra_ier); 2280 2281 spin_unlock_irq(&display->irq.lock); 2282 } 2283 2284 void gen8_irq_power_well_pre_disable(struct intel_display *display, 2285 u8 pipe_mask) 2286 { 2287 enum pipe pipe; 2288 2289 spin_lock_irq(&display->irq.lock); 2290 2291 if (!intel_parent_irq_enabled(display)) { 2292 spin_unlock_irq(&display->irq.lock); 2293 return; 2294 } 2295 2296 for_each_pipe_masked(display, pipe, pipe_mask) 2297 irq_reset(display, GEN8_DE_PIPE_IRQ_REGS(pipe)); 2298 2299 spin_unlock_irq(&display->irq.lock); 2300 2301 /* make sure we're done processing display irqs */ 2302 intel_parent_irq_synchronize(display); 2303 } 2304 2305 /* 2306 * SDEIER is also touched by the interrupt handler to work around missed PCH 2307 * interrupts. Hence we can't update it after the interrupt handler is enabled - 2308 * instead we unconditionally enable all PCH interrupt sources here, but then 2309 * only unmask them as needed with SDEIMR. 2310 * 2311 * Note that we currently do this after installing the interrupt handler, 2312 * but before we enable the master interrupt. That should be sufficient 2313 * to avoid races with the irq handler, assuming we have MSI. Shared legacy 2314 * interrupts could still race. 2315 */ 2316 static void ibx_irq_postinstall(struct intel_display *display) 2317 { 2318 u32 mask; 2319 2320 if (HAS_PCH_NOP(display)) 2321 return; 2322 2323 if (HAS_PCH_IBX(display)) 2324 mask = SDE_GMBUS | SDE_AUX_MASK | SDE_POISON; 2325 else if (HAS_PCH_CPT(display) || HAS_PCH_LPT(display)) 2326 mask = SDE_GMBUS_CPT | SDE_AUX_MASK_CPT; 2327 else 2328 mask = SDE_GMBUS_CPT; 2329 2330 irq_init(display, SDE_IRQ_REGS, ~mask, 0xffffffff); 2331 } 2332 2333 void valleyview_enable_display_irqs(struct intel_display *display) 2334 { 2335 spin_lock_irq(&display->irq.lock); 2336 2337 if (display->irq.vlv_display_irqs_enabled) 2338 goto out; 2339 2340 display->irq.vlv_display_irqs_enabled = true; 2341 2342 if (intel_parent_irq_enabled(display)) { 2343 _vlv_display_irq_reset(display); 2344 _vlv_display_irq_postinstall(display); 2345 } 2346 2347 out: 2348 spin_unlock_irq(&display->irq.lock); 2349 } 2350 2351 void valleyview_disable_display_irqs(struct intel_display *display) 2352 { 2353 spin_lock_irq(&display->irq.lock); 2354 2355 if (!display->irq.vlv_display_irqs_enabled) 2356 goto out; 2357 2358 display->irq.vlv_display_irqs_enabled = false; 2359 2360 if (intel_parent_irq_enabled(display)) 2361 _vlv_display_irq_reset(display); 2362 out: 2363 spin_unlock_irq(&display->irq.lock); 2364 } 2365 2366 static void ilk_de_irq_postinstall(struct intel_display *display) 2367 { 2368 u32 display_mask, extra_mask; 2369 2370 if (DISPLAY_VER(display) >= 7) { 2371 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE_IVB | 2372 DE_PCH_EVENT_IVB | DE_AUX_CHANNEL_A_IVB); 2373 extra_mask = (DE_PIPEC_VBLANK_IVB | DE_PIPEB_VBLANK_IVB | 2374 DE_PIPEA_VBLANK_IVB | DE_ERR_INT_IVB | 2375 DE_PLANE_FLIP_DONE_IVB(PLANE_C) | 2376 DE_PLANE_FLIP_DONE_IVB(PLANE_B) | 2377 DE_PLANE_FLIP_DONE_IVB(PLANE_A) | 2378 DE_DP_A_HOTPLUG_IVB); 2379 } else { 2380 display_mask = (DE_MASTER_IRQ_CONTROL | DE_GSE | 2381 DE_PCH_EVENT | DE_GTT_FAULT | 2382 DE_AUX_CHANNEL_A | DE_PIPEB_CRC_DONE | 2383 DE_PIPEA_CRC_DONE | DE_POISON); 2384 extra_mask = (DE_PIPEA_VBLANK | DE_PIPEB_VBLANK | 2385 DE_PIPEB_FIFO_UNDERRUN | DE_PIPEA_FIFO_UNDERRUN | 2386 DE_PLANE_FLIP_DONE(PLANE_A) | 2387 DE_PLANE_FLIP_DONE(PLANE_B) | 2388 DE_DP_A_HOTPLUG); 2389 } 2390 2391 if (display->platform.haswell) { 2392 assert_iir_is_zero(display, EDP_PSR_IIR); 2393 display_mask |= DE_EDP_PSR_INT_HSW; 2394 } 2395 2396 if (display->platform.ironlake && display->platform.mobile) 2397 extra_mask |= DE_PCU_EVENT; 2398 2399 display->irq.ilk_de_imr_mask = ~display_mask; 2400 2401 ibx_irq_postinstall(display); 2402 2403 irq_init(display, DE_IRQ_REGS, display->irq.ilk_de_imr_mask, 2404 display_mask | extra_mask); 2405 } 2406 2407 static void mtp_irq_postinstall(struct intel_display *display); 2408 static void icp_irq_postinstall(struct intel_display *display); 2409 2410 static void gen8_de_irq_postinstall(struct intel_display *display) 2411 { 2412 u32 de_pipe_masked = gen8_de_pipe_fault_mask(display) | 2413 GEN8_PIPE_CDCLK_CRC_DONE; 2414 u32 de_pipe_enables; 2415 u32 de_port_masked = gen8_de_port_aux_mask(display); 2416 u32 de_port_enables; 2417 u32 de_misc_masked = GEN8_DE_EDP_PSR; 2418 u32 trans_mask = BIT(TRANSCODER_A) | BIT(TRANSCODER_B) | 2419 BIT(TRANSCODER_C) | BIT(TRANSCODER_D); 2420 enum pipe pipe; 2421 2422 if (!HAS_DISPLAY(display)) 2423 return; 2424 2425 if (DISPLAY_VER(display) >= 14) 2426 mtp_irq_postinstall(display); 2427 else if (INTEL_PCH_TYPE(display) >= PCH_ICP) 2428 icp_irq_postinstall(display); 2429 else if (HAS_PCH_SPLIT(display)) 2430 ibx_irq_postinstall(display); 2431 2432 if (DISPLAY_VER(display) < 11) 2433 de_misc_masked |= GEN8_DE_MISC_GSE; 2434 2435 if (display->platform.geminilake || display->platform.broxton) 2436 de_port_masked |= BXT_DE_PORT_GMBUS; 2437 2438 if (DISPLAY_VER(display) >= 14) { 2439 de_misc_masked |= XELPDP_PMDEMAND_RSPTOUT_ERR | 2440 XELPDP_PMDEMAND_RSP | XELPDP_RM_TIMEOUT; 2441 } else if (DISPLAY_VER(display) >= 11) { 2442 enum port port; 2443 2444 if (intel_bios_is_dsi_present(display, &port)) 2445 de_port_masked |= DSI0_TE | DSI1_TE; 2446 } 2447 2448 if (HAS_DBUF_OVERLAP_DETECTION(display)) 2449 de_misc_masked |= XE2LPD_DBUF_OVERLAP_DETECTED; 2450 2451 if (HAS_DSB(display)) 2452 de_pipe_masked |= GEN12_DSB_INT(INTEL_DSB_0) | 2453 GEN12_DSB_INT(INTEL_DSB_1) | 2454 GEN12_DSB_INT(INTEL_DSB_2); 2455 2456 /* TODO figure PIPEDMC interrupts for pre-LNL */ 2457 if (DISPLAY_VER(display) >= 20) 2458 de_pipe_masked |= GEN12_PIPEDMC_INTERRUPT; 2459 2460 de_pipe_enables = de_pipe_masked | 2461 GEN8_PIPE_VBLANK | GEN8_PIPE_FIFO_UNDERRUN | 2462 gen8_de_pipe_flip_done_mask(display); 2463 2464 de_port_enables = de_port_masked; 2465 if (display->platform.geminilake || display->platform.broxton) 2466 de_port_enables |= BXT_DE_PORT_HOTPLUG_MASK; 2467 else if (display->platform.broadwell) 2468 de_port_enables |= BDW_DE_PORT_HOTPLUG_MASK; 2469 2470 if (DISPLAY_VER(display) >= 12) { 2471 enum transcoder trans; 2472 2473 for_each_cpu_transcoder_masked(display, trans, trans_mask) { 2474 enum intel_display_power_domain domain; 2475 2476 domain = POWER_DOMAIN_TRANSCODER(trans); 2477 if (!intel_display_power_is_enabled(display, domain)) 2478 continue; 2479 2480 assert_iir_is_zero(display, TRANS_PSR_IIR(display, trans)); 2481 } 2482 } else { 2483 assert_iir_is_zero(display, EDP_PSR_IIR); 2484 } 2485 2486 for_each_pipe(display, pipe) { 2487 display->irq.de_pipe_imr_mask[pipe] = ~de_pipe_masked; 2488 2489 if (intel_display_power_is_enabled(display, 2490 POWER_DOMAIN_PIPE(pipe))) 2491 irq_init(display, GEN8_DE_PIPE_IRQ_REGS(pipe), 2492 display->irq.de_pipe_imr_mask[pipe], 2493 de_pipe_enables); 2494 } 2495 2496 irq_init(display, GEN8_DE_PORT_IRQ_REGS, ~de_port_masked, de_port_enables); 2497 irq_init(display, GEN8_DE_MISC_IRQ_REGS, ~de_misc_masked, de_misc_masked); 2498 2499 if (IS_DISPLAY_VER(display, 11, 13)) { 2500 u32 de_hpd_masked = 0; 2501 u32 de_hpd_enables = GEN11_DE_TC_HOTPLUG_MASK | 2502 GEN11_DE_TBT_HOTPLUG_MASK; 2503 2504 irq_init(display, GEN11_DE_HPD_IRQ_REGS, ~de_hpd_masked, de_hpd_enables); 2505 } 2506 } 2507 2508 u32 xelpdp_pica_aux_mask(struct intel_display *display) 2509 { 2510 u32 mask = XELPDP_AUX_TC_MASK; 2511 2512 if (DISPLAY_VER(display) >= 20) 2513 mask |= XE2LPD_AUX_DDI_MASK; 2514 2515 return mask; 2516 } 2517 2518 static void mtp_irq_postinstall(struct intel_display *display) 2519 { 2520 u32 sde_mask = SDE_GMBUS_ICP | SDE_PICAINTERRUPT; 2521 u32 de_hpd_mask = xelpdp_pica_aux_mask(display); 2522 u32 de_hpd_enables = de_hpd_mask | XELPDP_DP_ALT_HOTPLUG_MASK | 2523 XELPDP_TBT_HOTPLUG_MASK; 2524 2525 irq_init(display, PICAINTERRUPT_IRQ_REGS, ~de_hpd_mask, de_hpd_enables); 2526 2527 irq_init(display, SDE_IRQ_REGS, ~sde_mask, 0xffffffff); 2528 } 2529 2530 static void icp_irq_postinstall(struct intel_display *display) 2531 { 2532 u32 mask = SDE_GMBUS_ICP; 2533 2534 irq_init(display, SDE_IRQ_REGS, ~mask, 0xffffffff); 2535 } 2536 2537 static void gen11_de_irq_postinstall(struct intel_display *display) 2538 { 2539 gen8_de_irq_postinstall(display); 2540 2541 intel_de_write(display, GEN11_DISPLAY_INT_CTL, GEN11_DISPLAY_IRQ_ENABLE); 2542 } 2543 2544 struct intel_display_irq_funcs { 2545 void (*reset)(struct intel_display *display); 2546 void (*postinstall)(struct intel_display *display); 2547 void (*ack)(struct intel_display *display, struct intel_display_irq_state *state); 2548 bool (*handler)(struct intel_display *display, const struct intel_display_irq_state *state); 2549 }; 2550 2551 static const struct intel_display_irq_funcs gen11_display_irq_funcs = { 2552 .reset = gen11_display_irq_reset, 2553 .postinstall = gen11_de_irq_postinstall, 2554 .handler = gen11_display_irq_handler, 2555 }; 2556 2557 static const struct intel_display_irq_funcs gen8_display_irq_funcs = { 2558 .reset = gen8_display_irq_reset, 2559 .postinstall = gen8_de_irq_postinstall, 2560 .handler = gen8_display_irq_handler, 2561 }; 2562 2563 static const struct intel_display_irq_funcs vlv_display_irq_funcs = { 2564 .reset = vlv_display_irq_reset, 2565 .postinstall = vlv_display_irq_postinstall, 2566 .ack = vlv_display_irq_ack, 2567 .handler = vlv_display_irq_handler, 2568 }; 2569 2570 static const struct intel_display_irq_funcs ilk_display_irq_funcs = { 2571 .reset = ilk_display_irq_reset, 2572 .postinstall = ilk_de_irq_postinstall, 2573 .handler = ilk_display_irq_handler, 2574 }; 2575 2576 static const struct intel_display_irq_funcs i965_display_irq_funcs = { 2577 .reset = i9xx_display_irq_reset, 2578 .postinstall = i965_display_irq_postinstall, 2579 .ack = i9xx_display_irq_ack, 2580 .handler = i965_display_irq_handler, 2581 }; 2582 2583 static const struct intel_display_irq_funcs i915_display_irq_funcs = { 2584 .reset = i9xx_display_irq_reset, 2585 .postinstall = i915_display_irq_postinstall, 2586 .ack = i9xx_display_irq_ack, 2587 .handler = i915_display_irq_handler, 2588 }; 2589 2590 void intel_display_irq_reset(struct intel_display *display) 2591 { 2592 if (!HAS_DISPLAY(display)) 2593 return; 2594 2595 display->irq.funcs->reset(display); 2596 } 2597 2598 void intel_display_irq_postinstall(struct intel_display *display) 2599 { 2600 if (!HAS_DISPLAY(display)) 2601 return; 2602 2603 display->irq.funcs->postinstall(display); 2604 } 2605 2606 void intel_display_irq_ack(struct intel_display *display, 2607 struct intel_display_irq_state *state) 2608 { 2609 if (!HAS_DISPLAY(display) || !display->irq.funcs->ack) 2610 return; 2611 2612 display->irq.funcs->ack(display, state); 2613 } 2614 2615 bool intel_display_irq_handler(struct intel_display *display, 2616 const struct intel_display_irq_state *state) 2617 { 2618 if (!HAS_DISPLAY(display) || !display->irq.funcs->handler) 2619 return true; 2620 2621 return display->irq.funcs->handler(display, state); 2622 } 2623 2624 void intel_display_irq_init(struct intel_display *display) 2625 { 2626 spin_lock_init(&display->irq.lock); 2627 2628 display->drm->vblank_disable_immediate = true; 2629 2630 intel_hotplug_irq_init(display); 2631 2632 INIT_WORK(&display->irq.vblank_notify_work, 2633 intel_display_vblank_notify_work); 2634 2635 if (DISPLAY_VER(display) >= 11) 2636 display->irq.funcs = &gen11_display_irq_funcs; 2637 else if (display->platform.cherryview || display->platform.valleyview) 2638 display->irq.funcs = &vlv_display_irq_funcs; 2639 else if (DISPLAY_VER(display) >= 8) 2640 display->irq.funcs = &gen8_display_irq_funcs; 2641 else if (DISPLAY_VER(display) >= 5) 2642 display->irq.funcs = &ilk_display_irq_funcs; 2643 else if (DISPLAY_VER(display) == 4) 2644 display->irq.funcs = &i965_display_irq_funcs; 2645 else 2646 display->irq.funcs = &i915_display_irq_funcs; 2647 } 2648 2649 struct intel_display_irq_snapshot { 2650 u32 derrmr; 2651 u32 err_int; 2652 }; 2653 2654 struct intel_display_irq_snapshot * 2655 intel_display_irq_snapshot_capture(struct intel_display *display) 2656 { 2657 struct intel_display_irq_snapshot *snapshot; 2658 2659 snapshot = kzalloc_obj(*snapshot, GFP_ATOMIC); 2660 if (!snapshot) 2661 return NULL; 2662 2663 if (DISPLAY_VER(display) >= 6 && DISPLAY_VER(display) < 20 && !HAS_GMCH(display)) 2664 snapshot->derrmr = intel_de_read(display, DERRMR); 2665 2666 if (DISPLAY_VER(display) == 7) 2667 snapshot->err_int = intel_de_read(display, GEN7_ERR_INT); 2668 2669 return snapshot; 2670 } 2671 2672 void intel_display_irq_snapshot_print(const struct intel_display_irq_snapshot *snapshot, 2673 struct drm_printer *p) 2674 { 2675 if (!snapshot) 2676 return; 2677 2678 drm_printf(p, "DERRMR: 0x%08x\n", snapshot->derrmr); 2679 drm_printf(p, "ERR_INT: 0x%08x\n", snapshot->err_int); 2680 } 2681 2682 void intel_display_irq_port_interrupt_mask(struct intel_display *display, u32 bits, bool mask) 2683 { 2684 spin_lock_irq(&display->irq.lock); 2685 bdw_update_port_irq(display, bits, mask ? 0 : bits); 2686 spin_unlock_irq(&display->irq.lock); 2687 } 2688