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