1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2023 Intel Corporation 4 */ 5 6 #include "xe_display.h" 7 #include "regs/xe_irq_regs.h" 8 9 #include <linux/fb.h> 10 11 #include <drm/drm_client.h> 12 #include <drm/drm_client_event.h> 13 #include <drm/drm_drv.h> 14 #include <drm/drm_managed.h> 15 #include <drm/drm_probe_helper.h> 16 #include <drm/intel/display_member.h> 17 #include <drm/intel/display_parent_interface.h> 18 #include <uapi/drm/xe_drm.h> 19 20 #include "intel_acpi.h" 21 #include "intel_audio.h" 22 #include "intel_bw.h" 23 #include "intel_display.h" 24 #include "intel_display_core.h" 25 #include "intel_display_device.h" 26 #include "intel_display_driver.h" 27 #include "intel_display_irq.h" 28 #include "intel_display_types.h" 29 #include "intel_dmc.h" 30 #include "intel_dmc_wl.h" 31 #include "intel_dp.h" 32 #include "intel_dram.h" 33 #include "intel_encoder.h" 34 #include "intel_fbdev.h" 35 #include "intel_hdcp.h" 36 #include "intel_hotplug.h" 37 #include "intel_opregion.h" 38 #include "skl_watermark.h" 39 #include "xe_display_bo.h" 40 #include "xe_display_pcode.h" 41 #include "xe_display_rpm.h" 42 #include "xe_dsb_buffer.h" 43 #include "xe_fb_pin.h" 44 #include "xe_frontbuffer.h" 45 #include "xe_hdcp_gsc.h" 46 #include "xe_initial_plane.h" 47 #include "xe_module.h" 48 #include "xe_panic.h" 49 #include "xe_stolen.h" 50 51 /* Ensure drm and display members are placed properly. */ 52 INTEL_DISPLAY_MEMBER_STATIC_ASSERT(struct xe_device, drm, display); 53 54 /* Xe device functions */ 55 56 /** 57 * xe_display_driver_probe_defer - Detect if we need to wait for other drivers 58 * early on 59 * @pdev: PCI device 60 * 61 * Note: This is called before xe or display device creation. 62 * 63 * Returns: true if probe needs to be deferred, false otherwise 64 */ 65 bool xe_display_driver_probe_defer(struct pci_dev *pdev) 66 { 67 if (!xe_modparam.probe_display) 68 return 0; 69 70 return intel_display_driver_probe_defer(pdev); 71 } 72 73 /** 74 * xe_display_driver_set_hooks - Add driver flags and hooks for display 75 * @driver: DRM device driver 76 * 77 * Set features and function hooks in @driver that are needed for driving the 78 * display IP. This sets the driver's capability of driving display, regardless 79 * if the device has it enabled 80 * 81 * Note: This is called before xe or display device creation. 82 */ 83 void xe_display_driver_set_hooks(struct drm_driver *driver) 84 { 85 if (!xe_modparam.probe_display) 86 return; 87 88 #ifdef CONFIG_DRM_FBDEV_EMULATION 89 driver->fbdev_probe = intel_fbdev_driver_fbdev_probe; 90 #endif 91 92 driver->driver_features |= DRIVER_MODESET | DRIVER_ATOMIC; 93 } 94 95 static void unset_display_features(struct xe_device *xe) 96 { 97 xe->drm.driver_features &= ~(DRIVER_MODESET | DRIVER_ATOMIC); 98 } 99 100 static void xe_display_fini_early(void *arg) 101 { 102 struct xe_device *xe = arg; 103 struct intel_display *display = xe->display; 104 105 if (!xe->info.probe_display) 106 return; 107 108 intel_hpd_cancel_work(display); 109 intel_display_driver_remove_nogem(display); 110 intel_display_driver_remove_noirq(display); 111 intel_opregion_cleanup(display); 112 intel_power_domains_cleanup(display); 113 } 114 115 int xe_display_init_early(struct xe_device *xe) 116 { 117 struct intel_display *display = xe->display; 118 int err; 119 120 if (!xe->info.probe_display) 121 return 0; 122 123 /* Fake uncore lock */ 124 spin_lock_init(&xe->uncore.lock); 125 126 intel_display_driver_early_probe(display); 127 128 /* Early display init.. */ 129 intel_opregion_setup(display); 130 131 /* 132 * Fill the dram structure to get the system dram info. This will be 133 * used for memory latency calculation. 134 */ 135 err = intel_dram_detect(display); 136 if (err) 137 goto err_opregion; 138 139 intel_bw_init_hw(display); 140 141 intel_display_device_info_runtime_init(display); 142 143 err = intel_display_driver_probe_noirq(display); 144 if (err) 145 goto err_opregion; 146 147 err = intel_display_driver_probe_nogem(display); 148 if (err) 149 goto err_noirq; 150 151 return devm_add_action_or_reset(xe->drm.dev, xe_display_fini_early, xe); 152 err_noirq: 153 intel_display_driver_remove_noirq(display); 154 intel_power_domains_cleanup(display); 155 err_opregion: 156 intel_opregion_cleanup(display); 157 return err; 158 } 159 160 static void xe_display_fini(void *arg) 161 { 162 struct xe_device *xe = arg; 163 struct intel_display *display = xe->display; 164 165 intel_hpd_poll_fini(display); 166 intel_hdcp_component_fini(display); 167 intel_audio_deinit(display); 168 intel_display_driver_remove(display); 169 } 170 171 int xe_display_init(struct xe_device *xe) 172 { 173 struct intel_display *display = xe->display; 174 int err; 175 176 if (!xe->info.probe_display) 177 return 0; 178 179 err = intel_display_driver_probe(display); 180 if (err) 181 return err; 182 183 return devm_add_action_or_reset(xe->drm.dev, xe_display_fini, xe); 184 } 185 186 void xe_display_register(struct xe_device *xe) 187 { 188 struct intel_display *display = xe->display; 189 190 if (!xe->info.probe_display) 191 return; 192 193 intel_display_driver_register(display); 194 intel_power_domains_enable(display); 195 } 196 197 void xe_display_unregister(struct xe_device *xe) 198 { 199 struct intel_display *display = xe->display; 200 201 if (!xe->info.probe_display) 202 return; 203 204 intel_power_domains_disable(display); 205 intel_display_driver_unregister(display); 206 } 207 208 /* IRQ-related functions */ 209 210 void xe_display_irq_handler(struct xe_device *xe, u32 master_ctl) 211 { 212 struct intel_display *display = xe->display; 213 214 if (!xe->info.probe_display) 215 return; 216 217 if (master_ctl & DISPLAY_IRQ) 218 gen11_display_irq_handler(display); 219 } 220 221 void xe_display_irq_enable(struct xe_device *xe, u32 gu_misc_iir) 222 { 223 struct intel_display *display = xe->display; 224 225 if (!xe->info.probe_display) 226 return; 227 228 if (gu_misc_iir & GU_MISC_GSE) 229 intel_opregion_asle_intr(display); 230 } 231 232 void xe_display_irq_reset(struct xe_device *xe) 233 { 234 struct intel_display *display = xe->display; 235 236 if (!xe->info.probe_display) 237 return; 238 239 gen11_display_irq_reset(display); 240 } 241 242 void xe_display_irq_postinstall(struct xe_device *xe) 243 { 244 struct intel_display *display = xe->display; 245 246 if (!xe->info.probe_display) 247 return; 248 249 gen11_de_irq_postinstall(display); 250 } 251 252 static bool suspend_to_idle(void) 253 { 254 #if IS_ENABLED(CONFIG_ACPI_SLEEP) 255 if (acpi_target_system_state() < ACPI_STATE_S3) 256 return true; 257 #endif 258 return false; 259 } 260 261 static void xe_display_flush_cleanup_work(struct xe_device *xe) 262 { 263 struct intel_crtc *crtc; 264 265 for_each_intel_crtc(&xe->drm, crtc) { 266 struct drm_crtc_commit *commit; 267 268 spin_lock(&crtc->base.commit_lock); 269 commit = list_first_entry_or_null(&crtc->base.commit_list, 270 struct drm_crtc_commit, commit_entry); 271 if (commit) 272 drm_crtc_commit_get(commit); 273 spin_unlock(&crtc->base.commit_lock); 274 275 if (commit) { 276 wait_for_completion(&commit->cleanup_done); 277 drm_crtc_commit_put(commit); 278 } 279 } 280 } 281 282 static void xe_display_enable_d3cold(struct xe_device *xe) 283 { 284 struct intel_display *display = xe->display; 285 286 if (!xe->info.probe_display) 287 return; 288 289 /* 290 * We do a lot of poking in a lot of registers, make sure they work 291 * properly. 292 */ 293 intel_power_domains_disable(display); 294 295 xe_display_flush_cleanup_work(xe); 296 297 intel_opregion_suspend(display, PCI_D3cold); 298 299 intel_dmc_suspend(display); 300 301 if (intel_display_device_present(display)) 302 intel_hpd_poll_enable(display); 303 } 304 305 static void xe_display_disable_d3cold(struct xe_device *xe) 306 { 307 struct intel_display *display = xe->display; 308 309 if (!xe->info.probe_display) 310 return; 311 312 intel_dmc_resume(display); 313 314 if (intel_display_device_present(display)) 315 drm_mode_config_reset(&xe->drm); 316 317 intel_display_driver_init_hw(display); 318 319 intel_hpd_init(display); 320 321 if (intel_display_device_present(display)) 322 intel_hpd_poll_disable(display); 323 324 intel_opregion_resume(display); 325 326 intel_power_domains_enable(display); 327 } 328 329 void xe_display_pm_suspend(struct xe_device *xe) 330 { 331 struct intel_display *display = xe->display; 332 bool s2idle = suspend_to_idle(); 333 334 if (!xe->info.probe_display) 335 return; 336 337 /* 338 * We do a lot of poking in a lot of registers, make sure they work 339 * properly. 340 */ 341 intel_power_domains_disable(display); 342 drm_client_dev_suspend(&xe->drm); 343 344 if (intel_display_device_present(display)) { 345 drm_kms_helper_poll_disable(&xe->drm); 346 intel_display_driver_disable_user_access(display); 347 intel_display_driver_suspend(display); 348 } 349 350 xe_display_flush_cleanup_work(xe); 351 352 intel_encoder_block_all_hpds(display); 353 354 intel_hpd_cancel_work(display); 355 356 if (intel_display_device_present(display)) { 357 intel_display_driver_suspend_access(display); 358 intel_encoder_suspend_all(display); 359 } 360 361 intel_opregion_suspend(display, s2idle ? PCI_D1 : PCI_D3cold); 362 363 intel_dmc_suspend(display); 364 } 365 366 void xe_display_pm_shutdown(struct xe_device *xe) 367 { 368 struct intel_display *display = xe->display; 369 370 if (!xe->info.probe_display) 371 return; 372 373 intel_power_domains_disable(display); 374 drm_client_dev_suspend(&xe->drm); 375 376 if (intel_display_device_present(display)) { 377 drm_kms_helper_poll_disable(&xe->drm); 378 intel_display_driver_disable_user_access(display); 379 intel_display_driver_suspend(display); 380 } 381 382 xe_display_flush_cleanup_work(xe); 383 intel_dp_mst_suspend(display); 384 intel_encoder_block_all_hpds(display); 385 intel_hpd_cancel_work(display); 386 387 if (intel_display_device_present(display)) 388 intel_display_driver_suspend_access(display); 389 390 intel_encoder_suspend_all(display); 391 intel_encoder_shutdown_all(display); 392 393 intel_opregion_suspend(display, PCI_D3cold); 394 395 intel_dmc_suspend(display); 396 } 397 398 void xe_display_pm_runtime_suspend(struct xe_device *xe) 399 { 400 struct intel_display *display = xe->display; 401 402 if (!xe->info.probe_display) 403 return; 404 405 if (xe->d3cold.allowed) { 406 xe_display_enable_d3cold(xe); 407 return; 408 } 409 410 intel_hpd_poll_enable(display); 411 } 412 413 void xe_display_pm_suspend_late(struct xe_device *xe) 414 { 415 struct intel_display *display = xe->display; 416 bool s2idle = suspend_to_idle(); 417 418 if (!xe->info.probe_display) 419 return; 420 421 intel_display_power_suspend_late(display, s2idle); 422 } 423 424 void xe_display_pm_runtime_suspend_late(struct xe_device *xe) 425 { 426 struct intel_display *display = xe->display; 427 428 if (!xe->info.probe_display) 429 return; 430 431 if (xe->d3cold.allowed) 432 xe_display_pm_suspend_late(xe); 433 434 /* 435 * If xe_display_pm_suspend_late() is not called, it is likely 436 * that we will be on dynamic DC states with DMC wakelock enabled. We 437 * need to flush the release work in that case. 438 */ 439 intel_dmc_wl_flush_release_work(display); 440 } 441 442 void xe_display_pm_shutdown_late(struct xe_device *xe) 443 { 444 struct intel_display *display = xe->display; 445 446 if (!xe->info.probe_display) 447 return; 448 449 /* 450 * The only requirement is to reboot with display DC states disabled, 451 * for now leaving all display power wells in the INIT power domain 452 * enabled. 453 */ 454 intel_power_domains_driver_remove(display); 455 } 456 457 void xe_display_pm_resume_early(struct xe_device *xe) 458 { 459 struct intel_display *display = xe->display; 460 461 if (!xe->info.probe_display) 462 return; 463 464 intel_display_power_resume_early(display); 465 } 466 467 void xe_display_pm_resume(struct xe_device *xe) 468 { 469 struct intel_display *display = xe->display; 470 471 if (!xe->info.probe_display) 472 return; 473 474 intel_dmc_resume(display); 475 476 if (intel_display_device_present(display)) 477 drm_mode_config_reset(&xe->drm); 478 479 intel_display_driver_init_hw(display); 480 481 if (intel_display_device_present(display)) 482 intel_display_driver_resume_access(display); 483 484 intel_hpd_init(display); 485 486 intel_encoder_unblock_all_hpds(display); 487 488 if (intel_display_device_present(display)) { 489 intel_display_driver_resume(display); 490 drm_kms_helper_poll_enable(&xe->drm); 491 intel_display_driver_enable_user_access(display); 492 } 493 494 if (intel_display_device_present(display)) 495 intel_hpd_poll_disable(display); 496 497 intel_opregion_resume(display); 498 499 drm_client_dev_resume(&xe->drm); 500 501 intel_power_domains_enable(display); 502 } 503 504 void xe_display_pm_runtime_resume(struct xe_device *xe) 505 { 506 struct intel_display *display = xe->display; 507 508 if (!xe->info.probe_display) 509 return; 510 511 if (xe->d3cold.allowed) { 512 xe_display_disable_d3cold(xe); 513 return; 514 } 515 516 intel_hpd_init(display); 517 intel_hpd_poll_disable(display); 518 skl_watermark_ipc_update(display); 519 } 520 521 522 static void display_device_remove(struct drm_device *dev, void *arg) 523 { 524 struct xe_device *xe = arg; 525 526 intel_display_device_remove(xe->display); 527 xe->display = NULL; 528 } 529 530 static bool irq_enabled(struct drm_device *drm) 531 { 532 struct xe_device *xe = to_xe_device(drm); 533 534 return atomic_read(&xe->irq.enabled); 535 } 536 537 static void irq_synchronize(struct drm_device *drm) 538 { 539 synchronize_irq(to_pci_dev(drm->dev)->irq); 540 } 541 542 static const struct intel_display_irq_interface xe_display_irq_interface = { 543 .enabled = irq_enabled, 544 .synchronize = irq_synchronize, 545 }; 546 547 static bool has_auxccs(struct drm_device *drm) 548 { 549 struct xe_device *xe = to_xe_device(drm); 550 551 return xe->info.platform == XE_ALDERLAKE_P; 552 } 553 554 static const struct intel_display_parent_interface parent = { 555 .bo = &xe_display_bo_interface, 556 .dsb = &xe_display_dsb_interface, 557 .fb_pin = &xe_display_fb_pin_interface, 558 .frontbuffer = &xe_display_frontbuffer_interface, 559 .hdcp = &xe_display_hdcp_interface, 560 .initial_plane = &xe_display_initial_plane_interface, 561 .irq = &xe_display_irq_interface, 562 .panic = &xe_display_panic_interface, 563 .pcode = &xe_display_pcode_interface, 564 .rpm = &xe_display_rpm_interface, 565 .stolen = &xe_display_stolen_interface, 566 .has_auxccs = has_auxccs, 567 }; 568 569 /** 570 * xe_display_probe - probe display and create display struct 571 * @xe: XE device instance 572 * 573 * Initialize all fields used by the display part. 574 * 575 * TODO: once everything can be inside a single struct, make the struct opaque 576 * to the rest of xe and return it to be xe->display. 577 * 578 * Returns: 0 on success 579 */ 580 int xe_display_probe(struct xe_device *xe) 581 { 582 struct pci_dev *pdev = to_pci_dev(xe->drm.dev); 583 struct intel_display *display; 584 int err; 585 586 if (!xe->info.probe_display) 587 goto no_display; 588 589 display = intel_display_device_probe(pdev, &parent); 590 if (IS_ERR(display)) 591 return PTR_ERR(display); 592 593 xe->display = display; 594 595 err = drmm_add_action_or_reset(&xe->drm, display_device_remove, xe); 596 if (err) 597 return err; 598 599 if (intel_display_device_present(display)) 600 return 0; 601 602 no_display: 603 xe->info.probe_display = false; 604 unset_display_features(xe); 605 return 0; 606 } 607