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