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